-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathsys-info.ts
118 lines (99 loc) · 3.14 KB
/
sys-info.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import * as path from "path";
import { format } from "util";
import { sysInfo } from "@nativescript/doctor";
import {
MacOSVersions,
MacOSDeprecationStringFormat,
XcodeDeprecationStringFormat,
} from "./constants";
import { getNodeWarning } from "./common/verify-node-version";
import { exported } from "./common/decorators";
import * as semver from "semver";
import {
ISysInfo,
IFileSystem,
IHostInfo,
ISystemWarning,
} from "./common/declarations";
import { injector } from "./common/yok";
export class SysInfo implements ISysInfo {
private sysInfo: ISysInfoData = null;
constructor(private $fs: IFileSystem, private $hostInfo: IHostInfo) {}
public async getSysInfo(
config?: NativeScriptDoctor.ISysInfoConfig
): Promise<NativeScriptDoctor.ISysInfoData> {
if (!this.sysInfo) {
const pathToNativeScriptCliPackageJson =
(config && config.pathToNativeScriptCliPackageJson) ||
path.join(__dirname, "..", "package.json");
const androidToolsInfo = config && config.androidToolsInfo;
this.sysInfo = await sysInfo.getSysInfo({
pathToNativeScriptCliPackageJson,
androidToolsInfo,
});
}
return this.sysInfo;
}
public getXcodeVersion(): Promise<string> {
return sysInfo.getXcodeVersion();
}
public getCocoaPodsVersion(): Promise<string> {
return sysInfo.getCocoaPodsVersion();
}
public getJavaPath(): Promise<string> {
return sysInfo.getJavaPath();
}
public getJavaCompilerVersion(): Promise<string> {
return sysInfo.getJavaCompilerVersion();
}
public getJavaVersionFromPath(): Promise<string> {
return sysInfo.getJavaVersionFromPath();
}
public getJavaVersionFromJavaHome(): Promise<string> {
return sysInfo.getJavaVersionFromJavaHome();
}
@exported("sysInfo")
public async getSystemWarnings(): Promise<ISystemWarning[]> {
const warnings: ISystemWarning[] = [];
const macOSWarningMessage = await this.getMacOSWarningMessage();
if (macOSWarningMessage) {
macOSWarningMessage.toString = function () {
return this.message;
};
warnings.push(macOSWarningMessage);
}
const nodeWarning = getNodeWarning();
if (nodeWarning) {
nodeWarning.toString = function () {
return this.message;
};
warnings.push(nodeWarning);
}
return warnings;
}
@exported("sysInfo")
public getSupportedNodeVersionRange(): string {
const pathToCLIPackageJson = path.join(__dirname, "..", "package.json");
const jsonContent = this.$fs.readJson(pathToCLIPackageJson);
return jsonContent && jsonContent.engines && jsonContent.engines.node;
}
public async getMacOSWarningMessage(): Promise<ISystemWarning> {
const macOSVersion = await this.$hostInfo.getMacOSVersion();
if (macOSVersion && macOSVersion < MacOSVersions.HighSierra) {
return {
message: format(MacOSDeprecationStringFormat, macOSVersion),
severity: SystemWarningsSeverity.high,
};
}
return null;
}
public async getXcodeWarning(): Promise<string> {
const xcodeVersion = await this.getXcodeVersion();
if (xcodeVersion && semver.lt(semver.coerce(xcodeVersion), "11.0.0")) {
const message = format(XcodeDeprecationStringFormat, xcodeVersion);
return message;
}
return null;
}
}
injector.register("sysInfo", SysInfo);