Skip to content

Commit

Permalink
generate type programmatically because the CLI has problems under win…
Browse files Browse the repository at this point in the history
…dows
  • Loading branch information
nonblocking committed Dec 18, 2023
1 parent 7fcf90a commit 7f01f5f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions packages/core/mashroom-json-schemas/gen-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

const { writeFileSync, readdirSync } = require('fs');
const { resolve } = require('path');
const { compileFromFile } = require('json-schema-to-typescript');

const schemaDir = resolve(__dirname, 'schemas');
const outDir = resolve(__dirname, 'type-definitions');

const IGNORE_SCHEMAS = ['mashroom-packagejson-extension.json'];

readdirSync(schemaDir)
.filter((file) => file.endsWith('json'))
.filter((schemaFile) => IGNORE_SCHEMAS.indexOf(schemaFile) === -1)
.forEach((schemaFile) => {
console.info('Generating types for:', schemaFile);
compileFromFile(resolve(schemaDir, schemaFile), {
unknownAny: false,
strictIndexSignatures: true,
additionalProperties: false,
cwd: schemaDir,
}).then(ts => {
writeFileSync(resolve(outDir, schemaFile.split('.')[0] + '.d.ts'), ts);
});
});
2 changes: 1 addition & 1 deletion packages/core/mashroom-json-schemas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
"scripts": {
"test": "jest",
"type-check": "tsc --noEmit",
"build": "json2ts --cwd schemas/ --no-unknownAny --strictIndexSignatures --no-additionalProperties -i schemas/ -o type-definitions/ && del-cli type-definitions/mashroom-packagejson-extension.d.ts"
"build": "node gen-types.js"
}
}

0 comments on commit 7f01f5f

Please sign in to comment.