This repository has been archived by the owner on Sep 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
67 lines (55 loc) · 1.59 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
var through = require('through2');
var gutil = require('gulp-util');
require('terminal-colors');
var Filesystem = require('asar/lib/filesystem');
var pickle = require('asar/node_modules/chromium-pickle-js');
const PLUGIN_NAME = 'gulp-asar';
module.exports = function(destFilename, opts) {
opts = opts || {};
if (!destFilename) {
throw new gutil.PluginError(PLUGIN_NAME, 'destFilename'.blue + ' required');
}
var cwd = opts.base || process.cwd(); // ?
var filesystem = new Filesystem(cwd);
var out = [];
var outLen = 0;
var stream = through.obj(function(file, enc, cb) {
if (file.isStream()) {
return cb(new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported'));
}
if(file.stat.isDirectory()) {
filesystem.insertDirectory(file.relative);
}
else if(file.stat.isSymbolicLink()) {
filesystem.insertLink(file.relative, file.stat);
}
else {
filesystem.insertFile(file.relative, false, file.stat);
outLen += file.contents.length;
out.push(file.contents);
}
cb();
}, function(cb) {
var headerPickle = pickle.createEmpty();
headerPickle.writeString(JSON.stringify(filesystem.header));
var headerBuf = headerPickle.toBuffer();
var sizePickle = pickle.createEmpty();
sizePickle.writeUInt32(headerBuf.length);
var sizeBuf = sizePickle.toBuffer();
outLen += headerBuf.length;
outLen += sizeBuf.length;
out.unshift(headerBuf);
out.unshift(sizeBuf);
var archive = Buffer.concat(out, outLen);
out = [];
this.push(new gutil.File({
cwd: cwd,
base: cwd,
path: destFilename,
contents: archive,
enc: 'utf8'
}));
cb();
});
return stream;
};