@@ -4,33 +4,11 @@ import * as vscode from 'vscode'
4
4
import * as git from '../services/git'
5
5
import node from '../services/node'
6
6
7
- // interface ErrorMessageFilter {
8
- // [lang: string]: {
9
- // [key: string]: string
10
- // }
11
- // }
12
-
13
- // TODO: should be loaded on startup based on language
14
- // const commandErrorMessageFilter: ErrorMessageFilter = {
15
- // #"diff-47d0c00fa3c186f7fc510aad6c9706e5d40404c1952033d7c544d0317de2b80b-16-6-0" data-selected="false" role="gridcell" tabindex="-1" valign="top">16
- // 'node-gyp': 'Error running npm setup command'
17
- // }
18
- // }
19
-
20
- // TODO: pass command and command name down for filtering. Eg. JAVASCRIPT, 'npm install'
21
7
const runCommands = async (commands: string[]) => {
22
8
for (const command of commands) {
23
9
const { stdout, stderr } = await node.exec(command)
24
10
if (stderr) {
25
11
console.error(stderr)
26
- // language specific error messages from running commands
27
- // const filteredMessages = Object.keys(commandErrorMessageFilter[language])
28
- // for (const message of filteredMessages) {
29
- // if (stderr.match(message)) {
30
- // // ignored error
31
- // throw new Error('Error running setup command')
32
- // }
33
- // }
34
12
}
35
13
console.log(`run command: ${command}`, stdout)
36
14
}
@@ -44,64 +22,52 @@ const disposeWatcher = (listener: string) => {
44
22
delete watchers[listener]
45
23
}
46
24
47
- const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, actions: G.StepActions): Promise<void> => {
48
- const { commands, commits, files, listeners } = actions
49
- // run commits
50
- if (commits) {
51
- for (const commit of commits) {
52
- await git.loadCommit(commit)
53
- }
54
- }
55
-
56
- // run file watchers (listeners)
57
- if (listeners) {
58
- console.log('listeners')
59
- for (const listener of listeners) {
60
- if (!watchers[listener]) {
61
- const rootUri = vscode.workspace.getWorkspaceFolder(workspaceRoot.uri)
62
- const pattern = new vscode.RelativePattern(rootUri!, listener) // eslint-disable-line
63
- console.log(pattern)
64
- const listen = vscode.workspace.createFileSystemWatcher(pattern)
65
- watchers[listener] = listen
66
- watchers[listener].onDidChange(() => {
67
- console.log('onDidChange')
68
- // trigger save
69
- vscode.commands.executeCommand('coderoad.run_test', null, () => {
70
- // cleanup watcher on success
71
- disposeWatcher(listener)
72
- })
25
+ const loadListeners = (listeners: string[], workspaceUri: vscode.Uri) => {
26
+ for (const listener of listeners) {
27
+ if (!watchers[listener]) {
28
+ const rootUri = vscode.workspace.getWorkspaceFolder(workspaceUri)
29
+ const pattern = new vscode.RelativePattern(rootUri!, listener) // eslint-disable-line
30
+ console.log(pattern)
31
+ const listen = vscode.workspace.createFileSystemWatcher(pattern)
32
+ watchers[listener] = listen
33
+ watchers[listener].onDidChange(() => {
34
+ console.log('onDidChange')
35
+ // trigger save
36
+ vscode.commands.executeCommand('coderoad.run_test', null, () => {
37
+ // cleanup watcher on success
38
+ disposeWatcher(listener)
73
39
})
74
- watchers[listener].onDidCreate(() => {
75
- console.log(' onDidCreate')
76
- // trigger save
77
- vscode.commands.executeCommand('coderoad.run_test', null, () => {
78
- // cleanup watcher on success
79
- disposeWatcher(listener)
80
- } )
40
+ })
41
+ watchers[listener]. onDidCreate(() => {
42
+ console.log('onDidCreate')
43
+ // trigger save
44
+ vscode.commands.executeCommand('coderoad.run_test', null, () => {
45
+ // cleanup watcher on success
46
+ disposeWatcher(listener )
81
47
})
82
- watchers[listener].onDidDelete(() => {
83
- console.log(' onDidDelete')
84
- // trigger save
85
- vscode.commands.executeCommand('coderoad.run_test', null, () => {
86
- // cleanup watcher on success
87
- disposeWatcher(listener)
88
- } )
48
+ })
49
+ watchers[listener]. onDidDelete(() => {
50
+ console.log('onDidDelete')
51
+ // trigger save
52
+ vscode.commands.executeCommand('coderoad.run_test', null, () => {
53
+ // cleanup watcher on success
54
+ disposeWatcher(listener )
89
55
})
90
- }
91
- }
92
- } else {
93
- // remove all watchers
94
- for (const listener of Object.keys(watchers)) {
95
- disposeWatcher(listener)
56
+ })
96
57
}
97
58
}
59
+ }
98
60
99
- // run command
100
- if (commands) {
101
- await runCommands(commands)
61
+ const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, actions: G.StepActions): Promise<void> => {
62
+ const { commands, commits, files, listeners } = actions
63
+ // 1. run commits
64
+ if (commits) {
65
+ for (const commit of commits) {
66
+ await git.loadCommit(commit)
67
+ }
102
68
}
103
69
104
- // open files
70
+ //2. open files
105
71
if (files) {
106
72
for (const filePath of files) {
107
73
try {
@@ -131,6 +97,21 @@ const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, actions: G.St
131
97
}
132
98
}
133
99
}
100
+
101
+ // 3. start file watchers (listeners)
102
+ if (listeners) {
103
+ loadListeners(listeners, workspaceRoot.uri)
104
+ } else {
105
+ // remove all watchers
106
+ for (const listener of Object.keys(watchers)) {
107
+ disposeWatcher(listener)
108
+ }
109
+ }
110
+
111
+ // 4. run command
112
+ if (commands) {
113
+ await runCommands(commands)
114
+ }
134
115
}
135
116
136
117
export default setupActions