fluentnode
Version:
Fluent apis for node (based on the concepts used in C#'s FluentSharp
68 lines (62 loc) • 1.94 kB
JavaScript
// Generated by CoffeeScript 1.12.7
(function() {
var child_process,
slice = [].slice;
child_process = require('child_process');
String.prototype.start_Process = function() {
var args;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
if (args == null) {
args = [];
}
if (args.first() instanceof Array) {
args = args.first();
}
return child_process.spawn(this._str(), args);
};
String.prototype.start_Process_Redirect_Console = function() {
var args, childProcess;
args = 1 <= arguments.length ? slice.call(arguments, 0) : [];
if (args == null) {
args = [];
}
childProcess = this.start_Process(args);
childProcess.stdout.on('data', function(data) {
return console.log(data._str().trim());
});
childProcess.stderr.on('data', function(data) {
return console.log(data._str().trim());
});
return childProcess;
};
String.prototype.start_Process_Capture_Console_Out = function() {
var args, call_Callback, callback, childProcess, closed, consoleData, exited, i;
args = 2 <= arguments.length ? slice.call(arguments, 0, i = arguments.length - 1) : (i = 0, []), callback = arguments[i++];
closed = false;
exited = false;
call_Callback = function() {
if (closed && exited) {
return process.nextTick(function() {
return callback(consoleData);
});
}
};
consoleData = "";
childProcess = this.start_Process(args);
childProcess.stdout.on('data', function(data) {
return consoleData += data;
});
childProcess.stderr.on('data', function(data) {
return consoleData += data;
});
childProcess.on('close', function() {
closed = true;
return call_Callback();
});
childProcess.on('exit', function() {
exited = true;
return call_Callback();
});
return childProcess;
};
}).call(this);