diff --git a/lib/classes/Utils.js b/lib/classes/Utils.js index 420a33b5d..be452f2f4 100644 --- a/lib/classes/Utils.js +++ b/lib/classes/Utils.js @@ -249,12 +249,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 && @@ -270,6 +272,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 && diff --git a/lib/plugins/aws/deployFunction/index.js b/lib/plugins/aws/deployFunction/index.js index eb133880c..fcb9361c2 100644 --- a/lib/plugins/aws/deployFunction/index.js +++ b/lib/plugins/aws/deployFunction/index.js @@ -19,11 +19,15 @@ 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:packageFunction': () => BbPromise.bind(this) + .then(this.packageFunction), + + 'deploy:function:deploy': () => BbPromise.bind(this) .then(this.deployFunction) .then(this.cleanup), }; @@ -31,7 +35,7 @@ class AwsDeployFunction { logStatus() { this.serverless.cli.log(`Deploying function: ${this.options.function}...`); - BbPromise.resolve(); + return BbPromise.resolve(); } checkIfFunctionExists() { @@ -62,7 +66,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 2dcb512ef..250155f0d 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()); - const zipFunctionStub = sinon - .stub(awsDeployFunction, 'zipFunction').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:packageFunction" promise chain in order', () => { + const packageFunctionStub = sinon + .stub(awsDeployFunction, 'packageFunction').returns(BbPromise.resolve()); + + return awsDeployFunction.hooks['deploy:function:packageFunction']().then(() => { + expect(packageFunctionStub.calledOnce).to.equal(true); + awsDeployFunction.packageFunction.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(); }); @@ -125,7 +136,7 @@ describe('AwsDeployFunction', () => { }); }); - describe('#zipFunction()', () => { + describe('#packageFunction()', () => { it('should zip the function', () => { const pkg = new Package(); @@ -134,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); diff --git a/lib/plugins/deploy/deploy.js b/lib/plugins/deploy/deploy.js index a45ec730a..a2993648f 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', + 'packageFunction', 'deploy', ], options: { diff --git a/lib/plugins/package/lib/packageService.js b/lib/plugins/package/lib/packageService.js index ea8446b9a..3454b4702 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); }