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.

273 lines (202 loc) 6.74 kB
(function() { var Configuration, Fs, Path, ProjectConfiguration, Util; Fs = require("fs"); Path = require("path"); Configuration = require("../configuration"); Util = require("../util"); /* The {@link ProjectConfiguration} class contains configuration of the project. @author Fabian M. <mail.fabianm@gmail.com> */ ProjectConfiguration = (function() { /* Constructs a new {@link ProjectConfiguration} instance. @since 1.0 @param workspace The workspace of this {@link ProjectConfiguration} instance. @param file The relative path to the project configuration file. */ function ProjectConfiguration(workspace, file) { this.workspace = workspace; this.file = file != null ? file : Configuration.DEFAULT_PROJECT_CONFIG_FILE; this.data = Configuration.SUPER_PROJECT_CONFIG; this.path = Path.join(this.getWorkspace().getPath(), this.file); this.data = Util.merge(this.data, this.read()); } /* Reads the package data file into a Javascript array. @since 0.0.1 */ ProjectConfiguration.prototype.read = function() { try { return JSON.parse(Fs.readFileSync(this.path, 'UTF-8')); } catch (e) { throw "Failed to load the project configuration file (" + this.path + ")\n" + e; } }; /* Updates the package data file. @param arr The array to update the package data file with. @since 0.0.1 */ ProjectConfiguration.prototype.update = function(arr) { if (arr == null) { arr = this.data; } return Fs.writeFileSync(this.path, JSON.stringify(arr)); }; /* Returns the path to the file that contains the project data. @since 0.1.1 @return The path to the file that contains the project data. */ ProjectConfiguration.prototype.getPath = function() { return this.path; }; /* Returns the {@link Workspace} of this {@link ProjectConfiguration} instance. @since 0.3.0 @return The {@link Workspace} of this {@link ProjectConfiguration} instance. */ ProjectConfiguration.prototype.getWorkspace = function() { return this.workspace; }; /* Returns the data that has been read. @since 0.1.1 @return The data that has been read. */ ProjectConfiguration.prototype.getData = function() { return this.data; }; /* Returns the name of this package. @since 0.3.0 @return The name of this package. */ ProjectConfiguration.prototype.getName = function() { return this.data.name; }; /* Returns the version of this package. @since 0.3.0 @return The version of this package. */ ProjectConfiguration.prototype.getVersion = function() { return this.data.version; }; /* Returns the dependencies of this package. @since 0.3.0 @return The dependencies of this package. */ ProjectConfiguration.prototype.getDependencies = function() { return this.data.dependencies; }; /* Returns the Kaffee configuration of this package. The Kaffee configuration of this package should look something like: configuration: plugins: "compiler" : module: "kaffee-coffeemaker" alias: ["coffeescript", "coffee-script"] "minify" : module: "kaffee-minify" "automatic-build-1": module: "kaffee-cyclus" goals: ["compile"] every: "hour" "automatic-build-2": module: "kaffee-cyclus" goals: ["compile"] every: "change" archtype: "kaffee-archtype-simple" @since 0.3.0 @return The Kaffee configuration of this package. */ ProjectConfiguration.prototype.getKaffeeConfiguration = function() { return (function(o) { /* Kaffee configuration */ var data; data = o.data.kaffee; /* Returns the plugins of this Kaffee project. @since 0.3.0 @return The plugins of this Kaffee project. */ this.getPlugins = function() { return data.plugins; }; /* Returns the directory structure of this Kaffee project. @since 0.3.0 @return The directory structure of this Kaffee project. */ this.getStructure = function() { /* Returns this directory structure as an array. @since 0.3.0 @return This directory structure as an array. */ this.toArray = function() { return data.structure; }; /* Returns the path of the directory with the specified name. @since 0.3.0 @return The path of the directory with the specified name. */ this.get = function(name) { return Path.join(o.getWorkspace().getPath(), this.toArray()[name]); }; return this; }; /* Returns the lifecycles of this Kaffee project. @since 0.3.0 @return The lifecycles of this Kaffee project. */ this.getLifecycles = function() { return data.lifecycles; }; /* Returns the parent project of this Kaffee project. @since 0.3.0 @return The parent project of this Kaffee project. */ this.getParent = function() { return data.parent; }; /* Returns the childs of this Kaffee project. @since 0.3.0 @return The childs of this Kaffee project. */ this.getModules = function() { return data.modules; }; /* Returns the archtype of this Kaffee project. @since 0.3.0 @return The archtype of this Kaffee project. */ this.getArchtype = function() { return data.archtype; }; return this; })(this); }; /* Determines if the configuration file exists. @since 0.0.1 @return <code>true</code> if the package.json exists, <code>false</code> otherwise. */ ProjectConfiguration.prototype.exists = function() { return Fs.existsSync(this.path); }; return ProjectConfiguration; })(); module.exports = ProjectConfiguration; }).call(this);