copy-releases.mjs
1 #!/usr/bin/env node 2 /** 3 * Copy and rename release artifacts to the releases/ folder 4 * 5 * This script copies the WXT-generated zip files to the releases/ folder 6 * with clearer names (chrome.zip and firefox.zip instead of the default names). 7 */ 8 9 import { copyFileSync, mkdirSync, existsSync, readdirSync, readFileSync } from 'fs'; 10 import { join, dirname } from 'path'; 11 import { fileURLToPath } from 'url'; 12 13 const __dirname = dirname(fileURLToPath(import.meta.url)); 14 const rootDir = join(__dirname, '..'); 15 const outputDir = join(rootDir, '.output'); 16 const releasesDir = join(rootDir, 'releases'); 17 18 // Read version from package.json 19 const packageJsonPath = join(rootDir, 'package.json'); 20 const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')); 21 const version = packageJson.version; 22 23 // Ensure releases directory exists 24 if (!existsSync(releasesDir)) { 25 mkdirSync(releasesDir, { recursive: true }); 26 } 27 28 // Find and copy release files 29 const files = readdirSync(outputDir); 30 31 // Mapping of source patterns to destination names 32 const copyMap = [ 33 { pattern: /mnemonic-.*-chrome\.zip$/, dest: `mnemonic-${version}-chrome.zip` }, 34 { pattern: /mnemonic-.*-firefox\.zip$/, dest: `mnemonic-${version}-firefox.zip` }, 35 // Also handle the combined build format 36 { pattern: /mnemonic-.*-chrome,firefox\.zip$/, dest: `mnemonic-${version}-chrome.zip` }, 37 ]; 38 39 let copied = 0; 40 41 for (const file of files) { 42 for (const { pattern, dest } of copyMap) { 43 if (pattern.test(file)) { 44 const src = join(outputDir, file); 45 const destPath = join(releasesDir, dest); 46 console.log(`Copying ${file} -> releases/${dest}`); 47 copyFileSync(src, destPath); 48 copied++; 49 break; 50 } 51 } 52 } 53 54 if (copied === 0) { 55 console.log('No release files found. Run npm run zip:all first.'); 56 process.exit(1); 57 } else { 58 console.log(`\nCopied ${copied} release file(s) to releases/`); 59 console.log('\nRelease files:'); 60 readdirSync(releasesDir).forEach(f => console.log(` - ${f}`)); 61 }