From 6e14a457c2bcb46ca08941af23626c8a4ef7fe1e Mon Sep 17 00:00:00 2001 From: Jamie Sutherland Date: Fri, 29 Jul 2016 09:22:08 +0100 Subject: [PATCH] refactor(deploy): Make resource ids camel case to make them easier to read --- .../compile/events/apiGateway/lib/resources.js | 8 ++++---- .../events/apiGateway/tests/resources.js | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/plugins/aws/deploy/compile/events/apiGateway/lib/resources.js b/lib/plugins/aws/deploy/compile/events/apiGateway/lib/resources.js index 2930c0622..28be76a13 100644 --- a/lib/plugins/aws/deploy/compile/events/apiGateway/lib/resources.js +++ b/lib/plugins/aws/deploy/compile/events/apiGateway/lib/resources.js @@ -50,8 +50,8 @@ module.exports = { const resourceName = path.split('/')[path.split('/').length - 1]; const resourcePath = path; const resourceIndex = this.resourcePaths.indexOf(resourcePath); - const resourceFunction = this.resourceFunctions[resourceIndex] + - path.replace(/\//g, ''); + const resourceFunction = _.capitalize(this.resourceFunctions[resourceIndex]) + + resourcesArray.map(_.capitalize).join(''); const resourceLogicalId = `ResourceApigEvent${resourceFunction}`; this.resourceLogicalIds[resourcePath] = resourceLogicalId; resourcesArray.pop(); @@ -62,8 +62,8 @@ module.exports = { } else { const resourceParentPath = resourcesArray.join('/'); const resourceParentIndex = this.resourcePaths.indexOf(resourceParentPath); - const resourceParentFunction = this.resourceFunctions[resourceParentIndex] + - resourcesArray.join(''); + const resourceParentFunction = _.capitalize(this.resourceFunctions[resourceParentIndex]) + + resourcesArray.map(_.capitalize).join(''); resourceParentId = `{ "Ref" : "ResourceApigEvent${resourceParentFunction}" }`; } diff --git a/lib/plugins/aws/deploy/compile/events/apiGateway/tests/resources.js b/lib/plugins/aws/deploy/compile/events/apiGateway/tests/resources.js index f194e65bc..e1fc8977e 100644 --- a/lib/plugins/aws/deploy/compile/events/apiGateway/tests/resources.js +++ b/lib/plugins/aws/deploy/compile/events/apiGateway/tests/resources.js @@ -39,10 +39,10 @@ describe('#compileResources()', () => { it('should construct the correct resourceLogicalIds object', () => awsCompileApigEvents .compileResources().then(() => { const expectedResourceLogicalIds = { - 'foo/bar': 'ResourceApigEventfirstfoobar', - foo: 'ResourceApigEventfirstfoo', - 'bar/foo': 'ResourceApigEventfirstbarfoo', - bar: 'ResourceApigEventfirstbar', + 'foo/bar': 'ResourceApigEventFirstFooBar', + foo: 'ResourceApigEventFirstFoo', + 'bar/foo': 'ResourceApigEventFirstBarFoo', + bar: 'ResourceApigEventFirstBar', }; expect(awsCompileApigEvents.resourceLogicalIds).to.deep.equal(expectedResourceLogicalIds); }) @@ -51,16 +51,16 @@ describe('#compileResources()', () => { it('should create resource resources when http events are given', () => awsCompileApigEvents .compileResources().then(() => { expect(awsCompileApigEvents.serverless.service.resources.Resources - .ResourceApigEventfirstfoobar.Properties.PathPart) + .ResourceApigEventFirstFooBar.Properties.PathPart) .to.equal('bar'); expect(awsCompileApigEvents.serverless.service.resources.Resources - .ResourceApigEventfirstfoobar.Properties.ParentId.Ref) - .to.equal('ResourceApigEventfirstfoo'); + .ResourceApigEventFirstFooBar.Properties.ParentId.Ref) + .to.equal('ResourceApigEventFirstFoo'); expect(awsCompileApigEvents.serverless.service.resources.Resources - .ResourceApigEventfirstfoo.Properties.ParentId['Fn::GetAtt'][0]) + .ResourceApigEventFirstFoo.Properties.ParentId['Fn::GetAtt'][0]) .to.equal('RestApiApigEvent'); expect(awsCompileApigEvents.serverless.service.resources.Resources - .ResourceApigEventfirstbar.Properties.ParentId['Fn::GetAtt'][1]) + .ResourceApigEventFirstBar.Properties.ParentId['Fn::GetAtt'][1]) .to.equal('RootResourceId'); }) );