-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.js
More file actions
65 lines (51 loc) · 2.06 KB
/
package.js
File metadata and controls
65 lines (51 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env node
import { execSync } from 'child_process';
import fs from 'fs/promises';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const ROOT = path.join(__dirname, '..');
const browser = process.argv[2];
if (!browser || !['chrome', 'firefox'].includes(browser)) {
console.error('Usage: node package.js [chrome|firefox]');
process.exit(1);
}
async function packageExtension() {
const buildDir = path.join(ROOT, 'build', browser);
const bundleDir = path.join(ROOT, 'build', 'bundle');
const manifestPath = path.join(buildDir, 'manifest.json');
// Create bundle directory
await fs.mkdir(bundleDir, { recursive: true });
// Read version name written by copy.js (works for both browsers)
const versionNamePath = path.join(buildDir, '.version_name');
const version = (await fs.readFile(versionNamePath, 'utf8')).trim();
const packageName = `github-bookmarked-issues-${version}`;
if (browser === 'chrome') {
// Create ZIP for Chrome
const zipFile = `${packageName}.zip`;
const zipPath = path.join(bundleDir, zipFile);
console.log(`Creating Chrome package: ${zipFile}...`);
const isWindows = process.platform === 'win32';
const cmd = isWindows
? `powershell -Command "Compress-Archive -Path '.\\*' -DestinationPath '${zipPath}' -Force"`
: `zip -r "${zipPath}" . -x "*.zip" -x ".version_name" -x ".DS_Store"`;
execSync(cmd, {
cwd: buildDir,
stdio: 'inherit'
});
console.log(`✓ Chrome package created at build/bundle/${zipFile}`);
} else {
// Use web-ext for Firefox
const xpiFile = `${packageName}.xpi`;
console.log(`Creating Firefox package: ${xpiFile}...`);
execSync(`web-ext build --source-dir=. --artifacts-dir="${bundleDir}" --filename="${xpiFile}" --overwrite-dest`, {
cwd: buildDir,
stdio: 'inherit'
});
console.log(`✓ Firefox package created at build/bundle/${xpiFile}`);
}
}
packageExtension().catch(err => {
console.error('Packaging failed:', err);
process.exit(1);
});