MCPcopy Create free account
hub / github.com/boringstack-xyz/boringstack / main

Function main

apps/ui/scripts/codegen/generate-api.ts:61–103  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

59
60async function generate(): Promise<string> {
61 const ast = await openapiTS(new URL(URL_FROM_ENV));
62
63 return BANNER + astToString(ast);
64}
65
66/*
67 * Strip the banner before drift comparison: the banner embeds the source
68 * URL, which varies by environment (dev :7330, alt port for CI smoke,
69 * staging URL, etc). Two regenerations that hit different URLs but the
70 * same spec produce identical bodies but different banners: that is
71 * not real drift and must not fail the check.
72 */
73const stripBanner = (source: string): string =>
74 source.replace(/^\/\*\*[\s\S]*?\*\/\s*/, "").trimStart();
75
76async function main(): Promise<void> {
77 const isCheckMode = process.argv.includes("--check");
78
79 if (!JSON_MODE) {
80 console.log(`[generate:api] Fetching ${URL_FROM_ENV}`);
81 }
82
83 let generated: string;
84
85 try {
86 generated = await generate();
87 } catch (error) {
88 if (!JSON_MODE) {
89 console.error(`[generate:api] FAILED: ${getErrorMessage(error)}`);
90 }
91
92 report("blocked", "openapi_unavailable_or_invalid");
93 console.error(
94 "[generate:api] Hint: start apps/api (bun run dev from apps/api/)" +
95 " or set OPENAPI_URL to a reachable spec."
96 );
97 process.exit(2);
98 }
99
100 if (isCheckMode) {
101 if (!existsSync(OUTPUT)) {
102 console.error(
103 `[generate:api:check] ${OUTPUT} does not exist — run \`bun run generate:api\``
104 );
105 report("failed", "schema_missing");
106 process.exit(1);

Callers 1

generate-api.tsFile · 0.70

Calls 4

getErrorMessageFunction · 0.90
generateFunction · 0.85
stripBannerFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected