Skip to content

Commit 32115da

Browse files
fix: Use correct messages and tracking for getting started prompters
1 parent 9497818 commit 32115da

File tree

4 files changed

+74
-47
lines changed

4 files changed

+74
-47
lines changed

lib/constants.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ export const enum TrackActionNames {
135135
CreateProject = "Create project",
136136
Debug = "Debug",
137137
Deploy = "Deploy",
138-
LiveSync = "LiveSync"
138+
LiveSync = "LiveSync",
139+
RunSetupScript = "Run Setup Script",
140+
CheckLocalBuildSetup = "Check Local Build Setup",
141+
CheckEnvironmentRequirements = "Check Environment Requirements"
139142
}
140143

141144
export const enum BuildStates {

lib/services/doctor-service.ts

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { EOL } from "os";
22
import * as path from "path";
33
import * as helpers from "../common/helpers";
4+
import { TrackActionNames } from "../constants";
45
import { doctor, constants } from "nativescript-doctor";
56

67
class DoctorService implements IDoctorService {
@@ -52,13 +53,13 @@ class DoctorService implements IDoctorService {
5253

5354
public async runSetupScript(): Promise<ISpawnResult> {
5455
await this.$analyticsService.trackEventActionInGoogleAnalytics({
55-
action: "Run setup script",
56-
additionalData: "Start",
56+
action: TrackActionNames.RunSetupScript,
57+
additionalData: "Starting",
5758
});
5859

5960
if (this.$hostInfo.isLinux) {
6061
await this.$analyticsService.trackEventActionInGoogleAnalytics({
61-
action: "Run setup script",
62+
action: TrackActionNames.RunSetupScript,
6263
additionalData: "Skipped as OS is Linux",
6364
});
6465
return;
@@ -75,26 +76,23 @@ class DoctorService implements IDoctorService {
7576
}
7677

7778
await this.$analyticsService.trackEventActionInGoogleAnalytics({
78-
action: "Run setup script",
79+
action: TrackActionNames.RunSetupScript,
7980
additionalData: "Finished",
8081
});
8182
}
8283

8384
public async canExecuteLocalBuild(platform?: string): Promise<boolean> {
8485
await this.$analyticsService.trackEventActionInGoogleAnalytics({
85-
action: "Check Local Build Setup",
86-
additionalData: "Started",
86+
action: TrackActionNames.CheckLocalBuildSetup,
87+
additionalData: "Starting",
8788
});
8889
const infos = await doctor.getInfos({ platform });
8990

9091
const warnings = this.filterInfosByType(infos, constants.WARNING_TYPE_NAME);
9192
const hasWarnings = warnings.length > 0;
9293
if (hasWarnings) {
93-
// TODO: Separate the track per platform:
94-
// Could be in two separate trackings or in the same, but with additional information, for example:
95-
// Errors:<platform>__<warnings for platform>.join(--)$$<platform>__<warnings for platform>.join(--)...
9694
await this.$analyticsService.trackEventActionInGoogleAnalytics({
97-
action: "Check Local Build Setup",
95+
action: TrackActionNames.CheckLocalBuildSetup,
9896
additionalData: `Warnings:${warnings.map(w => w.message).join("__")}`,
9997
});
10098
this.printInfosCore(infos);
@@ -103,8 +101,8 @@ class DoctorService implements IDoctorService {
103101
}
104102

105103
await this.$analyticsService.trackEventActionInGoogleAnalytics({
106-
action: "Check Local Build Setup",
107-
additionalData: `Finished: ${hasWarnings}`,
104+
action: TrackActionNames.CheckLocalBuildSetup,
105+
additionalData: `Finished: Is setup correct: ${!hasWarnings}`,
108106
});
109107

110108
return !hasWarnings;

lib/services/platform-environment-requirements.ts

+59-33
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as constants from "../constants";
1+
import { NATIVESCRIPT_CLOUD_EXTENSION_NAME, TrackActionNames } from "../constants";
22
import { isInteractive } from "../common/helpers";
33
import { EOL } from "os";
44

@@ -18,10 +18,10 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
1818
public static MANUALLY_SETUP_OPTION_NAME = "Skip Step and Configure Manually";
1919
private static BOTH_CLOUD_SETUP_AND_LOCAL_SETUP_OPTION_NAME = "Configure for Both Local and Cloud Builds";
2020
private static CHOOSE_OPTIONS_MESSAGE = "To continue, choose one of the following options: ";
21-
private static NOT_CONFIGURED_ENV_AFTER_SETUP_SCRIPT_MESSAGE = `The setup script was not able to configure your environment for local builds. To execute local builds, you have to set up your environment manually. In case you have any questions, you can check our forum: 'http://forum.nativescript.org' and our public Slack channel: 'https://nativescriptcommunity.slack.com/'. ${PlatformEnvironmentRequirements.CHOOSE_OPTIONS_MESSAGE}`;
21+
private static NOT_CONFIGURED_ENV_AFTER_SETUP_SCRIPT_MESSAGE = `The setup script was not able to configure your environment for local builds. To execute local builds, you have to set up your environment manually. In case you have any questions, you can check our forum: 'http://forum.nativescript.org' and our public Slack channel: 'https://nativescriptcommunity.slack.com/'.`;
2222
private static MISSING_LOCAL_SETUP_MESSAGE = "Your environment is not configured properly and you will not be able to execute local builds.";
23-
private static MISSING_LOCAL_AND_CLOUD_SETUP_MESSAGE = `You are missing the ${constants.NATIVESCRIPT_CLOUD_EXTENSION_NAME} extension and you will not be able to execute cloud builds. ${PlatformEnvironmentRequirements.MISSING_LOCAL_SETUP_MESSAGE} ${PlatformEnvironmentRequirements.CHOOSE_OPTIONS_MESSAGE} `;
24-
private static MISSING_LOCAL_BUT_CLOUD_SETUP_MESSAGE = `You have ${constants.NATIVESCRIPT_CLOUD_EXTENSION_NAME} extension installed but ${_.lowerFirst(PlatformEnvironmentRequirements.MISSING_LOCAL_SETUP_MESSAGE)}`;
23+
private static MISSING_LOCAL_AND_CLOUD_SETUP_MESSAGE = `You are missing the ${NATIVESCRIPT_CLOUD_EXTENSION_NAME} extension and you will not be able to execute cloud builds. ${PlatformEnvironmentRequirements.MISSING_LOCAL_SETUP_MESSAGE} ${PlatformEnvironmentRequirements.CHOOSE_OPTIONS_MESSAGE} `;
24+
private static MISSING_LOCAL_BUT_CLOUD_SETUP_MESSAGE = `You have ${NATIVESCRIPT_CLOUD_EXTENSION_NAME} extension installed, so you can execute cloud builds, but ${_.lowerFirst(PlatformEnvironmentRequirements.MISSING_LOCAL_SETUP_MESSAGE)}`;
2525
private static RUN_TNS_SETUP_MESSAGE = 'Run $ tns setup command to run the setup script to try to automatically configure your environment for local builds.';
2626

2727
private cliCommandToCloudCommandName: IStringDictionary = {
@@ -33,8 +33,8 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
3333
public async checkEnvironmentRequirements(platform?: string): Promise<boolean> {
3434
if (process.env.NS_SKIP_ENV_CHECK) {
3535
await this.$analyticsService.trackEventActionInGoogleAnalytics({
36-
action: "Check Environment Requirements",
37-
additionalData: "Skipped:NS_SKIP_ENV_CHECK is set"
36+
action: TrackActionNames.CheckEnvironmentRequirements,
37+
additionalData: "Skipped: NS_SKIP_ENV_CHECK is set"
3838
});
3939
return true;
4040
}
@@ -43,15 +43,27 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
4343
if (!canExecute) {
4444
if (!isInteractive()) {
4545
await this.$analyticsService.trackEventActionInGoogleAnalytics({
46-
action: "Check Environment Requirements",
46+
action: TrackActionNames.CheckEnvironmentRequirements,
4747
additionalData: "Non-interactive terminal, unable to execute local builds."
4848
});
4949
this.fail(this.getNonInteractiveConsoleMessage(platform));
5050
}
5151

52-
this.$logger.info(this.getInteractiveConsoleMessage(platform));
52+
const infoMessage = this.getInteractiveConsoleMessage(platform);
53+
this.$logger.info(infoMessage);
5354

54-
const selectedOption = await this.promptForChoice();
55+
const choices = this.$nativeScriptCloudExtensionService.isInstalled() ? [
56+
PlatformEnvironmentRequirements.TRY_CLOUD_OPERATION_OPTION_NAME,
57+
PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME,
58+
PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME,
59+
] : [
60+
PlatformEnvironmentRequirements.CLOUD_SETUP_OPTION_NAME,
61+
PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME,
62+
PlatformEnvironmentRequirements.BOTH_CLOUD_SETUP_AND_LOCAL_SETUP_OPTION_NAME,
63+
PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME,
64+
];
65+
66+
const selectedOption = await this.promptForChoice({ infoMessage, choices });
5567

5668
await this.processCloudBuildsIfNeeded(selectedOption, platform);
5769
this.processManuallySetupIfNeeded(selectedOption, platform);
@@ -64,12 +76,24 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
6476
}
6577

6678
if (this.$nativeScriptCloudExtensionService.isInstalled()) {
67-
this.processManuallySetup(platform);
79+
const option = await this.promptForChoice({
80+
infoMessage: PlatformEnvironmentRequirements.NOT_CONFIGURED_ENV_AFTER_SETUP_SCRIPT_MESSAGE,
81+
choices: [
82+
PlatformEnvironmentRequirements.TRY_CLOUD_OPERATION_OPTION_NAME,
83+
PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME
84+
]
85+
});
86+
87+
this.processTryCloudSetupIfNeeded(option, platform);
88+
this.processManuallySetupIfNeeded(option, platform);
6889
} else {
69-
const option = await this.$prompter.promptForChoice(PlatformEnvironmentRequirements.NOT_CONFIGURED_ENV_AFTER_SETUP_SCRIPT_MESSAGE, [
70-
PlatformEnvironmentRequirements.CLOUD_SETUP_OPTION_NAME,
71-
PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME
72-
]);
90+
const option = await this.promptForChoice({
91+
infoMessage: PlatformEnvironmentRequirements.NOT_CONFIGURED_ENV_AFTER_SETUP_SCRIPT_MESSAGE,
92+
choices: [
93+
PlatformEnvironmentRequirements.CLOUD_SETUP_OPTION_NAME,
94+
PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME
95+
]
96+
});
7397

7498
await this.processCloudBuildsIfNeeded(option, platform);
7599
this.processManuallySetupIfNeeded(option, platform);
@@ -85,9 +109,7 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
85109
this.processManuallySetup(platform);
86110
}
87111

88-
if (selectedOption === PlatformEnvironmentRequirements.TRY_CLOUD_OPERATION_OPTION_NAME) {
89-
this.fail(this.getCloudBuildsMessage(platform));
90-
}
112+
this.processTryCloudSetupIfNeeded(selectedOption, platform);
91113
}
92114

93115
return true;
@@ -121,6 +143,12 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
121143
return `Use the $ tns login command to log in with your account and then $ ${cloudCommandName.toLowerCase()} ${platform.toLowerCase()} command.`;
122144
}
123145

146+
private processTryCloudSetupIfNeeded(selectedOption: string, platform?: string) {
147+
if (selectedOption === PlatformEnvironmentRequirements.TRY_CLOUD_OPERATION_OPTION_NAME) {
148+
this.fail(this.getCloudBuildsMessage(platform));
149+
}
150+
}
151+
124152
private processManuallySetupIfNeeded(selectedOption: string, platform?: string) {
125153
if (selectedOption === PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME) {
126154
this.processManuallySetup(platform);
@@ -135,7 +163,7 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
135163
try {
136164
await this.processCloudBuildsCore();
137165
} catch (e) {
138-
this.$logger.trace(`Error while installing ${constants.NATIVESCRIPT_CLOUD_EXTENSION_NAME} extension. ${e.message}.`);
166+
this.$logger.trace(`Error while installing ${NATIVESCRIPT_CLOUD_EXTENSION_NAME} extension. ${e.message}.`);
139167
}
140168

141169
await this.$doctorService.runSetupScript();
@@ -156,7 +184,7 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
156184
this.buildMultilineMessage([
157185
PlatformEnvironmentRequirements.MISSING_LOCAL_AND_CLOUD_SETUP_MESSAGE,
158186
PlatformEnvironmentRequirements.RUN_TNS_SETUP_MESSAGE,
159-
`Run $ tns cloud setup command to install the ${constants.NATIVESCRIPT_CLOUD_EXTENSION_NAME} extension to configure your environment for cloud builds.`,
187+
`Run $ tns cloud setup command to install the ${NATIVESCRIPT_CLOUD_EXTENSION_NAME} extension to configure your environment for cloud builds.`,
160188
this.getEnvVerificationMessage()
161189
]);
162190
}
@@ -170,30 +198,28 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
170198
]) :
171199
this.buildMultilineMessage([
172200
PlatformEnvironmentRequirements.MISSING_LOCAL_AND_CLOUD_SETUP_MESSAGE,
173-
`Select "Configure for Cloud Builds" to install the ${constants.NATIVESCRIPT_CLOUD_EXTENSION_NAME} extension and automatically configure your environment for cloud builds.`,
201+
`Select "Configure for Cloud Builds" to install the ${NATIVESCRIPT_CLOUD_EXTENSION_NAME} extension and automatically configure your environment for cloud builds.`,
174202
`Select "Configure for Local Builds" to run the setup script and automatically configure your environment for local builds.`,
175203
`Select "Configure for Both Local and Cloud Builds" to automatically configure your environment for both options.`,
176204
`Select "Configure for Both Local and Cloud Builds" to automatically configure your environment for both options.`
177205
]);
178206
}
179207

180-
private async promptForChoice(): Promise<string> {
181-
const choices = this.$nativeScriptCloudExtensionService.isInstalled() ? [
182-
PlatformEnvironmentRequirements.TRY_CLOUD_OPERATION_OPTION_NAME,
183-
PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME,
184-
PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME,
185-
] : [
186-
PlatformEnvironmentRequirements.CLOUD_SETUP_OPTION_NAME,
187-
PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME,
188-
PlatformEnvironmentRequirements.BOTH_CLOUD_SETUP_AND_LOCAL_SETUP_OPTION_NAME,
189-
PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME,
190-
];
208+
private async promptForChoice(opts: { infoMessage: string, choices: string[], }): Promise<string> {
209+
this.$logger.info(opts.infoMessage);
191210

192-
const selection = await this.$prompter.promptForChoice(PlatformEnvironmentRequirements.CHOOSE_OPTIONS_MESSAGE, choices);
193211
await this.$analyticsService.trackEventActionInGoogleAnalytics({
194-
action: "Check Environment Requirements",
212+
action: TrackActionNames.CheckEnvironmentRequirements,
213+
additionalData: `User should select: ${opts.infoMessage}`
214+
});
215+
216+
const selection = await this.$prompter.promptForChoice(PlatformEnvironmentRequirements.CHOOSE_OPTIONS_MESSAGE, opts.choices);
217+
218+
await this.$analyticsService.trackEventActionInGoogleAnalytics({
219+
action: TrackActionNames.CheckEnvironmentRequirements,
195220
additionalData: `User selected: ${selection}`
196221
});
222+
197223
return selection;
198224
}
199225

lib/services/platform-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
341341
}
342342

343343
const platformData = this.$platformsData.getPlatformData(platform, projectData);
344-
const forDevice = !buildConfig || buildConfig.buildForDevice;
344+
const forDevice = !buildConfig || !!buildConfig.buildForDevice;
345345
outputPath = outputPath || (forDevice ? platformData.deviceBuildOutputPath : platformData.emulatorBuildOutputPath || platformData.deviceBuildOutputPath);
346346
if (!this.$fs.exists(outputPath)) {
347347
return true;

0 commit comments

Comments
 (0)