Clean-room copy of the reusable engines from comiida, with all instance data, secrets, dependencies, and build output excluded: - app/ Astro theme skeleton (no comiida blog posts; hero image -> placeholder) - api/ SeedProject PHP framework (no vendor/.env/config.php) - content-pipeline/ engine only (scripts/admin/prompts; empty runtime state) - astroagent.config.json + app/.astroagent/skills Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SYHWLHihq3v9nxNwoPCKSn
38 lines
1.5 KiB
JavaScript
38 lines
1.5 KiB
JavaScript
import { spawn } from "node:child_process";
|
|
import { mkdirSync } from "node:fs";
|
|
import { withLock } from "./lock.mjs";
|
|
|
|
function run(cmd, args, opts = {}) {
|
|
return new Promise((resolve, reject) => {
|
|
const child = spawn(cmd, args, { stdio: "inherit", ...opts });
|
|
child.on("error", reject);
|
|
child.on("close", (code) =>
|
|
code === 0 ? resolve() : reject(new Error(`${cmd} ${args.join(" ")} exited ${code}`))
|
|
);
|
|
});
|
|
}
|
|
|
|
/** Absolute path of the global build lock. Callers that build outside buildSite()
|
|
* (e.g. console preview builds) must take THIS same lock to serialize. */
|
|
export function buildLockPath(projectRoot) {
|
|
return `${projectRoot}/content-pipeline/state/build.lock`;
|
|
}
|
|
|
|
/**
|
|
* Build the Astro app and fix ownership so Apache can serve the output.
|
|
* Serialized behind the global build lock so it never races the console's
|
|
* preview/publish builds (concurrent astro builds would OOM this box).
|
|
*/
|
|
export async function buildSite({ projectRoot, appDir }) {
|
|
const lockPath = buildLockPath(projectRoot);
|
|
mkdirSync(`${projectRoot}/content-pipeline/state`, { recursive: true });
|
|
await withLock(lockPath, async () => {
|
|
await run("npm", ["run", "build"], { cwd: `${projectRoot}/${appDir}` });
|
|
// Best-effort ownership fix (ignore failure if not running as root).
|
|
try {
|
|
await run("chown", ["-R", "www:www", `${projectRoot}/${appDir}`, `${projectRoot}/public`]);
|
|
} catch (e) {
|
|
console.warn(`[build] chown skipped: ${e.message}`);
|
|
}
|
|
});
|
|
}
|