Skip to content

Commit 26ef91b

Browse files
committed
Don't check twice if env is properly configured
1 parent 762cfa4 commit 26ef91b

15 files changed

+166
-113
lines changed

docs/man_pages/cloud/cloud-setup.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ position: 5
77

88
Usage | Synopsis
99
------|-------
10-
Install the nativescript-cloud extension | `$ tns cloud setup`
10+
Install the `nativescript-cloud extension` | `$ tns cloud setup`
1111

12-
Install the nativescript-cloud extension to configure your environment for cloud builds.
12+
Install the `nativescript-cloud extension` to configure your environment for cloud builds.
1313

1414
### Related Commands
1515

lib/android-tools-info.ts

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,43 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
4040
return this.toolsInfo;
4141
}
4242

43-
public validateInfo(options?: { showWarningsAsErrors: boolean, validateTargetSdk: boolean }): boolean {
43+
public validateInfo(options?: IAndroidToolsInfoValidateInput): boolean {
4444
let detectedErrors = false;
4545
this.showWarningsAsErrors = options && options.showWarningsAsErrors;
46-
const toolsInfoData = this.getToolsInfo();
4746
const isAndroidHomeValid = this.validateAndroidHomeEnvVariable();
4847

4948
detectedErrors = androidToolsInfo.validateInfo().map(warning => this.printMessage(warning.warning)).length > 0;
5049

5150
if (options && options.validateTargetSdk) {
52-
const targetSdk = toolsInfoData.targetSdkVersion;
53-
const newTarget = `${AndroidToolsInfo.ANDROID_TARGET_PREFIX}-${targetSdk}`;
54-
if (!_.includes(AndroidToolsInfo.SUPPORTED_TARGETS, newTarget)) {
55-
const supportedVersions = AndroidToolsInfo.SUPPORTED_TARGETS.sort();
56-
const minSupportedVersion = this.parseAndroidSdkString(_.first(supportedVersions));
57-
58-
if (targetSdk && (targetSdk < minSupportedVersion)) {
59-
this.printMessage(`The selected Android target SDK ${newTarget} is not supported. You must target ${minSupportedVersion} or later.`);
60-
detectedErrors = true;
61-
} else if (!targetSdk || targetSdk > this.getMaxSupportedVersion()) {
62-
this.$logger.warn(`Support for the selected Android target SDK ${newTarget} is not verified. Your Android app might not work as expected.`);
63-
}
64-
}
51+
detectedErrors = this.validateTargetSdk();
6552
}
6653

6754
return detectedErrors || !isAndroidHomeValid;
6855
}
6956

70-
public validateJavacVersion(installedJavacVersion: string, options?: { showWarningsAsErrors: boolean }): boolean {
57+
public validateTargetSdk(options?: IAndroidToolsInfoOptions): boolean {
58+
this.showWarningsAsErrors = options && options.showWarningsAsErrors;
59+
60+
const toolsInfoData = this.getToolsInfo();
61+
const targetSdk = toolsInfoData.targetSdkVersion;
62+
const newTarget = `${AndroidToolsInfo.ANDROID_TARGET_PREFIX}-${targetSdk}`;
63+
64+
if (!_.includes(AndroidToolsInfo.SUPPORTED_TARGETS, newTarget)) {
65+
const supportedVersions = AndroidToolsInfo.SUPPORTED_TARGETS.sort();
66+
const minSupportedVersion = this.parseAndroidSdkString(_.first(supportedVersions));
67+
68+
if (targetSdk && (targetSdk < minSupportedVersion)) {
69+
this.printMessage(`The selected Android target SDK ${newTarget} is not supported. You must target ${minSupportedVersion} or later.`);
70+
return true;
71+
} else if (!targetSdk || targetSdk > this.getMaxSupportedVersion()) {
72+
this.$logger.warn(`Support for the selected Android target SDK ${newTarget} is not verified. Your Android app might not work as expected.`);
73+
}
74+
}
75+
76+
return false;
77+
}
78+
79+
public validateJavacVersion(installedJavacVersion: string, options?: IAndroidToolsInfoOptions): boolean {
7180
if (options) {
7281
this.showWarningsAsErrors = options.showWarningsAsErrors;
7382
}
@@ -88,7 +97,7 @@ export class AndroidToolsInfo implements IAndroidToolsInfo {
8897
}
8998

9099
@cache()
91-
public validateAndroidHomeEnvVariable(options?: { showWarningsAsErrors: boolean }): boolean {
100+
public validateAndroidHomeEnvVariable(options?: IAndroidToolsInfoOptions): boolean {
92101
if (options) {
93102
this.showWarningsAsErrors = options.showWarningsAsErrors;
94103
}

lib/commands/build.ts

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ export class BuildCommandBase {
77
protected $platformsData: IPlatformsData,
88
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
99
protected $platformService: IPlatformService,
10-
private $bundleValidatorHelper: IBundleValidatorHelper,
11-
private $platformEnvironmentRequirements: IPlatformEnvironmentRequirements) {
10+
private $bundleValidatorHelper: IBundleValidatorHelper) {
1211
this.$projectData.initializeProjectData();
1312
}
1413

@@ -45,18 +44,16 @@ export class BuildCommandBase {
4544
}
4645
}
4746

48-
protected async canExecuteCore(platform: string): Promise<boolean> {
49-
const result = await this.$platformEnvironmentRequirements.checkEnvironmentRequirements({ platform: platform, cloudCommandName: "build" });
50-
this.validatePlatform(platform);
51-
return result;
52-
}
53-
54-
private validatePlatform(platform: string): void {
47+
protected async validatePlatform(platform: string): Promise<void> {
5548
if (!this.$platformService.isPlatformSupportedForOS(platform, this.$projectData)) {
5649
this.$errors.fail(`Applications for platform ${platform} can not be built on this OS`);
5750
}
5851

5952
this.$bundleValidatorHelper.validate();
53+
54+
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
55+
const platformProjectService = platformData.platformProjectService;
56+
await platformProjectService.validate(this.$projectData);
6057
}
6158
}
6259

@@ -69,17 +66,17 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
6966
$platformsData: IPlatformsData,
7067
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
7168
$platformService: IPlatformService,
72-
$bundleValidatorHelper: IBundleValidatorHelper,
73-
$platformEnvironmentRequirements: IPlatformEnvironmentRequirements) {
74-
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper, $platformEnvironmentRequirements);
69+
$bundleValidatorHelper: IBundleValidatorHelper) {
70+
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper);
7571
}
7672

7773
public async execute(args: string[]): Promise<void> {
7874
return this.executeCore([this.$platformsData.availablePlatforms.iOS]);
7975
}
8076

8177
public async canExecute(args: string[]): Promise<boolean> {
82-
return await super.canExecuteCore(this.$devicePlatformsConstants.iOS) && args.length === 0 && this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, this.$platformsData.availablePlatforms.iOS);
78+
await super.validatePlatform(this.$devicePlatformsConstants.iOS);
79+
return args.length === 0 && this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, this.$platformsData.availablePlatforms.iOS);
8380
}
8481
}
8582

@@ -94,26 +91,20 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
9491
$platformsData: IPlatformsData,
9592
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
9693
$platformService: IPlatformService,
97-
$bundleValidatorHelper: IBundleValidatorHelper,
98-
$platformEnvironmentRequirements: IPlatformEnvironmentRequirements) {
99-
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper, $platformEnvironmentRequirements);
94+
$bundleValidatorHelper: IBundleValidatorHelper) {
95+
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper);
10096
}
10197

10298
public async execute(args: string[]): Promise<void> {
10399
return this.executeCore([this.$platformsData.availablePlatforms.Android]);
104100
}
105101

106102
public async canExecute(args: string[]): Promise<boolean> {
107-
await super.canExecuteCore(this.$devicePlatformsConstants.Android);
108-
103+
await super.validatePlatform(this.$devicePlatformsConstants.Android);
109104
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
110105
this.$errors.fail(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
111106
}
112107

113-
const platformData = this.$platformsData.getPlatformData(this.$devicePlatformsConstants.Android, this.$projectData);
114-
const platformProjectService = platformData.platformProjectService;
115-
await platformProjectService.validate(this.$projectData);
116-
117108
return args.length === 0 && await this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, this.$platformsData.availablePlatforms.Android);
118109
}
119110
}

lib/commands/run.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@ export class RunCommandBase implements ICommand {
99
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
1010
private $errors: IErrors,
1111
private $hostInfo: IHostInfo,
12-
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
13-
private $platformEnvironmentRequirements: IPlatformEnvironmentRequirements) { }
12+
private $liveSyncCommandHelper: ILiveSyncCommandHelper) { }
1413

1514
public allowedParameters: ICommandParameter[] = [];
1615
public async execute(args: string[]): Promise<void> {
1716
return this.$liveSyncCommandHelper.executeCommandLiveSync(this.platform);
1817
}
1918

2019
public async canExecute(args: string[]): Promise<boolean> {
21-
await this.$platformEnvironmentRequirements.checkEnvironmentRequirements({platform: this.platform, cloudCommandName: "run"});
22-
2320
if (args.length) {
2421
this.$errors.fail(ERROR_NO_VALID_SUBCOMMAND_FORMAT, "run");
2522
}

lib/commands/setup.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ export class CloudSetupCommand implements ICommand {
1919
constructor(private $extensibilityService: IExtensibilityService) { }
2020

2121
public async execute(args: string[]): Promise<any> {
22-
return this.$extensibilityService.installExtension("nativescript-cloud");
22+
const installedExtensions = this.$extensibilityService.getInstalledExtensions();
23+
if (!installedExtensions["nativescript-cloud"]) {
24+
return this.$extensibilityService.installExtension("nativescript-cloud");
25+
}
2326
}
2427

2528
public async canExecute(args: string[]): Promise<boolean> {

lib/declarations.d.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,22 +547,28 @@ interface IAndroidToolsInfo {
547547
* @param {any} options Defines if the warning messages should treated as error and if the targetSdk value should be validated as well.
548548
* @return {boolean} True if there are detected issues, false otherwise.
549549
*/
550-
validateInfo(options?: { showWarningsAsErrors: boolean, validateTargetSdk: boolean }): boolean;
550+
validateInfo(options?: IAndroidToolsInfoValidateInput): boolean;
551551

552552
/**
553553
* Validates the information about required JAVA version.
554554
* @param {string} installedJavaVersion The JAVA version that will be checked.
555555
* @param {any} options Defines if the warning messages should treated as error.
556556
* @return {boolean} True if there are detected issues, false otherwise.
557557
*/
558-
validateJavacVersion(installedJavaVersion: string, options?: { showWarningsAsErrors: boolean }): boolean;
558+
validateJavacVersion(installedJavaVersion: string, options?: IAndroidToolsInfoOptions): boolean;
559559

560560
/**
561561
* Validates if ANDROID_HOME environment variable is set correctly.
562562
* @param {any} options Defines if the warning messages should treated as error.
563563
* @returns {boolean} true in case ANDROID_HOME is correctly set, false otherwise.
564564
*/
565-
validateAndroidHomeEnvVariable(options?: { showWarningsAsErrors: boolean }): boolean;
565+
validateAndroidHomeEnvVariable(options?: IAndroidToolsInfoOptions): boolean;
566+
567+
/**
568+
* Validates target sdk
569+
* @returns {boolean} True if there are detected issues, false otherwise
570+
*/
571+
validateTargetSdk(options?: IAndroidToolsInfoOptions): boolean;
566572

567573
/**
568574
* Gets the path to `adb` executable from ANDROID_HOME. It should be `$ANDROID_HOME/platform-tools/adb` in case it exists.
@@ -607,6 +613,23 @@ interface IAndroidToolsInfoData {
607613
generateTypings: boolean;
608614
}
609615

616+
/**
617+
* Describes options that can be passed to methods from IAndroidToolsInfo interface
618+
*/
619+
interface IAndroidToolsInfoOptions {
620+
/**
621+
* Defines if the warning messages should treated as error.
622+
*/
623+
showWarningsAsErrors: boolean;
624+
}
625+
626+
interface IAndroidToolsInfoValidateInput extends IAndroidToolsInfoOptions {
627+
/**
628+
* Defines if the targetSdk value should be validated.
629+
*/
630+
validateTargetSdk: boolean;
631+
}
632+
610633
interface ISocketProxyFactory extends NodeJS.EventEmitter {
611634
createTCPSocketProxy(factory: () => Promise<any>): Promise<any>;
612635
createWebSocketProxy(factory: () => Promise<any>, deviceIdentifier: string): Promise<any>;

lib/definitions/platform.d.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,5 @@ interface IUpdateAppOptions extends IOptionalFilesToSync, IOptionalFilesToRemove
367367
}
368368

369369
interface IPlatformEnvironmentRequirements {
370-
checkEnvironmentRequirements(input: ICheckEnvironmentRequirementsInput): Promise<boolean>;
371-
}
372-
373-
interface ICheckEnvironmentRequirementsInput {
374-
platform: string;
375-
cloudCommandName: string;
370+
checkEnvironmentRequirements(platform: string): Promise<boolean>;
376371
}

lib/services/android-project-service.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
3232
private $hostInfo: IHostInfo,
3333
private $logger: ILogger,
3434
$projectDataService: IProjectDataService,
35-
private $sysInfo: ISysInfo,
3635
private $injector: IInjector,
3736
private $pluginVariablesService: IPluginVariablesService,
3837
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
3938
private $npm: INodePackageManager,
40-
private $androidPluginBuildService: IAndroidPluginBuildService) {
39+
private $androidPluginBuildService: IAndroidPluginBuildService,
40+
private $platformEnvironmentRequirements: IPlatformEnvironmentRequirements) {
4141
super($fs, $projectDataService);
4242
this._androidProjectPropertiesManagers = Object.create(null);
4343
this.isAndroidStudioTemplate = false;
@@ -155,13 +155,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
155155
this.validatePackageName(projectData.projectId);
156156
this.validateProjectName(projectData.projectName);
157157

158-
this.$androidToolsInfo.validateAndroidHomeEnvVariable({ showWarningsAsErrors: true });
159-
160-
const javaCompilerVersion = (await this.$sysInfo.getSysInfo()).javacVersion;
161-
162-
this.$androidToolsInfo.validateJavacVersion(javaCompilerVersion, { showWarningsAsErrors: true });
163-
164-
await this.$androidToolsInfo.validateInfo({ showWarningsAsErrors: true, validateTargetSdk: true });
158+
await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(this.getPlatformData(projectData).normalizedPlatformName);
159+
this.$androidToolsInfo.validateTargetSdk({ showWarningsAsErrors: true });
165160
}
166161

167162
public async validatePlugins(): Promise<void> {

lib/services/ios-project-service.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
4949
private $pbxprojDomXcode: IPbxprojDomXcode,
5050
private $xcode: IXcode,
5151
private $iOSEntitlementsService: IOSEntitlementsService,
52+
private $platformEnvironmentRequirements: IPlatformEnvironmentRequirements,
5253
private $sysInfo: ISysInfo,
5354
private $xCConfigService: XCConfigService) {
54-
super($fs, $projectDataService);
55+
super($fs, $projectDataService);
5556
}
5657

5758
private _platformsDirCache: string = null;
@@ -130,16 +131,12 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
130131
return path.join(this.getPlatformData(projectData).projectRoot, projectData.projectName, "Resources");
131132
}
132133

133-
public async validate(): Promise<void> {
134+
public async validate(projectData: IProjectData): Promise<void> {
134135
if (!this.$hostInfo.isDarwin) {
135136
return;
136137
}
137138

138-
try {
139-
await this.$childProcess.exec("which xcodebuild");
140-
} catch (error) {
141-
this.$errors.fail("Xcode is not installed. Make sure you have Xcode installed and added to your PATH");
142-
}
139+
await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(this.getPlatformData(projectData).normalizedPlatformName);
143140

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

0 commit comments

Comments
 (0)