diff --git a/README.md b/README.md
index 33d2228..7f93ca2 100644
--- a/README.md
+++ b/README.md
@@ -183,14 +183,20 @@ The configuration object above may seem daunting however, broken down, it's rath
* Emit an error event when an intergration throws when processing a file.
* Modify the info log when the monitor fires a chang event to render a path relative to the root directory.
* Make intergrations optional rather than installing them all.
-* Make use of the 'commander' module for the command line interface.
* Save log files in the directory specified in the configuration object's directory property.
-* Make a start on unit testing with Mocha and Chai.
+* Make a start on unit testing with Mocha, Chai, and Sinon.
* Improve (standardise) error reporting.
### Changelog
+ - v0.2.7
+ -
+
+ - Revised the command line interface to now use the 'commander' module.
+ - Added validation for the selected mode.
+
+
- v0.2.6
-
diff --git a/src/bin/cli.js b/src/bin/cli.js
index cbd7282..43da94e 100644
--- a/src/bin/cli.js
+++ b/src/bin/cli.js
@@ -1,67 +1,16 @@
#!/usr/bin/env node
+var Commander = require("commander");
var Compiler = require("../lib/Compiler");
-function parse(arguments, commands) {
- var pattern = /^\-\-\w+/;
- var command = null;
- var params = {};
-
- // Round up all the command pairs into an object.
- arguments.forEach(function(argument) {
- if (pattern.test(argument)) {
- var name = argument.substr(2);
- if (command = commands.filter(function(c) { return (c.name == name); })[0]) {
- params[name] = ((command.type == "boolean") ? true : command.default);
- }
- } else {
- if (command) {
- params[command.name] = argument;
- }
- }
- });
-
- // Check to ensure required paramters have been specified and fill in any default values.
- commands.forEach(function(command) {
- if (command.required) {
- var found = false;
- for (var param in params) {
- if (command.name == param) {
- found = true;
- break;
- }
- }
-
- if (!found) {
- throw new Error(command.name + " is a required parameter.");
- }
- }
-
- params[command.name] = (params[command.name] || command.default);
- });
-
- return params;
-}
-
-var params = parse(process.argv.slice(2), [
- {
- name: "config",
- required: true,
- type: "string"
- },
- {
- name: "mode",
- required: true,
- type: "string"
- },
- {
- name: "debug",
- default: false,
- type: "boolean"
- }
-]);
+var params = Commander
+ .option('-c, --config ', 'Configuration path')
+ .option('-m, --mode ', 'Compile mode')
+ .option('-d, --debug', 'Debug mode')
+ .parse(process.argv);
try {
var compiler = new Compiler(params.config, params.mode, params.debug);
+ compiler.on("compiled", function() { console.log("compiled"); });
compiler.compile();
} catch(e) {
console.log(e);
diff --git a/src/lib/Compiler.js b/src/lib/Compiler.js
index 9b479cf..f1abd16 100644
--- a/src/lib/Compiler.js
+++ b/src/lib/Compiler.js
@@ -51,7 +51,7 @@ function Compiler(config, mode, debug) {
config = JSON.parse(FS.readFileSync(config, "utf-8"));
}
- var invalid = this.validate(config);
+ var invalid = this.validateCompiler(config);
if (invalid) { throw new Error(invalid); }
Events.EventEmitter.call(this);
@@ -73,6 +73,9 @@ Compiler.prototype.init = function _init(config, mode) {
this.mode = config.modes.filter(function(m) { return m.id == mode; })[0];
if (!this.mode) { throw new Error("Failed to find configuration mode."); }
+ var invalid = this.validateMode(this.mode);
+ if (invalid) { throw new Error(invalid); }
+
Logger.debug("Initialising " + this.mode.name + " mode...");
this.name = config.name;
@@ -87,7 +90,7 @@ Compiler.prototype.init = function _init(config, mode) {
this.profiles = [];
this.mode.profiles.forEach(function(profileID) {
var found = config.profiles.filter(function(p) { return p.id == profileID; })[0];
- if (!found) { return Logger.warn("Invalid profile ID specified '" + profileID + "'."); }
+ if (!found) { return Logger.warn("Failed to find profile with ID '" + profileID + "'."); }
var profile = new Profile(this, found);
this.profiles.push(profile);
@@ -102,7 +105,7 @@ Compiler.prototype.compile = function _compile() {
this.emit("compiled");
};
-Compiler.prototype.validate = new Legitimize({
+Compiler.prototype.validateCompiler = new Legitimize({
name: {
type: "string",
error: "'name' property in configuration object is required and must be a string."
@@ -121,4 +124,19 @@ Compiler.prototype.validate = new Legitimize({
}
}, {required: true});
+Compiler.prototype.validateMode = new Legitimize({
+ id: {
+ type: "string",
+ error: "'directory' property in mode is required and must be a valid path."
+ },
+ name: {
+ type: "string",
+ error: "'name' property in mode is required and must be a string."
+ },
+ profiles: {
+ type: "array",
+ error: "'profiles' property in mode is required and must be an array."
+ }
+}, {required: true});
+
module.exports = Compiler;
\ No newline at end of file
diff --git a/src/package.json b/src/package.json
index 2b9fa3a..b1ca616 100644
--- a/src/package.json
+++ b/src/package.json
@@ -1,42 +1,43 @@
{
- "name": "node-compiler",
- "description": "Single page application compiler that supports Dust, JS, Sass, CoffeeScript, and Sync.",
- "keywords": [
- "node",
- "compiler",
- "dustjs",
- "sass",
- "coffee-script",
- "sync",
- "web",
- "minify",
- "concatenate",
- "build",
- "watch",
- "cli"
- ],
- "author": {
- "name": "Lewis Barnes"
- },
- "version": "0.2.6",
- "license": "MIT",
- "main": "./lib/Compiler.js",
- "repository": {
- "type" : "git",
- "url": "https://github.com/lewie9021/node-compiler"
- },
- "bin": "./bin/cli.js",
- "dependencies": {
- "coffee-script": "~1.8.0",
- "dustjs-linkedin": "~2.5.1",
- "fs-extra": "~0.13.0",
- "node-sass": "~1.2.3",
- "uglify-js": "~2.4.16",
- "chalk": "~0.5.1",
- "chokidar": "~0.12.4",
- "legitimize": "~0.0.3"
- },
- "engines": {
- "node": "0.10.x"
- }
-}
\ No newline at end of file
+ "name": "node-compiler",
+ "description": "Single page application compiler that supports Dust, JS, Sass, CoffeeScript, and Sync.",
+ "keywords": [
+ "node",
+ "compiler",
+ "dustjs",
+ "sass",
+ "coffee-script",
+ "sync",
+ "web",
+ "minify",
+ "concatenate",
+ "build",
+ "watch",
+ "cli"
+ ],
+ "author": {
+ "name": "Lewis Barnes"
+ },
+ "version": "0.2.7",
+ "license": "MIT",
+ "main": "./lib/Compiler.js",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/lewie9021/node-compiler"
+ },
+ "bin": "./bin/cli.js",
+ "dependencies": {
+ "chalk": "~0.5.1",
+ "chokidar": "~0.12.4",
+ "coffee-script": "~1.8.0",
+ "commander": "~2.5.1",
+ "dustjs-linkedin": "~2.5.1",
+ "fs-extra": "~0.13.0",
+ "legitimize": "~0.0.3",
+ "node-sass": "~1.2.3",
+ "uglify-js": "~2.4.16"
+ },
+ "engines": {
+ "node": "0.10.x"
+ }
+}