UNPKG

@mihon/spacejam

Version:

Run your meteor package tinytests and mocha tests from the command line with phantomjs.

144 lines (124 loc) 4.89 kB
// Generated by CoffeeScript 1.8.0 (function() { var ChildProcess, Pipe, expect, path; require('./log'); expect = require("chai").expect; Pipe = require("./Pipe"); path = require('path'); ChildProcess = (function() { ChildProcess._spawn = require("child_process").spawn; ChildProcess._exec = require("child_process").exec; ChildProcess.prototype.child = null; ChildProcess.prototype.descendants = []; ChildProcess.prototype.pipe = null; ChildProcess.prototype.command = null; ChildProcess.prototype.killed = false; function ChildProcess() { log.debug("ChildProcess.constructor()"); } ChildProcess.prototype.exec = function(command, options, cb) { var innerCB; log.debug("ChildProcess.exec()", arguments); expect(this.child).to.be["null"]; expect(command).to.be.a('string').that.is.ok; if (options != null) { expect(options).to.be.an('object'); } this.command = command.split(' ', 1)[0]; expect(this.command).to.be.a('string').that.is.ok; innerCB = (function(_this) { return function(err, stdout, stderr) { _this.killed = true; if ((err != null ? err.code : void 0) != null) { log.error("child_process.exec: Error: " + _this.command + " exit code: " + err.code); } if ((err != null ? err.signal : void 0) != null) { log.error("child_process.exec: Error: " + _this.command + " termination signal: " + err.signal); } if (cb != null) { return cb(err, stdout, stderr); } }; })(this); if (options != null) { this.child = ChildProcess._exec(command, options, innerCB); } else { this.child = ChildProcess._exec(command, innerCB); } this.child.stdout.pipe(process.stdout); return this.child.stderr.pipe(process.stderr); }; ChildProcess.prototype.spawn = function(command, args, options, pipeClass, pipeClassOptions) { if (args == null) { args = []; } if (options == null) { options = {}; } if (pipeClass == null) { pipeClass = void 0; } if (pipeClassOptions == null) { pipeClassOptions = void 0; } log.debug("ChildProcess.spawn()", command, args); expect(this.child, "ChildProcess is already running").to.be["null"]; expect(command, "Invalid @command argument").to.be.a("string"); expect(args, "Invalid @args argument").to.be.an("array"); expect(options, "Invalid @options").to.be.an("object"); if (pipeClass != null) { expect(pipeClass, "Invalid pipeClass").to.be.a('function'); } if (pipeClassOptions != null) { expect(pipeClassOptions, "Invalid pipeClassOptions").to.be.an('object'); } this.command = path.basename(command); log.info("spacejam: spawning " + this.command); process.on('exit', (function(_this) { return function(code) { log.debug("ChildProcess.process.on 'exit': @command=" + _this.command + " @killed=" + _this.killed + " code=" + code); return _this.kill(); }; })(this)); this.child = ChildProcess._spawn(command, args, options); if (pipeClass) { this.pipe = new pipeClass(this.child.stdout, this.child.stderr, pipeClassOptions); } else { this.pipe = new Pipe(this.child.stdout, this.child.stderr); } return this.child.on("exit", (function(_this) { return function(code, signal) { log.debug("ChildProcess.process.on 'exit': @command=" + _this.command + " @killed=" + _this.killed + " code=" + code + " signal=" + signal); _this.killed = true; if (code != null) { return log.info("spacejam: " + command + " exited with code: " + code); } else if (signal != null) { return log.info("spacejam: " + command + " killed with signal: " + signal); } else { return log.error("spacejam: " + command + " exited with arguments: " + arguments); } }; })(this)); }; ChildProcess.prototype.kill = function(signal) { var err, _ref; if (signal == null) { signal = "SIGTERM"; } log.debug("ChildProcess.kill() signal=" + signal + " @command=" + this.command + " @killed=" + this.killed); if (this.killed) { return; } log.info("spacejam: killing", this.command); this.killed = true; try { return (_ref = this.child) != null ? _ref.kill(signal) : void 0; } catch (_error) { err = _error; return log.warn("spacejam: Error: While killing " + this.command + " with pid " + this.child.pid + ":\n", err); } }; return ChildProcess; })(); module.exports = ChildProcess; }).call(this);