Skip to content

Commit 064a5af

Browse files
Merge pull request #30 from NativeScript/fatme/platform-specific-infos
Get sysInfos based on specified platform
2 parents df2dbec + cc416b6 commit 064a5af

File tree

4 files changed

+230
-138
lines changed

4 files changed

+230
-138
lines changed

lib/doctor.ts

+44-37
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,35 @@ export class Doctor implements NativeScriptDoctor.IDoctor {
3232
let result: NativeScriptDoctor.IInfo[] = [];
3333
const sysInfoData = await this.sysInfo.getSysInfo(config);
3434

35+
if (!config || !config.platform || config.platform === Constants.ANDROID_PLATFORM_NAME) {
36+
result = result.concat(this.getAndroidInfos(sysInfoData));
37+
}
38+
39+
if (!config || !config.platform || config.platform === Constants.IOS_PLATFORM_NAME) {
40+
result = result.concat(await this.getiOSInfos(sysInfoData));
41+
}
42+
43+
if (!this.hostInfo.isDarwin) {
44+
result.push({
45+
message: "Local builds for iOS can be executed only on a macOS system. To build for iOS on a different operating system, you can use the NativeScript cloud infrastructure.",
46+
additionalInformation: "",
47+
platforms: [Constants.IOS_PLATFORM_NAME],
48+
type: Constants.INFO_TYPE_NAME
49+
});
50+
}
51+
52+
return result;
53+
}
54+
55+
public async getWarnings(config?: NativeScriptDoctor.ISysInfoConfig): Promise<NativeScriptDoctor.IWarning[]> {
56+
const info = await this.getInfos(config);
57+
return info.filter(item => item.type === Constants.WARNING_TYPE_NAME)
58+
.map(item => this.convertInfoToWarning(item));
59+
}
60+
61+
private getAndroidInfos(sysInfoData: NativeScriptDoctor.ISysInfoData): NativeScriptDoctor.IInfo[] {
62+
let result: NativeScriptDoctor.IInfo[] = [];
63+
3564
result = result.concat(
3665
this.processValidationErrors({
3766
warnings: this.androidToolsInfo.validateAndroidHomeEnvVariable(),
@@ -66,9 +95,24 @@ export class Doctor implements NativeScriptDoctor.IDoctor {
6695
warnings: this.androidToolsInfo.validateJavacVersion(sysInfoData.javacVersion),
6796
infoMessage: "Javac is installed and is configured properly.",
6897
platforms: [Constants.ANDROID_PLATFORM_NAME]
98+
}),
99+
this.processSysInfoItem({
100+
item: sysInfoData.javacVersion,
101+
infoMessage: "The Java Development Kit (JDK) is installed and is configured properly.",
102+
warningMessage: "The Java Development Kit (JDK) is not installed or is not configured properly.",
103+
additionalInformation: "You will not be able to work with the Android SDK and you might not be able" + EOL
104+
+ "to perform some Android-related operations. To ensure that you can develop and" + EOL
105+
+ "test your apps for Android, verify that you have installed the JDK as" + EOL
106+
+ "described in http://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html (for JDK 8).",
107+
platforms: [Constants.ANDROID_PLATFORM_NAME]
69108
})
70109
);
71110

111+
return result;
112+
}
113+
114+
private async getiOSInfos(sysInfoData: NativeScriptDoctor.ISysInfoData): Promise<NativeScriptDoctor.IInfo[]> {
115+
let result: NativeScriptDoctor.IInfo[] = [];
72116
if (this.hostInfo.isDarwin) {
73117
result = result.concat(
74118
this.processSysInfoItem({
@@ -144,46 +188,9 @@ export class Doctor implements NativeScriptDoctor.IDoctor {
144188
);
145189
}
146190

147-
result = result.concat(
148-
this.processSysInfoItem({
149-
item: sysInfoData.javacVersion,
150-
infoMessage: "The Java Development Kit (JDK) is installed and is configured properly.",
151-
warningMessage: "The Java Development Kit (JDK) is not installed or is not configured properly.",
152-
additionalInformation: "You will not be able to work with the Android SDK and you might not be able" + EOL
153-
+ "to perform some Android-related operations. To ensure that you can develop and" + EOL
154-
+ "test your apps for Android, verify that you have installed the JDK as" + EOL
155-
+ "described in http://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html (for JDK 8).",
156-
platforms: [Constants.ANDROID_PLATFORM_NAME]
157-
}),
158-
this.processSysInfoItem({
159-
item: sysInfoData.gitVer,
160-
infoMessage: "Git is installed and is configured properly.",
161-
warningMessage: "Git is not installed or not configured properly.",
162-
additionalInformation: "You will not be able to create and work with Screen Builder projects." + EOL
163-
+ "To be able to work with Screen Builder projects, download and install Git as described" + EOL
164-
+ "in https://git-scm.com/downloads and add the git executable to your PATH.",
165-
platforms: Constants.SUPPORTED_PLATFORMS
166-
})
167-
);
168-
169-
if (!this.hostInfo.isDarwin) {
170-
result.push({
171-
message: "Local builds for iOS can be executed only on a macOS system. To build for iOS on a different operating system, you can use the NativeScript cloud infrastructure.",
172-
additionalInformation: "",
173-
platforms: [Constants.IOS_PLATFORM_NAME],
174-
type: Constants.INFO_TYPE_NAME
175-
});
176-
}
177-
178191
return result;
179192
}
180193

181-
public async getWarnings(config?: NativeScriptDoctor.ISysInfoConfig): Promise<NativeScriptDoctor.IWarning[]> {
182-
const info = await this.getInfos(config);
183-
return info.filter(item => item.type === Constants.WARNING_TYPE_NAME)
184-
.map(item => this.convertInfoToWarning(item));
185-
}
186-
187194
private processSysInfoItem(data: { item: string | boolean, infoMessage: string, warningMessage: string, additionalInformation?: string, platforms: string[] }): NativeScriptDoctor.IInfo {
188195
if (!data.item) {
189196
return {

lib/sys-info.ts

+65-36
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as path from "path";
99
import * as osenv from "osenv";
1010
import * as temp from "temp";
1111
import * as semver from "semver";
12+
import { Constants } from "./constants";
1213

1314
export class SysInfo implements NativeScriptDoctor.ISysInfo {
1415
private static JAVA_COMPILER_VERSION_REGEXP = /^javac (.*)/im;
@@ -34,7 +35,11 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
3435
private monoVerCache: string;
3536
private gitVerCache: string;
3637
private gradleVerCache: string;
37-
private sysInfoCache: NativeScriptDoctor.ISysInfoData;
38+
39+
private commonSysInfoCache: NativeScriptDoctor.ICommonSysInfoData;
40+
private androidSysInfoCache: NativeScriptDoctor.IAndroidSysInfoData;
41+
private iOSSysInfoCache: NativeScriptDoctor.IiOSSysInfoData;
42+
3843
private isCocoaPodsWorkingCorrectlyCache: boolean;
3944
private nativeScriptCliVersionCache: string;
4045
private xcprojInfoCache: NativeScriptDoctor.IXcprojInfo;
@@ -215,43 +220,16 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
215220
});
216221
}
217222

218-
public getSysInfo(config?: NativeScriptDoctor.ISysInfoConfig): Promise<NativeScriptDoctor.ISysInfoData> {
219-
return this.getValueForProperty(() => this.sysInfoCache, async (): Promise<NativeScriptDoctor.ISysInfoData> => {
220-
const result: NativeScriptDoctor.ISysInfoData = Object.create(null);
221-
222-
// os stuff
223-
result.platform = platform();
224-
result.shell = osenv.shell();
225-
result.os = await this.getOs();
226-
227-
// node stuff
228-
result.procArch = process.arch;
229-
result.nodeVer = await this.getNodeVersion();
230-
result.npmVer = await this.getNpmVersion();
231-
result.nodeGypVer = await this.getNodeGypVersion();
232-
233-
result.dotNetVer = await this.hostInfo.dotNetVersion();
234-
result.javacVersion = await this.getJavaCompilerVersion();
235-
result.xcodeVer = await this.getXcodeVersion();
236-
result.xcodeprojLocation = await this.getXcodeprojLocation();
237-
result.itunesInstalled = await this.isITunesInstalled();
238-
result.cocoaPodsVer = await this.getCocoaPodsVersion();
239-
result.adbVer = await this.getAdbVersion(config && config.androidToolsInfo && config.androidToolsInfo.pathToAdb);
240-
result.androidInstalled = await this.isAndroidInstalled();
241-
result.monoVer = await this.getMonoVersion();
242-
result.gitVer = await this.getGitVersion();
243-
result.gradleVer = await this.getGradleVersion();
244-
result.isCocoaPodsWorkingCorrectly = await this.isCocoaPodsWorkingCorrectly();
245-
246-
result.nativeScriptCliVersion = await this.getNativeScriptCliVersion();
247-
248-
result.isCocoaPodsUpdateRequired = await this.isCocoaPodsUpdateRequired();
249-
result.isAndroidSdkConfiguredCorrectly = await this.isAndroidSdkConfiguredCorrectly();
223+
public async getSysInfo(config?: NativeScriptDoctor.ISysInfoConfig): Promise<NativeScriptDoctor.ISysInfoData> {
224+
if (config && config.platform === Constants.ANDROID_PLATFORM_NAME) {
225+
return <NativeScriptDoctor.ISysInfoData>Object.assign(await this.getCommonSysInfo(), await this.getAndroidSysInfo(config));
226+
}
250227

251-
result.pythonInfo = await this.getPythonInfo();
228+
if (config && config.platform === Constants.IOS_PLATFORM_NAME) {
229+
return <NativeScriptDoctor.ISysInfoData>Object.assign(await this.getCommonSysInfo(), await this.getiOSSysInfo());
230+
}
252231

253-
return result;
254-
});
232+
return Object.assign(await this.getCommonSysInfo(), await this.getAndroidSysInfo(), await this.getiOSSysInfo());
255233
}
256234

257235
public isCocoaPodsWorkingCorrectly(): Promise<boolean> {
@@ -467,4 +445,55 @@ export class SysInfo implements NativeScriptDoctor.ISysInfo {
467445
private unixVer(): Promise<string> {
468446
return this.execCommand("uname -a");
469447
}
448+
449+
private getCommonSysInfo(): Promise<NativeScriptDoctor.ICommonSysInfoData> {
450+
return this.getValueForProperty(() => this.commonSysInfoCache, async (): Promise<NativeScriptDoctor.ICommonSysInfoData> => {
451+
const result: NativeScriptDoctor.ICommonSysInfoData = Object.create(null);
452+
453+
// os stuff
454+
result.platform = platform();
455+
result.shell = osenv.shell();
456+
result.os = await this.getOs();
457+
result.procArch = process.arch;
458+
result.nodeVer = await this.getNodeVersion();
459+
result.npmVer = await this.getNpmVersion();
460+
result.nodeGypVer = await this.getNodeGypVersion();
461+
result.nativeScriptCliVersion = await this.getNativeScriptCliVersion();
462+
result.gitVer = await this.getGitVersion();
463+
464+
return result;
465+
});
466+
}
467+
468+
private async getiOSSysInfo(): Promise<NativeScriptDoctor.IiOSSysInfoData> {
469+
return this.getValueForProperty(() => this.iOSSysInfoCache, async (): Promise<NativeScriptDoctor.IiOSSysInfoData> => {
470+
const result: NativeScriptDoctor.IiOSSysInfoData = Object.create(null);
471+
472+
result.xcodeVer = await this.getXcodeVersion();
473+
result.xcodeprojLocation = await this.getXcodeprojLocation();
474+
result.itunesInstalled = await this.isITunesInstalled();
475+
result.cocoaPodsVer = await this.getCocoaPodsVersion();
476+
result.isCocoaPodsWorkingCorrectly = await this.isCocoaPodsWorkingCorrectly();
477+
result.isCocoaPodsUpdateRequired = await this.isCocoaPodsUpdateRequired();
478+
result.pythonInfo = await this.getPythonInfo();
479+
480+
return result;
481+
});
482+
}
483+
484+
private async getAndroidSysInfo(config?: NativeScriptDoctor.ISysInfoConfig): Promise<NativeScriptDoctor.IAndroidSysInfoData> {
485+
return this.getValueForProperty(() => this.androidSysInfoCache, async (): Promise<NativeScriptDoctor.IAndroidSysInfoData> => {
486+
const result: NativeScriptDoctor.IAndroidSysInfoData = Object.create(null);
487+
488+
result.dotNetVer = await this.hostInfo.dotNetVersion();
489+
result.javacVersion = await this.getJavaCompilerVersion();
490+
result.adbVer = await this.getAdbVersion(config && config.androidToolsInfo && config.androidToolsInfo.pathToAdb);
491+
result.androidInstalled = await this.isAndroidInstalled();
492+
result.monoVer = await this.getMonoVersion();
493+
result.gradleVer = await this.getGradleVersion();
494+
result.isAndroidSdkConfiguredCorrectly = await this.isAndroidSdkConfiguredCorrectly();
495+
496+
return result;
497+
});
498+
}
470499
}

test/sys-info.ts

+69
Original file line numberDiff line numberDiff line change
@@ -493,5 +493,74 @@ ${expectedCliVersion}`;
493493
});
494494
});
495495
});
496+
497+
describe("returns correct sysInfo when", () => {
498+
const assertCommonSysInfo = (result: NativeScriptDoctor.ISysInfoData) => {
499+
assert.deepEqual(result.npmVer, childProcessResult.npmV.result.stdout);
500+
assert.deepEqual(result.nodeVer, "6.0.0");
501+
assert.deepEqual(result.nodeGypVer, childProcessResult.nodeGypVersion.result.stdout);
502+
assert.deepEqual(result.gitVer, "1.9.5");
503+
assert.deepEqual(result.nativeScriptCliVersion, childProcessResult.nativeScriptCliVersion.result.stdout);
504+
};
505+
506+
const assertAndroidSysInfo = (result: NativeScriptDoctor.IAndroidSysInfoData) => {
507+
assert.deepEqual(result.adbVer, "1.0.32");
508+
assert.deepEqual(result.androidInstalled, false);
509+
assert.deepEqual(result.monoVer, "1.0.6");
510+
assert.deepEqual(result.gradleVer, "2.8");
511+
assert.deepEqual(result.javacVersion, "1.8.0_60");
512+
assert.deepEqual(result.isAndroidSdkConfiguredCorrectly, undefined);
513+
};
514+
515+
const assertiOSSysInfo = (result: NativeScriptDoctor.IiOSSysInfoData) => {
516+
assert.deepEqual(result.xcodeVer, "6.4.0");
517+
assert.deepEqual(result.itunesInstalled, undefined);
518+
assert.deepEqual(result.cocoaPodsVer, "0.38.2");
519+
assert.deepEqual(result.xcodeprojLocation, null);
520+
assert.deepEqual(result.isCocoaPodsWorkingCorrectly, undefined);
521+
assert.deepEqual(result.xcprojInfo, undefined);
522+
assert.deepEqual(result.isCocoaPodsUpdateRequired, false);
523+
assert.deepEqual(result.pythonInfo, {isInstalled: false, isSixPackageInstalled: false, installationErrorMessage: "Cannot read property 'shouldThrowError' of undefined"});
524+
};
525+
526+
it("iOS platform is specified", async () => {
527+
sysInfo = mockSysInfo(childProcessResult, { isWindows: false, isDarwin: true, dotNetVersion });
528+
const result = await sysInfo.getSysInfo({platform: "iOS"});
529+
530+
assertCommonSysInfo(result);
531+
assertiOSSysInfo(result);
532+
// Android specific properties should be undefined
533+
assert.deepEqual(result.adbVer, undefined);
534+
assert.deepEqual(result.androidInstalled, undefined);
535+
assert.deepEqual(result.monoVer, undefined);
536+
assert.deepEqual(result.gradleVer, undefined);
537+
assert.deepEqual(result.javacVersion, undefined);
538+
assert.deepEqual(result.isAndroidSdkConfiguredCorrectly, undefined);
539+
});
540+
it("Android platform is specified", async () => {
541+
sysInfo = mockSysInfo(childProcessResult, { isWindows: false, isDarwin: true, dotNetVersion });
542+
const result = await sysInfo.getSysInfo({platform: "Android"});
543+
544+
assertCommonSysInfo(result);
545+
assertAndroidSysInfo(result);
546+
// iOS specific properties should be undefined
547+
assert.deepEqual(result.xcodeVer, undefined);
548+
assert.deepEqual(result.itunesInstalled, undefined);
549+
assert.deepEqual(result.cocoaPodsVer, undefined);
550+
assert.deepEqual(result.xcodeprojLocation, undefined);
551+
assert.deepEqual(result.isCocoaPodsWorkingCorrectly, undefined);
552+
assert.deepEqual(result.xcprojInfo, undefined);
553+
assert.deepEqual(result.isCocoaPodsUpdateRequired, undefined);
554+
assert.deepEqual(result.pythonInfo, undefined);
555+
556+
});
557+
it("no platform is specified", async() => {
558+
sysInfo = mockSysInfo(childProcessResult, { isWindows: false, isDarwin: true, dotNetVersion });
559+
const result = await sysInfo.getSysInfo();
560+
assertCommonSysInfo(result);
561+
assertAndroidSysInfo(result);
562+
assertiOSSysInfo(result);
563+
});
564+
});
496565
});
497566
});

0 commit comments

Comments
 (0)