Skip to content

Commit 8968ecb

Browse files
committed
update
1 parent 9f7af1e commit 8968ecb

File tree

2 files changed

+39
-9
lines changed

2 files changed

+39
-9
lines changed

lib/serverless-action.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default class ServerlessAction {
1515
return childProcess.spawn('sls', ['remove', '--region', region, '--stage', stage], {cwd: this.path})
1616
}
1717

18-
action (action, functionName, region, stage) {
18+
action (action, functionName, region, stage, inputJson) {
1919
switch (action) {
2020
case 'deploy-function':
2121
return childProcess.spawn('sls', [
@@ -29,17 +29,23 @@ export default class ServerlessAction {
2929
stage
3030
], {cwd: this.path})
3131
case 'invoke':
32-
return childProcess.spawn('sls', [
32+
const commandOption = [
3333
'invoke',
3434
'--function',
3535
functionName,
36-
'--data',
37-
'{}',
3836
'--region',
3937
region,
4038
'--stage',
4139
stage
42-
], {cwd: this.path})
40+
]
41+
if (inputJson) {
42+
commandOption.push('--path')
43+
commandOption.push(inputJson)
44+
} else {
45+
commandOption.push('--data')
46+
commandOption.push('{}')
47+
}
48+
return childProcess.spawn('sls', commandOption, {cwd: this.path})
4349
case 'logs':
4450
return childProcess.spawn('sls', [
4551
'logs',

lib/serverless-dashboard-view.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default class ServerlessDashboardView {
1515
this.properties = {
1616
consoleOutput: ''
1717
}
18+
this.inputJson = {}
1819
etch.initialize(this)
1920
this.action = new ServerlessAction(path.dirname(this.yamlPath))
2021
}
@@ -72,18 +73,22 @@ export default class ServerlessDashboardView {
7273

7374
slsAction (action, functionName) {
7475
this.resetCosnoleOutput()
76+
const inputJson = this.inputJson && this.inputJson[functionName] && this.inputJson[functionName].absolute
77+
? this.inputJson[functionName].absolute : false
7578
switch (action) {
7679
case 'deploy-function':
7780
this.properties.consoleOutput = `$ serverless deploy function --function ${functionName} --stage ${this.refs.stage.value} --region ${this.refs.region.value}<br/><br/>`
7881
break
7982
case 'invoke':
80-
this.properties.consoleOutput = `$ serverless invoke --function ${functionName} --stage ${this.refs.stage.value} --region ${this.refs.region.value}<br/><br/>`
83+
this.properties.consoleOutput = `$ serverless invoke --function ${functionName} --stage ${this.refs.stage.value} --region ${this.refs.region.value}`
84+
this.properties.consoleOutput += inputJson ? ` --path ${inputJson}` : ''
85+
this.properties.consoleOutput += '<br/><br/>'
8186
break
8287
case 'logs':
8388
this.properties.consoleOutput = `$ serverless logs --function ${functionName} --stage ${this.refs.stage.value} --region ${this.refs.region.value}<br/><br/>`
8489
break
8590
}
86-
const sls = this.action.action(action, functionName, this.refs.region.value, this.refs.stage.value)
91+
const sls = this.action.action(action, functionName, this.refs.region.value, this.refs.stage.value, inputJson)
8792
sls.stdout.on('data', (data) => {
8893
this.update({
8994
consoleOutput: `${this.properties.consoleOutput}${data.toString()}`
@@ -111,6 +116,18 @@ export default class ServerlessDashboardView {
111116
this.update()
112117
}
113118

119+
parseJson (functionName) {
120+
const remote = require('electron').remote
121+
const files = remote.dialog.showOpenDialog(remote.getCurrentWindow(), {properties: ['openFile']})
122+
if (files && files.length) {
123+
this.inputJson[functionName] = {
124+
absolute: files[0],
125+
file: files[0].split(path.sep).pop()
126+
}
127+
this.update()
128+
}
129+
}
130+
114131
render () {
115132
let functions = []
116133
if (this.slsObject.functions) {
@@ -191,6 +208,7 @@ export default class ServerlessDashboardView {
191208

192209
functionsRender (functionElem, functionName) {
193210
const events = []
211+
const jsxFunctionName = `sls-action-${functionName}`
194212
if (functionElem.events) {
195213
_.forEach(functionElem.events, (event) => {
196214
if (typeof event === 'object') {
@@ -385,15 +403,21 @@ export default class ServerlessDashboardView {
385403
</ul>
386404
<div class="apply-block">
387405
<div class="select-container">
388-
<select class="form-control" ref='sls-action'>
406+
<select class="form-control" ref={jsxFunctionName}>
389407
<option value="deploy-function">Deploy Function</option>
390408
<option value="invoke">Invoke</option>
391409
<option value="logs">Logs</option>
392410
</select>
393411
<button class="btn" onClick={() => {
394-
this.slsAction(this.refs['sls-action'].value, functionName)
412+
this.slsAction(this.refs[`sls-action-${functionName}`].value, functionName)
395413
}}>Apply</button>
396414
</div>
415+
<div class="pull-right">
416+
<button class="btn" onClick={() => {
417+
this.parseJson(functionName)
418+
}}>Input JSON</button><br />
419+
{this.inputJson && this.inputJson[functionName] && this.inputJson[functionName].file ? this.inputJson[functionName].file : ''}
420+
</div>
397421
</div>
398422
</div>
399423
</div>

0 commit comments

Comments
 (0)