-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
56 lines (43 loc) · 1.28 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
'use strict';
var gutil = require('gulp-util');
var map = require('map-stream');
var spawn = require('win-spawn');
var dargs = require('dargs');
module.exports = function (options) {
options = options || {};
var passedArgs = dargs(options, ['bundleExec']);
var bundleExec = options.bundleExec;
return map(function (file, cb) {
if (file.isStream()) {
return cb(new gutil.PluginError('gulp-jekyll', 'Streaming not supported'));
}
var args = [
'jekyll',
'build'
].concat(passedArgs);
if (bundleExec) {
args.unshift('bundle', 'exec');
}
var cp = spawn(args.shift(), args);
cp.on('error', function (err) {
return cb(new gutil.PluginError('gulp-jekyll', err));
});
var errors = '';
cp.stderr.setEncoding('utf8');
cp.stderr.on('data', function (data) {
errors += data;
});
cp.on('close', function (code) {
if (code === 127) {
return cb(new gutil.PluginError('gulp-jekyll', 'You need to have Ruby and Jekyll installed and in your PATH for this task to work.'));
}
if (errors) {
return cb(new gutil.PluginError('gulp-jekyll', '\n' + errors.replace('Use --trace for backtrace.\n', '')));
}
if (code > 0) {
return cb(new gutil.PluginError('gulp-jekyll', 'Exited with error code ' + code));
}
cb(null, null);
});
});
};