-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvspath.ts
53 lines (47 loc) · 1.19 KB
/
vspath.ts
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
import { execSync } from "child_process";
import path = require('path');
interface VisualStudioInfo
{
installationPath:string;
displayName:string;
version:number;
DEPOT_TOOLS_WIN_TOOLCHAIN:number;
GYP_MSVS_VERSION:number;
vs2017_install:string;
productPath:string;
}
function getVisualStudioPath():VisualStudioInfo
{
const vspath = JSON.parse(execSync(`${path.join(__dirname, 'vswhere.exe')} -format json`).toString()) as VisualStudioInfo[];
let selected:VisualStudioInfo|null = null;
let version = 0;
for (const v of vspath)
{
const name = v.displayName;
v.version = +name.substr(name.length-4);
if (v.version > version)
{
version = v.version;
selected = v;
}
}
if (!selected) throw Error('Visual studio does not installed');
let GYP_MSVS_VERSION:number;
if (selected.displayName.endsWith('2017'))
{
GYP_MSVS_VERSION = 2017;
}
else if(selected.displayName.endsWith('2019'))
{
GYP_MSVS_VERSION = 2019;
}
else
{
throw Error('Unknown version: '+ selected.displayName);
}
selected.DEPOT_TOOLS_WIN_TOOLCHAIN = 0;
selected.GYP_MSVS_VERSION = GYP_MSVS_VERSION;
selected.vs2017_install = selected.installationPath;
return selected;
}
export = getVisualStudioPath();