|
| 1 | +import fs from 'fs'; |
| 2 | +import path from 'path'; |
| 3 | +import { fileURLToPath } from 'url'; |
| 4 | + |
| 5 | +const __filename = fileURLToPath(import.meta.url); |
| 6 | +const __dirname = path.dirname(__filename); |
| 7 | + |
| 8 | +const dist = path.join(__dirname, 'dist'); |
| 9 | +const assetsDir = path.join(dist, 'assets'); |
| 10 | + |
| 11 | +// Clean dist folder |
| 12 | +if (fs.existsSync(dist)) { |
| 13 | + fs.rmSync(dist, { recursive: true }); |
| 14 | +} |
| 15 | + |
| 16 | +// Create dist structure |
| 17 | +fs.mkdirSync(dist, { recursive: true }); |
| 18 | +fs.mkdirSync(path.join(assetsDir, 'styles'), { recursive: true }); |
| 19 | +fs.mkdirSync(path.join(assetsDir, 'js'), { recursive: true }); |
| 20 | +fs.mkdirSync(path.join(assetsDir, 'icons', 'fontawesome'), { recursive: true }); |
| 21 | + |
| 22 | +// Copy HTML |
| 23 | +let html = fs.readFileSync('index.html', 'utf8'); |
| 24 | +// Update paths in HTML |
| 25 | +html = html.replace(/\.\/src\/styles\//g, './assets/styles/'); |
| 26 | +html = html.replace(/\.\/src\/js\//g, './assets/js/'); |
| 27 | +fs.writeFileSync(path.join(dist, 'index.html'), html); |
| 28 | + |
| 29 | +// Copy CSS |
| 30 | +fs.copyFileSync('src/styles/base.css', path.join(assetsDir, 'styles', 'base.css')); |
| 31 | +fs.copyFileSync('src/styles/modal.css', path.join(assetsDir, 'styles', 'modal.css')); |
| 32 | + |
| 33 | +// Copy JS files |
| 34 | +const jsFiles = ['app.js', 'export.js', 'gradient.js', 'icons.js', 'keyboard.js', 'presets.js', 'state.js', 'storage.js', 'ui.js']; |
| 35 | +jsFiles.forEach(file => { |
| 36 | + let content = fs.readFileSync(path.join('src/js', file), 'utf8'); |
| 37 | + // Update icon path in icons.js |
| 38 | + if (file === 'icons.js') { |
| 39 | + content = content.replace('./public/icons/fontawesome', './assets/icons/fontawesome'); |
| 40 | + } |
| 41 | + fs.writeFileSync(path.join(assetsDir, 'js', file), content); |
| 42 | +}); |
| 43 | + |
| 44 | +// Copy icons |
| 45 | +const iconFiles = fs.readdirSync('public/icons/fontawesome'); |
| 46 | +iconFiles.forEach(file => { |
| 47 | + fs.copyFileSync( |
| 48 | + path.join('public/icons/fontawesome', file), |
| 49 | + path.join(assetsDir, 'icons', 'fontawesome', file) |
| 50 | + ); |
| 51 | +}); |
| 52 | + |
| 53 | +console.log('✓ Build complete! Output in dist/'); |
0 commit comments