2018-12-30 23:16:09 +01:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const archiver = require('archiver');
|
|
|
|
|
2020-02-08 00:38:09 +01:00
|
|
|
const extractExtensionData = (browserPostfix) => {
|
|
|
|
const extPackageJson = require(`../dist-${browserPostfix}/manifest.json`);
|
2018-12-30 23:16:09 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
name: extPackageJson.name,
|
|
|
|
version: extPackageJson.version
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-12-03 22:11:29 +01:00
|
|
|
const makeDirIfNotExists = (dir) => {
|
|
|
|
if(!fs.existsSync(dir)) {
|
|
|
|
fs.mkdirSync(dir);
|
2018-12-30 23:16:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const buildZip = (src, dist, zipFilename) => {
|
|
|
|
console.info(`Building ${zipFilename}...`);
|
|
|
|
|
|
|
|
const archive = archiver('zip', { zlib: { level: 9 }});
|
|
|
|
const stream = fs.createWriteStream(path.join(dist, zipFilename));
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
archive
|
|
|
|
.directory(src, false)
|
|
|
|
.on('error', err => reject(err))
|
|
|
|
.pipe(stream);
|
|
|
|
|
|
|
|
stream.on('close', () => resolve());
|
|
|
|
archive.finalize();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const main = () => {
|
2019-09-22 02:38:13 +02:00
|
|
|
const browser = process.argv[2];
|
2019-12-03 22:11:29 +01:00
|
|
|
const testingOrNightly = process.argv[3];
|
2020-02-08 00:38:09 +01:00
|
|
|
let browserPostfix;
|
2020-02-08 00:08:07 +01:00
|
|
|
if (browser == 'firefox') {
|
2020-02-08 00:38:09 +01:00
|
|
|
browserPostfix = 'ff';
|
2020-02-08 00:08:07 +01:00
|
|
|
} else {
|
2020-02-08 00:38:09 +01:00
|
|
|
browserPostfix = browser;
|
2020-02-08 00:08:07 +01:00
|
|
|
}
|
2020-02-08 00:38:09 +01:00
|
|
|
const destDir = path.join(__dirname, `../dist-${browserPostfix}`);
|
2020-02-08 00:08:07 +01:00
|
|
|
const zipDir = path.join(__dirname, '../dist-zip');
|
2020-02-08 01:05:05 +01:00
|
|
|
const {name, version} = extractExtensionData(browserPostfix);
|
2019-12-03 22:11:29 +01:00
|
|
|
|
|
|
|
// collapse spaces and dashes into single dash
|
|
|
|
const baseFilename = `${name.replace(/[ -]+/g, '-')}-${version}`;
|
|
|
|
|
|
|
|
let realZipDir;
|
|
|
|
|
|
|
|
if (!!testingOrNightly) {
|
2020-02-08 00:08:07 +01:00
|
|
|
realZipDir = path.join(zipDir, version);
|
2020-01-19 21:08:34 +01:00
|
|
|
} else {
|
2020-02-08 00:08:07 +01:00
|
|
|
realZipDir = path.join(zipDir);
|
2019-12-03 22:11:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const zipFilename = `${baseFilename}-${browser}.zip`;
|
2018-12-30 23:16:09 +01:00
|
|
|
|
2020-01-19 20:27:05 +01:00
|
|
|
try {
|
|
|
|
makeDirIfNotExists(realZipDir, {recursive: true});
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Failed to make directory.\nDirectory we wanted to make', realZipDir, '\nerror we got:\n', e)
|
|
|
|
return 1;
|
|
|
|
}
|
2020-02-08 00:08:07 +01:00
|
|
|
buildZip(destDir, realZipDir, zipFilename)
|
2018-12-30 23:16:09 +01:00
|
|
|
.then(() => console.info('OK'))
|
|
|
|
.catch(console.err);
|
|
|
|
};
|
|
|
|
|
|
|
|
main();
|