Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

## How to use

1. Copy `serverless-predeploy-plugin.js` into `.serverless-plugins` in the serverless project. You may need to create this folder
1. Add `serverless-predeploy-plugin` to the list of plugins in `serverless.yml`. The plugins list is an array at the root level (an example `serverless.yml` is included in this project)
1. Add an array of commands to be run at `custom:predeploy_commands`
1. Copy `serverless-hooks-plugin.js` into `.serverless-plugins` in the serverless project. You may need to create this folder.
1. Add `serverless-hooks-plugin` to the list of plugins in `serverless.yml`. The plugins list is an array at the root level (an example `serverless.yml` is included in this project).
1. Add an array of hooks to be used as per examples, at `custom: hooks`.
35 changes: 35 additions & 0 deletions serverless-hooks-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

class ServerlessHooksPlugin {

constructor(serverless, options) {
this.serverless = serverless;
this.options = options;

const buildHookFunction = hook => (
() => {
const commands = serverless.service.custom.hooks[hook] || []
commands.forEach(
command => {
serverless.cli.log(`Running ${hook} command: "${command}"`)
exec(command)
}
)
}
)

const hooksObj = {}

const custom = serverless.service.custom || {}
const hooks = custom.hooks || {}
Object.keys(serverless.service.custom.hooks).forEach(
hook => {
hooksObj[hook] = buildHookFunction(hook)
}
)

this.hooks = hooksObj
}
}

module.exports = ServerlessHooksPlugin;
23 changes: 0 additions & 23 deletions serverless-predeploy-plugin.js

This file was deleted.

14 changes: 8 additions & 6 deletions serverless.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
service: serverless-predeploy-plugin # NOTE: update this with your service name
service: serverless-hooks-plugin # NOTE: update this with your service name

plugins:
- serverless-predeploy-plugin
- serverless-hooks-plugin

custom:
predeploy_commands:
- pwd
- echo "Hi there"
hooks:
before:command:lifecycleEvent:
- echo "Before a command called 'command': an example!"
after:command:lifecycleEvent:
- echo "After a command called 'command': another example!"

# Both provider and functions are required

# provider:
# name: aws
# runtime: nodejs4.3
# runtime: nodejs6.10
#
# functions:
# hello:
Expand Down