Skip to content

Commit ff04446

Browse files
feat: platform specific doctor (#5505)
* feat: platform specified doctor * Update docs/man_pages/general/doctor.md Co-authored-by: Igor Randjelovic <[email protected]> * Update docs/man_pages/start.md Co-authored-by: Igor Randjelovic <[email protected]> Co-authored-by: Igor Randjelovic <[email protected]>
1 parent 3150049 commit ff04446

File tree

8 files changed

+79
-17
lines changed

8 files changed

+79
-17
lines changed

docs/man_pages/general/doctor.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<% if (isJekyll) { %>---
2-
title: tns doctor
2+
title: ns doctor
33
position: 5
44
---<% } %>
55

6-
# tns doctor
6+
# ns doctor
77

88
### Description
99

10-
Checks your system for configuration problems which might prevent the NativeScript CLI from working properly.
10+
Checks your system for configuration problems which might prevent the NativeScript CLI from working properly for the specified platform, if configured.
1111

1212
### Commands
1313

1414
Usage | Synopsis
1515
------|-------
16-
General | `$ tns doctor`
16+
General | `$ ns doctor <platform>`
1717

1818
<% if(isHtml) { %>
1919

docs/man_pages/start.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Command | Description
1818
[autocomplete](general/autocomplete.html) | Configures your current command-line completion settings.
1919
[usage-reporting](general/usage-reporting.html) | Configures anonymous usage reporting for the NativeScript CLI.
2020
[error-reporting](general/error-reporting.html) | Configures anonymous error reporting for the NativeScript CLI.
21-
[doctor](general/doctor.html) | Checks your system for configuration problems which might prevent the NativeScript CLI from working properly.
21+
[doctor `<platform>`](general/doctor.html) | Checks your system for configuration problems which might prevent the NativeScript CLI from working properly for the specified platform, if configured.
2222
[info](general/info.html) | Displays version information about the NativeScript CLI, core modules, and runtimes.
2323
[proxy](general/proxy.html) | Displays proxy settings.
2424
[migrate](general/migrate.html) | Migrates the app dependencies to a form compatible with NativeScript 6.0.

lib/common/bootstrap.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ injector.requireCommand(
171171
"dev-generate-messages",
172172
"./commands/generate-messages"
173173
);
174-
injector.requireCommand("doctor", "./commands/doctor");
174+
injector.requireCommand("doctor|*all", "./commands/doctor");
175+
injector.requireCommand("doctor|ios", "./commands/doctor");
176+
injector.requireCommand("doctor|android", "./commands/doctor");
175177

176178
injector.requireCommand("proxy|*get", "./commands/proxy/proxy-get");
177179
injector.requireCommand("proxy|set", "./commands/proxy/proxy-set");

lib/common/commands/doctor.ts

+41-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { injector } from "../yok";
22
import { ICommand, ICommandParameter } from "../definitions/commands";
33
import { IDoctorService, IProjectHelper } from "../declarations";
4+
import { PlatformTypes } from "../../constants";
45

56
export class DoctorCommand implements ICommand {
67
constructor(
@@ -18,5 +19,44 @@ export class DoctorCommand implements ICommand {
1819
});
1920
}
2021
}
22+
injector.registerCommand("doctor|*all", DoctorCommand);
2123

22-
injector.registerCommand("doctor", DoctorCommand);
24+
export class DoctorIosCommand implements ICommand {
25+
constructor(
26+
private $doctorService: IDoctorService,
27+
private $projectHelper: IProjectHelper
28+
) {}
29+
30+
public allowedParameters: ICommandParameter[] = [];
31+
32+
public execute(args: string[]): Promise<void> {
33+
return this.$doctorService.printWarnings({
34+
trackResult: false,
35+
projectDir: this.$projectHelper.projectDir,
36+
forceCheck: true,
37+
platform: PlatformTypes.ios,
38+
});
39+
}
40+
}
41+
42+
injector.registerCommand("doctor|ios", DoctorIosCommand);
43+
44+
export class DoctorAndroidCommand implements ICommand {
45+
constructor(
46+
private $doctorService: IDoctorService,
47+
private $projectHelper: IProjectHelper
48+
) {}
49+
50+
public allowedParameters: ICommandParameter[] = [];
51+
52+
public execute(args: string[]): Promise<void> {
53+
return this.$doctorService.printWarnings({
54+
trackResult: false,
55+
projectDir: this.$projectHelper.projectDir,
56+
forceCheck: true,
57+
platform: PlatformTypes.android,
58+
});
59+
}
60+
}
61+
62+
injector.registerCommand("doctor|android", DoctorAndroidCommand);

lib/common/declarations.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,7 @@ interface IDoctorService {
13301330
runtimeVersion?: string;
13311331
options?: IOptions;
13321332
forceCheck?: boolean;
1333+
platform?: string;
13331334
}): Promise<void>;
13341335
/**
13351336
* Runs the setup script on host machine

lib/declarations.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -946,19 +946,19 @@ interface IVersionsService {
946946
* Gets versions information about nativescript runtimes.
947947
* @return {Promise<IVersionInformation[]>} The version information.
948948
*/
949-
getRuntimesVersions(): Promise<IVersionInformation[]>;
949+
getRuntimesVersions(platform?: string): Promise<IVersionInformation[]>;
950950

951951
/**
952952
* Gets versions information about all nativescript components.
953953
* @return {Promise<IVersionInformation[]>} The version information.
954954
*/
955-
getAllComponentsVersions(): Promise<IVersionInformation[]>;
955+
getAllComponentsVersions(platform?: string): Promise<IVersionInformation[]>;
956956

957957
/**
958958
* Checks version information about the nativescript components and prints versions information.
959959
* @return {Promise<void>}
960960
*/
961-
printVersionsInformation(): Promise<void>;
961+
printVersionsInformation(platform?: string): Promise<void>;
962962
}
963963

964964
/**

lib/services/doctor-service.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ export class DoctorService implements IDoctorService {
7979
runtimeVersion?: string;
8080
options?: IOptions;
8181
forceCheck?: boolean;
82+
platform?: string;
8283
}): Promise<void> {
8384
configOptions = configOptions || <any>{};
8485
const getInfosData: any = {
8586
projectDir: configOptions.projectDir,
8687
androidRuntimeVersion: configOptions.runtimeVersion,
88+
platform: configOptions.platform,
8789
};
8890
const infos = await this.$terminalSpinnerService.execute<
8991
NativeScriptDoctor.IInfo[]
@@ -128,7 +130,9 @@ export class DoctorService implements IDoctorService {
128130
}
129131

130132
try {
131-
await this.$versionsService.printVersionsInformation();
133+
await this.$versionsService.printVersionsInformation(
134+
configOptions.platform
135+
);
132136
} catch (err) {
133137
this.$logger.error(
134138
"Cannot get the latest versions information from npm. Please try again later."

lib/services/versions-service.ts

+21-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { IFileSystem, IVersionInformation } from "../common/declarations";
99
import { IInjector } from "../common/definitions/yok";
1010
import * as _ from "lodash";
1111
import { injector } from "../common/yok";
12+
import { PlatformTypes } from "../constants";
1213

1314
export enum VersionInformationType {
1415
UpToDate = "UpToDate",
@@ -121,7 +122,9 @@ class VersionsService implements IVersionsService {
121122
return versionInformations;
122123
}
123124

124-
public async getRuntimesVersions(): Promise<IVersionInformation[]> {
125+
public async getRuntimesVersions(
126+
platform?: string
127+
): Promise<IVersionInformation[]> {
125128
const iosRuntime = this.$projectDataService.getRuntimePackage(
126129
this.projectData.projectDir,
127130
constants.PlatformTypes.ios
@@ -130,7 +133,15 @@ class VersionsService implements IVersionsService {
130133
this.projectData.projectDir,
131134
constants.PlatformTypes.android
132135
);
133-
const runtimes: IBasePluginData[] = [iosRuntime, androidRuntime];
136+
let runtimes: IBasePluginData[] = [];
137+
138+
if (!platform) {
139+
runtimes = [iosRuntime, androidRuntime];
140+
} else if (platform === PlatformTypes.ios) {
141+
runtimes.push(iosRuntime);
142+
} else if (platform === PlatformTypes.android) {
143+
runtimes.push(androidRuntime);
144+
}
134145

135146
const runtimesVersions: IVersionInformation[] = await Promise.all(
136147
runtimes.map(async (runtime: IBasePluginData) => {
@@ -150,7 +161,9 @@ class VersionsService implements IVersionsService {
150161
return runtimesVersions;
151162
}
152163

153-
public async getAllComponentsVersions(): Promise<IVersionInformation[]> {
164+
public async getAllComponentsVersions(
165+
platform?: string
166+
): Promise<IVersionInformation[]> {
154167
try {
155168
let allComponents: IVersionInformation[] = [];
156169

@@ -165,7 +178,9 @@ class VersionsService implements IVersionsService {
165178
allComponents.push(...nativescriptCoreModulesInformation);
166179
}
167180

168-
const runtimesVersions: IVersionInformation[] = await this.getRuntimesVersions();
181+
const runtimesVersions: IVersionInformation[] = await this.getRuntimesVersions(
182+
platform
183+
);
169184
allComponents = allComponents.concat(runtimesVersions);
170185
}
171186

@@ -194,14 +209,14 @@ class VersionsService implements IVersionsService {
194209
}
195210
}
196211

197-
public async printVersionsInformation(): Promise<void> {
212+
public async printVersionsInformation(platform?: string): Promise<void> {
198213
const versionsInformation = await this.$terminalSpinnerService.execute<
199214
IVersionInformation[]
200215
>(
201216
{
202217
text: `Getting NativeScript components versions information...`,
203218
},
204-
() => this.getAllComponentsVersions()
219+
() => this.getAllComponentsVersions(platform)
205220
);
206221

207222
if (!helpers.isInteractive()) {

0 commit comments

Comments
 (0)