Merge pull request #63 from jaws-stack/v1.0-custom

jaws custom: create a command for custom commands
This commit is contained in:
Austen 2015-08-19 14:41:00 -07:00
commit 85ec040965
3 changed files with 43 additions and 0 deletions

View File

@ -27,4 +27,10 @@ program
JAWS.tag();
});
program
.command('*')
.action(function() {
JAWS.custom(arguments);
});
program.parse(process.argv);

View File

@ -35,6 +35,8 @@ require('./jaws_command_new')(JAWS);
require('./jaws_command_install')(JAWS);
// Command: tag
require('./jaws_command_tag')(JAWS);
// Command: custom
require('./jaws_command_custom')(JAWS);
// Export
module.exports = JAWS;

View File

@ -0,0 +1,35 @@
'use strict';
/**
* JAWS Command: custom
* - Run a custom command from jaws-commands.js
*/
// Defaults
var Promise = require('bluebird'),
fs = Promise.promisifyAll(require('fs'));
module.exports = function(JAWS) {
JAWS.custom = function(command) {
// Validate
if (!command || !command['0']) return console.log('JAWS Error: Sorry, this command was not recognized or is malformed');
command = command['0'].trim();
// Find Custom Command
try {
if (fs.existsSync(JAWS._meta.projectRootPath + '/jaws-commands.js')) command = require(JAWS._meta.projectRootPath + '/jaws-commands.js')[command];
if (fs.existsSync(JAWS._meta.cwd + '/jaws-commands.js')) command = require(JAWS._meta.projectRootPath + '/jaws-commands.js')[command];
} catch (e) {
return console.log('JAWS Error: Could not find this custom command');
}
if (!typeof command !== 'function') return console.log('JAWS Error: Sorry, this command could not be found in the current directory or your project\'s root folder.');
// Run
return command();
};
};