-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile.js
More file actions
46 lines (37 loc) · 1.11 KB
/
compile.js
File metadata and controls
46 lines (37 loc) · 1.11 KB
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
const fs = require('fs');
const archiver = require('archiver');
const data = fs.readFileSync('./src/manifest.json', 'utf8');
const manifest = JSON.parse(data);
console.log('Version:', manifest.version);
fs.mkdirSync('./build', { recursive: true });
// Create a file to stream archive data to
const output = fs.createWriteStream(
`./build/BulkDelete-${manifest.version}.xpi`
);
const archive = archiver('zip', {
zlib: { level: 9 }, // Set the compression level
});
// Listen for all archive data to be written
output.on('close', function () {
console.log(
`Archive created successfully. Total bytes: ${archive.pointer()}`
);
});
// Handle warnings (e.g., stat failures and other non-blocking errors)
archive.on('warning', function (err) {
if (err.code === 'ENOENT') {
console.warn('Warning:', err.message);
} else {
throw err;
}
});
// Handle errors
archive.on('error', function (err) {
throw err;
});
// Pipe archive data to the file
archive.pipe(output);
// Append files from the './src' directory into the root of the zip
archive.directory('./src/', false);
// Finalize the archive
archive.finalize();