Generate typed asynchronous service capability bindings
This commit is contained in:
+20
-9
@@ -1,6 +1,10 @@
|
||||
#!/usr/bin/env node
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { generateTypeScriptBindings, generatePortableTypeScriptBindings } from "./index.js";
|
||||
import {
|
||||
generateTypeScriptBindings,
|
||||
generatePortableTypeScriptBindings,
|
||||
generateRemoteTypeScriptBindings,
|
||||
} from "./index.js";
|
||||
import path from "node:path";
|
||||
import { reactPlatformTypes } from "./react-platform.js";
|
||||
import { generateReactBindings } from "./react.js";
|
||||
@@ -11,16 +15,23 @@ const main = async () => {
|
||||
throw new Error("usage: quixos-codegen-ts SCHEMA.json PACKAGE_REVISION OUTPUT.ts [OPTIONS.json]");
|
||||
const config = options ? JSON.parse(await readFile(options, "utf8")) : {};
|
||||
const contracts = JSON.parse(await readFile(schema, "utf8"));
|
||||
if (config.portable && config.react)
|
||||
throw new Error("Portable handlers and React component bindings are separate artifacts");
|
||||
if ([config.portable, config.remote, config.react].filter(Boolean).length > 1)
|
||||
throw new Error("Portable, remote and React bindings are separate artifacts");
|
||||
if (config.remote !== undefined && config.remote !== true) throw new Error("Remote binding mode must be true");
|
||||
if (config.portable && typeof config.portable.target !== "string")
|
||||
throw new Error("Portable bindings require an explicit target");
|
||||
const generated = config.portable
|
||||
? generatePortableTypeScriptBindings(contracts, revision, {
|
||||
...config.portable,
|
||||
...(config.runtimeModule ? { runtimeModule: config.runtimeModule } : {}),
|
||||
})
|
||||
: generateTypeScriptBindings(contracts, revision, config);
|
||||
const generated = config.remote
|
||||
? generateRemoteTypeScriptBindings(
|
||||
contracts,
|
||||
revision,
|
||||
config.runtimeModule ? { runtimeModule: config.runtimeModule } : {},
|
||||
)
|
||||
: config.portable
|
||||
? generatePortableTypeScriptBindings(contracts, revision, {
|
||||
...config.portable,
|
||||
...(config.runtimeModule ? { runtimeModule: config.runtimeModule } : {}),
|
||||
})
|
||||
: generateTypeScriptBindings(contracts, revision, config);
|
||||
await writeFile(output, generated);
|
||||
if (config.react) {
|
||||
await writeFile(path.join(path.dirname(output), "web-studio-react-runtime.d.ts"), reactPlatformTypes);
|
||||
|
||||
Reference in New Issue
Block a user