Skip to content

feat: platform specified doctor #5505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/man_pages/general/doctor.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<% if (isJekyll) { %>---
title: tns doctor
title: ns doctor
position: 5
---<% } %>

# tns doctor
# ns doctor

### Description

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

### Commands

Usage | Synopsis
------|-------
General | `$ tns doctor`
General | `$ ns doctor <platform>`

<% if(isHtml) { %>

Expand Down
2 changes: 1 addition & 1 deletion docs/man_pages/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Command | Description
[autocomplete](general/autocomplete.html) | Configures your current command-line completion settings.
[usage-reporting](general/usage-reporting.html) | Configures anonymous usage reporting for the NativeScript CLI.
[error-reporting](general/error-reporting.html) | Configures anonymous error reporting for the NativeScript CLI.
[doctor](general/doctor.html) | Checks your system for configuration problems which might prevent the NativeScript CLI from working properly.
[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.
[info](general/info.html) | Displays version information about the NativeScript CLI, core modules, and runtimes.
[proxy](general/proxy.html) | Displays proxy settings.
[migrate](general/migrate.html) | Migrates the app dependencies to a form compatible with NativeScript 6.0.
Expand Down
4 changes: 3 additions & 1 deletion lib/common/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ injector.requireCommand(
"dev-generate-messages",
"./commands/generate-messages"
);
injector.requireCommand("doctor", "./commands/doctor");
injector.requireCommand("doctor|*all", "./commands/doctor");
injector.requireCommand("doctor|ios", "./commands/doctor");
injector.requireCommand("doctor|android", "./commands/doctor");

injector.requireCommand("proxy|*get", "./commands/proxy/proxy-get");
injector.requireCommand("proxy|set", "./commands/proxy/proxy-set");
Expand Down
42 changes: 41 additions & 1 deletion lib/common/commands/doctor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { injector } from "../yok";
import { ICommand, ICommandParameter } from "../definitions/commands";
import { IDoctorService, IProjectHelper } from "../declarations";
import { PlatformTypes } from "../../constants";

export class DoctorCommand implements ICommand {
constructor(
Expand All @@ -18,5 +19,44 @@ export class DoctorCommand implements ICommand {
});
}
}
injector.registerCommand("doctor|*all", DoctorCommand);

injector.registerCommand("doctor", DoctorCommand);
export class DoctorIosCommand implements ICommand {
constructor(
private $doctorService: IDoctorService,
private $projectHelper: IProjectHelper
) {}

public allowedParameters: ICommandParameter[] = [];

public execute(args: string[]): Promise<void> {
return this.$doctorService.printWarnings({
trackResult: false,
projectDir: this.$projectHelper.projectDir,
forceCheck: true,
platform: PlatformTypes.ios,
});
}
}

injector.registerCommand("doctor|ios", DoctorIosCommand);

export class DoctorAndroidCommand implements ICommand {
constructor(
private $doctorService: IDoctorService,
private $projectHelper: IProjectHelper
) {}

public allowedParameters: ICommandParameter[] = [];

public execute(args: string[]): Promise<void> {
return this.$doctorService.printWarnings({
trackResult: false,
projectDir: this.$projectHelper.projectDir,
forceCheck: true,
platform: PlatformTypes.android,
});
}
}

injector.registerCommand("doctor|android", DoctorAndroidCommand);
1 change: 1 addition & 0 deletions lib/common/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,7 @@ interface IDoctorService {
runtimeVersion?: string;
options?: IOptions;
forceCheck?: boolean;
platform?: string;
}): Promise<void>;
/**
* Runs the setup script on host machine
Expand Down
6 changes: 3 additions & 3 deletions lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -946,19 +946,19 @@ interface IVersionsService {
* Gets versions information about nativescript runtimes.
* @return {Promise<IVersionInformation[]>} The version information.
*/
getRuntimesVersions(): Promise<IVersionInformation[]>;
getRuntimesVersions(platform?: string): Promise<IVersionInformation[]>;

/**
* Gets versions information about all nativescript components.
* @return {Promise<IVersionInformation[]>} The version information.
*/
getAllComponentsVersions(): Promise<IVersionInformation[]>;
getAllComponentsVersions(platform?: string): Promise<IVersionInformation[]>;

/**
* Checks version information about the nativescript components and prints versions information.
* @return {Promise<void>}
*/
printVersionsInformation(): Promise<void>;
printVersionsInformation(platform?: string): Promise<void>;
}

/**
Expand Down
6 changes: 5 additions & 1 deletion lib/services/doctor-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ export class DoctorService implements IDoctorService {
runtimeVersion?: string;
options?: IOptions;
forceCheck?: boolean;
platform?: string;
}): Promise<void> {
configOptions = configOptions || <any>{};
const getInfosData: any = {
projectDir: configOptions.projectDir,
androidRuntimeVersion: configOptions.runtimeVersion,
platform: configOptions.platform,
};
const infos = await this.$terminalSpinnerService.execute<
NativeScriptDoctor.IInfo[]
Expand Down Expand Up @@ -128,7 +130,9 @@ export class DoctorService implements IDoctorService {
}

try {
await this.$versionsService.printVersionsInformation();
await this.$versionsService.printVersionsInformation(
configOptions.platform
);
} catch (err) {
this.$logger.error(
"Cannot get the latest versions information from npm. Please try again later."
Expand Down
27 changes: 21 additions & 6 deletions lib/services/versions-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IFileSystem, IVersionInformation } from "../common/declarations";
import { IInjector } from "../common/definitions/yok";
import * as _ from "lodash";
import { injector } from "../common/yok";
import { PlatformTypes } from "../constants";

export enum VersionInformationType {
UpToDate = "UpToDate",
Expand Down Expand Up @@ -121,7 +122,9 @@ class VersionsService implements IVersionsService {
return versionInformations;
}

public async getRuntimesVersions(): Promise<IVersionInformation[]> {
public async getRuntimesVersions(
platform?: string
): Promise<IVersionInformation[]> {
const iosRuntime = this.$projectDataService.getRuntimePackage(
this.projectData.projectDir,
constants.PlatformTypes.ios
Expand All @@ -130,7 +133,15 @@ class VersionsService implements IVersionsService {
this.projectData.projectDir,
constants.PlatformTypes.android
);
const runtimes: IBasePluginData[] = [iosRuntime, androidRuntime];
let runtimes: IBasePluginData[] = [];

if (!platform) {
runtimes = [iosRuntime, androidRuntime];
} else if (platform === PlatformTypes.ios) {
runtimes.push(iosRuntime);
} else if (platform === PlatformTypes.android) {
runtimes.push(androidRuntime);
}

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

public async getAllComponentsVersions(): Promise<IVersionInformation[]> {
public async getAllComponentsVersions(
platform?: string
): Promise<IVersionInformation[]> {
try {
let allComponents: IVersionInformation[] = [];

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

const runtimesVersions: IVersionInformation[] = await this.getRuntimesVersions();
const runtimesVersions: IVersionInformation[] = await this.getRuntimesVersions(
platform
);
allComponents = allComponents.concat(runtimesVersions);
}

Expand Down Expand Up @@ -194,14 +209,14 @@ class VersionsService implements IVersionsService {
}
}

public async printVersionsInformation(): Promise<void> {
public async printVersionsInformation(platform?: string): Promise<void> {
const versionsInformation = await this.$terminalSpinnerService.execute<
IVersionInformation[]
>(
{
text: `Getting NativeScript components versions information...`,
},
() => this.getAllComponentsVersions()
() => this.getAllComponentsVersions(platform)
);

if (!helpers.isInteractive()) {
Expand Down