2025-12-06 07:25:31 +00:00
|
|
|
import { glob } from 'glob';
|
|
|
|
|
import { execSync } from 'node:child_process';
|
|
|
|
|
import path from 'node:path';
|
|
|
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
|
|
|
|
|
|
const _dirname = typeof __dirname !== 'undefined' ? __dirname : path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
|
const baseDir = process.argv[2] || '.';
|
2025-12-13 08:59:03 +00:00
|
|
|
const options = process.argv.slice(3);
|
2025-12-06 07:25:31 +00:00
|
|
|
|
|
|
|
|
const zmodelFiles = [...glob.sync(path.resolve(baseDir, '**/schema.zmodel'), { ignore: '**/node_modules/**' })];
|
|
|
|
|
for (const file of zmodelFiles) {
|
2025-12-13 08:59:03 +00:00
|
|
|
console.log(
|
|
|
|
|
`Generating TS schema for: ${file}${options.length > 0 ? ` with options: ${options.join(' ')}` : ''}`,
|
|
|
|
|
);
|
|
|
|
|
await generate(file, options);
|
2025-12-06 07:25:31 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-13 08:59:03 +00:00
|
|
|
async function generate(schemaPath: string, options: string[]) {
|
2026-04-15 19:13:34 +00:00
|
|
|
const cliPath = path.join(_dirname, '../packages/cli/dist/index.mjs');
|
2025-12-06 07:25:31 +00:00
|
|
|
const RUNTIME = process.env.RUNTIME ?? 'node';
|
2026-02-20 14:31:00 +00:00
|
|
|
execSync(
|
2026-05-06 00:17:08 +00:00
|
|
|
`${RUNTIME} ${cliPath} generate --schema ${schemaPath} --generate-models=false ${options.join(' ')} --generate-input=false --no-version-check --no-tips`,
|
2026-02-20 14:31:00 +00:00
|
|
|
{
|
|
|
|
|
cwd: path.dirname(schemaPath),
|
|
|
|
|
},
|
|
|
|
|
);
|
2025-12-06 07:25:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
main();
|