2026-09-08 14:27:24 -07:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
import { readFile, writeFile } from "node:fs/promises";
|
|
|
|
|
import { generateTypeScriptBindings } from "./index.js";
|
2026-09-14 23:38:07 -07:00
|
|
|
import path from "node:path";
|
2026-09-15 15:23:24 -07:00
|
|
|
import { reactPlatformTypes } from "./react-platform.js";
|
2026-09-16 11:25:20 -07:00
|
|
|
import { generateReactBindings } from "./react.js";
|
2026-09-08 14:27:24 -07:00
|
|
|
|
|
|
|
|
const main = async () => {
|
|
|
|
|
const [schema, revision, output, options, ...rest] = process.argv.slice(2);
|
2026-09-15 15:23:24 -07:00
|
|
|
if (!schema || !revision || !output || rest.length)
|
|
|
|
|
throw new Error("usage: quixos-codegen-ts SCHEMA.json PACKAGE_REVISION OUTPUT.ts [OPTIONS.json]");
|
2026-09-14 23:38:07 -07:00
|
|
|
const config = options ? JSON.parse(await readFile(options, "utf8")) : {};
|
2026-09-16 11:25:20 -07:00
|
|
|
const contracts = JSON.parse(await readFile(schema, "utf8"));
|
|
|
|
|
const generated = generateTypeScriptBindings(contracts, revision, config);
|
2026-09-08 14:27:24 -07:00
|
|
|
await writeFile(output, generated);
|
2026-09-16 11:25:20 -07:00
|
|
|
if (config.react) {
|
2026-09-15 20:13:10 -07:00
|
|
|
await writeFile(path.join(path.dirname(output), "web-studio-react-runtime.d.ts"), reactPlatformTypes);
|
2026-09-16 11:25:20 -07:00
|
|
|
await writeFile(
|
|
|
|
|
path.join(path.dirname(output), "react-props.gen.ts"),
|
|
|
|
|
generateReactBindings(contracts, revision, config.react.propsExports, config.react.components),
|
|
|
|
|
);
|
2026-09-14 23:38:07 -07:00
|
|
|
}
|
2026-09-08 14:27:24 -07:00
|
|
|
};
|
2026-09-15 15:23:24 -07:00
|
|
|
main().catch((error: unknown) => {
|
|
|
|
|
console.error(error instanceof Error ? error.message : error);
|
|
|
|
|
process.exitCode = 1;
|
|
|
|
|
});
|