Reduce repeated compiler startup in monorepo QX formatting
This commit is contained in:
@@ -595,6 +595,30 @@ const main = async () => {
|
||||
process.stdout.write(`${JSON.stringify(plan, null, 2)}\n`);
|
||||
return;
|
||||
}
|
||||
if (command === "format" && (args[0] === "--check" || args[0] === "--write")) {
|
||||
const check = args[0] === "--check",
|
||||
files = args.slice(1);
|
||||
if (!files.length || files.some((file) => file.startsWith("-")))
|
||||
throw new Error("usage: quixos-qx format --check|--write FILE...");
|
||||
for (const file of files) {
|
||||
try {
|
||||
const source = await readFile(file, "utf8"),
|
||||
formatted = formatQx(source);
|
||||
if (formatted === source) continue;
|
||||
if (check) {
|
||||
console.error(`Needs formatting: ${file}`);
|
||||
process.exitCode = 1;
|
||||
} else {
|
||||
await writeFile(file, formatted);
|
||||
console.log(`Formatted ${file}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`${file}: ${error instanceof Error ? error.message : error}`);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
const [file, flag, ...rest] = args;
|
||||
if (
|
||||
!file ||
|
||||
|
||||
Reference in New Issue
Block a user