Skip to content

Commit f460ade

Browse files
feat: remove cloud build option
Remove cloud build option when setup of local environment is not correct.
1 parent 2a78457 commit f460ade

File tree

5 files changed

+41
-238
lines changed

5 files changed

+41
-238
lines changed

lib/commands/debug.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
6666
this.$errors.failWithHelp("--release flag is not applicable to this command.");
6767
}
6868

69-
const result = await super.canExecuteCommandBase(this.platform, { validateOptions: true, notConfiguredEnvOptions: { hideCloudBuildOption: true, hideSyncToPreviewAppOption: true } });
69+
const result = await super.canExecuteCommandBase(this.platform, { validateOptions: true, notConfiguredEnvOptions: { hideSyncToPreviewAppOption: true } });
7070
return result;
7171
}
7272
}

lib/commands/test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ abstract class TestCommandBase {
7676
projectDir: this.$projectData.projectDir,
7777
options: this.$options,
7878
notConfiguredEnvOptions: {
79-
hideSyncToPreviewAppOption: true,
80-
hideCloudBuildOption: true
79+
hideSyncToPreviewAppOption: true
8180
}
8281
});
8382

lib/services/nativescript-cloud-extension-service.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ export class NativeScriptCloudExtensionService implements INativeScriptCloudExte
66
private $logger: ILogger,
77
private $packageInstallationManager: IPackageInstallationManager) { }
88

9-
public install(): Promise<IExtensionData> {
9+
public async install(): Promise<IExtensionData> {
10+
let extensionData: IExtensionData;
11+
1012
if (!this.isInstalled()) {
11-
return this.$extensibilityService.installExtension(constants.NATIVESCRIPT_CLOUD_EXTENSION_NAME);
13+
extensionData = await this.$extensibilityService.installExtension(constants.NATIVESCRIPT_CLOUD_EXTENSION_NAME);
14+
} else {
15+
this.$logger.info(`Extension ${constants.NATIVESCRIPT_CLOUD_EXTENSION_NAME} is already installed.`);
1216
}
1317

14-
this.$logger.info(`Extension ${constants.NATIVESCRIPT_CLOUD_EXTENSION_NAME} is already installed.`);
18+
this.$logger.warn(`Free cloud builds will be stopped on <date>. Paid cloud builds will be stopped on <date>. For more information check this blogpost: <url>`);
19+
20+
return extensionData;
1521
}
1622

1723
public isInstalled(): boolean {

lib/services/platform-environment-requirements.ts

+14-137
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import { NATIVESCRIPT_CLOUD_EXTENSION_NAME, TrackActionNames } from "../constants";
1+
import { TrackActionNames } from "../constants";
22
import { isInteractive, hook } from "../common/helpers";
33
import { EOL } from "os";
44

55
export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequirements {
6-
constructor(private $commandsService: ICommandsService,
7-
private $doctorService: IDoctorService,
6+
constructor(private $doctorService: IDoctorService,
87
private $errors: IErrors,
98
private $logger: ILogger,
10-
private $nativeScriptCloudExtensionService: INativeScriptCloudExtensionService,
119
private $prompter: IPrompter,
1210
private $staticConfig: IStaticConfig,
1311
private $analyticsService: IAnalyticsService,
@@ -18,27 +16,16 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
1816
return this.$injector.resolve("previewAppController");
1917
}
2018

21-
public static CLOUD_SETUP_OPTION_NAME = "Configure for Cloud Builds";
2219
public static LOCAL_SETUP_OPTION_NAME = "Configure for Local Builds";
23-
public static TRY_CLOUD_OPERATION_OPTION_NAME = "Try Cloud Operation";
2420
public static SYNC_TO_PREVIEW_APP_OPTION_NAME = "Sync to Playground";
2521
public static MANUALLY_SETUP_OPTION_NAME = "Skip Step and Configure Manually";
26-
private static BOTH_CLOUD_SETUP_AND_LOCAL_SETUP_OPTION_NAME = "Configure for Both Local and Cloud Builds";
2722
private static CHOOSE_OPTIONS_MESSAGE = "To continue, choose one of the following options: ";
2823
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. Please consult our setup instructions here 'https://docs.nativescript.org/start/quick-setup'.`;
2924
private static MISSING_LOCAL_SETUP_MESSAGE = "Your environment is not configured properly and you will not be able to execute local builds.";
30-
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} `;
31-
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)}`;
3225
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.';
3326
private static SYNC_TO_PREVIEW_APP_MESSAGE = `Select "Sync to Playground" to enjoy NativeScript without any local setup. All you need is a couple of companion apps installed on your devices.`;
3427
private static RUN_PREVIEW_COMMAND_MESSAGE = `Run $ tns preview command to enjoy NativeScript without any local setup.`;
3528

36-
private cliCommandToCloudCommandName: IStringDictionary = {
37-
"build": "tns cloud build",
38-
"run": "tns cloud run",
39-
"deploy": "tns cloud deploy"
40-
};
41-
4229
@hook("checkEnvironment")
4330
public async checkEnvironmentRequirements(input: ICheckEnvironmentRequirementsInput): Promise<ICheckEnvironmentRequirementsOutput> {
4431
const { platform, projectDir, runtimeVersion } = input;
@@ -75,7 +62,6 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
7562

7663
selectedOption = await this.promptForChoice({ infoMessage, choices });
7764

78-
await this.processCloudBuildsIfNeeded(selectedOption, platform);
7965
this.processManuallySetupIfNeeded(selectedOption, platform);
8066
await this.processSyncToPreviewAppIfNeeded(selectedOption, projectDir, options);
8167

@@ -89,44 +75,8 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
8975
};
9076
}
9177

92-
if (this.$nativeScriptCloudExtensionService.isInstalled()) {
93-
const option = await this.promptForChoice({
94-
infoMessage: PlatformEnvironmentRequirements.NOT_CONFIGURED_ENV_AFTER_SETUP_SCRIPT_MESSAGE,
95-
choices: [
96-
PlatformEnvironmentRequirements.TRY_CLOUD_OPERATION_OPTION_NAME,
97-
PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME
98-
]
99-
});
100-
101-
this.processTryCloudSetupIfNeeded(option, platform);
102-
this.processManuallySetupIfNeeded(option, platform);
103-
} else {
104-
const option = await this.promptForChoice({
105-
infoMessage: PlatformEnvironmentRequirements.NOT_CONFIGURED_ENV_AFTER_SETUP_SCRIPT_MESSAGE,
106-
choices: [
107-
PlatformEnvironmentRequirements.CLOUD_SETUP_OPTION_NAME,
108-
PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME
109-
]
110-
});
111-
112-
await this.processCloudBuildsIfNeeded(option, platform);
113-
this.processManuallySetupIfNeeded(option, platform);
114-
}
78+
this.fail(PlatformEnvironmentRequirements.NOT_CONFIGURED_ENV_AFTER_SETUP_SCRIPT_MESSAGE);
11579
}
116-
117-
if (selectedOption === PlatformEnvironmentRequirements.BOTH_CLOUD_SETUP_AND_LOCAL_SETUP_OPTION_NAME) {
118-
await this.processBothCloudBuildsAndSetupScript();
119-
if (await this.$doctorService.canExecuteLocalBuild({ platform, projectDir, runtimeVersion, forceCheck: input.forceCheck })) {
120-
return {
121-
canExecute: true,
122-
selectedOption
123-
};
124-
}
125-
126-
this.processManuallySetup(platform);
127-
}
128-
129-
this.processTryCloudSetupIfNeeded(selectedOption, platform);
13080
}
13181

13282
return {
@@ -135,40 +85,6 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
13585
};
13686
}
13787

138-
private async processCloudBuildsIfNeeded(selectedOption: string, platform?: string): Promise<void> {
139-
if (selectedOption === PlatformEnvironmentRequirements.CLOUD_SETUP_OPTION_NAME) {
140-
await this.processCloudBuilds(platform);
141-
}
142-
}
143-
144-
private async processCloudBuilds(platform: string): Promise<void> {
145-
await this.processCloudBuildsCore();
146-
this.fail(this.getCloudBuildsMessage(platform));
147-
}
148-
149-
private processCloudBuildsCore(): Promise<IExtensionData> {
150-
return this.$nativeScriptCloudExtensionService.install();
151-
}
152-
153-
private getCloudBuildsMessage(platform?: string): string {
154-
const cloudCommandName = this.cliCommandToCloudCommandName[(this.$commandsService.currentCommandData || <any>{}).commandName];
155-
if (!cloudCommandName) {
156-
return `In order to test your application use the $ tns login command to log in with your account and then $ tns cloud build command to build your app in the cloud.`;
157-
}
158-
159-
if (!platform) {
160-
return `Use the $ tns login command to log in with your account and then $ ${cloudCommandName.toLowerCase()} command.`;
161-
}
162-
163-
return `Use the $ tns login command to log in with your account and then $ ${cloudCommandName.toLowerCase()} ${platform.toLowerCase()} command.`;
164-
}
165-
166-
private processTryCloudSetupIfNeeded(selectedOption: string, platform?: string) {
167-
if (selectedOption === PlatformEnvironmentRequirements.TRY_CLOUD_OPERATION_OPTION_NAME) {
168-
this.fail(this.getCloudBuildsMessage(platform));
169-
}
170-
}
171-
17288
private processManuallySetupIfNeeded(selectedOption: string, platform?: string) {
17389
if (selectedOption === PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME) {
17490
this.processManuallySetup(platform);
@@ -195,52 +111,25 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
195111
this.fail(`To be able to ${platform ? `build for ${platform}` : 'build'}, verify that your environment is configured according to the system requirements described at ${this.$staticConfig.SYS_REQUIREMENTS_LINK}. If you have any questions, check Stack Overflow: 'https://stackoverflow.com/questions/tagged/nativescript' and our public Slack channel: 'https://nativescriptcommunity.slack.com/'`);
196112
}
197113

198-
private async processBothCloudBuildsAndSetupScript(): Promise<void> {
199-
try {
200-
await this.processCloudBuildsCore();
201-
} catch (e) {
202-
this.$logger.trace(`Error while installing ${NATIVESCRIPT_CLOUD_EXTENSION_NAME} extension. ${e.message}.`);
203-
}
204-
205-
await this.$doctorService.runSetupScript();
206-
}
207-
208114
private fail(message: string): void {
209115
this.$errors.fail({ formatStr: message, printOnStdout: true });
210116
}
211117

212118
private getNonInteractiveConsoleMessage(platform: string) {
213-
return this.$nativeScriptCloudExtensionService.isInstalled() ?
214-
this.buildMultilineMessage([
215-
`${PlatformEnvironmentRequirements.MISSING_LOCAL_SETUP_MESSAGE} ${PlatformEnvironmentRequirements.CHOOSE_OPTIONS_MESSAGE}`,
216-
PlatformEnvironmentRequirements.RUN_PREVIEW_COMMAND_MESSAGE,
217-
PlatformEnvironmentRequirements.RUN_TNS_SETUP_MESSAGE,
218-
this.getCloudBuildsMessage(platform),
219-
this.getEnvVerificationMessage()
220-
]) :
221-
this.buildMultilineMessage([
222-
PlatformEnvironmentRequirements.MISSING_LOCAL_AND_CLOUD_SETUP_MESSAGE,
223-
PlatformEnvironmentRequirements.RUN_PREVIEW_COMMAND_MESSAGE,
224-
PlatformEnvironmentRequirements.RUN_TNS_SETUP_MESSAGE,
225-
`Run $ tns cloud setup command to install the ${NATIVESCRIPT_CLOUD_EXTENSION_NAME} extension to configure your environment for cloud builds.`,
226-
this.getEnvVerificationMessage()
227-
]);
119+
return this.buildMultilineMessage([
120+
`${PlatformEnvironmentRequirements.MISSING_LOCAL_SETUP_MESSAGE} ${PlatformEnvironmentRequirements.CHOOSE_OPTIONS_MESSAGE}`,
121+
PlatformEnvironmentRequirements.RUN_PREVIEW_COMMAND_MESSAGE,
122+
PlatformEnvironmentRequirements.RUN_TNS_SETUP_MESSAGE,
123+
this.getEnvVerificationMessage()
124+
]);
228125
}
229126

230127
private getInteractiveConsoleMessage(options: INotConfiguredEnvOptions) {
231-
const isNativeScriptCloudExtensionInstalled = this.$nativeScriptCloudExtensionService.isInstalled();
232-
const message = isNativeScriptCloudExtensionInstalled ?
233-
`${PlatformEnvironmentRequirements.MISSING_LOCAL_BUT_CLOUD_SETUP_MESSAGE} ${PlatformEnvironmentRequirements.CHOOSE_OPTIONS_MESSAGE}` :
234-
PlatformEnvironmentRequirements.MISSING_LOCAL_AND_CLOUD_SETUP_MESSAGE;
235-
const choices = isNativeScriptCloudExtensionInstalled ? [
128+
const message = PlatformEnvironmentRequirements.MISSING_LOCAL_SETUP_MESSAGE;
129+
const choices = [
236130
`Select "Configure for Local Builds" to run the setup script and automatically configure your environment for local builds.`,
237131
`Select "Skip Step and Configure Manually" to disregard this option and install any required components manually.`
238-
] : [
239-
`Select "Configure for Cloud Builds" to install the ${NATIVESCRIPT_CLOUD_EXTENSION_NAME} extension and automatically configure your environment for cloud builds.`,
240-
`Select "Configure for Local Builds" to run the setup script and automatically configure your environment for local builds.`,
241-
`Select "Configure for Both Local and Cloud Builds" to automatically configure your environment for both options.`,
242-
`Select "Configure for Both Local and Cloud Builds" to automatically configure your environment for both options.`
243-
];
132+
];
244133

245134
if (!options.hideSyncToPreviewAppOption) {
246135
choices.unshift(PlatformEnvironmentRequirements.SYNC_TO_PREVIEW_APP_MESSAGE);
@@ -279,21 +168,9 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
279168

280169
private getChoices(options: INotConfiguredEnvOptions): string[] {
281170
const choices: string[] = [];
282-
if (this.$nativeScriptCloudExtensionService.isInstalled()) {
283-
choices.push(...[PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME,
284-
PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME]);
285171

286-
if (!options.hideCloudBuildOption) {
287-
choices.unshift(PlatformEnvironmentRequirements.TRY_CLOUD_OPERATION_OPTION_NAME);
288-
}
289-
} else {
290-
choices.push(...[
291-
PlatformEnvironmentRequirements.CLOUD_SETUP_OPTION_NAME,
292-
PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME,
293-
PlatformEnvironmentRequirements.BOTH_CLOUD_SETUP_AND_LOCAL_SETUP_OPTION_NAME,
294-
PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME,
295-
]);
296-
}
172+
choices.push(...[PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME,
173+
PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME]);
297174

298175
if (!options.hideSyncToPreviewAppOption) {
299176
choices.unshift(PlatformEnvironmentRequirements.SYNC_TO_PREVIEW_APP_OPTION_NAME);

0 commit comments

Comments
 (0)