forked from darkreader/darkreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzip.js
More file actions
32 lines (27 loc) · 1006 Bytes
/
Copy pathzip.js
File metadata and controls
32 lines (27 loc) · 1006 Bytes
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
const fs = require('fs');
const globby = require('globby');
const yazl = require('yazl');
const {getDestDir} = require('./paths');
const {createTask} = require('./task');
function archiveFiles({files, dest, cwd}) {
return new Promise((resolve) => {
const archive = new yazl.ZipFile();
files.forEach((file) => archive.addFile(file, file.startsWith(`${cwd}/`) ? file.substring(cwd.length + 1) : file));
archive.outputStream.pipe(fs.createWriteStream(dest)).on('close', () => resolve());
archive.end();
});
}
async function archiveDirectory({dir, dest}) {
const files = await globby(`${dir}/**/*.*`);
await archiveFiles({files, dest, cwd: dir});
}
async function zip({debug}) {
const dir = getDestDir({debug});
const firefoxDir = getDestDir({debug, firefox: true});
await archiveDirectory({dir, dest: 'build.zip'});
await archiveDirectory({dir: firefoxDir, dest: 'build-firefox.xpi'});
}
module.exports = createTask(
'zip',
zip,
);