Skip to content

Commit b19c8f4

Browse files
1 parent 61a3feb commit b19c8f4

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

bundle-schemas.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
const $RefParser = require('@apidevtools/json-schema-ref-parser');
2-
const fs = require('fs');
1+
import $RefParser from "@apidevtools/json-schema-ref-parser";
32

43
async function bundleSchemas() {
5-
try {
6-
const inputFile = 'ruleset.json'; // The ruleset generated in your workflow
7-
const outputFile = 'bundled-ruleset.json'; // The output file after bundling
4+
try {
5+
const inputFile = 'ruleset.json'; // The ruleset generated in your workflow
6+
const outputFile = 'bundled-ruleset.json'; // The output file after bundling
87

9-
// Load and bundle the JSON Schema
10-
const bundled = await $RefParser.bundle(inputFile);
8+
// if you want to avoid modifying the original schema, you can disable the `mutateInputSchema` option
9+
let bundled = await $RefParser.dereference(mySchema, { mutateInputSchema: false });
1110

12-
// Save the bundled schema to a file
13-
fs.writeFileSync(outputFile, JSON.stringify(bundled, null, 2));
11+
fs.writeFileSync(outputFile, JSON.stringify(bundled, null, 2));
12+
console.log(`Bundled schema written to ${outputFile}`);
1413

15-
console.log(`Bundled schema written to ${outputFile}`);
16-
} catch (error) {
17-
console.error('Error bundling schemas:', error);
18-
process.exit(1); // Exit with an error code if something fails
19-
}
14+
} catch (error) {
15+
console.error('Error bundling schemas:', error);
16+
process.exit(1); // Exit with an error code if something fails
17+
}
2018
}
21-
2219
bundleSchemas();

bundle-schemas.js.old

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const $RefParser = require('@apidevtools/json-schema-ref-parser');
2+
const fs = require('fs');
3+
4+
async function bundleSchemas() {
5+
try {
6+
const inputFile = 'ruleset.json'; // The ruleset generated in your workflow
7+
const outputFile = 'bundled-ruleset.json'; // The output file after bundling
8+
9+
// Load and bundle the JSON Schema
10+
const bundled = await $RefParser.bundle(inputFile);
11+
12+
// Save the bundled schema to a file
13+
fs.writeFileSync(outputFile, JSON.stringify(bundled, null, 2));
14+
15+
console.log(`Bundled schema written to ${outputFile}`);
16+
} catch (error) {
17+
console.error('Error bundling schemas:', error);
18+
process.exit(1); // Exit with an error code if something fails
19+
}
20+
}
21+
22+
bundleSchemas();

0 commit comments

Comments
 (0)