forked from fauna-labs/serverless-fauna
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (39 loc) · 1.23 KB
/
index.js
File metadata and controls
44 lines (39 loc) · 1.23 KB
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
'use strict'
const Logger = require('./Logger')
const DeployCommand = require('./commands/DeployCommand')
const RemoveCommand = require('./commands/RemoveCommand')
const faunaSchemaProperties = require('./schemaProps/fauna')
const getClient = require('./fauna/client')
class ServerlessFaunaPlugin {
constructor(serverless, options) {
this.serverless = serverless
this.config = this.serverless.service.initialServerlessConfig.fauna
this.options = options
this.logger = new Logger(serverless.cli)
this.faunaClient = getClient(this.config.client)
this.serverless.configSchemaHandler.defineTopLevelProperty(
'fauna',
faunaSchemaProperties
)
this.commands = {
fauna: {
commands: {},
},
}
this.hooks = {}
const cmdList = [DeployCommand, RemoveCommand]
cmdList.forEach((CmdCls) => this.registerCommand(CmdCls))
}
registerCommand(CmdCls) {
const cmd = new CmdCls({
faunaClient: this.faunaClient,
serverless: this.serverless,
config: this.config,
options: this.options,
logger: this.logger,
})
Object.assign(this.hooks, cmd.hooks)
Object.assign(this.commands.fauna.commands, cmd.command)
}
}
module.exports = ServerlessFaunaPlugin