Files
ruflo/scripts/build-codex-mod-hooks.mjs
T

35 lines
1.8 KiB
JavaScript

#!/usr/bin/env node
// Bundle exact existing pure guard/screen/status functions, never a second secret detector.
import fs from 'node:fs';
import path from 'node:path';
import os from 'node:os';
import { execFileSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const isWin = process.platform === 'win32';
const esbuildCmd = isWin ? 'npx' : (process.env.ESBUILD ?? path.join(root, 'node_modules', '.bin', 'esbuild'));
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'ruflo-codex-mod-build-'));
try {
for (const name of ['adr', 'ddd', 'sparc']) {
const target = path.join(root, `plugins/ruflo-${name}/hooks/codex-hook.cjs`);
const output = path.join(temp, `${name}.cjs`);
const args = isWin
? ['esbuild', path.join(root, `plugins/ruflo-${name}/hooks/codex.ts`), '--bundle', '--platform=node', '--target=node20', '--format=cjs', '--minify-whitespace', `--outfile=${output}`]
: [path.join(root, `plugins/ruflo-${name}/hooks/codex.ts`), '--bundle', '--platform=node', '--target=node20', '--format=cjs', '--minify-whitespace', `--outfile=${output}`];
execFileSync(esbuildCmd, args, { stdio: 'pipe', shell: isWin });
const bytes = `// Generated by scripts/build-codex-mod-hooks.mjs; edit codex.ts or shared runtime, not this bundle.\n${fs.readFileSync(output, 'utf8')}`;
if (process.argv.includes('--check')) {
if (!fs.existsSync(target) || fs.readFileSync(target, 'utf8') !== bytes) throw new Error(`${name}: native bundle drift; rebuild before release`);
} else {
fs.writeFileSync(target, bytes);
}
}
console.log('codex-mod-hooks: three bundles match their shared sources');
} finally {
fs.rmSync(temp, { recursive: true, force: true });
}