diff --git a/bin/jaws b/bin/jaws index f07b8cbf7..21a1df72e 100755 --- a/bin/jaws +++ b/bin/jaws @@ -7,6 +7,7 @@ var JawsError = require('../lib/jaws-error'), program = require('commander'), utils = require('../lib/utils'), Promise = require('bluebird'), + minimist = require('minimist'), handleExit = utils.handleExit; var JAWS = new Jaws(); @@ -20,31 +21,26 @@ program .version(JAWS._meta.version); program - .command('new [regionName] [stageName]') - .description('Creates JAWS "project" or "region"/"stage" in existing project. Does so in cwd. ' + - 'If type is region|stage, regionName and stageName are required. If region, the stageName is the stage that will' + - 'be primed in the new region.') - .option('-d, --dont-exe-cf', 'Dont execute CloudFormation file') - //Things only valid for new project below: - .option('-p, --profile ', 'AWS profile to use (as defined in ~/.aws/credentials). Only valid for new project.') - .option('-n, --proj-name ', 'Project name. Only valid for new project.') - .option('-s, --stage ', 'Stage to create. all lowercase Only valid for new project.') - .option('-r, --region ', 'Region lambda(s)&endpoints(s) will be created in (Can add more later). Only valid for new project.') - .option('-3, --s3-bucket ', 'S3 bucket to store stage env files. Key is JAWS/envVars//. Bucket will be created if it DNE. Only valid for new project.') - .option('-e, --notification-email ', 'Email to be notified with stack alerts. Only valid for new project.') - .action(function(type, regionName, stageName, options) { - type = type.toLowerCase(); + .command('new ') + .allowUnknownOption() + .description('Make a new "project", "stage", "region", "lambda" or "endpoint"') + .action(function() { + + // Parse Args + var args = minimist(process.argv.slice(3)); + var type = args._[0] ? args._[0].toLowerCase() : null; if (type == 'project') { - var theCmd = require('../lib/commands/new_project'); - handleExit(theCmd.run( - options.projName, // name is reserved in commander... - options.stage ? options.stage.toLowerCase() : null, - options.s3Bucket, - options.region, - options.notificationEmail, - options.profile, - options.dontExeCf + + var CmdNewProject = require('../lib/commands/new_project'); + handleExit(CmdNewProject.run( + args.name, + args.stage ? args.stage.toLowerCase() : null, + args.s3Bucket, + args.region, + args.email, + args.profile, + args.noCf )); } else if (type == 'region' || type == 'stage') { var theCmd = require('../lib/commands/new_region_stage'), diff --git a/lib/commands/deploy_endpoint.js b/lib/commands/deploy_endpoint.js index 9317c9835..4ce72c859 100644 --- a/lib/commands/deploy_endpoint.js +++ b/lib/commands/deploy_endpoint.js @@ -1,7 +1,7 @@ 'use strict'; /** - * JAWS Command: deploy api + * JAWS Command: deploy endpoint * - Deploys project's API Gateway REST API to the specified stage and one or all regions */ diff --git a/lib/commands/new_project.js b/lib/commands/new_project.js index c7ff5bd88..b1c309d5d 100644 --- a/lib/commands/new_project.js +++ b/lib/commands/new_project.js @@ -21,7 +21,31 @@ var JawsError = require('../jaws-error'), Promise.promisifyAll(fs); /** - * Command Class + * Run + * @param name + * @param stage + * @param s3Bucket + * @param notificationEmail + * @param region + * @param profile + * @param noCf + * @returns {*} + */ + +module.exports.run = function(name, stage, s3Bucket, notificationEmail, region, profile, noCf) { + var command = new CMD( + name, + stage, + s3Bucket, + notificationEmail, + region, + profile, + noCf); + return command.run(); +}; + +/** + * CMD Class * @param name * @param stage * @param s3Bucket @@ -31,7 +55,8 @@ Promise.promisifyAll(fs); * @param noExeCf * @constructor */ -function CMD(name, stage, s3Bucket, notificationEmail, region, profile, noExeCf) { + +function CMD(name, stage, s3Bucket, notificationEmail, region, profile, noCf) { // Defaults this._name = name ? name : null; @@ -40,17 +65,18 @@ function CMD(name, stage, s3Bucket, notificationEmail, region, profile, noExeCf) this._notificationEmail = notificationEmail; this._region = region; this._profile = profile; - this._execCf = noExeCf; + this._noCf = noCf; this._prompts = { properties: {}, }; this.Prompter = JawsCLI.prompt(); this.Prompter.override = {}; -}; +} /** - * Run + * CMD: Run */ + CMD.prototype.run = Promise.method(function() { var _this = this; @@ -67,7 +93,7 @@ CMD.prototype.run = Promise.method(function() { .then(_this._createS3JawsStructure) //see if bucket is avail first before doing work .then(_this._createProjectDirectory) .then(function() { - if (!_this._noExeCf) { + if (!_this._noCf) { return _this._createCfStack(); } else { utils.logIfVerbose('No exec cf specified, updating proj jaws.json only'); @@ -79,8 +105,9 @@ CMD.prototype.run = Promise.method(function() { }); /** - * Prompt + * CMD: Prompt */ + CMD.prototype._prompt = Promise.method(function() { var _this = this; @@ -222,10 +249,11 @@ CMD.prototype._prompt = Promise.method(function() { }); /** - * Prepare Project Data + * CMD: Prepare Project Data * @returns {Promise} * @private */ + CMD.prototype._prepareProjectData = Promise.method(function() { var _this = this; @@ -268,10 +296,11 @@ CMD.prototype._prepareProjectData = Promise.method(function() { }); /** - * Create Project Directory + * CMD: Create Project Directory * @returns {Promise} * @private */ + CMD.prototype._createProjectDirectory = Promise.method(function() { var _this = this; @@ -307,15 +336,14 @@ CMD.prototype._createProjectDirectory = Promise.method(function() { }); /** - * Create S3 Bucket - * + * CMD Create S3 Bucket * (if DNE) and upload the 1st stage env var - * * Format: /JAWS/envVars// * * @returns {Promise} * @private */ + CMD.prototype._createS3JawsStructure = Promise.method(function() { var _this = this; @@ -337,8 +365,9 @@ CMD.prototype._createS3JawsStructure = Promise.method(function() { }); /** - * Create CloudFormation Stack + * CMD: Create CloudFormation Stack */ + CMD.prototype._createCfStack = Promise.method(function() { var _this = this; @@ -365,12 +394,13 @@ CMD.prototype._createCfStack = Promise.method(function() { }); /** - * Create Project JSON + * CMD: Create Project JSON * * @param cfOutputs. Optional * @returns {Promise} jaws json js obj * @private */ + CMD.prototype._createProjectJson = Promise.method(function(cfOutputs) { var _this = this; @@ -420,29 +450,4 @@ CMD.prototype._createProjectJson = Promise.method(function(cfOutputs) { + '" has been successfully created in the current directory.'); return jawsJson; -}); - -/** - * - * @param name - * @param stage - * @param s3Bucket store things like env vars: /JAWS/envVars//. Create bucket if DNE - * @param region - * @param notificationEmail - * @param profile - * @param noExeCf don't execute CloudFormation at the end - * @returns {*} - */ -module.exports.run = function(name, stage, s3Bucket, notificationEmail, region, profile, noExeCf) { - - var command = new CMD( - name, - stage, - s3Bucket, - notificationEmail, - region, - profile, - noExeCf); - return command.run(); - -}; +}); \ No newline at end of file diff --git a/package.json b/package.json index 5bbf0aba1..50c447767 100644 --- a/package.json +++ b/package.json @@ -46,8 +46,9 @@ "inquirer": "^0.9.0", "insert-module-globals": "^6.5.2", "jaws-api-gateway-client": "0.11.0", - "mkdirp-then": "^1.1.0", "keypress": "^0.2.1", + "minimist": "^1.2.0", + "mkdirp-then": "^1.1.0", "moment": "^2.10.6", "node-uuid": "^1.4.2", "node-zip": "^1.1.0", diff --git a/tests/all.js b/tests/all.js index 3a5af90e8..6298cfad2 100644 --- a/tests/all.js +++ b/tests/all.js @@ -5,13 +5,13 @@ require('./config'); //init config describe('AllTests', function() { + before(function(done) { this.timeout(0); //dont timeout anything done(); }); - after(function() { - }); + after(function() {}); //require tests vs inline so we can run sequentially //require('./cli/tag'); @@ -22,8 +22,8 @@ describe('AllTests', function() { /** * Tests below create AWS Resources */ - require('./cli/dash'); + //require('./cli/dash'); //require('./cli/deploy_lambda'); - //require('./cli/deploy_api'); - //require('./cli/new_project'); + //require('./cli/deploy_endpoint'); + require('./cli/new_project'); }); \ No newline at end of file diff --git a/tests/cli/deploy_api.js b/tests/cli/deploy_endpoint.js similarity index 100% rename from tests/cli/deploy_api.js rename to tests/cli/deploy_endpoint.js diff --git a/tests/cli/new_project.js b/tests/cli/new_project.js index 56b47f15e..590aff05a 100644 --- a/tests/cli/new_project.js +++ b/tests/cli/new_project.js @@ -42,6 +42,7 @@ describe('Test new command', function() { .then(function() { var jawsJson = require(path.join(os.tmpdir(), config.newName, 'jaws.json')); var region = false; + for (var i = 0; i < jawsJson.project.stages[config.stage].length; i++) { var stage = jawsJson.project.stages[config.stage][i]; if (stage.region === config.region) {