@@ -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