-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
41 lines (34 loc) · 1.02 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
const Zip = require('node-zip');
const { promisify } = require('util');
const fs = require('fs');
const readFile = promisify(fs.readFile);
const glob = promisify(require('glob'));
const extensionZip = new Zip();
const zipFileName = 'chrome-clipboard-data-generator-extension.zip';
const filesToPackage = [
glob('generators/*'),
Promise.resolve(['background.js', 'manifest.json', 'popup.html', 'popup.js']),
];
const zipIndividualFilesPromises = filesToPackage.map(filesPromise =>
filesPromise.then(files => {
return Promise.all(
files.map(file =>
readFile(file, { encoding: 'utf8' }).then(fileData =>
extensionZip.file(file, fileData),
),
),
);
}),
);
Promise.all(zipIndividualFilesPromises)
.then(() => {
var zipData = extensionZip.generate({
base64: false,
compression: 'DEFLATE',
});
fs.writeFileSync(zipFileName, zipData, 'binary');
console.log('Saved to', zipFileName);
})
.catch(error => {
console.error('An error occurred', error);
});