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.
253 lines (177 loc) • 5.72 kB
JavaScript
(function() {
var EventManager, Goal, Path, Plugin, Request, Result;
Path = require('path');
Goal = require('./goal');
Request = require('../execution/request');
Result = require('../execution/result');
EventManager = require('../event/manager');
/*
A {@link Plugin} instance represents a Kaffee plugin.
@author Fabian M. <mail.fabianm@gmail.com>
*/
Plugin = (function() {
/*
Constructs a new {@link Plugin} instance.
@since 0.2.1
@param name The name of this {@link Plugin}.
@param project The {@link Project} of this {@link Plugin}.
@param configuration The configuration of this {@link Plugin}.
*/
function Plugin(name, project, configuration) {
this.name = name;
this.project = project;
this.configuration = configuration != null ? configuration : {};
this.goals = [];
this.event = new EventManager("plugin-" + this.name, project.getEventManager(), this);
}
/*
Loads this plugin.
@since 0.3.0
*/
Plugin.prototype.load = function() {
var obj;
this.event.fire("enter", this);
this.logger = this.getLogger();
try {
module.paths = process.mainModule.paths.concat(module.paths, [Path.join(this.project.getConfiguration().getWorkspace().getPath(), "node_modules")]);
obj = require(this.getModule());
if (typeof obj !== 'function') {
throw "Module " + (this.getModule()) + " isn't a valid module.";
}
obj.call(this, this.configuration);
} catch (e) {
this.event.getLogger().error(e);
return;
}
this.logger = void 0;
this.event.fire("leave", this);
return true;
};
/*
Returns the name of the module of this {@link Plugin}.
@since 0.3.3
@return The name of the module of this {@link Plugin}.
*/
Plugin.prototype.getModule = function() {
return this.configuration.module || this.name;
};
/*
Returns the aliases of this {@link Plugin}.
@since 0.3.3
@return The aliases of this {@link Plugin}.
*/
Plugin.prototype.getAliases = function() {
return this.configuration.alias || [];
};
/*
Returns the name of this {@link Plugin}.
@since 0.2.1
@return The name of this {@link Plugin}.
*/
Plugin.prototype.getName = function() {
return this.name;
};
/*
Returns the {@link Project} of this {@link Plugin}.
@since 0.2.1
@return The {@link Project} of this {@link Plugin}.
*/
Plugin.prototype.getProject = function() {
return this.project;
};
/*
Returns the configuration of this {@link Plugin}.
@since 0.2.1
@return The configuration of this {@link Plugin}.
*/
Plugin.prototype.getConfiguration = function() {
return this.configuration;
};
/*
Returns the {@link Goal}s of this {@link Plugin}.
@since 0.2.1
@return The {@link Goal}s of this {@link Plugin}.
*/
Plugin.prototype.getGoals = function() {
return this.goals;
};
/*
Returns the {@link EventManager} of this {@link Plugin}.
@since 0.3.0
@return The {@link EventManager} of this {@link Plugin}.
*/
Plugin.prototype.getEventManager = function() {
return this.event;
};
/*
Returns the logging object of this {@link Plugin}.
@since 0.3.1
@return The logging object of this {@link Plugin}.
*/
Plugin.prototype.getLogger = function() {
return this.getEventManager().getLogger();
};
/*
Returns a {@link Goal} of this {@link Plugin}.
@since 0.3.0
@param name The name of the goal to get.
@return The {@link Goal}.
*/
Plugin.prototype.getGoal = function(name) {
var goal, _i, _len, _ref;
_ref = this.goals;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
goal = _ref[_i];
if (goal.getName() === name) {
return goal;
}
}
};
/*
Determines if this {@link Plugin} has a {@link Goal}.
@since 0.2.1
@param name The name of the {@link Goal}.
@return <code>true</code> if this {@link Plugin} has this {@link Goal}, <code>false</code> otherwise.
*/
Plugin.prototype.hasGoal = function(name) {
return !!this.getGoal(name);
};
/*
Determines if this {@link Plugin} has defined an archtype.
@since 0.3.3
@return <code>true</code> if this {@link Plugin} has defined an archtype, <code>false</code> otherwise.
*/
Plugin.prototype.hasArchtype = function() {
return !!this.archtype;
};
/*
Returns the archtype of this {@link Plugin}.
@since 0.3.3
@return The archtype of this {@link Plugin} if it has one.
*/
Plugin.prototype.getArchtype = function() {
return this.archtype;
};
/*
Defines an archtype.
@since 0.3.3
@param archtype The archtype to define.
*/
Plugin.prototype.archtype = function(archtype) {
if (typeof archtype === 'object') {
return this.archtype = archtype;
}
};
/*
Registers a goal.
@since 0.3.0
@param name The name of the goal to register.
@param call The function of this goal.
*/
Plugin.prototype.register = function(name, call) {
return this.goals.push(new Goal(this, name, call));
};
return Plugin;
})();
module.exports = Plugin;
}).call(this);