Skip to content

Commit

Permalink
fixup! WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltoken committed Feb 25, 2020
1 parent d8006df commit b38adb2
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions scripts/generate-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,46 @@ if (!fs.existsSync(baseDir)) {
const target = path.join(baseDir, `assets.json`);
const assets = {};

console.log('1');
(async () => {
['oas', 'aas'].forEach(async (kind) => {
for (const kind of ['oas', 'aas']) {
console.log('2');
await processDirectory(assets, path.join(__dirname, `../rulesets/${kind}`));
console.log('3');
await writeFileAsync(target, JSON.stringify(assets, null, 2));
})
console.log('4');
}
})();

async function processDirectory(assets, dir) {
await Promise.all((await readdirAsync(dir)).map(async name => {
console.log(name);
if (name === 'schemas') return;
const target = path.join(dir, name);
const stats = await statAsync(target);
if (stats.isDirectory()) {
return processDirectory(assets, target);
} else {
let content = await readFileAsync(target, 'utf8');
console.log('pro ' + target)
if (path.extname(name) === '.json') {
content = JSON.stringify((await httpAndFileResolver.resolve(JSON.parse(content), {
console.log('awaiting ' + target)
const x = await httpAndFileResolver.resolve(JSON.parse(content), {
dereferenceRemote: true,
dereferenceInline: false,
baseUri: target,
parseResolveResult(opts) {
opts.result = parse(opts.result);
console.log('parsed ' + opts.targetAuthority.toString());

return opts;
},
})).result);
})
console.log('awaited ' + target)
content = JSON.stringify((x).result);
console.log('done ' + target);
}

console.log('asset target');
assets[path.join('@stoplight/spectral', path.relative(path.join(__dirname, '..'), target))] = content;
}
}));
Expand Down

0 comments on commit b38adb2

Please sign in to comment.