kaffee-cli
Version:
Command line interface for the Kaffee library.
118 lines (96 loc) • 3.43 kB
JavaScript
(function() {
var Cli, Commander, Configuration, Kaffee, Project, ProjectConfiguration, Request, Winston, Workspace;
Commander = require('commander');
Winston = require('winston');
Kaffee = require('kaffee');
Configuration = Kaffee.Configuration;
Workspace = Kaffee.project.Workspace;
ProjectConfiguration = Kaffee.project.ProjectConfiguration;
Project = Kaffee.project.Project;
Request = Kaffee.execution.Request;
/*
Command line interface for the Kaffee library.
@version 0.3.0
@author Fabian M. <mail.fabianm@gmail.com>
*/
Cli = (function() {
function Cli() {}
/*
Runs Kaffee using command line arguments.
@since 0.2.1
@param args The command line arguments.
*/
Cli.run = function(args) {
var config, goals, logger, project, result, workspace;
logger = new Winston.Logger({
transports: [
new Winston.transports.Console({
colorize: true
})
]
});
goals = [];
Commander.version(Configuration.VERSION).usage(Configuration.NAME + " [options] [goal(s)]");
Commander.option("-w, --workspace <path>", "Changes the working directory.", ".");
Commander.option("-c, --config <path>", "Sets the path to the package.json file.", void 0);
Commander.option("-f, --force", "Forces Kaffee.", Boolean, false);
Commander.command('*').action(function() {
var a;
a = goals.concat(Array.prototype.slice.call(arguments));
a.pop();
return goals = a;
});
Commander.parse(args);
try {
workspace = new Workspace(Commander.workspace);
config = new ProjectConfiguration(workspace, Commander.config);
} catch (e) {
return !logger.error(e);
}
project = new Project(config);
project.getEventManager().on("attain", function(goal) {
return console.log(">> Running goal \"" + (goal.getPlugin().getName()) + ":" + (goal.getName()) + "\"");
});
project.getEventManager().on("attained", function(goal, result) {
var errors, log, warnings;
errors = (function() {
var _i, _len, _ref, _results;
_ref = result.getLogs();
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
log = _ref[_i];
if (log.getLevel().value >= 3) {
_results.push(log);
}
}
return _results;
})();
warnings = (function() {
var _i, _len, _ref, _results;
_ref = result.getLogs();
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
log = _ref[_i];
if (log.getLevel().value === 2) {
_results.push(log);
}
}
return _results;
})();
return console.log(">> Finished with " + errors.length + " error(s) and " + warnings.length + " warning(s)");
});
project.getEventManager().on("*log", function(log) {
if (log.getLevel().value >= 3) {
return logger.error(log.getStack());
}
return logger.log(log.getLevel().name, log.getMessage());
});
if (!project.load()) {
return;
}
return result = project.execute(new Request(goals, Commander.force));
};
return Cli;
})();
module.exports = Cli;
}).call(this);