import fs from "node:fs"; import path from "node:path"; import { spawnSync } from "node:child_process"; const ROOTS = ["index.js", "deployCommands.js", "src", "public/scripts", "scripts", "test"]; function collectJavaScriptFiles(entry) { const absolutePath = path.resolve(entry); const stat = fs.statSync(absolutePath); if (stat.isFile()) { return absolutePath.endsWith(".js") ? [absolutePath] : []; } return fs .readdirSync(absolutePath, { withFileTypes: true }) .flatMap((child) => collectJavaScriptFiles(path.join(absolutePath, child.name)) ); } const files = ROOTS.flatMap(collectJavaScriptFiles); for (const file of files) { const result = spawnSync(process.execPath, ["--check", file], { stdio: "inherit", }); if (result.status !== 0) { process.exit(result.status || 1); } } console.log(`Syntax checked: ${files.length} JavaScript files`);