|
| 1 | +import { execSync } from 'child_process' |
| 2 | +import { resolve, dirname } from 'path' |
| 3 | +import { existsSync, renameSync, unlinkSync, rmSync } from 'fs' |
| 4 | +import { fileURLToPath } from 'url' |
| 5 | + |
| 6 | +const __dirname = dirname(fileURLToPath(import.meta.url)) |
| 7 | +const root = resolve(__dirname, '..') |
| 8 | + |
| 9 | +const target = process.argv[2] |
| 10 | +if (!target) { |
| 11 | + console.error('Usage: node scripts/build-zip.js <target-dir>') |
| 12 | + process.exit(1) |
| 13 | +} |
| 14 | + |
| 15 | +const srcDir = resolve(root, target, 'drplayer') |
| 16 | +const zipFile = resolve(root, target, 'drplayer.zip') |
| 17 | +const finalFile = resolve(root, target, 'drplayer') |
| 18 | + |
| 19 | +if (!existsSync(srcDir)) { |
| 20 | + console.error(`Source directory not found: ${srcDir}`) |
| 21 | + process.exit(1) |
| 22 | +} |
| 23 | + |
| 24 | +// Remove leftover zip if exists |
| 25 | +if (existsSync(zipFile)) unlinkSync(zipFile) |
| 26 | + |
| 27 | +// Compress contents of srcDir (no nesting — files go directly into zip root) |
| 28 | +execSync( |
| 29 | + `powershell -Command "Compress-Archive -Path '${srcDir}\\*' -DestinationPath '${zipFile}'"`, |
| 30 | + { stdio: 'inherit' } |
| 31 | +) |
| 32 | + |
| 33 | +// Remove the source directory, then rename zip to final name |
| 34 | +rmSync(srcDir, { recursive: true, force: true }) |
| 35 | +renameSync(zipFile, finalFile) |
| 36 | + |
| 37 | +console.log(`Done: ${finalFile}`) |
0 commit comments