-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathserverless-action.js
61 lines (56 loc) · 1.47 KB
/
serverless-action.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
54
55
56
57
58
59
60
61
'use babel'
import childProcess from 'child_process'
export default class ServerlessAction {
constructor (path) {
this.path = path
}
deploy (region, stage) {
return childProcess.spawn('sls', ['deploy', '--region', region, '--stage', stage], {cwd: this.path})
}
remove (region, stage) {
return childProcess.spawn('sls', ['remove', '--region', region, '--stage', stage], {cwd: this.path})
}
action (action, functionName, region, stage, inputJson) {
switch (action) {
case 'deploy-function':
return childProcess.spawn('sls', [
'deploy',
'function',
'--function',
functionName,
'--region',
region,
'--stage',
stage
], {cwd: this.path})
case 'invoke':
const commandOption = [
'invoke',
'--function',
functionName,
'--region',
region,
'--stage',
stage
]
if (inputJson) {
commandOption.push('--path')
commandOption.push(inputJson)
} else {
commandOption.push('--data')
commandOption.push('{}')
}
return childProcess.spawn('sls', commandOption, {cwd: this.path})
case 'logs':
return childProcess.spawn('sls', [
'logs',
'--function',
functionName,
'--region',
region,
'--stage',
stage
], {cwd: this.path})
}
}
}