-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.js
42 lines (34 loc) · 947 Bytes
/
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
const fs = require('fs');
const archiver = require('archiver');
const pkg = require('./package.json');
const distPkg = require('./dist/manifest.json');
if (distPkg.version !== pkg.version) {
console.log('changing', 'dist/package.json from', distPkg.version, 'to', pkg.version);
distPkg.version = pkg.version;
fs.writeFileSync('./dist/manifest.json', JSON.stringify(distPkg, null, 2));
}
console.log('Creating dist.zip');
const zip = fs.createWriteStream('./dist.zip');
const archive = archiver('zip', {
zlib: { level: 9 }
});
zip.on('close', function () {
console.log('done!');
});
archive.on('error', function (err) {
throw err;
});
archive.pipe(zip);
fs.readdir('./dist', (err, files) => {
if (err) {
throw err;
}
files.forEach(file => {
if (file[0] === '.') {
return;
}
console.log(file);
archive.append(fs.createReadStream('./dist/' + file), { name: file });
});
archive.finalize();
});