Skip to content

Commit dac46b7

Browse files
committed
feat: add validations for --aab command
1 parent 58d57fd commit dac46b7

9 files changed

+58
-11
lines changed

lib/bootstrap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ $injector.require("devicePathProvider", "./device-path-provider");
125125
$injector.requireCommand("platform|clean", "./commands/platform-clean");
126126

127127
$injector.require("bundleValidatorHelper", "./helpers/bundle-validator-helper");
128+
$injector.require("androidBundleValidatorHelper", "./helpers/android-bundle-validator-helper");
128129
$injector.require("liveSyncCommandHelper", "./helpers/livesync-command-helper");
129130
$injector.require("deployCommandHelper", "./helpers/deploy-command-helper");
130131

lib/commands/build.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,19 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
118118
$platformsData: IPlatformsData,
119119
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
120120
$platformService: IPlatformService,
121-
$bundleValidatorHelper: IBundleValidatorHelper) {
121+
$bundleValidatorHelper: IBundleValidatorHelper,
122+
protected $logger: ILogger) {
122123
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper);
123124
}
124125

125126
public async execute(args: string[]): Promise<void> {
126-
return this.executeCore([this.$platformsData.availablePlatforms.Android]);
127+
const buildResult = await this.executeCore([this.$platformsData.availablePlatforms.Android]);
128+
129+
if(this.$options.aab) {
130+
this.$logger.info("Link to documentation article");
131+
}
132+
133+
return buildResult
127134
}
128135

129136
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {

lib/commands/debug.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
1919
private $debugDataService: IDebugDataService,
2020
private $liveSyncService: IDebugLiveSyncService,
2121
private $prompter: IPrompter,
22-
private $liveSyncCommandHelper: ILiveSyncCommandHelper) {
22+
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
23+
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) {
2324
super($options, $platformsData, $platformService, $projectData);
2425
}
2526

@@ -108,6 +109,8 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements
108109
}
109110

110111
public async canExecute(args: string[]): Promise<ICanExecuteCommandOutput> {
112+
this.$androidBundleValidatorHelper.validateNoAab();
113+
111114
if (!this.$platformService.isPlatformSupportedForOS(this.platform, this.$projectData)) {
112115
this.$errors.fail(`Applications for platform ${this.platform} can not be built on this OS`);
113116
}

lib/commands/deploy.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implement
1212
private $errors: IErrors,
1313
private $mobileHelper: Mobile.IMobileHelper,
1414
$platformsData: IPlatformsData,
15-
private $bundleValidatorHelper: IBundleValidatorHelper) {
15+
private $bundleValidatorHelper: IBundleValidatorHelper,
16+
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) {
1617
super($options, $platformsData, $platformService, $projectData);
1718
this.$projectData.initializeProjectData();
1819
}
@@ -24,6 +25,7 @@ export class DeployOnDeviceCommand extends ValidatePlatformCommandBase implement
2425
}
2526

2627
public async canExecute(args: string[]): Promise<boolean | ICanExecuteCommandOutput> {
28+
this.$androidBundleValidatorHelper.validateNoAab();
2729
this.$bundleValidatorHelper.validate();
2830
if (!args || !args.length || args.length > 1) {
2931
return false;

lib/commands/run.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export class RunCommandBase implements ICommand {
1010
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
1111
private $errors: IErrors,
1212
private $hostInfo: IHostInfo,
13-
private $liveSyncCommandHelper: ILiveSyncCommandHelper) { }
13+
private $liveSyncCommandHelper: ILiveSyncCommandHelper,
14+
private $androidBundleValidatorHelper: IAndroidBundleValidatorHelper) { }
1415

1516
public allowedParameters: ICommandParameter[] = [];
1617
public async execute(args: string[]): Promise<void> {
@@ -22,6 +23,8 @@ export class RunCommandBase implements ICommand {
2223
this.$errors.fail(ERROR_NO_VALID_SUBCOMMAND_FORMAT, "run");
2324
}
2425

26+
this.$androidBundleValidatorHelper.validateNoAab();
27+
2528
this.$projectData.initializeProjectData();
2629
this.platform = args[0] || this.platform;
2730

@@ -35,7 +38,6 @@ export class RunCommandBase implements ICommand {
3538
const checkEnvironmentRequirementsOutput = validatePlatformOutput[this.platform.toLowerCase()].checkEnvironmentRequirementsOutput;
3639
this.liveSyncCommandHelperAdditionalOptions.syncToPreviewApp = checkEnvironmentRequirementsOutput && checkEnvironmentRequirementsOutput.selectedOption === "Sync to Playground";
3740
}
38-
3941
return true;
4042
}
4143
}
@@ -66,14 +68,14 @@ export class RunIosCommand implements ICommand {
6668
}
6769

6870
public async execute(args: string[]): Promise<void> {
69-
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
70-
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
71-
}
72-
7371
return this.runCommand.execute(args);
7472
}
7573

7674
public async canExecute(args: string[]): Promise<boolean> {
75+
if (!this.$platformService.isPlatformSupportedForOS(this.$devicePlatformsConstants.iOS, this.$projectData)) {
76+
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
77+
}
78+
7779
const result = await this.runCommand.canExecute(args) && await this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, this.$platformsData.availablePlatforms.iOS);
7880
return result;
7981
}

lib/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,5 @@ export class BundleValidatorMessages {
243243
public static MissingBundlePlugin = "Passing --bundle requires a bundling plugin. No bundling plugin found or the specified bundling plugin is invalid.";
244244
public static NotSupportedVersion = `The NativeScript CLI requires nativescript-dev-webpack %s or later to work properly. After updating nativescript-dev-webpack you need to ensure "webpack.config.js" file is up to date with the one in the new version of nativescript-dev-webpack. You can automatically update it using "./node_modules/.bin/update-ns-webpack --configs" command.`;
245245
}
246+
247+
export const AAB_NOT_SUPPORTED_BY_COMMNAND_MESSAGE = "This command does not support --aab (Android Application Bundle) parameter.";

lib/declarations.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,16 @@ interface IBundleValidatorHelper {
864864
validate(minSupportedVersion?: string): void;
865865
}
866866

867+
868+
interface IAndroidBundleValidatorHelper {
869+
/**
870+
* Validates android bundling option is not provided.
871+
* Commands that require deploy of the application must not be called with --aab option
872+
* @return {void}
873+
*/
874+
validateNoAab(): void;
875+
}
876+
867877
interface INativeScriptCloudExtensionService {
868878
/**
869879
* Installs nativescript-cloud extension
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { AAB_NOT_SUPPORTED_BY_COMMNAND_MESSAGE } from "../constants";
2+
3+
export class AndroidBundleValidatorHelper implements IAndroidBundleValidatorHelper {
4+
constructor(protected $projectData: IProjectData,
5+
protected $errors: IErrors,
6+
protected $options: IOptions) {
7+
}
8+
9+
public validateNoAab(minSupportedVersion?: string): void {
10+
if(this.$options.aab) {
11+
this.$errors.fail(AAB_NOT_SUPPORTED_BY_COMMNAND_MESSAGE);
12+
}
13+
}
14+
}
15+
16+
$injector.register("androidBundleValidatorHelper", AndroidBundleValidatorHelper);

lib/services/platform-service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,11 @@ export class PlatformService extends EventEmitter implements IPlatformService {
256256
return true;
257257
}
258258

259-
public async validateOptions(provision: true | string, teamId: true | string, projectData: IProjectData, platform?: string): Promise<boolean> {
259+
public async validateOptions(provision: true | string, teamId: true | string, projectData: IProjectData, platform?: string, aab?: boolean): Promise<boolean> {
260+
if (platform && this.$mobileHelper.isiOSPlatform(platform) && aab) {
261+
this.$errors.failWithoutHelp("Option --aab is supported for Android platform only.");
262+
}
263+
260264
if (platform) {
261265
platform = this.$mobileHelper.normalizePlatformName(platform);
262266
this.$logger.trace("Validate options for platform: " + platform);

0 commit comments

Comments
 (0)