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.

149 lines (108 loc) 3.37 kB
(function() { var EventManager, Goal, Result; EventManager = require('../event/manager'); Result = require('../execution/result'); /* A {@link Goal} instance represents a Kaffee goal. @author Fabian M. <mail.fabianm@gmail.com> */ Goal = (function() { /* Constructs a new {@link Goal}. @since 0.2.1 @param plugin The {@link Plugin} of this {@link Goal}. @param name The name of this {@link Goal}. @param call The function of this {@link Goal}. */ function Goal(plugin, name, call) { this.plugin = plugin; this.name = name; this.call = call; this.event = new EventManager("goal-" + name, plugin.getEventManager(), this); } /* Returns the {@link Project} of this {@link Goal}. @since 0.3.0 @return The {@link Project} of this {@link Goal}. */ Goal.prototype.getProject = function() { return this.getPlugin().getProject(); }; /* Returns the name of this {@link Goal}. @since 0.2.1 @return The name of this {@link Goal}. */ Goal.prototype.getName = function() { return this.name; }; /* Returns the {@link Plugin} of this {@link Goal}. @since 0.2.1 @return The {@link Plugin} of this {@link Goal}. */ Goal.prototype.getPlugin = function() { return this.plugin; }; /* Returns the {@link EventManager} of this {@link Goal}. @since 0.3.0 @return The {@link EventManager} of this {@link Goal}. */ Goal.prototype.getEventManager = function() { return this.event; }; /* Returns the logging object of this {@link Goal}. @since 0.3.1 @return The logging object of this {@link Goal}. */ Goal.prototype.getLogger = function() { return this.getEventManager().getLogger(); }; /* The {@link #dependsOn} methods should be called if this {@link Goal} dependends on another {@link Goal}. @since 0.3.0 @param name The name of the {@link Goal} to depend on. @param request The {@link ExecutionRequest} instance. @return The result. */ Goal.prototype.dependsOn = function(name, request) { if (!name) { return; } return typeof name.attain === "function" ? name.attain(request) : void 0; return this.getPlugin().getProject().attainGoal(name, request); }; /* Attains this {@link Goal}. @since 0.3.0 @param request The {@link ExecutionRequest} instance. @return The result. */ Goal.prototype.attain = function(request) { var result; result = new Result(this.getProject()); this.event.fire("attain", this); this.event.on("*log", function(log) { return result.getLogs().push(log); }); this.logger = this.getLogger(); try { if (!this.call) { throw new Error("Invalid Goal"); } result.setMessage(this.call.call(this, request)); } catch (e) { this.getLogger().error(e); } result.time = Date.now(); this.logger = void 0; this.event.fire("attained", this, result); return result; }; return Goal; })(); module.exports = Goal; }).call(this);