-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
55 lines (50 loc) · 1.84 KB
/
index.js
File metadata and controls
55 lines (50 loc) · 1.84 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
45
46
47
48
49
50
51
52
53
54
55
const { executeCommandOnAllServices } = require('./lib/runHook');
const { runOffline } = require('./lib/runOfflineHook');
const { generateYamlAndSymlinks } = require('./lib/symlinkHook');
class DeployMultiplePlugin {
constructor(serverless, options) {
const acceptedCommands = serverless.pluginManager.getCommands();
const names = Object.keys(acceptedCommands);
const defaultCommands = {
add: {
usage: 'create new micro service folder',
lifecycleEvents: ['add'],
},
generate: {
usage: 'generate serverless.yml and symlinks',
lifecycleEvents: ['symlinks'],
},
};
const commonOptions = {
service: {
usage: 'specify which services to target',
},
parallel: {
usage: 'run all service commands in parallel',
},
};
this.commands = {
multi: {
usage: 'run serverless commands on multiple mirco services',
commands: names.reduce((cmds, name) => {
cmds[name] = {
options: Object.assign({}, commonOptions, acceptedCommands[name].options),
usage: `calls serverless ${name} [options] on each managed micro service`,
lifecycleEvents: ['symlinks', 'run'],
};
return cmds;
}, defaultCommands),
},
};
const boundExecFn = executeCommandOnAllServices.bind(null, serverless, options);
const boundOfflineFn = runOffline.bind(null, serverless, options);
const boundGenerateSymlinks = generateYamlAndSymlinks.bind(null, serverless, options);
names.push(...Object.keys(defaultCommands));
this.hooks = names.reduce((hks, name) => {
hks[`multi:${name}:symlinks`] = boundGenerateSymlinks;
hks[`multi:${name}:run`] = (name !== 'offline') ? boundExecFn : boundOfflineFn;
return hks;
}, {});
}
}
module.exports = DeployMultiplePlugin;