-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathbuild.js
44 lines (34 loc) · 1.43 KB
/
build.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
#!/usr/bin/env node
const fs = require('fs');
const process = require('process');
const path = require('path');
const archiver = require('archiver');
const { execSync } = require('child_process');
const { program } = require('commander');
const options = program.option('-f --firefox', 'Build for Firefox').parse(process.argv).opts();
const getGitInfo = () => {
const branch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
const commitHash = execSync('git rev-parse HEAD').toString().trim();
return { branch, commitHash };
};
const build = async ({ branch, commitHash }) => {
const mode = options.firefox ? 'firefox' : 'chrome';
const zipName = `${branch.replace('/', '_')}_${commitHash.slice(0,5)}_${mode}.zip`;
fs.mkdirSync(path.join(__dirname, 'dst'), { recursive: true });
const output = fs.createWriteStream(path.join(__dirname, 'dst', zipName));
process.chdir(path.join(__dirname, 'src'));
const archive = archiver('zip', {
zlib: { level: 9 }
});
archive.pipe(output);
archive.glob('**/*', { ignore: ['**/*.json'] });
const manifest = JSON.parse(fs.readFileSync('manifest.json'));
if (options.firefox) {
const manifestFirefox = JSON.parse(fs.readFileSync('manifest-firefox.json'));
Object.assign(manifest, manifestFirefox);
}
archive.append(JSON.stringify(manifest, null, 2), { name: 'manifest.json' });
archive.finalize();
console.log('BUILD', zipName);
};
build(getGitInfo());