Files
agentic-dev/scripts/compliance/emit-all.mjs
Danijel Martinek 239cfcadfa feat(scripts): pre-commit hook + CI gate for compliance drift
Wire pnpm compliance:emit-all into the pre-commit hook (conditional on
staged Payload configs, library traces, or compliance/ files) and add a
hard-fail compliance drift check step to the CI validate job positioned
after pnpm conformance.

Also fix emit-all.mjs: it previously hardcoded --check on every invocation,
so it never actually regenerated artifacts. Now the default mode writes and
--check mode diffs only — matching the pre-commit (write) vs CI (check) split.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 20:14:45 +00:00

63 lines
1.7 KiB
JavaScript

#!/usr/bin/env node
/**
* emit-all.mjs — Compliance artifact orchestrator.
*
* Default: regenerates all three compliance artifacts (write mode).
* --check: diffs each artifact against the committed file; exits non-zero
* if any generator reports a mismatch or validation failure.
*
* Usage:
* node scripts/compliance/emit-all.mjs # regenerate all artifacts
* node scripts/compliance/emit-all.mjs --check # drift check (CI gate)
* pnpm compliance:emit-all
* pnpm compliance:emit-all --check
*/
import { spawnSync } from "node:child_process";
import { fileURLToPath } from "node:url";
import path from "node:path";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const SCRIPTS = [
"emit-data-map.mjs",
"emit-retention-policy.mjs",
"emit-sub-processors.mjs",
];
const checkMode = process.argv.includes("--check");
const subArgs = checkMode ? ["--check"] : [];
let anyFailed = false;
for (const script of SCRIPTS) {
const scriptPath = path.join(__dirname, script);
const result = spawnSync(process.execPath, [scriptPath, ...subArgs], {
stdio: "inherit",
});
if (result.status !== 0) {
anyFailed = true;
}
}
if (anyFailed) {
if (checkMode) {
process.stderr.write(
"\n✗ compliance:emit-all — one or more artifacts are out of date.\n" +
" Run `pnpm compliance:emit-all` to regenerate.\n",
);
} else {
process.stderr.write(
"\n✗ compliance:emit-all — one or more artifacts failed to generate.\n",
);
}
process.exit(1);
}
if (checkMode) {
console.log("✓ compliance:emit-all — all artifacts are up to date");
} else {
console.log("✓ compliance:emit-all — all artifacts regenerated");
}