Generate typed QX bindings and add source editing tools
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env node
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { parseQx, formatQx, lintQx } from "./source.js";
|
||||
import { scaffoldAtom } from "./scaffold.js";
|
||||
import { createGitCapabilityResolver } from "./git-resolver.js";
|
||||
|
||||
const main = async () => {
|
||||
const [command, ...args] = process.argv.slice(2);
|
||||
if (command === "scaffold-atom") {
|
||||
const [root, name, id, ...flags] = args;
|
||||
if (!root || !name || !id || flags.some((flag) => flag !== "--write")) throw new Error("usage: quixos-qx scaffold-atom ROOT NAME ID [--write]");
|
||||
const resolveResource = await createGitCapabilityResolver({ checkoutRoot: `${root}/.quixos/resource-checkouts` });
|
||||
const plan = await scaffoldAtom({ root, name, id, write: flags.includes("--write"), resolveResource });
|
||||
process.stdout.write(`${JSON.stringify(plan, null, 2)}\n`);
|
||||
return;
|
||||
}
|
||||
const [file, flag, ...rest] = args;
|
||||
if (!file || rest.length || (flag && flag !== "--write") || !["parse", "lint", "format"].includes(command ?? "") ||
|
||||
(flag && command !== "format")) throw new Error("usage: quixos-qx parse|lint|format FILE [--write (format only)]");
|
||||
const source = await readFile(file, "utf8");
|
||||
if (command === "format") {
|
||||
const formatted = formatQx(source);
|
||||
if (flag) await writeFile(file, formatted); else process.stdout.write(formatted);
|
||||
} else {
|
||||
const result = command === "parse" ? parseQx(source, file) : lintQx(source, file);
|
||||
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
||||
if (Array.isArray(result) ? result.some((entry) => entry.severity === "error") : result.diagnostics.length) process.exitCode = 1;
|
||||
}
|
||||
};
|
||||
main().catch((error: unknown) => { console.error(error instanceof Error ? error.message : error); process.exitCode = 1; });
|
||||
Reference in New Issue
Block a user