-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathgenerate.js
More file actions
30 lines (30 loc) · 877 Bytes
/
Copy pathgenerate.js
File metadata and controls
30 lines (30 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const fs = require("fs");
try {
const content = fs.readFileSync("src/entrypoints/sdk/coreSchemas.ts", "utf8");
const lines = content.split("\n");
const outLines = [
"import * as z from 'zod';",
"import * as schemas from './coreSchemas.js';",
];
let count = 0;
for (const l of lines) {
if (l.startsWith("export const ") && l.includes("Schema ")) {
const name = l.split("export const ")[1].split("Schema")[0];
if (name && name.match(/^[A-Za-z0-9_]+$/)) {
outLines.push(
`export type ${name} = z.infer<typeof schemas.${name}Schema>;`,
);
count++;
}
}
}
fs.writeFileSync(
"src/entrypoints/sdk/coreTypes.generated.ts",
outLines.join("\n"),
);
console.log("Successfully generated " + count + " types");
process.exit(0);
} catch (e) {
console.error("Error:", e);
process.exit(1);
}