smart-check.mjs 1.36 KB
#!/usr/bin/env node

import childProcess from "node:child_process";
import process from "node:process";

import { requireWorkspaceRoot } from "./workspace-root.mjs";

const repoRoot = requireWorkspaceRoot();
const tier = readFlag("--tier") || "fast";
const commands = [
	{ id: "lint", command: "pnpm run lint:changed" },
	{ id: "typecheck", command: "pnpm run check:type" },
	{ id: "template-contract", command: "pnpm run check:template-contract" },
	{ id: "review-trigger", command: "pnpm run review:trigger" },
	{ id: "file-budget", command: "pnpm run check:file-budget" },
	{ id: "fitness", command: `pnpm run check:fitness -- --tier ${tier}` },
	{ id: "capture-pitfalls", command: "pnpm run ai:capture-pitfalls", allowFail: true },
];

for (const step of commands) {
	console.log(`[smart-check] ${step.id}`);
	const status = childProcess.spawnSync(step.command, {
		cwd: repoRoot,
		shell: true,
		stdio: "inherit",
	});

	if (status.status !== 0) {
		if (step.allowFail) {
			console.warn(`[smart-check] ${step.id} exited with ${status.status} (non-blocking)`);
		} else {
			console.error(`[smart-check] failed at ${step.id}`);
			process.exit(status.status ?? 1);
		}
	}
}

console.log("[smart-check] passed");

function readFlag(name) {
	const index = process.argv.indexOf(name);
	if (index !== -1 && index + 1 < process.argv.length) {
		return process.argv[index + 1];
	}
	return "";
}