Skip to content

Commit

Permalink
fixup! WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltoken committed Feb 26, 2020
1 parent b38adb2 commit e685572
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"jest": "~25.1",
"jest-mock": "^25.1.0",
"jest-when": "~2.7",
"json-schema-ref-parser": "^7.1.3",
"karma": "^4.4.1",
"karma-chrome-launcher": "^3.1.0",
"karma-jasmine": "^3.1.0",
Expand Down
29 changes: 5 additions & 24 deletions scripts/generate-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
const path = require('@stoplight/path');
const fs = require('fs');
const { promisify } = require('util');
const { parse } = require('@stoplight/yaml');
const { httpAndFileResolver } = require('../dist/resolvers/http-and-file');
const $RefParser = require("json-schema-ref-parser");

const readFileAsync = promisify(fs.readFile);
const writeFileAsync = promisify(fs.writeFile);
Expand All @@ -29,46 +28,28 @@ if (!fs.existsSync(baseDir)) {
const target = path.join(baseDir, `assets.json`);
const assets = {};

console.log('1');
(async () => {
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') {
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;
},
})
console.log('awaited ' + target)
content = JSON.stringify((x).result);
console.log('done ' + target);
if (path.extname(name) === '.json') {
const result = await $RefParser.bundle(target, content, {});
content = JSON.stringify(result);
}
console.log('asset target');

assets[path.join('@stoplight/spectral', path.relative(path.join(__dirname, '..'), target))] = content;
}
}));
Expand Down
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,11 @@ cache-base@^1.0.1:
union-value "^1.0.0"
unset-value "^1.0.0"

call-me-maybe@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/call-me-maybe/-/call-me-maybe-1.0.1.tgz#26d208ea89e37b5cbde60250a15f031c16a4d66b"
integrity sha1-JtII6onje1y95gJQoV8DHBak1ms=

[email protected]:
version "1.0.0"
resolved "https://registry.yarnpkg.com/callsite/-/callsite-1.0.0.tgz#280398e5d664bd74038b6f0905153e6e8af1bc20"
Expand Down Expand Up @@ -4462,6 +4467,15 @@ json-parse-better-errors@^1.0.1:
resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"
integrity sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==

json-schema-ref-parser@^7.1.3:
version "7.1.3"
resolved "https://registry.yarnpkg.com/json-schema-ref-parser/-/json-schema-ref-parser-7.1.3.tgz#21468cd180b2f1939ce93fe291f743b441e97d49"
integrity sha512-/Lmyl0PW27dOmCO03PI339+1gs4Z2PlqIyUgzIOtoRp08zkkMCB30TRbdppbPO7WWzZX0uT98HqkDiZSujkmbA==
dependencies:
call-me-maybe "^1.0.1"
js-yaml "^3.13.1"
ono "^6.0.0"

json-schema-traverse@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660"
Expand Down Expand Up @@ -5462,6 +5476,11 @@ onetime@^5.1.0:
dependencies:
mimic-fn "^2.1.0"

ono@^6.0.0:
version "6.0.1"
resolved "https://registry.yarnpkg.com/ono/-/ono-6.0.1.tgz#1bc14ffb8af1e5db3f7397f75b88e4a2d64bbd71"
integrity sha512-5rdYW/106kHqLeG22GE2MHKq+FlsxMERZev9DCzQX1zwkxnFwBivSn5i17a5O/rDmOJOdf4Wyt80UZljzx9+DA==

opencollective-postinstall@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/opencollective-postinstall/-/opencollective-postinstall-2.0.2.tgz#5657f1bede69b6e33a45939b061eb53d3c6c3a89"
Expand Down

0 comments on commit e685572

Please sign in to comment.