-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (48 loc) · 1.57 KB
/
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const _ = require('lodash')
const commands = require('./commands')
const Finder = require('./helpers/finder')
const Logger = require('./helpers/logger')
class ServerlessPlugin {
constructor (serverless, options) {
this.serverless = serverless
this.options = options
this.cwd = process.cwd()
this.config = _.get(this.serverless.service, 'custom.service', {})
this.commands = {
microservices: {
usage: 'Microservices manager',
commands: {
init: commands.init.command,
deploy: commands.deploy.command,
delete: commands.delete.command
}
}
}
this.hooks = {
'microservices:init:handler': commands.init.controller.bind(this),
'microservices:deploy:handler': commands.deploy.controller.bind(this),
'microservices:delete:handler': commands.delete.controller.bind(this)
}
this.logger = new Logger(this.serverless)
this.servicesPath = _.get(this.config, 'path', 'node_modules/*/serverless.yml')
this.finder = new Finder(this.servicesPath, this.cwd)
}
/**
* Load services
*/
async loadServices () {
this.logger.log(`Searching for services in '${this.servicesPath}'..`)
await this.finder.find()
if (this.config.only && Array.isArray(this.config.only)) {
this.finder.filter(this.config.only)
}
const services = this.finder.get()
if (services.length === 0) {
this.logger.warn(`No services found`)
} else {
this.logger.log(`Found ${services.length} services`)
}
return services
}
}
module.exports = ServerlessPlugin