build: only generate types for actual JSON schemas

This commit is contained in:
Charles Lyding 2019-03-19 10:21:51 -04:00 committed by Alex Eagle
parent 7439faba12
commit fda683b874

View File

@ -60,11 +60,17 @@ export default async function(
}
const content = fs.readFileSync(fileName, 'utf-8');
const json = JSON.parse(content);
if (!json.$schema) {
let json;
try {
json = JSON.parse(content);
if (typeof json.$schema !== 'string' || !json.$schema.startsWith('http://json-schema.org/')) {
// Skip non-schema files.
continue;
}
} catch {
// malformed or JSON5
continue;
}
const tsContent = await quicktypeRunner.generate(fileName);
const tsPath = path.join(dist, fileName.replace(/\.json$/, '.ts'));