-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
27 lines (22 loc) · 925 Bytes
/
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
'use strict';
class ServerlessPlugin {
constructor(serverless, options) {
this.serverless = serverless
this.options = options
this.hooks = {
'before:package:initialize': this.checkStage.bind(this),
'before:deploy:function:initialize': this.checkStage.bind(this)
}
}
checkStage() {
let stage = this.options.stage ? this.options.stage : this.serverless.service.provider.stage
if (!this.serverless.service.custom.stages || !Array.isArray(this.serverless.service.custom.stages)) {
throw new Error(`A "stages" array must be defined in your serverless.yml's "custom" section.`)
} else {
if (this.serverless.service.custom.stages.indexOf(stage) === -1) {
throw new Error(`'${stage}' is not a valid deployment stage. Add it to your serverless.yml's "custom.stages" section.`)
}
}
} // end checkStage
} // end class
module.exports = ServerlessPlugin;