Skip to content

Commit

Permalink
moved listing stacks into a separate plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nikgraf committed Oct 19, 2016
1 parent 18b0fae commit a7d42e4
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 25 deletions.
3 changes: 2 additions & 1 deletion lib/plugins/Plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"./aws/deploy/compile/events/apiGateway/index.js",
"./aws/deploy/compile/events/sns/index.js",
"./aws/deploy/compile/events/stream/index.js",
"./aws/deployFunction/index.js"
"./aws/deployFunction/index.js",
"./aws/deployList/index.js"
]
}
11 changes: 1 addition & 10 deletions lib/plugins/aws/deploy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ const monitorStack = require('../lib/monitorStack');
const createStack = require('./lib/createStack');
const mergeCustomProviderResources = require('./lib/mergeCustomProviderResources');
const generateArtifactDirectoryName = require('./lib/generateArtifactDirectoryName');
const setBucketName = require('./lib/setBucketName');
const setBucketName = require('../lib/setBucketName');
const cleanupS3Bucket = require('./lib/cleanupS3Bucket');
const uploadArtifacts = require('./lib/uploadArtifacts');
const updateStack = require('./lib/updateStack');
const configureStack = require('./lib/configureStack');
const listStacks = require('./lib/listStacks');
const mergeIamTemplates = require('./lib/mergeIamTemplates');

class AwsDeploy {
Expand All @@ -32,7 +31,6 @@ class AwsDeploy {
updateStack,
monitorStack,
configureStack,
listStacks,
mergeIamTemplates
);

Expand All @@ -59,13 +57,6 @@ class AwsDeploy {
.then(() => {
if (this.options.noDeploy) this.serverless.cli.log('Did not deploy due to --noDeploy');
}),

'before:deploy:list:log': () => BbPromise.bind(this)
.then(this.validate),

'deploy:list:log': () => BbPromise.bind(this)
.then(this.setBucketName)
.then(this.listStacks),
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/aws/deploy/lib/cleanupS3Bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

const BbPromise = require('bluebird');
const _ = require('lodash');
const findAndGroupStacks = require('../utils/findAndGroupStacks');
const getS3ObjectsFromStacks = require('../utils/getS3ObjectsFromStacks');
const findAndGroupStacks = require('../../utils/findAndGroupStacks');
const getS3ObjectsFromStacks = require('../../utils/getS3ObjectsFromStacks');

module.exports = {
getObjectsToRemove() {
Expand Down
4 changes: 0 additions & 4 deletions lib/plugins/aws/deploy/tests/all.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
'use strict';

require('./listStacks');
require('./createStack');
require('./generateArtifactDirectoryName');
require('./mergeCustomProviderResources');
require('./setBucketName');
require('./cleanupS3Bucket');
require('./uploadArtifacts');
require('./updateStack');
require('./index');
require('./configureStack');
require('./findAndGroupStacks');
require('./getS3ObjectsFromStacks');
require('./mergeIamTemplates');
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
'use strict';

const BbPromise = require('bluebird');
const validate = require('../lib/validate');
const findAndGroupStacks = require('../utils/findAndGroupStacks');
const setBucketName = require('../lib/setBucketName');

class AwsDeployList {
constructor(serverless, options) {
this.serverless = serverless;
this.options = options || {};
this.provider = this.serverless.getProvider('aws');

Object.assign(
this,
validate,
setBucketName
);

this.hooks = {
'before:deploy:list:log': () => BbPromise.bind(this)
.then(this.validate),
'deploy:list:log': () => BbPromise.bind(this)
.then(this.setBucketName)
.then(this.listStacks),
};
}

module.exports = {
listStacks() {
const service = this.serverless.service.service;
const stage = this.options.stage;
Expand Down Expand Up @@ -38,5 +60,7 @@ module.exports = {
});
return BbPromise.resolve();
});
},
};
}
}

module.exports = AwsDeployList;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const sinon = require('sinon');
const BbPromise = require('bluebird');
const expect = require('chai').expect;
const AwsDeploy = require('../index');
const AwsDeployList = require('../index');
const AwsProvider = require('../../provider/awsProvider');
const Serverless = require('../../../../Serverless');

Expand All @@ -21,7 +21,7 @@ describe('listStacks', () => {
region: 'us-east-1',
};
s3Key = `serverless/${serverless.service.service}/${options.stage}`;
awsDeploy = new AwsDeploy(serverless, options);
awsDeploy = new AwsDeployList(serverless, options);
awsDeploy.bucketName = 'deployment-bucket';
awsDeploy.serverless.cli = {
log: sinon.spy(),
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

const expect = require('chai').expect;
const sinon = require('sinon');
const AwsProvider = require('../../provider/awsProvider');
const AwsDeploy = require('../index');
const Serverless = require('../../../../Serverless');
const AwsProvider = require('../provider/awsProvider');
const AwsDeploy = require('../deploy/index');
const Serverless = require('../../../Serverless');
const BbPromise = require('bluebird');

describe('#setBucketName()', () => {
Expand Down
20 changes: 20 additions & 0 deletions lib/plugins/aws/utils/findAndGroupStacks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

const _ = require('lodash');

module.exports = (s3Response, service, stage) => {
if (s3Response.Contents.length) {
const regex = new RegExp(`serverless/${service}/${stage}/(.+-.+-.+-.+)/(.+)`);
const s3Objects = s3Response.Contents.filter((s3Object) => s3Object.Key.match(regex));
const names = s3Objects.map((s3Object) => {
const match = s3Object.Key.match(regex);
return {
directory: match[1],
file: match[2],
};
});
const grouped = _.groupBy(names, 'directory');
return _.map(grouped, (value) => value);
}
return [];
};
4 changes: 4 additions & 0 deletions tests/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ require('../lib/plugins/slstats/tests/slstats');
require('../lib/plugins/aws/provider/awsProvider.test');
require('../lib/plugins/aws/tests/validate');
require('../lib/plugins/aws/tests/monitorStack');
require('../lib/plugins/aws/tests/setBucketName');
require('../lib/plugins/aws/tests/findAndGroupStacks');
require('../lib/plugins/aws/tests/getS3ObjectsFromStacks');
require('../lib/plugins/aws/info/tests');
require('../lib/plugins/aws/invoke/tests');
require('../lib/plugins/aws/logs/tests');
Expand All @@ -37,6 +40,7 @@ require('../lib/plugins/aws/deploy/compile/events/apiGateway/tests/all');
require('../lib/plugins/aws/deploy/compile/events/sns/tests');
require('../lib/plugins/aws/deploy/compile/events/stream/tests');
require('../lib/plugins/aws/deployFunction/tests/index');
require('../lib/plugins/aws/deployList/tests/index');

// Other Tests
require('./utils/tests');

0 comments on commit a7d42e4

Please sign in to comment.