34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
/**
|
|
* Child-process entry point for loading a TS/JS template module.
|
|
*
|
|
* Usage (via tsx): `tsx template-module-loader.js <absolute-template-path>`
|
|
*
|
|
* Writes serialized Extended JSON to stdout. Errors go to stderr with exit code 1.
|
|
* Running in a subprocess isolates module evaluation from the wallet process.
|
|
*/
|
|
|
|
import { pathToFileURL } from "node:url";
|
|
|
|
import { serializeTemplate } from "@xo-cash/utils";
|
|
import type { XOTemplate } from "@xo-cash/types";
|
|
|
|
import { pickTemplateExport } from "./pick-template-export.js";
|
|
|
|
const templateFilePath = process.argv[2];
|
|
|
|
if (templateFilePath === undefined || templateFilePath.length === 0) {
|
|
console.error("Usage: template-module-loader <absolute-template-path>");
|
|
process.exit(1);
|
|
}
|
|
|
|
try {
|
|
const moduleUrl = pathToFileURL(templateFilePath).href;
|
|
const loadedModule = (await import(moduleUrl)) as Record<string, unknown>;
|
|
const template = pickTemplateExport(loadedModule);
|
|
process.stdout.write(serializeTemplate(template as XOTemplate));
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
console.error(`Failed to load template module: ${message}`);
|
|
process.exit(1);
|
|
}
|