-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.js
More file actions
69 lines (55 loc) · 3.24 KB
/
package.js
File metadata and controls
69 lines (55 loc) · 3.24 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
66
67
68
69
/**
* Veridian packaging script — pure Node, no system zip required.
* Produces distributable archives after a clean build:
*
* artifacts/veridian-chrome-X.Y.Z.zip — load unpacked in Chrome or submit to CWS
* artifacts/veridian-firefox-X.Y.Z.xpi — submit to AMO (unsigned)
*
* Usage: node package.js (or: npm run pack)
*/
import { execSync } from 'child_process';
import { createReadStream, existsSync, mkdirSync, rmSync } from 'fs';
import { readFileSync } from 'fs';
import { readdir } from 'fs/promises';
import { createWriteStream } from 'fs';
import { join, relative } from 'path';
import archiver from 'archiver';
const version = JSON.parse(readFileSync('manifest.json', 'utf8')).version;
const outDir = 'artifacts';
mkdirSync(outDir, { recursive: true });
// ── 1. Build ──────────────────────────────────────────────────────────────────
console.log('[pack] building…');
execSync('node build.js', { stdio: 'inherit' });
// ── 2. Chrome zip ─────────────────────────────────────────────────────────────
const chromeOut = join(outDir, `veridian-chrome-${version}.zip`);
console.log(`[pack] chrome → ${chromeOut}`);
await zipDir('dist', chromeOut, { exclude: 'manifest.firefox.json' });
// ── 3. Firefox xpi ────────────────────────────────────────────────────────────
// AMO requires manifest.json at the root — swap in manifest.firefox.json.
const tmpDir = '.tmp-ff-pack';
const firefoxOut = join(outDir, `veridian-firefox-${version}.xpi`);
if (existsSync(tmpDir)) rmSync(tmpDir, { recursive: true });
// Build into a temp copy with swapped manifest
execSync(`cp -r dist ${tmpDir}`, { stdio: 'inherit', shell: true });
execSync(`cp ${tmpDir}/manifest.firefox.json ${tmpDir}/manifest.json`, { stdio: 'inherit', shell: true });
execSync(`rm ${tmpDir}/manifest.firefox.json`, { stdio: 'inherit', shell: true });
console.log(`[pack] firefox → ${firefoxOut}`);
await zipDir(tmpDir, firefoxOut);
rmSync(tmpDir, { recursive: true });
console.log(`[pack] done — artifacts in ${outDir}/`);
// ─── helpers ──────────────────────────────────────────────────────────────────
function zipDir(srcDir, destFile, { exclude } = {}) {
return new Promise((resolve, reject) => {
const output = createWriteStream(destFile);
const archive = archiver('zip', { zlib: { level: 9 } });
output.on('close', resolve);
archive.on('error', reject);
archive.pipe(output);
archive.glob('**/*', {
cwd: srcDir,
ignore: exclude ? [exclude] : [],
dot: false,
});
archive.finalize();
});
}