diff --git a/src/main/kaffee/configuration.coffee b/src/main/kaffee/configuration.coffee index 0970c55..3af0790 100644 --- a/src/main/kaffee/configuration.coffee +++ b/src/main/kaffee/configuration.coffee @@ -6,29 +6,7 @@ ### class Configuration @NAME: "Kaffee" - @VERSION: "0.3.2" - - ### - Merges two objects into one. - - @since 0.3.0 - @param o Original object. - @param a The object to merge it with. - @return The result. - ### - @merge = (o, a) -> - r = [] - for key, value of o - r[key] = value - return r if typeof o != 'object' || typeof a != 'object' - for key, value of a - if typeof o[key] == 'object' - r[key] = @merge(o[key], value) - else if typeof o[key] == 'array' - r[key] = o[key].concat value - else - r[key] = value - r + @VERSION: "0.3.3" ### Default filename of the project configuration file. @@ -74,22 +52,8 @@ class Configuration parent: "" ### - Childs of this project. + Child projects of this project. ### modules: [] - ### - Currently available archtypes. - ### - @ARCHTYPES: - "default": @SUPER_PROJECT_CONFIG - "kaffee-coffeemaker": @merge(@SUPER_PROJECT_CONFIG, { - kaffee: - plugins: - "kaffee-coffeemaker" : {} - lifecycles: - "compile" : ["kaffee-coffeemaker:compile"] - "test" : ["kaffee-coffeemaker:test"] - }) - module.exports = Configuration; diff --git a/src/main/kaffee/execution/request.coffee b/src/main/kaffee/execution/request.coffee index 2937c13..71cb400 100644 --- a/src/main/kaffee/execution/request.coffee +++ b/src/main/kaffee/execution/request.coffee @@ -21,8 +21,8 @@ class ExecutionRequest ### addGoal: (goal) -> return if not goal - this.goals.push goal if typeof goal is 'string' - this.goals.concat goal if typeof goal is 'array' + @goals.push goal if typeof goal is 'string' + @goals.concat goal if typeof goal is 'array' ### Returns the goals of this {@link ExecutionRequest}. @@ -30,7 +30,7 @@ class ExecutionRequest @since 0.2.1 @return The goals of this {@link ExecutionRequest}. ### - getGoals: -> this.goals + getGoals: -> @goals ### Sets the force field of this {@link ExecutionRequest}. @@ -46,5 +46,5 @@ class ExecutionRequest @since 0.2.1 @return true if Kaffee is forced, false otherwise. ### - isForced: -> this.force + isForced: -> @force module.exports = ExecutionRequest diff --git a/src/main/kaffee/execution/result.coffee b/src/main/kaffee/execution/result.coffee index 73bee74..b1e4897 100644 --- a/src/main/kaffee/execution/result.coffee +++ b/src/main/kaffee/execution/result.coffee @@ -13,8 +13,8 @@ class Result @param parent The parent {@link Result} of this {@link Result}. ### constructor: (@project) -> - this.childs = [] - this.logs = [] + @childs = [] + @logs = [] ### Returns the {@link LogEvent}s of this {@link Result} instance. @@ -22,7 +22,7 @@ class Result @since 0.3.0 @return The {@link LogEvent}s of this {@link Result} instance. ### - getLogs: -> this.logs + getLogs: -> @logs ### Returns the {@link Project} of this {@link ProjectResult} instance. @@ -30,7 +30,7 @@ class Result @since 0.2.1 @return The {@link Project} of this {@link ProjectResult} instance. ### - getProject: -> this.project + getProject: -> @project ### Adds a child {@link Result} to this {@link Result} instance. @@ -39,9 +39,9 @@ class Result @param child The {@link Result} to add. ### addChild: (child) -> - return this.childs if not child - return this.childs.push child if child instanceof Result - return this.childs = this.childs.concat child + return @childs if not child + return @childs.push child if child instanceof Result + return @childs = @childs.concat child ### Returns the child {@link Result}s of this {@link Result} instance. @@ -49,7 +49,7 @@ class Result @since 0.2.1 @return The child {@link Result}s of this {@link Result} instance. ### - getChilds: -> this.childs + getChilds: -> @childs ### Sets the result message of this {@link Result} instance. @@ -65,6 +65,6 @@ class Result @since 0.2.1 @return The result message of this {@link Result} instance. ### - getMessage: -> this.message + getMessage: -> @message module.exports = Result diff --git a/src/main/kaffee/plugin/goal.coffee b/src/main/kaffee/plugin/goal.coffee index e691d9f..485e93e 100644 --- a/src/main/kaffee/plugin/goal.coffee +++ b/src/main/kaffee/plugin/goal.coffee @@ -14,7 +14,7 @@ class Goal @param name The name of this {@link Goal}. @param call The function of this {@link Goal}. ### - constructor: (@plugin, @name, @call) -> this.event = new EventManager "goal-#{ name }", plugin.getEventManager(), this + constructor: (@plugin, @name, @call) -> @event = new EventManager "goal-#{ name }", plugin.getEventManager(), this ### Returns the {@link Project} of this {@link Goal}. @@ -22,7 +22,7 @@ class Goal @since 0.3.0 @return The {@link Project} of this {@link Goal}. ### - getProject: -> this.getPlugin().getProject() + getProject: -> @getPlugin().getProject() ### Returns the name of this {@link Goal}. @@ -30,7 +30,7 @@ class Goal @since 0.2.1 @return The name of this {@link Goal}. ### - getName: -> this.name + getName: -> @name ### Returns the {@link Plugin} of this {@link Goal}. @@ -38,7 +38,7 @@ class Goal @since 0.2.1 @return The {@link Plugin} of this {@link Goal}. ### - getPlugin: -> this.plugin + getPlugin: -> @plugin ### Returns the {@link EventManager} of this {@link Goal}. @@ -46,7 +46,7 @@ class Goal @since 0.3.0 @return The {@link EventManager} of this {@link Goal}. ### - getEventManager: -> this.event + getEventManager: -> @event ### Returns the logging object of this {@link Goal}. @@ -54,7 +54,7 @@ class Goal @since 0.3.1 @return The logging object of this {@link Goal}. ### - getLogger: -> this.getEventManager().getLogger() + getLogger: -> @getEventManager().getLogger() ### The {@link #dependsOn} methods should be called if @@ -68,7 +68,7 @@ class Goal dependsOn: (name, request) -> return unless name return name.attain? request - this.getPlugin().getProject().attainGoal name, request + @getPlugin().getProject().attainGoal name, request ### Attains this {@link Goal}. @@ -78,17 +78,18 @@ class Goal @return The result. ### attain: (request) -> - result = new Result this.getProject() - this.event.fire "attain", this - this.event.on "*log", (log) -> result.getLogs().push log - this.logger = this.getLogger() + result = new Result @getProject() + @event.fire "attain", this + @event.on "*log", (log) -> result.getLogs().push log + @logger = @getLogger() try - throw new Error "Invalid Goal" unless this.call - result.setMessage this.call.call(this, request) + throw new Error "Invalid Goal" unless @call + result.setMessage @call.call(this, request) catch e - this.getLogger().error e - this.logger = undefined - this.event.fire "attained", this, result + @getLogger().error e + result.time = Date.now() + @logger = undefined + @event.fire "attained", this, result result module.exports = Goal diff --git a/src/main/kaffee/plugin/plugin.coffee b/src/main/kaffee/plugin/plugin.coffee index 67e4cd2..d0044b1 100644 --- a/src/main/kaffee/plugin/plugin.coffee +++ b/src/main/kaffee/plugin/plugin.coffee @@ -33,8 +33,8 @@ class Plugin try # Modify path. module.paths = process.mainModule.paths.concat module.paths, [Path.join @project.getConfiguration().getWorkspace().getPath(), "node_modules"] - obj = require @name - throw "Plugin " + @name + " is invalid." if typeof obj != 'function' + obj = require @getModule() + throw "Module #{ @getModule() } isn't a valid module." if typeof obj isnt 'function' obj.call this, @configuration catch e @event.getLogger().error e @@ -43,6 +43,21 @@ class Plugin @event.fire "leave", this 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}. + ### + getModule: -> @configuration.module or @name + + ### + Returns the aliases of this {@link Plugin}. + + @since 0.3.3 + @return The aliases of this {@link Plugin}. + ### + getAliases: -> @configuration.alias or [] ### Returns the name of this {@link Plugin}. @@ -102,12 +117,37 @@ class Plugin getGoal: (name) -> return goal for goal in @goals when goal.getName() is name ### - Determines if this {@link Project} has a {@link Plugin}. + Determines if this {@link Plugin} has a {@link Goal}. @since 0.2.1 @param name The name of the {@link Goal}. + @return true if this {@link Plugin} has this {@link Goal}, false otherwise. ### hasGoal: (name) -> !!@getGoal name + + ### + Determines if this {@link Plugin} has defined an archtype. + + @since 0.3.3 + @return true if this {@link Plugin} has defined an archtype, false otherwise. + ### + hasArchtype: -> !!@archtype + + ### + Returns the archtype of this {@link Plugin}. + + @since 0.3.3 + @return The archtype of this {@link Plugin} if it has one. + ### + getArchtype: -> @archtype + + ### + Defines an archtype. + + @since 0.3.3 + @param archtype The archtype to define. + ### + archtype: (archtype) -> @archtype = archtype if typeof archtype is 'object' ### Registers a goal. diff --git a/src/main/kaffee/project/configuration.coffee b/src/main/kaffee/project/configuration.coffee index e4ab264..e1ad598 100644 --- a/src/main/kaffee/project/configuration.coffee +++ b/src/main/kaffee/project/configuration.coffee @@ -1,7 +1,8 @@ -Fs = require 'fs' -Path = require 'path' +Fs = require "fs" +Path = require "path" -Configuration = require '../configuration' +Configuration = require "../configuration" +Util = require "../util" ### The {@link ProjectConfiguration} class contains configuration of the project. @@ -16,10 +17,9 @@ class ProjectConfiguration @param file The relative path to the project configuration file. ### constructor: (@workspace, @file = Configuration.DEFAULT_PROJECT_CONFIG_FILE) -> - this.data = Configuration.SUPER_PROJECT_CONFIG - this.path = Path.join this.getWorkspace().getPath(), this.file - this.data = Configuration.merge this.data, this.read() - this.data = Configuration.merge(Configuration.ARCHTYPES[this.getKaffeeConfiguration().getArchtype()], this.data) if Configuration.ARCHTYPES[this.getKaffeeConfiguration().getArchtype()] + @data = Configuration.SUPER_PROJECT_CONFIG + @path = Path.join @getWorkspace().getPath(), @file + @data = Util.merge @data, @read() ### Reads the package data file into a Javascript array. @@ -28,9 +28,9 @@ class ProjectConfiguration ### read: -> try - return JSON.parse(Fs.readFileSync(this.path, 'UTF-8')) + return JSON.parse(Fs.readFileSync(@path, 'UTF-8')) catch e - throw "Failed to load the project configuration file (#{ this.path })\n#{ e }" + throw "Failed to load the project configuration file (#{ @path })\n#{ e }" ### @@ -39,7 +39,7 @@ class ProjectConfiguration @param arr The array to update the package data file with. @since 0.0.1 ### - update: (arr = this.data) -> Fs.writeFileSync(this.path, JSON.stringify(arr)) + update: (arr = @data) -> Fs.writeFileSync(@path, JSON.stringify(arr)) ### Returns the path to the file that contains the project data. @@ -47,7 +47,7 @@ class ProjectConfiguration @since 0.1.1 @return The path to the file that contains the project data. ### - getPath: -> this.path + getPath: -> @path ### Returns the {@link Workspace} of this {@link ProjectConfiguration} instance. @@ -55,7 +55,7 @@ class ProjectConfiguration @since 0.3.0 @return The {@link Workspace} of this {@link ProjectConfiguration} instance. ### - getWorkspace: -> this.workspace + getWorkspace: -> @workspace ### Returns the data that has been read. @@ -63,7 +63,7 @@ class ProjectConfiguration @since 0.1.1 @return The data that has been read. ### - getData: -> this.data + getData: -> @data ### Returns the name of this package. @@ -71,7 +71,7 @@ class ProjectConfiguration @since 0.3.0 @return The name of this package. ### - getName: -> this.data.name + getName: -> @data.name ### Returns the version of this package. @@ -79,7 +79,7 @@ class ProjectConfiguration @since 0.3.0 @return The version of this package. ### - getVersion: -> this.data.version + getVersion: -> @data.version ### Returns the dependencies of this package. @@ -87,11 +87,28 @@ class ProjectConfiguration @since 0.3.0 @return The dependencies of this package. ### - getDependencies: -> this.data.dependencies + getDependencies: -> @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. ### @@ -107,7 +124,7 @@ class ProjectConfiguration @since 0.3.0 @return The plugins of this Kaffee project. ### - this.getPlugins = -> data.plugins + @getPlugins = -> data.plugins ### Returns the directory structure of this Kaffee project. @@ -115,14 +132,14 @@ class ProjectConfiguration @since 0.3.0 @return The directory structure of this Kaffee project. ### - this.getStructure = -> + @getStructure = -> ### Returns this directory structure as an array. @since 0.3.0 @return This directory structure as an array. ### - this.toArray = -> data.structure + @toArray = -> data.structure ### Returns the path of the directory with the specified name. @@ -130,8 +147,8 @@ class ProjectConfiguration @since 0.3.0 @return The path of the directory with the specified name. ### - this.get = (name) -> - Path.join o.getWorkspace().getPath(), this.toArray()[name] + @get = (name) -> + Path.join o.getWorkspace().getPath(), @toArray()[name] this ### @@ -140,7 +157,7 @@ class ProjectConfiguration @since 0.3.0 @return The lifecycles of this Kaffee project. ### - this.getLifecycles = -> data.lifecycles + @getLifecycles = -> data.lifecycles ### Returns the parent project of this Kaffee project. @@ -148,7 +165,7 @@ class ProjectConfiguration @since 0.3.0 @return The parent project of this Kaffee project. ### - this.getParent = -> data.parent + @getParent = -> data.parent ### Returns the childs of this Kaffee project. @@ -156,7 +173,7 @@ class ProjectConfiguration @since 0.3.0 @return The childs of this Kaffee project. ### - this.getModules = -> data.modules + @getModules = -> data.modules ### Returns the archtype of this Kaffee project. @@ -164,7 +181,7 @@ class ProjectConfiguration @since 0.3.0 @return The archtype of this Kaffee project. ### - this.getArchtype = -> data.archtype + @getArchtype = -> data.archtype this ) this @@ -175,5 +192,5 @@ class ProjectConfiguration @since 0.0.1 @return true if the package.json exists, false otherwise. ### - exists: -> Fs.existsSync this.path + exists: -> Fs.existsSync @path module.exports = ProjectConfiguration diff --git a/src/main/kaffee/project/project.coffee b/src/main/kaffee/project/project.coffee index e9e89ef..a621c23 100644 --- a/src/main/kaffee/project/project.coffee +++ b/src/main/kaffee/project/project.coffee @@ -1,10 +1,12 @@ -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' +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. @@ -20,12 +22,12 @@ class Project @param parent The parent {@link Project} of this {@link Project}. ### constructor: (@configuration, @parent) -> - this.plugins = [] - this.childs = [] + @plugins = [] + @childs = [] - this.event = new EventManager "project", null, this - this.event.setParent parent?.getEventManager() - this.event.setName "project-" + this.configuration.getName() + @event = new EventManager "project", null, this + @event.setParent parent?.getEventManager() + @event.setName "project-" + @configuration.getName() ### Returns the parent {@link Project} instance. @@ -33,7 +35,7 @@ class Project @since 0.3.0 @return The parent {@link Project} instance. ### - getParent: -> this.parent + getParent: -> @parent ### Loads this {@link Project}. @@ -41,26 +43,33 @@ class Project @since 0.2.1 ### load: -> - this.event.fire "enter", this + @event.fire "enter", this try - for child in this.configuration.getKaffeeConfiguration().getModules() + for child in @configuration.getKaffeeConfiguration().getModules() continue if typeof child isnt 'string' workspace = new Workspace child - continue if workspace.getPath() is this.configuration.getWorkspace().getPath() + continue if workspace.getPath() is @configuration.getWorkspace().getPath() project = new Project new ProjectConfiguration(workspace), this project.load() - this.childs.push project + @childs.push project # Add the `kaffee-plugin` to this project. - this.plugins.push new (require "../plugin/default")(this) + @plugins.push new (require "../plugin/default")(this) - for name, configuration of this.configuration.getKaffeeConfiguration().getPlugins() + for name, configuration of @configuration.getKaffeeConfiguration().getPlugins() plugin = new Plugin name, this, configuration return unless plugin.load() - this.plugins.push plugin + @plugins.push plugin + + archtype = @configuration.getKaffeeConfiguration().getArchtype() + plugin = @getPlugin archtype + if plugin and plugin.hasArchtype() + @configuration.data = Util.merge plugin.getArchtype(), @configuration.data + else if archtype # Archtype is given, but it doesn't exists. + throw "Invalid archtype \"#{ archtype }\"" catch e - this.event.getLogger().error e + @event.getLogger().error e return - this.event.fire "leave", this + @event.fire "leave", this true ### @@ -69,7 +78,7 @@ class Project @since 0.3.0 @return The {@link EventManager} of this {@link Project}. ### - getEventManager: -> this.event + getEventManager: -> @event ### Returns the {@link ProjectConfiguration} of this {@link Project}. @@ -77,14 +86,14 @@ class Project @since 0.2.1 @return The {@link ProjectConfiguration} of this {@link Project}. ### - getConfiguration: -> this.configuration + getConfiguration: -> @configuration ### Returns the {@link Plugin}s of this {@link Project}. @since 0.2.1 @return The {@link Plugin}s of this {@link Project}. ### - getPlugins: -> if this.getParent() then this.plugins.concat this.getParent().getPlugins() else this.plugins + getPlugins: -> if @getParent() then @plugins.concat @getParent().getPlugins() else @plugins ### Returns a {@link Plugin} of this {@link Project}. @@ -93,7 +102,8 @@ class Project @param name The name of the {@link Plugin} to get. @return The {@link Plugin}. ### - getPlugin: (name) -> return plugin for plugin in this.getPlugins() when plugin.getName() is name + getPlugin: (name) -> + return plugin for plugin in @getPlugins() when plugin.getName() is name or plugin.getAliases().indexOf(name) isnt -1 ### Determines if this {@link Plugin} has a {@link Goal}. @@ -101,7 +111,7 @@ class Project @since 0.2.1 @param name The name of the {@link Plugin}. ### - hasPlugin: (name) -> !!this.getPlugin name + hasPlugin: (name) -> !!@getPlugin name ### Returns the lifecycles of this {@link Plugin}. @@ -110,21 +120,18 @@ class Project @return The lifecycles of this {@link Plugin}. ### getLifecycles: -> - c = this.getParent()?.getLifecycles()?.slice(0) + c = @getParent()?.getLifecycles()?.slice(0) c or= [] - for key, value of this.getConfiguration().getKaffeeConfiguration().getLifecycles() + for key, value of @getConfiguration().getKaffeeConfiguration().getLifecycles() c[key] = value 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}. ### - getChilds: -> this.childs + getChilds: -> @childs ### Executes a {@link ExecutionRequest}. @@ -134,13 +141,16 @@ class Project @return The {@link ExecutionResult} instance. ### execute: (request) -> + request.time = Date.now() result = new Result this try - result.addChild this.attainGoal(goal) for goal in request.getGoals() - result.addChild child.execute(request) for child in this.childs + result.addChild @attainGoal(goal) for goal in request.getGoals() + result.addChild child.execute(request) for child in @childs catch e - this.event.getLogger().error e + @event.getLogger().error e return + result.time = Date.now() + result ### Attains a {@link Goal}. @@ -156,17 +166,17 @@ class Project split = name.split(':') plugin = split[0] goal = split[1] - if not this.hasPlugin plugin - this.event.getLogger().error "No such plugin \"#{ plugin }\"" + if not @hasPlugin plugin + @event.getLogger().error "No such plugin \"#{ plugin }\"" return - if not this.getPlugin(plugin).hasGoal goal - this.event.getLogger().error "Plugin #{ plugin } doesn't have goal \"#{ goal }\"" + if not @getPlugin(plugin).hasGoal goal + @event.getLogger().error "Plugin #{ plugin } doesn't have goal \"#{ goal }\"" return - return this.getPlugin(plugin).getGoal(goal).attain request - lifecycle = this.getLifecycles()[name] + return @getPlugin(plugin).getGoal(goal).attain request + lifecycle = @getLifecycles()[name] if not lifecycle - this.event.getLogger().error "Unknown lifecycle \"#{ name }\"" + @event.getLogger().error "Unknown lifecycle \"#{ name }\"" return - this.attainGoal goal for goal in lifecycle when goal isnt name + @attainGoal goal for goal in lifecycle when goal isnt name module.exports = Project diff --git a/src/main/kaffee/project/workspace.coffee b/src/main/kaffee/project/workspace.coffee index c3d9b0f..892fa94 100644 --- a/src/main/kaffee/project/workspace.coffee +++ b/src/main/kaffee/project/workspace.coffee @@ -1,5 +1,5 @@ -Fs = require 'fs' -Path = require 'path' +Fs = require "fs" +Path = require "path" ### The {@link Workspace} class is a pointer to the workspace of a {@link Project} @@ -14,7 +14,7 @@ class Workspace @since 0.1.1 @param path The path pointing to the workspace. ### - constructor: (path = ".") -> this.path = Path.resolve path + constructor: (path = ".") -> @path = Path.resolve path ### Returns the path pointing to the workspace. @@ -22,7 +22,7 @@ class Workspace @since 0.1.1 @return The path pointing to the workspace. ### - getPath: -> this.path + getPath: -> @path ### Determines if this workspace exists or not. @@ -30,12 +30,12 @@ class Workspace @since 0.1.1 @return true if this workspace exists, false otherwise. ### - exists: -> Fs.existsSync this.path + exists: -> Fs.existsSync @path ### Creates this workspace. @since 0.1.1 ### - create: -> Fs.mkdirSync this.path + create: -> Fs.mkdirSync @path module.exports = Workspace