@mihon/spacejam
Version:
Run your meteor package tinytests and mocha tests from the command line with phantomjs.
128 lines (104 loc) • 3.63 kB
JavaScript
// Generated by CoffeeScript 1.8.0
(function() {
var CLI, Meteor, Spacejam, expect, fs, path, _,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
require('./log');
fs = require("graceful-fs");
path = require("path");
_ = require("underscore");
expect = require("chai").expect;
Spacejam = require('./Spacejam');
Meteor = require('./Meteor');
require.extensions['.txt'] = function(module, filename) {
return module.exports = fs.readFileSync(filename, 'utf8');
};
CLI = (function() {
var instance;
instance = null;
CLI.get = function() {
return instance != null ? instance : instance = new CLI();
};
CLI.prototype.commands = {
"test": "testApp",
"test-packages": "testPackages"
};
CLI.prototype.options = null;
CLI.prototype.spacejam = null;
CLI.prototype.pidPath = null;
function CLI() {
this.onProcessExit = __bind(this.onProcessExit, this);
this.spacejam = new Spacejam();
log.debug("CLI.constructor()");
process.on('SIGPIPE', (function(_this) {
return function(code) {
var _ref;
log.info("spacejam: Received a SIGPIPE signal. Killing all child processes...");
return (_ref = _this.spacejam) != null ? _ref.killChildren() : void 0;
};
})(this));
}
CLI.prototype.onProcessExit = function(code) {
var err;
log.info("spacejam: spacejam is exiting with code " + code + ", deleting pid file.");
try {
return fs.unlinkSync(this.pidPath);
} catch (_error) {
err = _error;
log.trace(err);
return log.error("spacejam: Error deleting pid file " + this.pidPath, err);
}
};
CLI.prototype.exec = function() {
var command, err, version;
log.debug("CLI.exec()");
expect(this.options, "You can only call CLI.exec() once").to.be["null"];
this.options = require("rc")("spacejam", {});
command = this.options._[0];
log.debug("command: " + command);
if (command === 'help') {
this.printHelp();
process.exit(0);
} else if (command === 'package-version') {
version = Meteor.getPackageVersion();
console.log(version);
process.exit(0);
}
if (!_.has(this.commands, command)) {
if (command) {
log.error("spacejam: Error: \n'" + command + "' is not a recognized command\n");
}
return this.printHelp();
}
this.options.packages = this.options._.slice(1);
this.options.command = command;
delete this.options._;
log.debug("CLI.exec() options:", this.options);
this.spacejam.on('done', (function(_this) {
return function(code) {
var exitMsg;
if (Spacejam.DONE_MESSAGE[code] != null) {
exitMsg = "spacejam: " + Spacejam.DONE_MESSAGE[code] + ". Exiting.";
} else {
exitMsg = "spacejam: Unknown error with exit code '" + code + "'. Exiting.";
}
log.error(exitMsg);
return process.exit(code);
};
})(this));
try {
return this.spacejam.runTests(command, this.options);
} catch (_error) {
err = _error;
console.trace(err);
log.error("spacejam: Usage or initialization error. Exiting.");
return process.exit(1);
}
};
CLI.prototype.printHelp = function() {
log.debug("CLI.printHelp()");
return process.stdout.write(require('../bin/help.txt'));
};
return CLI;
})();
module.exports = CLI;
}).call(this);