From 1fd250998f20eaa1023fbfbb8dc425e2507f0265 Mon Sep 17 00:00:00 2001 From: doapp-ryanp Date: Thu, 27 Oct 2016 21:41:24 -0500 Subject: [PATCH 1/9] add lifecycle events to deploy function --- lib/plugins/aws/deployFunction/index.js | 8 +++++--- lib/plugins/deploy/deploy.js | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/plugins/aws/deployFunction/index.js b/lib/plugins/aws/deployFunction/index.js index cb2b855f7..d89bfe950 100644 --- a/lib/plugins/aws/deployFunction/index.js +++ b/lib/plugins/aws/deployFunction/index.js @@ -18,11 +18,13 @@ class AwsDeployFunction { Object.assign(this, validate); this.hooks = { - 'deploy:function:deploy': () => BbPromise.bind(this) + 'deploy:function:initialize': () => BbPromise.bind(this) .then(this.validate) .then(this.logStatus) - .then(this.checkIfFunctionExists) - .then(this.zipFunction) + .then(this.checkIfFunctionExists), + 'deploy:function:zipFunction': () => BbPromise.bind(this) + .then(this.zipFunction), + 'deploy:function:deploy': () => BbPromise.bind(this) .then(this.deployFunction) .then(this.cleanup), }; diff --git a/lib/plugins/deploy/deploy.js b/lib/plugins/deploy/deploy.js index a45ec730a..5d04b026b 100644 --- a/lib/plugins/deploy/deploy.js +++ b/lib/plugins/deploy/deploy.js @@ -38,6 +38,8 @@ class Deploy { function: { usage: 'Deploy a single function from the service', lifecycleEvents: [ + 'initialize', + 'zipFunction', 'deploy', ], options: { From e29c539faa89dcf80832f3536ce63f23261bd362 Mon Sep 17 00:00:00 2001 From: doapp-ryanp Date: Thu, 27 Oct 2016 21:46:39 -0500 Subject: [PATCH 2/9] formatting --- lib/plugins/aws/deployFunction/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/plugins/aws/deployFunction/index.js b/lib/plugins/aws/deployFunction/index.js index d89bfe950..f1b6eb63d 100644 --- a/lib/plugins/aws/deployFunction/index.js +++ b/lib/plugins/aws/deployFunction/index.js @@ -22,8 +22,10 @@ class AwsDeployFunction { .then(this.validate) .then(this.logStatus) .then(this.checkIfFunctionExists), + 'deploy:function:zipFunction': () => BbPromise.bind(this) .then(this.zipFunction), + 'deploy:function:deploy': () => BbPromise.bind(this) .then(this.deployFunction) .then(this.cleanup), From 6634145c94d5c5599d83788c2ccd8b23d1e6c08d Mon Sep 17 00:00:00 2001 From: doapp-ryanp Date: Thu, 27 Oct 2016 22:05:15 -0500 Subject: [PATCH 3/9] fix tests --- lib/plugins/aws/deployFunction/index.js | 2 +- lib/plugins/aws/deployFunction/tests/index.js | 31 +++++++++++++------ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/plugins/aws/deployFunction/index.js b/lib/plugins/aws/deployFunction/index.js index f1b6eb63d..cbfe3b0c3 100644 --- a/lib/plugins/aws/deployFunction/index.js +++ b/lib/plugins/aws/deployFunction/index.js @@ -25,7 +25,7 @@ class AwsDeployFunction { 'deploy:function:zipFunction': () => BbPromise.bind(this) .then(this.zipFunction), - + 'deploy:function:deploy': () => BbPromise.bind(this) .then(this.deployFunction) .then(this.cleanup), diff --git a/lib/plugins/aws/deployFunction/tests/index.js b/lib/plugins/aws/deployFunction/tests/index.js index bf5ca7248..0f42b8da9 100644 --- a/lib/plugins/aws/deployFunction/tests/index.js +++ b/lib/plugins/aws/deployFunction/tests/index.js @@ -60,32 +60,43 @@ describe('AwsDeployFunction', () => { expect(awsDeployFunctionWithEmptyOptions.options).to.deep.equal({}); }); + }); - it('should run promise chain in order', () => { + describe('hooks', () => { + it('should run "deploy:function:initialize" promise chain in order', () => { const validateStub = sinon .stub(awsDeployFunction, 'validate').returns(BbPromise.resolve()); const checkIfFunctionExistsStub = sinon .stub(awsDeployFunction, 'checkIfFunctionExists').returns(BbPromise.resolve()); + + return awsDeployFunction.hooks['deploy:function:initialize']().then(() => { + expect(validateStub.calledOnce).to.equal(true); + expect(checkIfFunctionExistsStub.calledAfter(validateStub)).to.equal(true); + awsDeployFunction.checkIfFunctionExists.restore(); + }); + }); + + it('should run "deploy:function:zipFunction" promise chain in order', () => { const zipFunctionStub = sinon .stub(awsDeployFunction, 'zipFunction').returns(BbPromise.resolve()); + + return awsDeployFunction.hooks['deploy:function:zipFunction']().then(() => { + expect(zipFunctionStub.calledOnce).to.equal(true); + awsDeployFunction.zipFunction.restore(); + }); + }); + + it('should run "deploy:function:deploy" promise chain in order', () => { const deployFunctionStub = sinon .stub(awsDeployFunction, 'deployFunction').returns(BbPromise.resolve()); const cleanupStub = sinon .stub(awsDeployFunction, 'cleanup').returns(BbPromise.resolve()); return awsDeployFunction.hooks['deploy:function:deploy']().then(() => { - expect(validateStub.calledOnce).to.equal(true); - expect(checkIfFunctionExistsStub.calledAfter(validateStub)) - .to.equal(true); - expect(zipFunctionStub.calledAfter(checkIfFunctionExistsStub)) - .to.equal(true); - expect(deployFunctionStub.calledAfter(zipFunctionStub)) - .to.equal(true); + expect(deployFunctionStub.calledOnce).to.equal(true); expect(cleanupStub.calledAfter(deployFunctionStub)) .to.equal(true); - awsDeployFunction.checkIfFunctionExists.restore(); - awsDeployFunction.zipFunction.restore(); awsDeployFunction.deployFunction.restore(); awsDeployFunction.cleanup.restore(); }); From 012e0f4aa82594c0070b3003b5f7c8d44bb862df Mon Sep 17 00:00:00 2001 From: doapp-ryanp Date: Fri, 28 Oct 2016 11:15:17 -0500 Subject: [PATCH 4/9] be consistent in naming --- lib/plugins/aws/deployFunction/index.js | 9 +++++---- lib/plugins/aws/deployFunction/tests/index.js | 16 ++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/plugins/aws/deployFunction/index.js b/lib/plugins/aws/deployFunction/index.js index cbfe3b0c3..ff9c02f27 100644 --- a/lib/plugins/aws/deployFunction/index.js +++ b/lib/plugins/aws/deployFunction/index.js @@ -23,8 +23,8 @@ class AwsDeployFunction { .then(this.logStatus) .then(this.checkIfFunctionExists), - 'deploy:function:zipFunction': () => BbPromise.bind(this) - .then(this.zipFunction), + 'deploy:function:packageFunction': () => BbPromise.bind(this) + .then(this.packageFunction), 'deploy:function:deploy': () => BbPromise.bind(this) .then(this.deployFunction) @@ -34,7 +34,7 @@ class AwsDeployFunction { logStatus() { this.serverless.cli.log(`Deploying function: ${this.options.function}...`); - BbPromise.resolve(); + return BbPromise.resolve(); } checkIfFunctionExists() { @@ -65,7 +65,8 @@ class AwsDeployFunction { return BbPromise.resolve(); } - zipFunction() { + packageFunction() { + this.serverless.cli.log(`Packaging function: ${this.options.function}...`); return this.pkg.packageFunction(this.options.function); } diff --git a/lib/plugins/aws/deployFunction/tests/index.js b/lib/plugins/aws/deployFunction/tests/index.js index 0f42b8da9..a52072dcc 100644 --- a/lib/plugins/aws/deployFunction/tests/index.js +++ b/lib/plugins/aws/deployFunction/tests/index.js @@ -76,13 +76,13 @@ describe('AwsDeployFunction', () => { }); }); - it('should run "deploy:function:zipFunction" promise chain in order', () => { - const zipFunctionStub = sinon - .stub(awsDeployFunction, 'zipFunction').returns(BbPromise.resolve()); + it('should run "deploy:function:packageFunction" promise chain in order', () => { + const packageFunctionStub = sinon + .stub(awsDeployFunction, 'packageFunction').returns(BbPromise.resolve()); - return awsDeployFunction.hooks['deploy:function:zipFunction']().then(() => { - expect(zipFunctionStub.calledOnce).to.equal(true); - awsDeployFunction.zipFunction.restore(); + return awsDeployFunction.hooks['deploy:function:packageFunction']().then(() => { + expect(packageFunctionStub.calledOnce).to.equal(true); + awsDeployFunction.packageFunction.restore(); }); }); @@ -136,7 +136,7 @@ describe('AwsDeployFunction', () => { }); }); - describe('#zipFunction()', () => { + describe('#packageFunction()', () => { it('should zip the function', () => { const pkg = new Package(); @@ -145,7 +145,7 @@ describe('AwsDeployFunction', () => { const packageFunctionStub = sinon .stub(pkg, 'packageFunction').returns(BbPromise.resolve()); - return awsDeployFunction.zipFunction().then(() => { + return awsDeployFunction.packageFunction().then(() => { expect(packageFunctionStub.calledOnce).to.be.equal(true); expect(packageFunctionStub.args[0][0]).to.be.equal(awsDeployFunction.options.function); From 5a485fbf951ec3045d3e34e2ef140cfffc45d792 Mon Sep 17 00:00:00 2001 From: doapp-ryanp Date: Fri, 28 Oct 2016 11:17:00 -0500 Subject: [PATCH 5/9] clear naming of deploy function lifecycle events --- lib/plugins/deploy/deploy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plugins/deploy/deploy.js b/lib/plugins/deploy/deploy.js index 5d04b026b..a2993648f 100644 --- a/lib/plugins/deploy/deploy.js +++ b/lib/plugins/deploy/deploy.js @@ -39,7 +39,7 @@ class Deploy { usage: 'Deploy a single function from the service', lifecycleEvents: [ 'initialize', - 'zipFunction', + 'packageFunction', 'deploy', ], options: { From d035fb2f0fc3fd23184823537615dec7806884d9 Mon Sep 17 00:00:00 2001 From: doapp-ryanp Date: Fri, 28 Oct 2016 16:20:06 -0500 Subject: [PATCH 6/9] clear statement when skipping default pkging --- lib/plugins/package/lib/packageService.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/plugins/package/lib/packageService.js b/lib/plugins/package/lib/packageService.js index 9829ecd95..6cd3890f7 100644 --- a/lib/plugins/package/lib/packageService.js +++ b/lib/plugins/package/lib/packageService.js @@ -67,6 +67,10 @@ module.exports = { functionObject.artifact = null; // reset the current artifact if (funcPackageConfig.artifact) { + if (process.env.SLS_DEBUG) { + this.serverless.cli.log(`package.artifact is defined, skipping packaging`); + } + functionObject.artifact = funcPackageConfig.artifact; return BbPromise.resolve(funcPackageConfig.artifact); } From 7fd01a4e2174dcd8b20bc7241413abf37ef6de65 Mon Sep 17 00:00:00 2001 From: doapp-ryanp Date: Tue, 1 Nov 2016 11:55:18 -0500 Subject: [PATCH 7/9] bump to fix CI --- lib/classes/Utils.js | 4 ++-- lib/plugins/package/lib/packageService.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/classes/Utils.js b/lib/classes/Utils.js index 13e6fe3e1..1ad9a27f3 100644 --- a/lib/classes/Utils.js +++ b/lib/classes/Utils.js @@ -83,7 +83,7 @@ class Utils { if (filePath.endsWith('.json')) { contents = JSON.parse(contents); } else if (filePath.endsWith('.yml') || filePath.endsWith('.yaml')) { - contents = YAML.load(contents.toString(), { filename: filePath }); + contents = YAML.load(contents.toString(), {filename: filePath}); } else { contents = contents.toString().trim(); } @@ -218,7 +218,7 @@ class Utils { const name = Object.keys(event)[0]; funcEventsArray.push(name); - const alreadyPresentEvent = _.find(numberOfEventsPerType, { name }); + const alreadyPresentEvent = _.find(numberOfEventsPerType, {name}); if (alreadyPresentEvent) { alreadyPresentEvent.count++; } else { diff --git a/lib/plugins/package/lib/packageService.js b/lib/plugins/package/lib/packageService.js index c9eb0bdb3..8d85179f2 100644 --- a/lib/plugins/package/lib/packageService.js +++ b/lib/plugins/package/lib/packageService.js @@ -68,7 +68,7 @@ module.exports = { if (funcPackageConfig.artifact) { if (process.env.SLS_DEBUG) { - this.serverless.cli.log(`package.artifact is defined, skipping packaging`); + this.serverless.cli.log('package.artifact is defined, skipping packaging'); } functionObject.artifact = funcPackageConfig.artifact; From d59129870a46e3ee0df96451cc9b92ce4675eb31 Mon Sep 17 00:00:00 2001 From: doapp-ryanp Date: Tue, 1 Nov 2016 12:37:36 -0500 Subject: [PATCH 8/9] formatting --- lib/classes/Utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/classes/Utils.js b/lib/classes/Utils.js index 1ad9a27f3..13e6fe3e1 100644 --- a/lib/classes/Utils.js +++ b/lib/classes/Utils.js @@ -83,7 +83,7 @@ class Utils { if (filePath.endsWith('.json')) { contents = JSON.parse(contents); } else if (filePath.endsWith('.yml') || filePath.endsWith('.yaml')) { - contents = YAML.load(contents.toString(), {filename: filePath}); + contents = YAML.load(contents.toString(), { filename: filePath }); } else { contents = contents.toString().trim(); } @@ -218,7 +218,7 @@ class Utils { const name = Object.keys(event)[0]; funcEventsArray.push(name); - const alreadyPresentEvent = _.find(numberOfEventsPerType, {name}); + const alreadyPresentEvent = _.find(numberOfEventsPerType, { name }); if (alreadyPresentEvent) { alreadyPresentEvent.count++; } else { From b2373bdd4e7fd172d26f1fbdfd88b9e5f2263c03 Mon Sep 17 00:00:00 2001 From: doapp-ryanp Date: Tue, 1 Nov 2016 16:44:35 -0500 Subject: [PATCH 9/9] fix missing airbnb formatting --- lib/classes/Utils.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/classes/Utils.js b/lib/classes/Utils.js index 13e6fe3e1..25c889563 100644 --- a/lib/classes/Utils.js +++ b/lib/classes/Utils.js @@ -235,12 +235,14 @@ class Utils { } let hasCustomResourcesDefined = false; + // check if configuration in resources.Resources is defined if ((serverless.service.resources && serverless.service.resources.Resources && Object.keys(serverless.service.resources.Resources).length)) { hasCustomResourcesDefined = true; } + // check if configuration in resources.Outputs is defined if ((serverless.service.resources && serverless.service.resources.Outputs && @@ -256,6 +258,7 @@ class Utils { serverless.service.defaults.variableSyntax !== defaultVariableSyntax) { hasCustomVariableSyntaxDefined = true; } + // check if the variableSyntax in the provider section is defined if (serverless.service.provider && serverless.service.provider.variableSyntax &&