Skip to content

Commit 676b774

Browse files
fix: Getting started prompter fails
The prompter for getting started changes fails in some cases, as we do not await the validation of the livesyncCommandHelper.validate call. So we try to execute some operations as we think the environment is setup correctly, but we are unable to do so and the code fails. Also add additional option to prompter in case cloud extension is installed. This gives better visibility of the feature
1 parent b1101cc commit 676b774

File tree

7 files changed

+76
-20
lines changed

7 files changed

+76
-20
lines changed

lib/commands/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class RunCommandBase implements ICommand {
2828
this.platform = this.$devicePlatformsConstants.Android;
2929
}
3030

31-
this.$liveSyncCommandHelper.validatePlatform(this.platform);
31+
await this.$liveSyncCommandHelper.validatePlatform(this.platform);
3232

3333
return true;
3434
}

lib/definitions/platform.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,5 +381,5 @@ interface IUpdateAppOptions extends IOptionalFilesToSync, IOptionalFilesToRemove
381381
}
382382

383383
interface IPlatformEnvironmentRequirements {
384-
checkEnvironmentRequirements(platform: string): Promise<boolean>;
384+
checkEnvironmentRequirements(platform: string, projectDir: string): Promise<boolean>;
385385
}

lib/services/analytics/analytics-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class AnalyticsService extends AnalyticsServiceBase {
7373

7474
// In some cases (like in case action is Build and platform is Android), we do not know if the deviceType is emulator or device.
7575
// Just exclude the device_type in this case.
76-
if (isForDevice !== null) {
76+
if (isForDevice !== null && isForDevice !== undefined) {
7777
const deviceType = isForDevice ? DeviceTypes.Device : (this.$mobileHelper.isAndroidPlatform(platform) ? DeviceTypes.Emulator : DeviceTypes.Simulator);
7878
label = this.addDataToLabel(label, deviceType);
7979
}

lib/services/android-project-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
133133
this.validatePackageName(projectData.projectId);
134134
this.validateProjectName(projectData.projectName);
135135

136-
await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(this.getPlatformData(projectData).normalizedPlatformName);
136+
await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(this.getPlatformData(projectData).normalizedPlatformName, projectData.projectDir);
137137
this.$androidToolsInfo.validateTargetSdk({ showWarningsAsErrors: true });
138138
}
139139

lib/services/doctor-service.ts

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,32 +53,64 @@ class DoctorService implements IDoctorService {
5353
}
5454
}
5555

56-
public runSetupScript(): Promise<ISpawnResult> {
56+
public async runSetupScript(): Promise<ISpawnResult> {
57+
await this.$analyticsService.trackEventActionInGoogleAnalytics({
58+
action: "Run setup script",
59+
additionalData: "Start",
60+
});
61+
5762
if (this.$hostInfo.isLinux) {
63+
await this.$analyticsService.trackEventActionInGoogleAnalytics({
64+
action: "Run setup script",
65+
additionalData: "Skipped as OS is Linux",
66+
});
5867
return;
5968
}
6069

6170
this.$logger.out("Running the setup script to try and automatically configure your environment.");
6271

6372
if (this.$hostInfo.isDarwin) {
64-
return this.runSetupScriptCore(DoctorService.DarwinSetupScriptLocation, []);
73+
await this.runSetupScriptCore(DoctorService.DarwinSetupScriptLocation, []);
6574
}
6675

6776
if (this.$hostInfo.isWindows) {
68-
return this.runSetupScriptCore(DoctorService.WindowsSetupScriptExecutable, DoctorService.WindowsSetupScriptArguments);
77+
await this.runSetupScriptCore(DoctorService.WindowsSetupScriptExecutable, DoctorService.WindowsSetupScriptArguments);
6978
}
79+
80+
await this.$analyticsService.trackEventActionInGoogleAnalytics({
81+
action: "Run setup script",
82+
additionalData: "Finished",
83+
});
7084
}
7185

7286
public async canExecuteLocalBuild(platform?: string): Promise<boolean> {
87+
await this.$analyticsService.trackEventActionInGoogleAnalytics({
88+
action: "Check Local Build Setup",
89+
additionalData: "Started",
90+
});
7391
const infos = await doctor.getInfos({ platform });
7492

7593
const warnings = this.filterInfosByType(infos, constants.WARNING_TYPE_NAME);
76-
if (warnings.length > 0) {
94+
const hasWarnings = warnings.length > 0;
95+
if (hasWarnings) {
96+
// TODO: Separate the track per platform:
97+
// Could be in two separate trackings or in the same, but with additional information, for example:
98+
// Errors:<platform>__<warnings for platform>.join(--)$$<platform>__<warnings for platform>.join(--)...
99+
await this.$analyticsService.trackEventActionInGoogleAnalytics({
100+
action: "Check Local Build Setup",
101+
additionalData: `Warnings:${warnings.map(w => w.message).join("__")}`,
102+
});
77103
this.printInfosCore(infos);
78104
} else {
79105
infos.map(info => this.$logger.trace(info.message));
80106
}
81-
return warnings.length === 0;
107+
108+
await this.$analyticsService.trackEventActionInGoogleAnalytics({
109+
action: "Check Local Build Setup",
110+
additionalData: `Finished: ${hasWarnings}`,
111+
});
112+
113+
return !hasWarnings;
82114
}
83115

84116
private async promptForDocs(link: string): Promise<void> {

lib/services/ios-project-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
139139
return;
140140
}
141141

142-
await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(this.getPlatformData(projectData).normalizedPlatformName);
142+
await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(this.getPlatformData(projectData).normalizedPlatformName, projectData.projectDir);
143143

144144
const xcodeBuildVersion = await this.getXcodeVersion();
145145
if (helpers.versionCompare(xcodeBuildVersion, IOSProjectService.XCODEBUILD_MIN_VERSION) < 0) {

lib/services/platform-environment-requirements.ts

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
99
private $logger: ILogger,
1010
private $nativeScriptCloudExtensionService: INativeScriptCloudExtensionService,
1111
private $prompter: IPrompter,
12-
private $staticConfig: IStaticConfig) { }
12+
private $staticConfig: IStaticConfig,
13+
private $analyticsService: IAnalyticsService) { }
1314

1415
public static CLOUD_SETUP_OPTION_NAME = "Configure for Cloud Builds";
1516
public static LOCAL_SETUP_OPTION_NAME = "Configure for Local Builds";
17+
public static TRY_CLOUD_OPERATION_OPTION_NAME = "Try Cloud Operation";
1618
public static MANUALLY_SETUP_OPTION_NAME = "Skip Step and Configure Manually";
1719
private static BOTH_CLOUD_SETUP_AND_LOCAL_SETUP_OPTION_NAME = "Configure for Both Local and Cloud Builds";
1820
private static CHOOSE_OPTIONS_MESSAGE = "To continue, choose one of the following options: ";
@@ -27,14 +29,24 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
2729
"deploy": "tns cloud deploy"
2830
};
2931

30-
public async checkEnvironmentRequirements(platform: string): Promise<boolean> {
32+
public async checkEnvironmentRequirements(platform: string, projectDir: string): Promise<boolean> {
3133
if (process.env.NS_SKIP_ENV_CHECK) {
34+
await this.$analyticsService.trackEventActionInGoogleAnalytics({
35+
action: "Check Environment Requirements",
36+
additionalData: "Skipped:NS_SKIP_ENV_CHECK is set",
37+
projectDir
38+
});
3239
return true;
3340
}
3441

3542
const canExecute = await this.$doctorService.canExecuteLocalBuild(platform);
3643
if (!canExecute) {
3744
if (!isInteractive()) {
45+
await this.$analyticsService.trackEventActionInGoogleAnalytics({
46+
action: "Check Environment Requirements",
47+
additionalData: "Non-interactive terminal, unable to execute local builds.",
48+
projectDir
49+
});
3850
this.fail(this.getNonInteractiveConsoleMessage(platform));
3951
}
4052

@@ -74,6 +86,11 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
7486

7587
this.processManuallySetup(platform);
7688
}
89+
90+
if (selectedOption === PlatformEnvironmentRequirements.TRY_CLOUD_OPERATION_OPTION_NAME) {
91+
const message = `You can use ${_.lowerFirst(this.getCloudBuildsMessage(platform))}`;
92+
this.fail(message);
93+
}
7794
}
7895

7996
return true;
@@ -166,18 +183,25 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
166183
]);
167184
}
168185

169-
private promptForChoice(): Promise<string> {
186+
private async promptForChoice(): Promise<string> {
170187
const choices = this.$nativeScriptCloudExtensionService.isInstalled() ? [
188+
PlatformEnvironmentRequirements.TRY_CLOUD_OPERATION_OPTION_NAME,
171189
PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME,
172190
PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME,
173191
] : [
174-
PlatformEnvironmentRequirements.CLOUD_SETUP_OPTION_NAME,
175-
PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME,
176-
PlatformEnvironmentRequirements.BOTH_CLOUD_SETUP_AND_LOCAL_SETUP_OPTION_NAME,
177-
PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME,
178-
];
179-
180-
return this.$prompter.promptForChoice(PlatformEnvironmentRequirements.CHOOSE_OPTIONS_MESSAGE, choices);
192+
PlatformEnvironmentRequirements.CLOUD_SETUP_OPTION_NAME,
193+
PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME,
194+
PlatformEnvironmentRequirements.BOTH_CLOUD_SETUP_AND_LOCAL_SETUP_OPTION_NAME,
195+
PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME,
196+
];
197+
198+
const selection = await this.$prompter.promptForChoice(PlatformEnvironmentRequirements.CHOOSE_OPTIONS_MESSAGE, choices);
199+
await this.$analyticsService.trackEventActionInGoogleAnalytics({
200+
action: "Check Environment Requirements",
201+
additionalData: `User selected: ${selection}`
202+
// consider passing projectDir here
203+
});
204+
return selection;
181205
}
182206

183207
private getEnvVerificationMessage() {

0 commit comments

Comments
 (0)