1+ import * as T from 'typings'
12import * as G from 'typings/graphql'
23import * as vscode from 'vscode'
34import * as git from '../services/git'
@@ -6,25 +7,38 @@ import node from '../services/node'
67import openFiles from './utils/openFiles'
78import loadWatchers from './utils/loadWatchers'
89
9- const runCommands = async ( commands : string [ ] ) => {
10+ const runCommands = async ( commands : string [ ] , send : ( action : T . Action ) => void ) => {
1011 if ( ! commands . length ) {
1112 return
1213 }
1314 for ( const command of commands ) {
15+ const process = {
16+ title : command ,
17+ description : 'Running process' ,
18+ }
19+ send ( { type : 'COMMAND_START' , payload : { process : { ...process , status : 'RUNNING' } } } )
1420 const { stdout, stderr } = await node . exec ( command )
1521 if ( stderr ) {
22+ // TODO: distinguish fail & error
1623 console . error ( stderr )
24+ send ( { type : 'COMMAND_FAIL' , payload : { process : { ...process , status : 'FAIL' } } } )
25+ } else {
26+ send ( { type : 'COMMAND_SUCCESS' , payload : { process : { ...process , status : 'SUCCESS' } } } )
1727 }
18- console . log ( `run command: ${ command } ` , stdout )
1928 }
2029}
2130
22- const setupActions = async ( workspaceRoot : vscode . WorkspaceFolder , actions : G . StepActions ) : Promise < void > => {
31+ const setupActions = async (
32+ workspaceRoot : vscode . WorkspaceFolder ,
33+ actions : G . StepActions ,
34+ send : ( action : T . Action ) => void , // send messages to client
35+ ) : Promise < void > => {
2336 const { commands, commits, files, watchers } = actions
2437
2538 // 1. run commits
2639 if ( commits ) {
2740 for ( const commit of commits ) {
41+ // TODO handle git errors
2842 await git . loadCommit ( commit )
2943 }
3044 }
@@ -36,7 +50,7 @@ const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, actions: G.St
3650 loadWatchers ( watchers || [ ] , workspaceRoot . uri )
3751
3852 // 4. run command
39- await runCommands ( commands || [ ] )
53+ await runCommands ( commands || [ ] , send )
4054}
4155
4256export default setupActions
0 commit comments