stock-bot/scripts/check.ts
2026-10-20 12:39:38 -04:00

42 lines
1.1 KiB
TypeScript

/** Run every repository gate and report failures without hiding later checks. */
import { fileURLToPath } from 'node:url';
export const checks = [
'build',
'typecheck',
'test:contracts',
'test:tooling',
'lint:check',
] as const;
async function runTask(check: string): Promise<number> {
process.stdout.write(`\nRunning ${check}\n`);
const child = Bun.spawn([process.execPath, 'run', check], {
cwd: fileURLToPath(new URL('..', import.meta.url)),
stdin: 'inherit',
stdout: 'inherit',
stderr: 'inherit',
});
return child.exited;
}
export async function runChecks(
tasks: readonly string[] = checks,
run: (task: string) => Promise<number> = runTask
): Promise<string[]> {
const failed: string[] = [];
for (const task of tasks) {
if ((await run(task)) !== 0) failed.push(task);
}
return failed;
}
if (import.meta.main) {
const failed = await runChecks();
if (failed.length > 0) {
process.stderr.write(`\nFailed checks: ${failed.join(', ')}\n`);
process.exitCode = 1;
} else {
process.stdout.write('\nAll repository checks passed.\n');
}
}