forked from imyelo/gulp-duojs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (51 loc) · 1.34 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
var _ = require('lodash');
var Duo = require('duo');
var through = require('through2');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;
const PLUGIN_NAME = 'gulp-duo';
function gulpDuo (opts, func) {
var options = _.defaults(opts || {}, {
root: process.cwd(),
standalone: '',
development: false,
cache: true,
copy: false,
global: '',
concurrency: 50
});
func = _.isFunction(func) ? func : function () {};
function compile (path, callback) {
var duo = Duo(options.root)
.entry(path)
.standalone(options.standalone)
.development(options.development)
.cache(options.cache)
.copy(options.copy)
.global(options.global)
.concurrency(options.concurrency);
func(duo);
duo.run(function (err, bundle) {
callback(err, bundle);
});
}
function duo (file, encoding, callback) {
if (file.isNull()) {
return callback(null, file);
}
compile(file.path, function (err, bundle) {
if (err) {
return callback(err);
}
if (file.isStream()) {
return callback(new PluginError(PLUGIN_NAME, 'Streams not supported!'));
}
if (file.isBuffer()) {
file.contents = new Buffer(bundle.code);
}
callback(null, file);
});
}
return through.obj(duo);
}
module.exports = gulpDuo;