forked from flow/flow-for-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.js
More file actions
61 lines (56 loc) · 1.54 KB
/
util.js
File metadata and controls
61 lines (56 loc) · 1.54 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
56
57
58
59
60
61
/** @flow */
import spawn from 'cross-spawn';
import {window, workspace} from 'vscode'
import {
buildSearchFlowCommand,
getPathToFlow
} from "../pkg/flow-base/lib/FlowHelpers"
const NODE_NOT_FOUND = '[Flow] Cannot find node in PATH. The simpliest way to resolve it is install node globally'
const FLOW_NOT_FOUND = '[Flow] Cannot find flow in PATH. Try to install it by npm install flow-bin -g'
export function isFlowEnabled() {
return workspace.getConfiguration('flow').get('enabled')
}
export function checkNode() {
try {
const check = spawn(process.platform === 'win32' ? 'where' : 'which', ['node'])
let
flowOutput = "",
flowOutputError = ""
check.stdout.on('data', function (data) {
flowOutput += data.toString();
})
check.stderr.on('data', function (data) {
flowOutputError += data.toString();
})
check.on('exit', function (code) {
if (code != 0) {
window.showErrorMessage(NODE_NOT_FOUND);
}
})
} catch(e) {
window.showErrorMessage(NODE_NOT_FOUND);
}
}
export async function checkFlow() {
const path = await getPathToFlow()
try {
const {command, args} = buildSearchFlowCommand(path)
const check = spawn(command, args)
let
flowOutput = "",
flowOutputError = ""
check.stdout.on('data', function (data) {
flowOutput += data.toString();
})
check.stderr.on('data', function (data) {
flowOutputError += data.toString();
})
check.on('exit', function (code) {
if (code != 0) {
window.showErrorMessage(FLOW_NOT_FOUND);
}
})
} catch(e) {
window.showErrorMessage(FLOW_NOT_FOUND);
}
}