@@ -39,7 +39,7 @@ function createDirectories() {
3939}
4040
4141// Copy common files
42- function copyCommonFiles ( ) {
42+ function copyCommonFiles ( bundlePath ) {
4343 commonFiles . forEach ( file => {
4444 const source = file ;
4545 const chromeDest = path . join ( chromeDir , file ) ;
@@ -55,6 +55,22 @@ function copyCommonFiles() {
5555 fs . copyFileSync ( source , firefoxDest ) ;
5656 }
5757 } ) ;
58+
59+ // Copy the bundled CSS to the extension's src/styles directory
60+ if ( bundlePath && fs . existsSync ( bundlePath ) ) {
61+ const chromeStylesDir = path . join ( chromeDir , 'src/styles' ) ;
62+ const firefoxStylesDir = path . join ( firefoxDir , 'src/styles' ) ;
63+
64+ if ( ! fs . existsSync ( chromeStylesDir ) ) {
65+ fs . mkdirSync ( chromeStylesDir , { recursive : true } ) ;
66+ }
67+ if ( ! fs . existsSync ( firefoxStylesDir ) ) {
68+ fs . mkdirSync ( firefoxStylesDir , { recursive : true } ) ;
69+ }
70+
71+ fs . copyFileSync ( bundlePath , path . join ( chromeStylesDir , 'core-bundle.css' ) ) ;
72+ fs . copyFileSync ( bundlePath , path . join ( firefoxStylesDir , 'core-bundle.css' ) ) ;
73+ }
5874}
5975
6076function copyDirectoryRecursive ( src , dest ) {
@@ -137,13 +153,55 @@ function createZips() {
137153 } ) ;
138154}
139155
156+ // Bundle all CSS files (core + panels)
157+ function bundleCoreCss ( ) {
158+ const srcCssDir = 'src/styles' ;
159+ const buildCssDir = path . join ( buildDir , 'css' ) ;
160+ const files = [
161+ 'tokens/color.css' ,
162+ 'tokens/size.css' ,
163+ 'tokens/typography.css' ,
164+ 'themes/default.css' ,
165+ 'generic/typography.css' ,
166+ 'core.css' ,
167+ 'welcome.css' ,
168+ 'results.css'
169+ ] ;
170+
171+ // Create build/css directory if it doesn't exist
172+ if ( ! fs . existsSync ( buildCssDir ) ) {
173+ fs . mkdirSync ( buildCssDir , { recursive : true } ) ;
174+ }
175+
176+ let bundledCss = '/* Core CSS Bundle for Carbon Visualizer Extension */\n' ;
177+ bundledCss += '/* This file combines all design system CSS files in the correct dependency order */\n\n' ;
178+
179+ files . forEach ( file => {
180+ const filePath = path . join ( srcCssDir , file ) ;
181+ try {
182+ const content = fs . readFileSync ( filePath , 'utf-8' ) ;
183+ bundledCss += `/* ===== ${ file } ===== */\n` ;
184+ bundledCss += content ;
185+ bundledCss += '\n\n' ;
186+ } catch ( error ) {
187+ console . error ( `⚠️ Warning: Could not read CSS file ${ filePath } :` , error . message ) ;
188+ }
189+ } ) ;
190+
191+ const bundleOutputPath = path . join ( buildCssDir , 'core-bundle.css' ) ;
192+ fs . writeFileSync ( bundleOutputPath , bundledCss ) ;
193+ console . log ( `✅ Bundled core CSS: ${ bundleOutputPath } ` ) ;
194+ return bundleOutputPath ;
195+ }
196+
140197// Main build function
141198async function build ( ) {
142199 try {
143200 console . log ( '🚀 Building Carbon Visualizer extension for Chrome and Firefox...' ) ;
144-
201+
202+ const bundlePath = bundleCoreCss ( ) ;
145203 createDirectories ( ) ;
146- copyCommonFiles ( ) ;
204+ copyCommonFiles ( bundlePath ) ;
147205 copyManifests ( ) ;
148206 patchFirefoxManifest ( ) ;
149207
0 commit comments