Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c84b69c
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# package directories | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# serverless-stage-manager | ||
Super simple [serverless](http://www.serverless.com) plugin for validating stage names before deployment. | ||
|
||
[![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com) | ||
[![npm](https://img.shields.io/npm/v/serverless-stage-manager.svg)](https://www.npmjs.com/package/serverless-stage-manager) | ||
[![npm](https://img.shields.io/npm/l/serverless-stage-manager.svg)](https://www.npmjs.com/package/serverless-stage-manager) | ||
|
||
## Installation & Configuration | ||
|
||
Install the module using npm: | ||
``` | ||
npm install serverless-stage-manager --save | ||
``` | ||
|
||
Add `serverless-stage-manager` to the plugin list of your `serverless.yml` file: | ||
|
||
```yaml | ||
plugins: | ||
- serverless-stage-manager | ||
``` | ||
|
||
Add a `stages` value in the `custom` section of your `serverless.yml` file and specify an array of valid stage names. | ||
|
||
```yaml | ||
custom: | ||
stages: | ||
- dev | ||
- staging | ||
- prod | ||
``` | ||
|
||
## Usage | ||
|
||
When running `serverless deploy` or `serverless deploy function`, it will check to make sure it is a valid stage name before continuing. For example: | ||
|
||
```bash | ||
# These will work | ||
serverless deploy -s prod | ||
serverless deploy functon -f funcName -s dev | ||
|
||
# These will fail | ||
serverless deploy -s foo | ||
serverless deploy functon -f funcName -s bar | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
class ServerlessPlugin { | ||
constructor(serverless, options) { | ||
this.serverless = serverless; | ||
this.options = options; | ||
this.stage = this.options.stage ? this.options.stage : this.serverless.service.provider.stage | ||
|
||
this.hooks = { | ||
'before:package:initialize': this.checkStage.bind(this), | ||
'before:deploy:function:initialize': this.checkStage.bind(this) | ||
}; | ||
|
||
} | ||
|
||
checkStage() { | ||
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(this.stage) === -1) { | ||
throw new Error(`'${this.stage}' is not a valid deployment stage. Add it to your serverless.yml's "custom.stages" section.`) | ||
} | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
module.exports = ServerlessPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "serverless-stage-manager", | ||
"version": "1.0.0", | ||
"description": "Super simple serverless for validating stage names before deployment", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/jeremydaly/serverless-stage-manager.git" | ||
}, | ||
"keywords": [ | ||
"serverless", | ||
"serverless-plugin", | ||
"aws", | ||
"nodejs", | ||
"deployment" | ||
], | ||
"author": "Jeremy Daly <jeremy@jeremydaly.com>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/jeremydaly/serverless-stage-manager/issues" | ||
}, | ||
"homepage": "https://github.com/jeremydaly/serverless-stage-manager#readme" | ||
} |