mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
Merge pull request #63 from jaws-stack/v1.0-custom
jaws custom: create a command for custom commands
This commit is contained in:
commit
85ec040965
6
bin/jaws
6
bin/jaws
@ -27,4 +27,10 @@ program
|
||||
JAWS.tag();
|
||||
});
|
||||
|
||||
program
|
||||
.command('*')
|
||||
.action(function() {
|
||||
JAWS.custom(arguments);
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
@ -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;
|
||||
|
||||
35
lib/jaws_command_custom.js
Normal file
35
lib/jaws_command_custom.js
Normal 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();
|
||||
|
||||
};
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user