Harden local setup and development startup
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { spawn, spawnSync } from "node:child_process";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const projectDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
||||
const runtimeDir = path.join(projectDir, ".cache", "runtime");
|
||||
fs.mkdirSync(runtimeDir, { recursive: true });
|
||||
|
||||
const preflight = spawnSync(process.execPath, [path.join(projectDir, "scripts", "preflight.mjs"), "--ports=3000,5173"], {
|
||||
cwd: projectDir,
|
||||
stdio: "inherit",
|
||||
shell: false,
|
||||
});
|
||||
if (preflight.status !== 0) process.exit(preflight.status ?? 1);
|
||||
|
||||
const npmCli = process.env.npm_execpath || path.join(path.dirname(process.execPath), "node_modules", "npm", "bin", "npm-cli.js");
|
||||
const stdout = fs.openSync(path.join(runtimeDir, "dev.stdout.log"), "a");
|
||||
const stderr = fs.openSync(path.join(runtimeDir, "dev.stderr.log"), "a");
|
||||
const child = spawn(process.execPath, [npmCli, "run", "dev"], {
|
||||
cwd: projectDir,
|
||||
detached: true,
|
||||
stdio: ["ignore", stdout, stderr],
|
||||
shell: false,
|
||||
windowsHide: true,
|
||||
});
|
||||
|
||||
child.unref();
|
||||
console.log(`AgendaPro dev iniciado en segundo plano (PID ${child.pid}). Logs: ${path.join(runtimeDir, "dev.stdout.log")}`);
|
||||
Reference in New Issue
Block a user