-
Notifications
You must be signed in to change notification settings - Fork 328
/
xpi.js
52 lines (51 loc) · 1.54 KB
/
xpi.js
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
const fs = require('fs');
const merge = require('merge');
const common = require('../extension-config');
const signAddon = require('sign-addon').default;
const exec = require('child_process').exec;
module.exports = function(manifest, outputDir) {
return new Promise(resolve => {
// replace manifest
const newManifest = merge(true, manifest);
newManifest.applications = {
gecko: {
id: common.config.firefox.xpi,
strict_min_version: common.config.firefox.version,
update_url: common.config.firefox.update
}
};
fs.writeFileSync(common.manifest, JSON.stringify(newManifest));
const zipPath = common.packFile('xpi.zip');
exec(`cd ${common.dist} && zip -r ${zipPath} ./*`, (error, stdout, stderr) => {
if (error) {
console.info('Error : ' + stderr);
resolve();
} else {
signAddon({
xpiPath: zipPath,
version: common.version,
apiKey: common.config.firefox.mozilla.key,
apiSecret: process.env[common.config.firefox.mozilla.secret],
id: common.config.firefox.xpi,
downloadDir: common.pack
})
.then(result => {
if (result.success) {
console.log("Downloaded signed addon");
fs.unlinkSync(zipPath);
const out = common.resolve(outputDir, common.config.dist.replace('{VER}', common.version) + '.xpi');
// Move download file to output dir
if (result.downloadedFiles[0]) {
fs.renameSync(result.downloadedFiles[0], out);
resolve(out);
} else {
resolve();
}
} else {
console.log("Sign failed");
}
})
}
});
})
}