diff --git a/docs/man_pages/general/doctor.md b/docs/man_pages/general/doctor.md index 9cbd693e9c..95cbdfee33 100644 --- a/docs/man_pages/general/doctor.md +++ b/docs/man_pages/general/doctor.md @@ -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 ` <% if(isHtml) { %> diff --git a/docs/man_pages/start.md b/docs/man_pages/start.md index a1c87a5cb3..2ba51499b5 100644 --- a/docs/man_pages/start.md +++ b/docs/man_pages/start.md @@ -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 ``](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. diff --git a/lib/common/bootstrap.ts b/lib/common/bootstrap.ts index 5585e575a6..aeea16c25c 100644 --- a/lib/common/bootstrap.ts +++ b/lib/common/bootstrap.ts @@ -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"); diff --git a/lib/common/commands/doctor.ts b/lib/common/commands/doctor.ts index 0d7b38c0e7..40b4fecbc7 100644 --- a/lib/common/commands/doctor.ts +++ b/lib/common/commands/doctor.ts @@ -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( @@ -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 { + 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 { + return this.$doctorService.printWarnings({ + trackResult: false, + projectDir: this.$projectHelper.projectDir, + forceCheck: true, + platform: PlatformTypes.android, + }); + } +} + +injector.registerCommand("doctor|android", DoctorAndroidCommand); diff --git a/lib/common/declarations.d.ts b/lib/common/declarations.d.ts index 676b4fac34..077b3c04da 100644 --- a/lib/common/declarations.d.ts +++ b/lib/common/declarations.d.ts @@ -1330,6 +1330,7 @@ interface IDoctorService { runtimeVersion?: string; options?: IOptions; forceCheck?: boolean; + platform?: string; }): Promise; /** * Runs the setup script on host machine diff --git a/lib/declarations.d.ts b/lib/declarations.d.ts index 8c720a1bad..fbfe4877bd 100644 --- a/lib/declarations.d.ts +++ b/lib/declarations.d.ts @@ -946,19 +946,19 @@ interface IVersionsService { * Gets versions information about nativescript runtimes. * @return {Promise} The version information. */ - getRuntimesVersions(): Promise; + getRuntimesVersions(platform?: string): Promise; /** * Gets versions information about all nativescript components. * @return {Promise} The version information. */ - getAllComponentsVersions(): Promise; + getAllComponentsVersions(platform?: string): Promise; /** * Checks version information about the nativescript components and prints versions information. * @return {Promise} */ - printVersionsInformation(): Promise; + printVersionsInformation(platform?: string): Promise; } /** diff --git a/lib/services/doctor-service.ts b/lib/services/doctor-service.ts index 1dbbecf254..072e6b89c8 100644 --- a/lib/services/doctor-service.ts +++ b/lib/services/doctor-service.ts @@ -79,11 +79,13 @@ export class DoctorService implements IDoctorService { runtimeVersion?: string; options?: IOptions; forceCheck?: boolean; + platform?: string; }): Promise { configOptions = configOptions || {}; const getInfosData: any = { projectDir: configOptions.projectDir, androidRuntimeVersion: configOptions.runtimeVersion, + platform: configOptions.platform, }; const infos = await this.$terminalSpinnerService.execute< NativeScriptDoctor.IInfo[] @@ -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." diff --git a/lib/services/versions-service.ts b/lib/services/versions-service.ts index 615aa622ac..e37882e2b7 100644 --- a/lib/services/versions-service.ts +++ b/lib/services/versions-service.ts @@ -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", @@ -121,7 +122,9 @@ class VersionsService implements IVersionsService { return versionInformations; } - public async getRuntimesVersions(): Promise { + public async getRuntimesVersions( + platform?: string + ): Promise { const iosRuntime = this.$projectDataService.getRuntimePackage( this.projectData.projectDir, constants.PlatformTypes.ios @@ -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) => { @@ -150,7 +161,9 @@ class VersionsService implements IVersionsService { return runtimesVersions; } - public async getAllComponentsVersions(): Promise { + public async getAllComponentsVersions( + platform?: string + ): Promise { try { let allComponents: IVersionInformation[] = []; @@ -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); } @@ -194,14 +209,14 @@ class VersionsService implements IVersionsService { } } - public async printVersionsInformation(): Promise { + public async printVersionsInformation(platform?: string): Promise { const versionsInformation = await this.$terminalSpinnerService.execute< IVersionInformation[] >( { text: `Getting NativeScript components versions information...`, }, - () => this.getAllComponentsVersions() + () => this.getAllComponentsVersions(platform) ); if (!helpers.isInteractive()) {