Skip to content

Commit b6fed22

Browse files
Added minified bundling
Signed-off-by: Steve Springett <[email protected]>
1 parent c4d6c82 commit b6fed22

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

.github/workflows/bundle_2.0_schemas.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,18 @@ jobs:
4242
- name: Check for changes and commit
4343
run: |
4444
BUNDLED_FILE="schema/2.0/cyclonedx-2.0-bundled.schema.json"
45+
MINIFIED_FILE="schema/2.0/cyclonedx-2.0-bundled.min.schema.json"
4546
46-
# Add the file (works for both new and modified files)
47-
git add "$BUNDLED_FILE"
47+
# Add both files (works for both new and modified files)
48+
git add "$BUNDLED_FILE" "$MINIFIED_FILE"
4849
4950
# Check if there are staged changes
5051
if git diff --staged --quiet; then
51-
echo "No changes to bundled schema"
52+
echo "No changes to bundled schemas"
5253
else
5354
echo "Committing bundled schema changes"
5455
git config --local user.email "github-actions[bot]@users.noreply.github.com"
5556
git config --local user.name "github-actions[bot]"
56-
git commit -m "chore: update bundled schema [skip ci]"
57+
git commit -m "chore: update bundled schemas [skip ci]"
5758
git push
5859
fi

tools/src/main/js/bundle-schemas.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,16 @@ async function bundleSchemas(modelsDirectory, rootSchemaPath, options = {}) {
6161
console.log(`Models directory: ${absoluteModelsDir}`);
6262
console.log(`Root schema: ${absoluteRootPath}`);
6363

64-
// Generate output filename by inserting "-bundled" before ".schema.json"
65-
const outputFilename = rootSchemaFilename.replace('.schema.json', '-bundled.schema.json');
66-
const outputPath = path.join(rootSchemaDir, outputFilename);
64+
// Generate output filenames
65+
const baseFilename = rootSchemaFilename.replace('.schema.json', '');
66+
const bundledFilename = `${baseFilename}-bundled.schema.json`;
67+
const minifiedFilename = `${baseFilename}-bundled.min.schema.json`;
6768

68-
console.log(`Output: ${outputPath}\n`);
69+
const bundledPath = path.join(rootSchemaDir, bundledFilename);
70+
const minifiedPath = path.join(rootSchemaDir, minifiedFilename);
71+
72+
console.log(`Output (bundled): ${bundledPath}`);
73+
console.log(`Output (minified): ${minifiedPath}\n`);
6974

7075
// Read all schema files in the models directory
7176
const files = await fs.readdir(absoluteModelsDir);
@@ -96,7 +101,7 @@ async function bundleSchemas(modelsDirectory, rootSchemaPath, options = {}) {
96101
// Read the root schema
97102
console.log(`\nReading root schema...`);
98103
const rootContent = await fs.readFile(absoluteRootPath, 'utf8');
99-
const rootSchema = JSON.parse(rootContent); // Fixed: was 'content', should be 'rootContent'
104+
const rootSchema = JSON.parse(rootContent);
100105
const rootSchemaName = path.basename(rootSchemaFilename, '.schema.json');
101106

102107
// Add root schema to the schemas collection
@@ -156,14 +161,21 @@ async function bundleSchemas(modelsDirectory, rootSchemaPath, options = {}) {
156161
}
157162
}
158163

159-
await fs.writeFile(outputPath, JSON.stringify(finalSchema, null, 2));
164+
// Write bundled (pretty) version
165+
console.log('\nWriting bundled schema...');
166+
await fs.writeFile(bundledPath, JSON.stringify(finalSchema, null, 2));
167+
const bundledStats = await fs.stat(bundledPath);
168+
const bundledSizeKB = (bundledStats.size / 1024).toFixed(2);
169+
console.log(`✓ Bundled schema: ${bundledFilename} (${bundledSizeKB} KB)`);
160170

161-
console.log(`\n✓ Bundled ${Object.keys(schemas).length} schemas to ${outputFilename}`);
171+
// Write minified version
172+
console.log('Writing minified schema...');
173+
await fs.writeFile(minifiedPath, JSON.stringify(finalSchema));
174+
const minifiedStats = await fs.stat(minifiedPath);
175+
const minifiedSizeKB = (minifiedStats.size / 1024).toFixed(2);
176+
console.log(`✓ Minified schema: ${minifiedFilename} (${minifiedSizeKB} KB)`);
162177

163-
// Show file size
164-
const stats = await fs.stat(outputPath);
165-
const sizeKB = (stats.size / 1024).toFixed(2);
166-
console.log(` File size: ${sizeKB} KB`);
178+
console.log(`\n✓ Successfully bundled ${Object.keys(schemas).length} schemas`);
167179

168180
return finalSchema;
169181

@@ -185,7 +197,9 @@ if (require.main === module) {
185197
console.log(' ./schema/2.0/model \\');
186198
console.log(' ./schema/2.0/cyclonedx-2.0.schema.json');
187199
console.log('');
188-
console.log('This will create: ./schema/2.0/cyclonedx-2.0-bundled.schema.json');
200+
console.log('This will create:');
201+
console.log(' ./schema/2.0/cyclonedx-2.0-bundled.schema.json (pretty-printed)');
202+
console.log(' ./schema/2.0/cyclonedx-2.0-bundled.min.schema.json (minified)');
189203
process.exit(1);
190204
}
191205

0 commit comments

Comments
 (0)