mirror of
https://github.com/zenstackhq/zenstack
synced 2026-05-24 10:08:55 +00:00
29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import { TsSchemaGenerator } from '@zenstackhq/sdk';
|
|
import { glob } from 'glob';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const dir = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
async function main() {
|
|
// glob all zmodel files in "e2e" directory
|
|
const zmodelFiles = glob.sync(path.resolve(dir, '../schemas/**/*.zmodel'));
|
|
for (const file of zmodelFiles) {
|
|
console.log(`Generating TS schema for: ${file}`);
|
|
await generate(file);
|
|
}
|
|
}
|
|
|
|
async function generate(schemaPath: string) {
|
|
const generator = new TsSchemaGenerator();
|
|
const outputDir = path.dirname(schemaPath);
|
|
const tsPath = path.join(outputDir, 'schema.ts');
|
|
const pluginModelFiles = glob.sync(path.resolve(dir, '../../dist/**/plugin.zmodel'));
|
|
await generator.generate(schemaPath, pluginModelFiles, outputDir);
|
|
const content = fs.readFileSync(tsPath, 'utf-8');
|
|
fs.writeFileSync(tsPath, content.replace(/@zenstackhq\/runtime/g, '../../../dist'));
|
|
console.log('TS schema generated at:', outputDir);
|
|
}
|
|
|
|
main();
|