Skip to content

Commit b83c9ba

Browse files
committed
Support for non interactive console
1 parent 6bf8a49 commit b83c9ba

File tree

2 files changed

+36
-9
lines changed

2 files changed

+36
-9
lines changed

lib/services/platform-environment-requirements.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { isInteractive } from "../common/helpers";
2+
import { EOL } from "os";
3+
14
export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequirements {
25
constructor(private $doctorService: IDoctorService,
36
private $errors: IErrors,
@@ -16,6 +19,13 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
1619
public async checkEnvironmentRequirements(data: ICheckEnvironmentRequirementsInput): Promise<boolean> {
1720
const canExecute = await this.$doctorService.canExecuteLocalBuild(data.platform);
1821
if (!canExecute) {
22+
if (!isInteractive()) {
23+
this.fail("Your environment is not configured properly and you will not be able to execute local builds. You are missing the nativescript-cloud extension and you will not be able to execute cloud builds. To continue, choose one of the following options: " + EOL
24+
+ "Run $ tns setup command to run the setup script to try to automatically configure your environment for local builds." + EOL
25+
+ "Run $ tns cloud setup command to install the nativescript-cloud extension to configure your environment for cloud builds." + EOL
26+
+ `Verify that your environment is configured according to the system requirements described at ${this.$staticConfig.SYS_REQUIREMENTS_LINK}`);
27+
}
28+
1929
const selectedOption = await this.$prompter.promptForChoice(PlatformEnvironmentRequirements.NOT_CONFIGURED_ENV_MESSAGE, [
2030
PlatformEnvironmentRequirements.CLOUD_BUILDS_OPTION_NAME,
2131
PlatformEnvironmentRequirements.SETUP_SCRIPT_OPTION_NAME,
@@ -67,7 +77,8 @@ export class PlatformEnvironmentRequirements implements IPlatformEnvironmentRequ
6777

6878
private async processCloudBuilds(data: ICheckEnvironmentRequirementsInput): Promise<void> {
6979
await this.processCloudBuildsCore(data);
70-
this.fail(`Use the $ tns login command to log in with your account and then $ tns cloud ${data.cloudCommandName.toLowerCase()} ${data.platform.toLowerCase()} command to build your app in the cloud.`);
80+
const cloudCommandName = data.platform ? `$ tns cloud ${data.cloudCommandName.toLowerCase()} ${data.platform.toLowerCase()}` : `$ tns cloud ${data.cloudCommandName.toLowerCase()}`;
81+
this.fail(`Use the $ tns login command to log in with your account and then ${cloudCommandName} command to build your app in the cloud.`);
7182
}
7283

7384
private async processCloudBuildsCore(data: ICheckEnvironmentRequirementsInput): Promise<IExtensionData> {

test/services/platform-environment-requirements.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ import { assert } from "chai";
55

66
const data = {platform: "android", cloudCommandName: "build"};
77
const cloudBuildsErrorMessage = `Use the $ tns login command to log in with your account and then $ tns cloud ${data.cloudCommandName.toLowerCase()} ${data.platform.toLowerCase()} command to build your app in the cloud.`;
8-
function getManuallySetupErrorMessage(testInjector: IInjector) {
9-
const staticConfig = testInjector.resolve("staticConfig");
10-
return `To be able to build for ${data.platform}, verify that your environment is configured according to the system requirements described at ${staticConfig.SYS_REQUIREMENTS_LINK}`;
11-
}
8+
const manuallySetupErrorMessage = `To be able to build for ${data.platform}, verify that your environment is configured according to the system requirements described at `;
9+
const nonInteractiveConsoleErrorMessage = `Your environment is not configured properly and you will not be able to execute local builds. You are missing the nativescript-cloud extension and you will not be able to execute cloud builds. To continue, choose one of the following options: \nRun $ tns setup command to run the setup script to try to automatically configure your environment for local builds.\nRun $ tns cloud setup command to install the nativescript-cloud extension to configure your environment for cloud builds.\nVerify that your environment is configured according to the system requirements described at `;
1210

1311
function createTestInjector() {
1412
const testInjector = new Yok();
1513

1614
testInjector.register("doctorService", {});
17-
testInjector.register("errors", stubs.ErrorsStub);
15+
testInjector.register("errors", {
16+
fail: (err: any) => {
17+
throw new Error(err.formatStr || err.message || err);
18+
}
19+
});
1820
testInjector.register("extensibilityService", {});
1921
testInjector.register("logger", stubs.LoggerStub);
2022
testInjector.register("prompter", {});
@@ -24,14 +26,16 @@ function createTestInjector() {
2426
return testInjector;
2527
}
2628

27-
describe("platformEnvironmentRequirements ", () => {
29+
describe.only("platformEnvironmentRequirements ", () => {
2830
describe("checkRequirements", () => {
2931
let testInjector: IInjector = null;
3032
let platformEnvironmentRequirements: IPlatformEnvironmentRequirements = null;
3133

3234
beforeEach(() => {
3335
testInjector = createTestInjector();
3436
platformEnvironmentRequirements = testInjector.resolve("platformEnvironmentRequirements");
37+
process.stdout.isTTY = true;
38+
process.stdin.isTTY = true;
3539
});
3640

3741
it("should show prompt when environment is not configured", async () => {
@@ -151,7 +155,7 @@ describe("platformEnvironmentRequirements ", () => {
151155
return PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME;
152156
};
153157

154-
await assert.isRejected(platformEnvironmentRequirements.checkEnvironmentRequirements(data), getManuallySetupErrorMessage(testInjector));
158+
await assert.isRejected(platformEnvironmentRequirements.checkEnvironmentRequirements(data), manuallySetupErrorMessage);
155159
assert.isTrue(isPromptForChoiceCalled);
156160
});
157161
});
@@ -182,7 +186,19 @@ describe("platformEnvironmentRequirements ", () => {
182186
const prompter = testInjector.resolve("prompter");
183187
prompter.promptForChoice = () => PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME;
184188

185-
await assert.isRejected(platformEnvironmentRequirements.checkEnvironmentRequirements(data), getManuallySetupErrorMessage(testInjector));
189+
await assert.isRejected(platformEnvironmentRequirements.checkEnvironmentRequirements(data), manuallySetupErrorMessage);
190+
});
191+
});
192+
193+
describe("when console is not interactive", () => {
194+
it("should fail when console is not interactive", async () => {
195+
process.stdout.isTTY = false;
196+
process.stdin.isTTY = false;
197+
198+
const doctorService = testInjector.resolve("doctorService");
199+
doctorService.canExecuteLocalBuild = () => false;
200+
201+
await assert.isRejected(platformEnvironmentRequirements.checkEnvironmentRequirements(data), nonInteractiveConsoleErrorMessage);
186202
});
187203
});
188204
});

0 commit comments

Comments
 (0)