-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
130 lines (119 loc) · 11 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Generated by CoffeeScript 1.9.3
var exe, exec, handlers, index, merge, options, run, spawn,
slice = [].slice;
require("source-map-support").install();
exec = require("child_process").exec;
spawn = require('cross-spawn-async');
merge = require("lodash.merge");
options = require("./options");
exe = function(cmd, opts, cb) {
return exec(cmd, opts, function(err, stdout, stderr) {
if (stderr) {
process.stderr.write(stderr);
}
if (err !== null) {
return console.trace(JSON.stringify(err, null, 2));
} else if (cb != null) {
return cb(stdout);
} else {
return process.stdout.write(stdout);
}
});
};
handlers = function(opts) {
var defaults;
defaults = {
stdout: function(data) {
return process.stdout.write(data);
},
stderr: function(data) {
return process.stderr.write(data);
},
error: function(err, context) {
return console.trace(JSON.stringify(err, null, 2));
},
close: function(code, context) {
if (code !== 0) {
return console.log("This `" + context.cmd + "` process exited with " + code + ".");
}
}
};
if (opts != null) {
return merge({}, defaults, opts);
} else {
return defaults;
}
};
run = function(cmd, opts) {
var chips, cmdArgs, command, context, handles;
if (opts == null) {
opts = {};
}
if (typeof cmd !== "string") {
console.log("Expecting command string, instead got:");
console.log(cmd);
throw new Error("Wrong command type: '" + (typeof cmd) + "'.");
}
cmdArgs = cmd.split(/\s+/);
command = cmdArgs.shift();
handles = handlers(opts.childish);
context = {
"cmd": cmd
};
chips = spawn(command, cmdArgs, opts);
chips.stdout.on("data", function(data) {
return handles.stdout(data);
});
chips.stderr.on("data", function(data) {
return handles.stderr(data);
});
chips.on("error", function(err) {
return handles.error(err, context);
});
return chips.on("close", function(code) {
return handles.close(code, context);
});
};
index = function() {
var args, cmd, n;
cmd = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
n = args.length;
if (n > 0) {
if (typeof args[n - 1] === "function") {
if (n === 1) {
return exe(cmd, {}, args[0]);
} else {
return exe(cmd, args[0], args[n - 1]);
}
} else {
if (args[0].childish != null) {
args[0].childish = options(args[0].childish);
}
return run(cmd, args[0]);
}
} else {
return run(cmd);
}
};
module.exports = function() {
var rest, what;
what = arguments[0], rest = 2 <= arguments.length ? slice.call(arguments, 1) : [];
if (arguments.length === 1 && typeof what === "object") {
return function() {
var args, cmd;
cmd = arguments[0], args = 2 <= arguments.length ? slice.call(arguments, 1) : [];
if (args.length) {
if (typeof args[args.length - 1] === "function") {
return index.apply(null, arguments);
} else {
return index.call(null, cmd, merge({}, what, args[0]));
}
} else {
return index.call(null, cmd);
}
};
} else {
return index.apply(null, arguments);
}
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguY29mZmVlIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiaW5kZXguY29mZmVlIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxJQUFBLHNEQUFBO0VBQUE7O0FBQUEsT0FBQSxDQUFRLG9CQUFSLENBQTZCLENBQUMsT0FBOUIsQ0FBQTs7QUFFQSxJQUFBLEdBQU8sT0FBQSxDQUFRLGVBQVIsQ0FBd0IsQ0FBQzs7QUFDaEMsS0FBQSxHQUFRLE9BQUEsQ0FBUSxtQkFBUjs7QUFDUixLQUFBLEdBQVEsT0FBQSxDQUFRLGNBQVI7O0FBQ1IsT0FBQSxHQUFVLE9BQUEsQ0FBUSxXQUFSOztBQUdWLEdBQUEsR0FBTSxTQUFDLEdBQUQsRUFBTSxJQUFOLEVBQVksRUFBWjtTQUNKLElBQUEsQ0FBSyxHQUFMLEVBQV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