Skip to content

Commit 9184434

Browse files
authored
doctor doesn't crash on missing xcode tools (#3043)
* doctor doesn't crash on missing xcode tools set a better message when components are up to date * renamed method and fixed check * added method return type
1 parent cc99451 commit 9184434

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

lib/declarations.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,9 @@ interface IVersionsService {
604604
getRuntimesVersions(): Promise<IVersionInformation[]>;
605605

606606
/**
607-
* Gets versions information about the nativescript components with new.
608-
* @return {Promise<IVersionInformation[]>} The version information.
607+
* Checks version information about the nativescript components and prints available updates if any.
609608
*/
610-
getComponentsForUpdate(): Promise<IVersionInformation[]>;
609+
checkComponentsForUpdate(): Promise<void>;
611610

612611
/**
613612
* Gets versions information about all nativescript components.

lib/services/doctor-service.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class DoctorService implements IDoctorService {
9595
result = true;
9696
}
9797

98-
if (await this.$xcprojService.verifyXcproj(false)) {
98+
if (sysInfo.xcodeVer && sysInfo.cocoapodVer && await this.$xcprojService.verifyXcproj(false)) {
9999
result = true;
100100
}
101101
} else {
@@ -123,28 +123,15 @@ class DoctorService implements IDoctorService {
123123
}
124124
}
125125

126-
let versionsInformation: IVersionInformation[] = [];
127126
try {
128-
versionsInformation = await this.$versionsService.getComponentsForUpdate();
129-
this.printVersionsInformation(versionsInformation);
127+
await this.$versionsService.checkComponentsForUpdate();
130128
} catch (err) {
131129
this.$logger.error("Cannot get the latest versions information from npm. Please try again later.");
132130
}
133131

134132
return doctorResult;
135133
}
136134

137-
private printVersionsInformation(versionsInformation: IVersionInformation[]) {
138-
if (versionsInformation && versionsInformation.length) {
139-
let table: any = this.$versionsService.createTableWithVersionsInformation(versionsInformation);
140-
141-
this.$logger.warn("Updates available");
142-
this.$logger.out(table.toString() + EOL);
143-
} else {
144-
this.$logger.out("Your components are up-to-date." + EOL);
145-
}
146-
}
147-
148135
private async promptForDocs(link: string): Promise<void> {
149136
if (await this.$prompter.confirm("Do you want to visit the official documentation?", () => helpers.isInteractive())) {
150137
this.$opener.open(link);

lib/services/versions-service.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { EOL } from "os";
12
import * as constants from "../constants";
23
import * as semver from "semver";
34
import * as path from "path";
@@ -14,7 +15,8 @@ class VersionsService implements IVersionsService {
1415
private $npmInstallationManager: INpmInstallationManager,
1516
private $injector: IInjector,
1617
private $staticConfig: Config.IStaticConfig,
17-
private $pluginsService: IPluginsService) {
18+
private $pluginsService: IPluginsService,
19+
private $logger: ILogger) {
1820
this.projectData = this.getProjectData();
1921
}
2022

@@ -84,7 +86,7 @@ class VersionsService implements IVersionsService {
8486
return runtimesVersions;
8587
}
8688

87-
public async getComponentsForUpdate(): Promise<IVersionInformation[]> {
89+
public async checkComponentsForUpdate(): Promise<void> {
8890
let allComponents: IVersionInformation[] = await this.getAllComponentsVersions();
8991
let componentsForUpdate: IVersionInformation[] = [];
9092

@@ -94,7 +96,18 @@ class VersionsService implements IVersionsService {
9496
}
9597
});
9698

97-
return componentsForUpdate;
99+
this.printVersionsInformation(componentsForUpdate, allComponents);
100+
}
101+
102+
private printVersionsInformation(versionsInformation: IVersionInformation[], allComponents: IVersionInformation[]): void {
103+
if (versionsInformation && versionsInformation.length) {
104+
let table: any = this.createTableWithVersionsInformation(versionsInformation);
105+
106+
this.$logger.warn("Updates available");
107+
this.$logger.out(table.toString() + EOL);
108+
} else {
109+
this.$logger.out(`Your components are up-to-date: ${EOL}${allComponents.map(component => component.componentName)}${EOL}`);
110+
}
98111
}
99112

100113
public async getAllComponentsVersions(): Promise<IVersionInformation[]> {

0 commit comments

Comments
 (0)