UNPKG

kaffee

Version:

Kaffee is a software project management tool similar to Maven and is written in Coffeescript. Kaffee allows you to compile, test, minify and many other tasks to make building your application simple and fun again.

294 lines (232 loc) 7.99 kB
(function() { var Configuration, EventManager, Plugin, Project, ProjectConfiguration, Request, Result, Util, Workspace; ProjectConfiguration = require("./configuration"); Workspace = require("./workspace"); Plugin = require("../plugin/plugin"); EventManager = require("../event/manager"); Result = require("../execution/result"); Request = require("../execution/request"); Configuration = require("../configuration"); Util = require("../util"); /* The {@link Project} class represents a Kaffee project. @author Fabian M. <mail.fabianm@gmail.com> */ Project = (function() { /* Constructs a new {@link Project} instance. @since 0.0.1 @param configuration The {@link ProjectConfiguration} of this project. @param parent The parent {@link Project} of this {@link Project}. */ function Project(configuration, parent) { this.configuration = configuration; this.parent = parent; this.plugins = []; this.childs = []; this.event = new EventManager("project", null, this); this.event.setParent(parent != null ? parent.getEventManager() : void 0); this.event.setName("project-" + this.configuration.getName()); } /* Returns the parent {@link Project} instance. @since 0.3.0 @return The parent {@link Project} instance. */ Project.prototype.getParent = function() { return this.parent; }; /* Loads this {@link Project}. @since 0.2.1 */ Project.prototype.load = function() { var archtype, child, configuration, name, plugin, project, workspace, _i, _len, _ref, _ref1; this.event.fire("enter", this); try { _ref = this.configuration.getKaffeeConfiguration().getModules(); for (_i = 0, _len = _ref.length; _i < _len; _i++) { child = _ref[_i]; if (typeof child !== 'string') { continue; } workspace = new Workspace(child); if (workspace.getPath() === this.configuration.getWorkspace().getPath()) { continue; } project = new Project(new ProjectConfiguration(workspace), this); project.load(); this.childs.push(project); } this.plugins.push(new (require("../plugin/default"))(this)); _ref1 = this.configuration.getKaffeeConfiguration().getPlugins(); for (name in _ref1) { configuration = _ref1[name]; plugin = new Plugin(name, this, configuration); if (!plugin.load()) { return; } this.plugins.push(plugin); } archtype = this.configuration.getKaffeeConfiguration().getArchtype(); plugin = this.getPlugin(archtype); if (plugin && plugin.hasArchtype()) { this.configuration.data = Util.merge(plugin.getArchtype(), this.configuration.data); } else if (archtype) { throw "Invalid archtype \"" + archtype + "\""; } } catch (e) { this.event.getLogger().error(e); return; } this.event.fire("leave", this); return true; }; /* Returns the {@link EventManager} of this {@link Project}. @since 0.3.0 @return The {@link EventManager} of this {@link Project}. */ Project.prototype.getEventManager = function() { return this.event; }; /* Returns the {@link ProjectConfiguration} of this {@link Project}. @since 0.2.1 @return The {@link ProjectConfiguration} of this {@link Project}. */ Project.prototype.getConfiguration = function() { return this.configuration; }; /* Returns the {@link Plugin}s of this {@link Project}. @since 0.2.1 @return The {@link Plugin}s of this {@link Project}. */ Project.prototype.getPlugins = function() { if (this.getParent()) { return this.plugins.concat(this.getParent().getPlugins()); } else { return this.plugins; } }; /* Returns a {@link Plugin} of this {@link Project}. @since 0.3.0 @param name The name of the {@link Plugin} to get. @return The {@link Plugin}. */ Project.prototype.getPlugin = function(name) { var plugin, _i, _len, _ref; _ref = this.getPlugins(); for (_i = 0, _len = _ref.length; _i < _len; _i++) { plugin = _ref[_i]; if (plugin.getName() === name || plugin.getAliases().indexOf(name) !== -1) { return plugin; } } }; /* Determines if this {@link Plugin} has a {@link Goal}. @since 0.2.1 @param name The name of the {@link Plugin}. */ Project.prototype.hasPlugin = function(name) { return !!this.getPlugin(name); }; /* Returns the lifecycles of this {@link Plugin}. @since 0.3.0 @return The lifecycles of this {@link Plugin}. */ Project.prototype.getLifecycles = function() { var c, key, value, _ref, _ref1, _ref2; c = (_ref = this.getParent()) != null ? (_ref1 = _ref.getLifecycles()) != null ? _ref1.slice(0) : void 0 : void 0; c || (c = []); _ref2 = this.getConfiguration().getKaffeeConfiguration().getLifecycles(); for (key in _ref2) { value = _ref2[key]; c[key] = value; } return c; }; /* Returns the child {@link Project}s of this {@link Project}. @since 0.3.0 @return The child {@link Project}s of this {@link Project}. */ Project.prototype.getChilds = function() { return this.childs; }; /* Executes a {@link ExecutionRequest}. @since 0.1.1 @param request The {@link ExecutionRequest} instance. @return The {@link ExecutionResult} instance. */ Project.prototype.execute = function(request) { var child, goal, result, _i, _j, _len, _len1, _ref, _ref1; request.time = Date.now(); result = new Result(this); try { _ref = request.getGoals(); for (_i = 0, _len = _ref.length; _i < _len; _i++) { goal = _ref[_i]; result.addChild(this.attainGoal(goal)); } _ref1 = this.childs; for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { child = _ref1[_j]; result.addChild(child.execute(request)); } } catch (e) { this.event.getLogger().error(e); return; } result.time = Date.now(); return result; }; /* Attains a {@link Goal}. @since 0.3.0 @param name The name of the goal to execute. @param request The {@link ExecutionRequest} instance. @return The result */ Project.prototype.attainGoal = function(name, request) { var goal, lifecycle, plugin, split, _i, _len, _results; if (!name) { return; } if (name.split(':').length > 1) { split = name.split(':'); plugin = split[0]; goal = split[1]; if (!this.hasPlugin(plugin)) { this.event.getLogger().error("No such plugin \"" + plugin + "\""); return; } if (!this.getPlugin(plugin).hasGoal(goal)) { this.event.getLogger().error("Plugin " + plugin + " doesn't have goal \"" + goal + "\""); return; } return this.getPlugin(plugin).getGoal(goal).attain(request); } lifecycle = this.getLifecycles()[name]; if (!lifecycle) { this.event.getLogger().error("Unknown lifecycle \"" + name + "\""); return; } _results = []; for (_i = 0, _len = lifecycle.length; _i < _len; _i++) { goal = lifecycle[_i]; if (goal !== name) { _results.push(this.attainGoal(goal)); } } return _results; }; return Project; })(); module.exports = Project; }).call(this);