diff --git a/README.md b/README.md index e100dcb3b..82dbc0b58 100755 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ JAWS is a 100% free and open-source framework for building serverless applicatio * ```$ npm install jaws-framework -g``` -* ```$ jaws new project``` +* ```$ jaws project create``` **Note:** We recommend camelCase for project names. [Why?](https://github.com/jaws-framework/JAWS/wiki/Best-practices#project-names) diff --git a/bin/jaws b/bin/jaws index a37c3366d..524678d73 100755 --- a/bin/jaws +++ b/bin/jaws @@ -4,6 +4,7 @@ var JawsError = require('../lib/jaws-error'), Jaws = require('../lib/index.js'), + JawsCLI = require('../lib/utils/cli.js'), program = require('commander'), utils = require('../lib/utils'), Promise = require('bluebird'), @@ -21,54 +22,107 @@ program .version(JAWS._meta.version); /** - * New - * - Create a new project|stage|region + * Project + * - Create a new JAWS Project */ program - .command('new ') - .description('new project, stage and region commands\n\nValid \'s:' + - '\n\nproject: create new JAWS project in CWD.' + - '\n\t Ex: jaws new project' + - '\n\nstage: create new stage in existing region' + - '\n\t Ex: jaws new stage dev' + - '\n\nregion: create new region for given stage' + - '\n\t Ex: jaws new region dev' - ) - .option('-d, --dont-exe-cf', 'Don\'t execute CloudFormation, just generate it.') - .option('-r, --region ', 'name of aws region to use') - .option('-u, --domain ', '[project] only: domain') - .option('-n, --proj-name ', '[project] only: name for new project') - .option('-s, --stage ', '[project] only: same of stage for new project') - .option('-e, --email ', '[project] only: notification email to use in CloudFormation') - .option('-p, --aws-profile ', '[project] only: Admin AWS profile as defined in ~/.aws/credentials to use') + .command('project ') + .description('Create a new JAWS Project. Valid \'s: create') + .option('-d, --dont-exe-cf', 'Don\'t execute CloudFormation, just generate it') + .option('-s, --stage ', 'Name for the stage to create') + .option('-r, --region ', 'Name of AWS region to use') + .option('-u, --domain ', 'domain ex: myapp.com') + .option('-n, --proj-name ', 'Name for the new project') + .option('-e, --email ', 'Notification email to use in CloudFormation') + .option('-p, --aws-profile ', 'Admin AWS profile as defined in ~/.aws/credentials to use') .action(function(cmd, options) { - if (cmd == 'project') { - var CmdNewProject = require('../lib/commands/new_project'); - execute(CmdNewProject.run( - options.projName, - options.stage ? options.stage.toLowerCase() : null, - options.region, - options.domain, - options.email, - options.awsProfile, - options.dontExeCf - )); + if (!JawsCLI.validateCmd(cmd, ['create'])) process.exit(1); - } else if (cmd == 'region' || cmd == 'stage') { + switch (cmd){ + case 'create': + var theCmd = require('../lib/commands/project_new'); + execute(theCmd.run( + options.projName, + options.stage ? options.stage.toLowerCase() : null, + options.region, + options.domain, + options.email, + options.awsProfile, + options.dontExeCf + )); + break; + default: + console.error('Something went very wrong. :O'); + process.exit(1); + } - var CmdNewStageRegion = require('../lib/commands/new_stage_region'); - execute(CmdNewStageRegion.run( - JAWS, - cmd, - options.stage, - options.region, - options.dontExeCf - )); - } else { - console.error('Unsupported cmd ' + cmd + '. Must be project|stage|region'); - process.exit(1); + }); + +/** + * Region + * - Create a new JAWS Region in the Current Project + */ + +program + .command('region ') + .description('Work with AWS Regions. Valid \'s: create') + .option('-d, --dont-exe-cf', 'Don\'t execute CloudFormation, just generate it') + .option('-s, --stage ', 'Name for the stage to be created in the region') + .option('-r, --region ', 'Name of AWS region to use') + .option('-p, --aws-profile ', 'Admin AWS profile as defined in ~/.aws/credentials to use') + .action(function(cmd, options) { + + if (!JawsCLI.validateCmd(cmd, ['create'])) process.exit(1); + + switch (cmd){ + case 'create': + var theCmd = require('../lib/commands/new_stage_region'); + execute(theCmd.run( + JAWS, + cmd, + options.stage, + options.region, + options.dontExeCf + )); + break; + default: + console.error('Something went very wrong. :O'); + process.exit(1); + } + }); + +/** + * Stage + * - Create a new JAWS Stage in the Current Project + */ + +program + .command('stage ') + .description('Work with JAWS stages in a region. Valid \'s: create') + .option('-d, --dont-exe-cf', 'Don\'t execute CloudFormation, just generate it') + .option('-s, --stage ', 'Name for the stage create') + .option('-r, --region ', 'Name of aws region to use') + .option('-p, --aws-profile ', 'Admin AWS profile as defined in ~/.aws/credentials to use') + .action(function(cmd, options) { + + if (!JawsCLI.validateCmd(cmd, ['create'])) process.exit(1); + + switch (cmd){ + case 'create': + var theCmd = require('../lib/commands/new_stage_region'); + execute(theCmd.run( + JAWS, + cmd, + options.stage, + options.region, + options.dontExeCf + )); + break; + default: + console.error('Something went very wrong. :O'); + process.exit(1); } }); @@ -82,7 +136,7 @@ program program .command('module [params]') - .description('aws-module commands\n\nValid \'s:' + + .description('aws-module commands\n\nValid \'s: create' + '\n\ncreate: create aws-module action. Module will be created if DNE. create ' + '\n\t Ex: jaws module create users list' ) diff --git a/docs/commands.md b/docs/commands.md index 930dafe01..9cc560e02 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -4,7 +4,7 @@ Create a project, a project region or a project stage using the `new` commands. -* ##### `$ jaws new project` +* ##### `$ jaws project create` * Makes a new JAWS project by generating scaffolding in the current working directory. The new command by default creates resources (like IAM roles) in AWS via CloudFormation. * Walks the user through the following prompts asking for their AWS credentials/profile and their project specifications * Creates a CloudFormation Stack for the user’s first stage, which creates an IAM Group and a staged IAM Role for that IAM Group @@ -12,11 +12,11 @@ Create a project, a project region or a project stage using the `new` commands. * Creates an AWS API Gateway REST API for the project * Creates environment var file in the s3 bucket (created if DNE) for the initial stage. [Why S3?](https://github.com/jaws-framework/JAWS/wiki/FAQ#why-do-you-use-an-s3-bucket-to-store-env-vars) -* ##### `$ jaws new region` +* ##### `$ jaws region create` * Creates new region in existing project. By default executes CloudFormation to make one stage in new region. -* ##### `$ jaws new stage` +* ##### `$ jaws stage create` * Creates a new stage in existing region. By default executes CloudFormation to make new stage. diff --git a/lib/commands/new_project.js b/lib/commands/project_new.js similarity index 100% rename from lib/commands/new_project.js rename to lib/commands/project_new.js diff --git a/lib/utils/cli.js b/lib/utils/cli.js index 3e68fbd28..9fc19fbc7 100644 --- a/lib/utils/cli.js +++ b/lib/utils/cli.js @@ -62,6 +62,19 @@ exports.prompt = function() { return prompt; }; +/** + * Command validator + */ + +exports.validateCmd = function(option, valid_options) { + if (-1 == valid_options.indexOf(option)) { + console.log('Unsupported command "' + option + '". Valid command(s): ' + valid_options.join(', ')); + return false; + } else { + return true; + } +}; + /** * Prompt: Select * diff --git a/tests/cli/new_project.js b/tests/cli/project_new.js similarity index 97% rename from tests/cli/new_project.js rename to tests/cli/project_new.js index 5a1490f5b..b601816bd 100644 --- a/tests/cli/new_project.js +++ b/tests/cli/project_new.js @@ -8,7 +8,7 @@ var Jaws = require('../../lib/index.js'), JawsError = require('../../lib/jaws-error'), - theCmd = require('../../lib/commands/new_project'), + theCmd = require('../../lib/commands/project_new'), path = require('path'), os = require('os'), utils = require('../../lib/utils'),