-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathzip-for-chromestore.js
52 lines (44 loc) · 1.27 KB
/
zip-for-chromestore.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 archiver = require('archiver');
// Array of files to be added to the zip
const files = [
'background.js',
'background-service.js',
'logo.png',
'logo16.png',
'logo32.png',
'logo48.png',
'logo64.png',
'manifest.json',
'popup.css',
'popup.html',
'popup.js'
];
// Create a file to stream archive data to
const output = fs.createWriteStream('segment-chromeextension.zip');
const archive = archiver('zip', {
zlib: { level: 9 } // Sets the compression level
});
// Listen for all archive data to be written
output.on('close', () => {
console.log('Archive: segment-chromeextension.zip, has been saved.');
console.log(`${archive.pointer()} total bytes`);
});
// Good practice to catch warnings (e.g., stat failures and other non-blocking errors)
archive.on('warning', (err) => {
if (err.code !== 'ENOENT') {
throw err;
}
});
// Good practice to catch this error explicitly
archive.on('error', (err) => {
throw err;
});
// Pipe archive data to the file
archive.pipe(output);
// Append files from the array
files.forEach((file) => {
archive.file(file, { name: file.split('/').pop() });
});
// Finalize the archive (i.e., we are done appending files but streams have to finish yet)
archive.finalize();