forked from trek10inc/serverless-cloudformation-changesets
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
45 lines (38 loc) · 1.42 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict'
const _ = require('lodash')
const createChangeSet = require('./lib/createChangeSet')
const setBucketName = require('serverless/lib/plugins/aws/lib/setBucketName')
class ServerlessCloudFormationChangeSets {
constructor (serverless, options) {
this.serverless = serverless
this.options = _.merge(
{},
_.omit(options, ['changeset']),
_.get(serverless.service, 'custom.cf-changesets') || {}
)
this.provider = this.serverless.getProvider('aws')
if (options.changeset) {
this.options.requireChangeSet = true
if (typeof options.changeset === 'string') {
this.options.changeSetName = options.changeset
}
}
if (this.options.requireChangeSet) {
this.hooks = {
'before:aws:deploy:deploy:updateStack': this.lockStackDeployment.bind(this),
'aws:deploy:deploy:updateStack': () => Promise.resolve()
.then(setBucketName.setBucketName.bind(this))
.then(createChangeSet.createChangeSet.bind(this)),
'after:aws:deploy:deploy:updateStack': this.unlockStackDeployment.bind(this)
}
}
}
lockStackDeployment () {
this.shouldNotDeploy = this.serverless.service.provider.shouldNotDeploy
this.serverless.service.provider.shouldNotDeploy = true
}
unlockStackDeployment () {
this.serverless.service.provider.shouldNotDeploy = this.shouldNotDeploy
}
}
module.exports = ServerlessCloudFormationChangeSets