#!/usr/bin/env node import path from 'node:path' import { PlataEnvLoader } from '../libs/env' import { PlataBuild } from '../libs/build' import { PlataBuildWasm } from '../libs/build_wasm' async function compile() { if (Plata.cluster.isPrimary !== true) return await PlataBuild.compile({ basePath: Plata.ProjectDir, mapFiles: true, packageJsonSetup: false, otimizar: false, }) } const shouldCompile = async () => { // TODO Colocar a compilição e essa função em um arquivo separado if (process.argv.findIndex(p => p === '--skip-recompile') !== -1 || Plata.ProjectJson['plata_skip_recompile'] !== undefined) return Plata.files.access(path.join(Plata.ProjectDir, '__BUILD__')).then(r => !r) ; return true } const main = async () => { const g = global as any const { PlataGlobalRuntime } = require('../libs/runtime') g.Plata = new PlataGlobalRuntime() if (await shouldCompile()) await compile() ; const { PlataRequire } = require('../libs/require') PlataRequire.setup() const envFile = await PlataEnvLoader.load() if (envFile.errorID !== undefined) { console.log(envFile) process.exit(1) } for (const key in envFile) { Plata.config[key] = envFile[key] } await PlataBuildWasm.loadFilesWasm() // roda o sript solicitado const run = process.argv[process.argv.indexOf('+') + 1] if (global.gc !== undefined) { // Se disponivel tenta limpar a memoria para reduzir uso de RAM setTimeout(global.gc, 60_000) } const app: { main: () => Promise } = require(`++/bin/${run}`) await app.main() } main()