Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydaly committed Oct 20, 2017
0 parents commit c84b69c
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
# package directories
node_modules
44 changes: 44 additions & 0 deletions README.md
@@ -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
```
29 changes: 29 additions & 0 deletions index.js
@@ -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;
26 changes: 26 additions & 0 deletions package.json
@@ -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"
}

0 comments on commit c84b69c

Please sign in to comment.