mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
new project: improve command
This commit is contained in:
parent
fe6e9328b8
commit
33087f367a
42
bin/jaws
42
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 <type> [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 <profile name>', 'AWS profile to use (as defined in ~/.aws/credentials). Only valid for new project.')
|
||||
.option('-n, --proj-name <name>', 'Project name. Only valid for new project.')
|
||||
.option('-s, --stage <stage>', 'Stage to create. all lowercase Only valid for new project.')
|
||||
.option('-r, --region <region>', 'Region lambda(s)&endpoints(s) will be created in (Can add more later). Only valid for new project.')
|
||||
.option('-3, --s3-bucket <bucketName>', 'S3 bucket to store stage env files. Key is JAWS/envVars/<projName>/<stage>. Bucket will be created if it DNE. Only valid for new project.')
|
||||
.option('-e, --notification-email <email>', 'Email to be notified with stack alerts. Only valid for new project.')
|
||||
.action(function(type, regionName, stageName, options) {
|
||||
type = type.toLowerCase();
|
||||
.command('new <type>')
|
||||
.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'),
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* JAWS Command: deploy api <stage> <region>
|
||||
* JAWS Command: deploy endpoint <stage> <region>
|
||||
* - Deploys project's API Gateway REST API to the specified stage and one or all regions
|
||||
*/
|
||||
|
||||
|
||||
@ -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: <bucket>/JAWS/envVars/<name>/<stage>
|
||||
*
|
||||
* @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: <bucket>/JAWS/envVars/<proj-name>/<stage>. 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();
|
||||
|
||||
};
|
||||
});
|
||||
@ -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",
|
||||
|
||||
10
tests/all.js
10
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');
|
||||
});
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user