Skip to content

Commit 3f8a29d

Browse files
committed
Fix PR comments
1 parent dcdecdf commit 3f8a29d

File tree

8 files changed

+87
-82
lines changed

8 files changed

+87
-82
lines changed

lib/bootstrap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,4 @@ $injector.require("nodeModulesDependenciesBuilder", "./tools/node-modules/node-m
154154
$injector.require("subscriptionService", "./services/subscription-service");
155155
$injector.require("terminalSpinnerService", "./services/terminal-spinner-service");
156156
$injector.require("platformEnvironmentRequirements", "./services/platform-environment-requirements");
157+
$injector.require("nativescriptCloudExtensionService", "./services/nativescript-cloud-extension-service");

lib/commands/setup.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,19 @@ export class SetupCommand implements ICommand {
33

44
constructor(private $doctorService: IDoctorService) { }
55

6-
public async execute(args: string[]): Promise<any> {
6+
public execute(args: string[]): Promise<any> {
77
return this.$doctorService.runSetupScript();
88
}
9-
10-
public async canExecute(args: string[]): Promise<boolean> {
11-
return true;
12-
}
139
}
1410
$injector.registerCommand("setup", SetupCommand);
1511

1612
export class CloudSetupCommand implements ICommand {
1713
public allowedParameters: ICommandParameter[] = [];
1814

19-
constructor(private $extensibilityService: IExtensibilityService) { }
20-
21-
public async execute(args: string[]): Promise<any> {
22-
const installedExtensions = this.$extensibilityService.getInstalledExtensions();
23-
if (!installedExtensions["nativescript-cloud"]) {
24-
return this.$extensibilityService.installExtension("nativescript-cloud");
25-
}
26-
}
15+
constructor(private $nativescriptCloudExtensionService: INativescriptCloudExtensionService) { }
2716

28-
public async canExecute(args: string[]): Promise<boolean> {
29-
return true;
17+
public execute(args: string[]): Promise<any> {
18+
return this.$nativescriptCloudExtensionService.install();
3019
}
3120
}
3221
$injector.registerCommand("cloud|setup", CloudSetupCommand);

lib/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,5 @@ export const enum BuildStates {
137137
Clean = "Clean",
138138
Incremental = "Incremental"
139139
}
140+
141+
export const NATIVESCRIPT_CLOUD_EXTENSION_NAME = "nativescript-cloud";

lib/declarations.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ interface IAndroidToolsInfo {
566566

567567
/**
568568
* Validates target sdk
569+
* @param {IAndroidToolsInfoOptions} options @optional Defines if the warning messages should treated as error.
569570
* @returns {boolean} True if there are detected issues, false otherwise
570571
*/
571572
validateTargetSdk(options?: IAndroidToolsInfoOptions): boolean;
@@ -785,3 +786,11 @@ interface IBundleValidatorHelper {
785786
*/
786787
validate(): void;
787788
}
789+
790+
interface INativescriptCloudExtensionService {
791+
/**
792+
* Installs nativescript-cloud extension
793+
* @return {Promise<IExtensionData>} returns the extension data
794+
*/
795+
install(): Promise<IExtensionData>;
796+
}

lib/services/doctor-service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ class DoctorService implements IDoctorService {
5353
return hasWarnings;
5454
}
5555

56-
public async runSetupScript(): Promise<ISpawnResult> {
56+
public runSetupScript(): Promise<ISpawnResult> {
57+
if (this.$hostInfo.isLinux) {
58+
return;
59+
}
60+
5761
this.$logger.out("Running the setup script to try and automatically configure your environment.");
5862

5963
if (this.$hostInfo.isDarwin) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as constants from "../constants";
2+
3+
export class NativescriptCloudExtensionService implements INativescriptCloudExtensionService {
4+
5+
constructor(private $extensibilityService: IExtensibilityService) { }
6+
7+
public install(): Promise<IExtensionData> {
8+
const installedExtensions = this.$extensibilityService.getInstalledExtensions();
9+
if (!installedExtensions[constants.NATIVESCRIPT_CLOUD_EXTENSION_NAME]) {
10+
return this.$extensibilityService.installExtension(constants.NATIVESCRIPT_CLOUD_EXTENSION_NAME);
11+
}
12+
}
13+
}
14+
$injector.register("nativescriptCloudExtensionService", NativescriptCloudExtensionService);

lib/services/platform-environment-requirements.ts

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import * as constants from "../constants";
12
import { isInteractive } from "../common/helpers";
23
import { EOL } from "os";
34

45
export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequirements {
56
constructor(private $commandsService: ICommandsService,
67
private $doctorService: IDoctorService,
78
private $errors: IErrors,
8-
private $extensibilityService: IExtensibilityService,
9+
private $nativescriptCloudExtensionService: INativescriptCloudExtensionService,
910
private $logger: ILogger,
1011
private $prompter: IPrompter,
1112
private $staticConfig: IStaticConfig) { }
@@ -16,7 +17,6 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
1617
private static BOTH_CLOUD_BUILDS_AND_SETUP_SCRIPT_OPTION_NAME = "Configure for Both Local and Cloud Builds";
1718
private static NOT_CONFIGURED_ENV_MESSAGE = "To continue, choose one of the following options: ";
1819
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. To continue, choose one of the following options:";
19-
private static NATIVESCRIPT_CLOUD_EXTENSION_NAME = "nativescript-cloud";
2020

2121
private cliCommandToCloudCommandName: IStringDictionary = {
2222
"build": "tns cloud build",
@@ -28,28 +28,28 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
2828
const canExecute = await this.$doctorService.canExecuteLocalBuild(platform);
2929
if (!canExecute) {
3030
if (!isInteractive()) {
31-
this.fail("You are missing the nativescript-cloud extension and you will not be able to execute cloud builds. Your environment is not configured properly and you will not be able to execute local builds. To continue, choose one of the following options: " + EOL
31+
this.fail(`You are missing the ${constants.NATIVESCRIPT_CLOUD_EXTENSION_NAME} extension and you will not be able to execute cloud builds. Your environment is not configured properly and you will not be able to execute local builds. To continue, choose one of the following options: ` + EOL
3232
+ "Run $ tns setup command to run the setup script to try to automatically configure your environment for local builds." + EOL
33-
+ "Run $ tns cloud setup command to install the nativescript-cloud extension to configure your environment for cloud builds." + EOL
33+
+ `Run $ tns cloud setup command to install the ${constants.NATIVESCRIPT_CLOUD_EXTENSION_NAME} extension to configure your environment for cloud builds.` + EOL
3434
+ `Verify that your environment is configured according to the system requirements described at ${this.$staticConfig.SYS_REQUIREMENTS_LINK}`);
3535
}
3636

37-
this.$logger.info("You are missing the nativescript-cloud extension and you will not be able to execute cloud builds. Your environment is not configured properly and you will not be able to execute local builds. " + EOL
38-
+ "Select Configure for Cloud Builds to install the nativescript-cloud extension and automatically configure your environment for cloud builds." + EOL
39-
+ "Select Configure for Local Builds to run the setup script and automatically configure your environment for local builds."
40-
+ "Select Configure for Both Local and Cloud Builds to automatically configure your environment for both options."
41-
+ "Select Skip Step and Configure Manually to disregard these options and install any required components manually.");
37+
this.$logger.info(`You are missing the ${constants.NATIVESCRIPT_CLOUD_EXTENSION_NAME} extension and you will not be able to execute cloud builds. Your environment is not configured properly and you will not be able to execute local builds. ` + EOL
38+
+ `Select "Configure for Cloud Builds" to install the ${constants.NATIVESCRIPT_CLOUD_EXTENSION_NAME} extension and automatically configure your environment for cloud builds.` + EOL
39+
+ `Select "Configure for Local Builds" to run the setup script and automatically configure your environment for local builds.`
40+
+ `Select "Configure for Both Local and Cloud Builds" to automatically configure your environment for both options.`
41+
+ `Select "Skip Step and Configure Manually" to disregard these options and install any required components manually.`);
4242

4343
const selectedOption = await this.$prompter.promptForChoice(PlatformEnvironmentRequirements.NOT_CONFIGURED_ENV_MESSAGE, [
4444
PlatformEnvironmentRequirements.CLOUD_BUILDS_OPTION_NAME,
4545
PlatformEnvironmentRequirements.SETUP_SCRIPT_OPTION_NAME,
46+
PlatformEnvironmentRequirements.BOTH_CLOUD_BUILDS_AND_SETUP_SCRIPT_OPTION_NAME,
4647
PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME,
47-
PlatformEnvironmentRequirements.BOTH_CLOUD_BUILDS_AND_SETUP_SCRIPT_OPTION_NAME
4848
]);
4949

50-
if (selectedOption === PlatformEnvironmentRequirements.CLOUD_BUILDS_OPTION_NAME) {
51-
await this.processCloudBuilds(platform);
52-
}
50+
await this.processCloudBuildsIfNeeded(platform, selectedOption);
51+
52+
this.processManuallySetupIfNeeded(platform, selectedOption);
5353

5454
if (selectedOption === PlatformEnvironmentRequirements.SETUP_SCRIPT_OPTION_NAME) {
5555
await this.$doctorService.runSetupScript();
@@ -63,17 +63,9 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
6363
PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME
6464
]);
6565

66-
if (option === PlatformEnvironmentRequirements.CLOUD_BUILDS_OPTION_NAME) {
67-
await this.processCloudBuilds(platform);
68-
}
66+
await this.processCloudBuildsIfNeeded(platform, option);
6967

70-
if (option === PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME) {
71-
this.processManuallySetup(platform);
72-
}
73-
}
74-
75-
if (selectedOption === PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME) {
76-
this.processManuallySetup(platform);
68+
this.processManuallySetupIfNeeded(platform, option);
7769
}
7870

7971
if (selectedOption === PlatformEnvironmentRequirements.BOTH_CLOUD_BUILDS_AND_SETUP_SCRIPT_OPTION_NAME) {
@@ -89,16 +81,19 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
8981
return true;
9082
}
9183

84+
private async processCloudBuildsIfNeeded(platform: string, selectedOption: string): Promise<void> {
85+
if (selectedOption === PlatformEnvironmentRequirements.CLOUD_BUILDS_OPTION_NAME) {
86+
await this.processCloudBuilds(platform);
87+
}
88+
}
89+
9290
private async processCloudBuilds(platform: string): Promise<void> {
9391
await this.processCloudBuildsCore(platform);
9492
this.fail(this.getCloudBuildsMessage(platform));
9593
}
9694

97-
private async processCloudBuildsCore(platform: string): Promise<IExtensionData> {
98-
const installedExtensions = this.$extensibilityService.getInstalledExtensions();
99-
if (!installedExtensions[PlatformEnvironmentRequirements.NATIVESCRIPT_CLOUD_EXTENSION_NAME]) {
100-
return this.$extensibilityService.installExtension(PlatformEnvironmentRequirements.NATIVESCRIPT_CLOUD_EXTENSION_NAME);
101-
}
95+
private processCloudBuildsCore(platform: string): Promise<IExtensionData> {
96+
return this.$nativescriptCloudExtensionService.install();
10297
}
10398

10499
private getCloudBuildsMessage(platform: string): string {
@@ -108,10 +103,16 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
108103
}
109104

110105
if (!platform) {
111-
return `Use the $ tns login command to log in with your account and then $ tns cloud ${cloudCommandName.toLowerCase()} command to build your app in the cloud.`;
106+
return `Use the $ tns login command to log in with your account and then $ ${cloudCommandName.toLowerCase()} command.`;
112107
}
113108

114-
return `Use the $ tns login command to log in with your account and then $ tns cloud ${cloudCommandName.toLowerCase()} ${platform.toLowerCase()} command to build your app in the cloud.`;
109+
return `Use the $ tns login command to log in with your account and then $ ${cloudCommandName.toLowerCase()} ${platform.toLowerCase()} command.`;
110+
}
111+
112+
private processManuallySetupIfNeeded(platform: string, selectedOption: string) {
113+
if (selectedOption === PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME) {
114+
this.processManuallySetup(platform);
115+
}
115116
}
116117

117118
private processManuallySetup(platform: string): void {
@@ -122,7 +123,7 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
122123
try {
123124
await this.processCloudBuildsCore(platform);
124125
} catch (e) {
125-
this.$logger.trace(`Error while installing nativescript-cloud extension. ${e.message}.`);
126+
this.$logger.trace(`Error while installing ${constants.NATIVESCRIPT_CLOUD_EXTENSION_NAME} extension. ${e.message}.`);
126127
}
127128

128129
await this.$doctorService.runSetupScript();

test/services/platform-environment-requirements.ts

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ function createTestInjector() {
1818
throw new Error(err.formatStr || err.message || err);
1919
}
2020
});
21-
testInjector.register("extensibilityService", {});
2221
testInjector.register("logger", stubs.LoggerStub);
2322
testInjector.register("prompter", {});
2423
testInjector.register("platformEnvironmentRequirements", PlatformEnvironmentRequirements);
2524
testInjector.register("staticConfig", { SYS_REQUIREMENTS_LINK: "" });
25+
testInjector.register("nativescriptCloudExtensionService", {});
2626

2727
return testInjector;
2828
}
@@ -51,9 +51,8 @@ describe("platformEnvironmentRequirements ", () => {
5151
};
5252

5353
let isInstallExtensionCalled = false;
54-
const extensibilityService = testInjector.resolve("extensibilityService");
55-
extensibilityService.installExtension = () => {isInstallExtensionCalled = true; };
56-
extensibilityService.getInstalledExtensions = () => { return {}; };
54+
const nativescriptCloudExtensionService = testInjector.resolve("nativescriptCloudExtensionService");
55+
nativescriptCloudExtensionService.install = () => {isInstallExtensionCalled = true; };
5756

5857
await assert.isRejected(platformEnvironmentRequirements.checkEnvironmentRequirements(platform));
5958
assert.isTrue(isPromptForChoiceCalled);
@@ -70,17 +69,9 @@ describe("platformEnvironmentRequirements ", () => {
7069

7170
describe("when setup script option is selected ", () => {
7271
it("should return true when env is configured after executing setup script", async () => {
73-
let index = 0;
7472
const doctorService = testInjector.resolve("doctorService");
75-
doctorService.canExecuteLocalBuild = () => {
76-
if (index === 0) {
77-
index++;
78-
return false;
79-
}
80-
81-
return true;
82-
};
83-
doctorService.runSetupScript = () => Promise.resolve();
73+
doctorService.canExecuteLocalBuild = () => false;
74+
doctorService.runSetupScript = async () => { doctorService.canExecuteLocalBuild = () => true; };
8475

8576
const prompter = testInjector.resolve("prompter");
8677
prompter.promptForChoice = () => Promise.resolve(PlatformEnvironmentRequirements.SETUP_SCRIPT_OPTION_NAME);
@@ -93,12 +84,11 @@ describe("platformEnvironmentRequirements ", () => {
9384
doctorService.canExecuteLocalBuild = () => false;
9485
doctorService.runSetupScript = () => Promise.resolve();
9586

96-
let index = 0;
97-
let isPromptForChoiceCalled = false;
87+
let isPromptForChoiceCalled = true;
9888
const prompter = testInjector.resolve("prompter");
9989
prompter.promptForChoice = () => {
100-
if (index === 0) {
101-
index++;
90+
if (isPromptForChoiceCalled) {
91+
isPromptForChoiceCalled = false;
10292
return PlatformEnvironmentRequirements.SETUP_SCRIPT_OPTION_NAME;
10393
}
10494

@@ -107,9 +97,8 @@ describe("platformEnvironmentRequirements ", () => {
10797
};
10898

10999
let isInstallExtensionCalled = false;
110-
const extensibilityService = testInjector.resolve("extensibilityService");
111-
extensibilityService.installExtension = () => {isInstallExtensionCalled = true; };
112-
extensibilityService.getInstalledExtensions = () => { return {}; };
100+
const nativescriptCloudExtensionService = testInjector.resolve("nativescriptCloudExtensionService");
101+
nativescriptCloudExtensionService.install = () => {isInstallExtensionCalled = true; };
113102

114103
await assert.isRejected(platformEnvironmentRequirements.checkEnvironmentRequirements(platform));
115104
assert.isTrue(isInstallExtensionCalled);
@@ -123,12 +112,11 @@ describe("platformEnvironmentRequirements ", () => {
123112
doctorService.runSetupScript = () => Promise.resolve();
124113
});
125114
it("should install nativescript-cloud extension when cloud builds option is selected", async () => {
126-
let index = 0;
127-
let isPromptForChoiceCalled = false;
115+
let isPromptForChoiceCalled = true;
128116
const prompter = testInjector.resolve("prompter");
129117
prompter.promptForChoice = () => {
130-
if (index === 0) {
131-
index++;
118+
if (isPromptForChoiceCalled) {
119+
isPromptForChoiceCalled = false;
132120
return PlatformEnvironmentRequirements.SETUP_SCRIPT_OPTION_NAME;
133121
}
134122

@@ -137,21 +125,19 @@ describe("platformEnvironmentRequirements ", () => {
137125
};
138126

139127
let isInstallExtensionCalled = false;
140-
const extensibilityService = testInjector.resolve("extensibilityService");
141-
extensibilityService.installExtension = () => isInstallExtensionCalled = true;
142-
extensibilityService.getInstalledExtensions = () => { return {}; };
128+
const nativescriptCloudExtensionService = testInjector.resolve("nativescriptCloudExtensionService");
129+
nativescriptCloudExtensionService.install = () => {isInstallExtensionCalled = true; };
143130

144131
await assert.isRejected(platformEnvironmentRequirements.checkEnvironmentRequirements(platform), cloudBuildsErrorMessage);
145132
assert.isTrue(isInstallExtensionCalled);
146133
assert.isTrue(isPromptForChoiceCalled);
147134
});
148135
it("should fail when manually setup option is selected", async () => {
149-
let index = 0;
150-
let isPromptForChoiceCalled = false;
136+
let isPromptForChoiceCalled = true;
151137
const prompter = testInjector.resolve("prompter");
152138
prompter.promptForChoice = () => {
153-
if (index === 0) {
154-
index++;
139+
if (isPromptForChoiceCalled) {
140+
isPromptForChoiceCalled = false;
155141
return PlatformEnvironmentRequirements.SETUP_SCRIPT_OPTION_NAME;
156142
}
157143

@@ -174,9 +160,8 @@ describe("platformEnvironmentRequirements ", () => {
174160
prompter.promptForChoice = () => Promise.resolve(PlatformEnvironmentRequirements.CLOUD_BUILDS_OPTION_NAME);
175161

176162
let isInstallExtensionCalled = false;
177-
const extensibilityService = testInjector.resolve("extensibilityService");
178-
extensibilityService.installExtension = () => isInstallExtensionCalled = true;
179-
extensibilityService.getInstalledExtensions = () => { return {}; };
163+
const nativescriptCloudExtensionService = testInjector.resolve("nativescriptCloudExtensionService");
164+
nativescriptCloudExtensionService.install = () => {isInstallExtensionCalled = true; };
180165

181166
await assert.isRejected(platformEnvironmentRequirements.checkEnvironmentRequirements(platform), cloudBuildsErrorMessage);
182167
assert.isTrue(isInstallExtensionCalled);

0 commit comments

Comments
 (0)