forked from robrich/gulp-exec
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (41 loc) · 1.02 KB
/
index.js
File metadata and controls
47 lines (41 loc) · 1.02 KB
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
/*jshint node:true */
"use strict";
var map = require('map-stream'),
gutil = require('gulp-util'),
exec = require('child_process').exec;
module.exports = function(command, opt){
if (!command) {
throw new Error('command is blank');
}
// defaults
if (!opt) {
opt = {};
}
if (typeof opt.silent === 'undefined') {
opt.silent = false;
}
if (typeof opt.continueOnError === 'undefined') {
opt.continueOnError = false;
}
if (typeof opt.pipeStdout === 'undefined') {
opt.pipeStdout = false;
}
return map(function (file, cb){
var cmd = gutil.template(command, {file: file, options: opt});
exec(cmd, function (error, stdout, stderr) {
if (!opt.silent && stderr) {
gutil.log(stderr);
}
if (stdout) {
stdout = stdout.trim(); // Trim trailing cr-lf
}
if (!opt.silent && !opt.pipeStdout && stdout) {
gutil.log(stdout);
}
if (opt.pipeStdout) {
file.contents = new Buffer(stdout);
}
cb(opt.continueOnError ? null : error, file);
});
});
};