|
3 | 3 | const fs = require('fs'); |
4 | 4 | const path = require('path'); |
5 | 5 | const archiver = require('archiver'); |
| 6 | +const { bundleCarbonCalculator } = require('./bundle.js'); |
6 | 7 |
|
7 | 8 | // Check if archiver is available, if not, provide instructions |
8 | 9 | try { |
@@ -44,7 +45,7 @@ function copyCommonFiles(bundlePath) { |
44 | 45 | const source = file; |
45 | 46 | const chromeDest = path.join(chromeDir, file); |
46 | 47 | const firefoxDest = path.join(firefoxDir, file); |
47 | | - |
| 48 | + |
48 | 49 | if (fs.lstatSync(source).isDirectory()) { |
49 | 50 | // Copy directory recursively |
50 | 51 | copyDirectoryRecursive(source, chromeDest); |
@@ -77,12 +78,12 @@ function copyDirectoryRecursive(src, dest) { |
77 | 78 | if (!fs.existsSync(dest)) { |
78 | 79 | fs.mkdirSync(dest, { recursive: true }); |
79 | 80 | } |
80 | | - |
| 81 | + |
81 | 82 | const files = fs.readdirSync(src); |
82 | 83 | files.forEach(file => { |
83 | 84 | const srcPath = path.join(src, file); |
84 | 85 | const destPath = path.join(dest, file); |
85 | | - |
| 86 | + |
86 | 87 | if (fs.lstatSync(srcPath).isDirectory()) { |
87 | 88 | copyDirectoryRecursive(srcPath, destPath); |
88 | 89 | } else { |
@@ -122,30 +123,30 @@ function createZips() { |
122 | 123 | return new Promise((resolve, reject) => { |
123 | 124 | const chromeZip = fs.createWriteStream(path.join(buildDir, 'carbon-visualizer-chrome.zip')); |
124 | 125 | const firefoxZip = fs.createWriteStream(path.join(buildDir, 'carbon-visualizer-firefox.zip')); |
125 | | - |
| 126 | + |
126 | 127 | const chromeArchive = archiver('zip', { zlib: { level: 9 } }); |
127 | 128 | const firefoxArchive = archiver('zip', { zlib: { level: 9 } }); |
128 | | - |
| 129 | + |
129 | 130 | chromeZip.on('close', () => { |
130 | 131 | console.log('✅ Chrome extension packaged: build/carbon-visualizer-chrome.zip'); |
131 | 132 | }); |
132 | | - |
| 133 | + |
133 | 134 | firefoxZip.on('close', () => { |
134 | 135 | console.log('✅ Firefox extension packaged: build/carbon-visualizer-firefox.zip'); |
135 | 136 | }); |
136 | | - |
| 137 | + |
137 | 138 | chromeArchive.on('error', reject); |
138 | 139 | firefoxArchive.on('error', reject); |
139 | | - |
| 140 | + |
140 | 141 | chromeArchive.pipe(chromeZip); |
141 | 142 | firefoxArchive.pipe(firefoxZip); |
142 | | - |
| 143 | + |
143 | 144 | chromeArchive.directory(chromeDir, false); |
144 | 145 | firefoxArchive.directory(firefoxDir, false); |
145 | | - |
| 146 | + |
146 | 147 | chromeArchive.finalize(); |
147 | 148 | firefoxArchive.finalize(); |
148 | | - |
| 149 | + |
149 | 150 | Promise.all([ |
150 | 151 | new Promise(resolve => chromeArchive.on('end', resolve)), |
151 | 152 | new Promise(resolve => firefoxArchive.on('end', resolve)) |
@@ -200,21 +201,23 @@ async function build() { |
200 | 201 | console.log('🚀 Building Carbon Visualizer extension for Chrome and Firefox...'); |
201 | 202 |
|
202 | 203 | const bundlePath = bundleCoreCss(); |
| 204 | + await bundleCarbonCalculator(); |
| 205 | + |
203 | 206 | createDirectories(); |
204 | 207 | copyCommonFiles(bundlePath); |
205 | 208 | copyManifests(); |
206 | 209 | patchFirefoxManifest(); |
207 | | - |
| 210 | + |
208 | 211 | await createZips(); |
209 | | - |
| 212 | + |
210 | 213 | console.log('\n🎉 Build complete!'); |
211 | 214 | console.log('\n📦 Extension packages created:'); |
212 | 215 | console.log(' Chrome: build/carbon-visualizer-chrome.zip'); |
213 | 216 | console.log(' Firefox: build/carbon-visualizer-firefox.zip'); |
214 | 217 | console.log('\n📋 Installation instructions:'); |
215 | 218 | console.log(' Chrome: Load unpacked from build/chrome/'); |
216 | 219 | console.log(' Firefox: Load temporary add-on from build/firefox/'); |
217 | | - |
| 220 | + |
218 | 221 | } catch (error) { |
219 | 222 | console.error('❌ Build failed:', error); |
220 | 223 | process.exit(1); |
|
0 commit comments