diff --git a/bin/jaws b/bin/jaws index 0aab8d72c..455bd96e2 100755 --- a/bin/jaws +++ b/bin/jaws @@ -27,4 +27,10 @@ program JAWS.tag(); }); +program + .command('*') + .action(function() { + JAWS.custom(arguments); + }); + program.parse(process.argv); diff --git a/lib/jaws.js b/lib/jaws.js index 802a5fe18..3cdbb35d8 100755 --- a/lib/jaws.js +++ b/lib/jaws.js @@ -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; diff --git a/lib/jaws_command_custom.js b/lib/jaws_command_custom.js new file mode 100644 index 000000000..05999b739 --- /dev/null +++ b/lib/jaws_command_custom.js @@ -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(); + + }; +};