forked from lukeed/taskr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (30 loc) · 854 Bytes
/
index.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
'use strict';
const p = require('path');
const JSZip = require('jszip');
module.exports = function (task, utils) {
const zip = new JSZip();
task.plugin('zip', { every:false }, function * (files, opts) {
opts = Object.assign({ file:'archive.zip' }, opts);
let curr;
for (const file of files) {
if (file.data) {
curr = p.relative(task.root, p.format(file));
zip.file(curr, file.data, { base64:true });
}
}
const outdata = yield zip.generateAsync({ type:'nodebuffer' });
// if an alt `dest` was given
if (opts.dest !== void 0) {
// write file without overwriting files
const outfile = p.resolve(task.root, opts.dest, opts.file);
yield utils.write(outfile, outdata);
} else {
// overwrite with the archive
this._.files = [{
dir: files[0].dir,
base: opts.file,
data: outdata
}];
}
});
};