Skip to content

Commit ba7cac4

Browse files
committed
chore: fix comments
1 parent d5432f7 commit ba7cac4

10 files changed

+56
-36
lines changed

lib/commands/build.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
1+
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE, AndroidAppBundleMessages } from "../constants";
22
import { ValidatePlatformCommandBase } from "./command-base";
33

44
export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
@@ -8,7 +8,8 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
88
$platformsData: IPlatformsData,
99
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
1010
$platformService: IPlatformService,
11-
private $bundleValidatorHelper: IBundleValidatorHelper) {
11+
private $bundleValidatorHelper: IBundleValidatorHelper,
12+
protected $logger: ILogger) {
1213
super($options, $platformsData, $platformService, $projectData);
1314
this.$projectData.initializeProjectData();
1415
}
@@ -44,9 +45,13 @@ export abstract class BuildCommandBase extends ValidatePlatformCommandBase {
4445
keyStorePassword: this.$options.keyStorePassword,
4546
androidBundle: this.$options.aab
4647
};
48+
4749
const outputPath = await this.$platformService.buildPlatform(platform, buildConfig, this.$projectData);
50+
4851
if (this.$options.copyTo) {
4952
this.$platformService.copyLastOutput(platform, this.$options.copyTo, buildConfig, this.$projectData);
53+
} else {
54+
this.$logger.info(`Your build result is located at: ${outputPath}`);
5055
}
5156

5257
return outputPath;
@@ -87,8 +92,9 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
8792
$platformsData: IPlatformsData,
8893
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
8994
$platformService: IPlatformService,
90-
$bundleValidatorHelper: IBundleValidatorHelper) {
91-
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper);
95+
$bundleValidatorHelper: IBundleValidatorHelper,
96+
$logger: ILogger) {
97+
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper, $logger);
9298
}
9399

94100
public async execute(args: string[]): Promise<void> {
@@ -123,15 +129,18 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
123129
$bundleValidatorHelper: IBundleValidatorHelper,
124130
protected $androidBundleValidatorHelper: IAndroidBundleValidatorHelper,
125131
protected $logger: ILogger) {
126-
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper);
132+
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper, $logger);
127133
}
128134

129135
public async execute(args: string[]): Promise<void> {
130-
const buildResult = await this.executeCore([this.$platformsData.availablePlatforms.Android]);
136+
await this.executeCore([this.$platformsData.availablePlatforms.Android]);
131137

132138
if (this.$options.aab) {
133-
this.$logger.info(`Your .aab file is located at: ${buildResult}`);
134-
this.$logger.info("Link to documentation article");
139+
this.$logger.info(AndroidAppBundleMessages.ANDROID_APP_BUNDLE_DOCS_MESSAGE);
140+
141+
if (this.$options.release) {
142+
this.$logger.info(AndroidAppBundleMessages.ANDROID_APP_BUNDLE_PUBLISH_DOCS_MESSAGE);
143+
}
135144
}
136145
}
137146

lib/constants.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ export class BundleValidatorMessages {
245245
}
246246

247247
export class AndroidBundleValidatorMessages {
248-
public static AAB_NOT_SUPPORTED_BY_COMMNAND_MESSAGE = "This command does not support --aab (Android Application Bundle) parameter.";
249-
public static RUNTIME_VERSION_TOO_LOW = "Android Application Bundle (--aab) option requires NativeScript Android Runtime (tns-android) version %s and above.";
248+
public static AAB_NOT_SUPPORTED_BY_COMMNAND_MESSAGE = "This command does not support --aab (Android App Bundle) parameter.";
249+
public static NOT_SUPPORTED_RUNTIME_VERSION = "Android App Bundle (--aab) option requires NativeScript Android Runtime (tns-android) version %s and above.";
250+
}
251+
252+
export class AndroidAppBundleMessages {
253+
public static ANDROID_APP_BUNDLE_DOCS_MESSAGE = "What is Android App Bundle: https://docs.nativescript.org/tooling/publishing/android-app-bundle";
254+
public static ANDROID_APP_BUNDLE_PUBLISH_DOCS_MESSAGE = "How to use Android App Bundle for publishing: https://docs.nativescript.org/tooling/publishing/publishing-android-apps#android-app-bundle";
250255
}

lib/declarations.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,9 @@ interface IEnvOptions {
535535
env: Object;
536536
}
537537

538-
interface IAndroidBuildOptionsSettings extends IAndroidReleaseOptions, IRelease, IAndroidBundle { }
538+
interface IAndroidBuildOptionsSettings extends IAndroidReleaseOptions, IRelease, IHasAndroidBundle { }
539539

540-
interface IAndroidBundle {
540+
interface IHasAndroidBundle {
541541
androidBundle?: boolean;
542542
}
543543

lib/definitions/platform.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ interface IValidBuildOutputData {
286286
regexes?: RegExp[];
287287
}
288288

289-
interface IBuildOutputOptions extends Partial<IBuildForDevice>, IRelease, IAndroidBundle {}
289+
interface IBuildOutputOptions extends Partial<IBuildForDevice>, IRelease, IHasAndroidBundle {}
290290

291291
interface IPlatformsData {
292292
availablePlatforms: any;

lib/helpers/android-bundle-validator-helper.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import * as semver from "semver";
22
import * as util from "util";
33
import { AndroidBundleValidatorMessages, TNS_ANDROID_RUNTIME_NAME } from "../constants";
4+
import { VersionValidatorHelper } from "./version-validator-helper";
45

5-
export class AndroidBundleValidatorHelper implements IAndroidBundleValidatorHelper {
6+
export class AndroidBundleValidatorHelper extends VersionValidatorHelper implements IAndroidBundleValidatorHelper {
67
public static MIN_RUNTIME_VERSION = "5.0.0";
78

89
constructor(protected $projectData: IProjectData,
910
protected $errors: IErrors,
1011
protected $options: IOptions,
1112
protected $projectDataService: IProjectDataService) {
13+
super();
1214
}
1315

1416
public validateNoAab(): void {
@@ -22,14 +24,10 @@ export class AndroidBundleValidatorHelper implements IAndroidBundleValidatorHelp
2224
const androidRuntimeInfo = this.$projectDataService.getNSValue(projectData.projectDir, TNS_ANDROID_RUNTIME_NAME);
2325
const androidRuntimeVersion = androidRuntimeInfo ? androidRuntimeInfo.version : "";
2426

25-
if (androidRuntimeVersion) {
26-
const shouldSkipCheck = !semver.valid(androidRuntimeVersion) && !semver.validRange(androidRuntimeVersion);
27-
if (!shouldSkipCheck) {
28-
const isAndroidBundleSupported = semver.gte(semver.coerce(androidRuntimeVersion), semver.coerce(AndroidBundleValidatorHelper.MIN_RUNTIME_VERSION));
29-
if (!isAndroidBundleSupported) {
30-
this.$errors.failWithoutHelp(util.format(AndroidBundleValidatorMessages.RUNTIME_VERSION_TOO_LOW, AndroidBundleValidatorHelper.MIN_RUNTIME_VERSION));
31-
}
32-
}
27+
if (androidRuntimeVersion &&
28+
this.isValidVersion(androidRuntimeVersion) &&
29+
!this.compareCoerceVersions(androidRuntimeVersion, AndroidBundleValidatorHelper.MIN_RUNTIME_VERSION, semver.gte)) {
30+
this.$errors.failWithoutHelp(util.format(AndroidBundleValidatorMessages.NOT_SUPPORTED_RUNTIME_VERSION, AndroidBundleValidatorHelper.MIN_RUNTIME_VERSION));
3331
}
3432
}
3533
}

lib/helpers/bundle-validator-helper.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import * as semver from "semver";
22
import * as util from "util";
33
import { BundleValidatorMessages } from "../constants";
4+
import { VersionValidatorHelper } from "./version-validator-helper";
45

5-
export class BundleValidatorHelper implements IBundleValidatorHelper {
6+
export class BundleValidatorHelper extends VersionValidatorHelper implements IBundleValidatorHelper {
67
private bundlersMap: IStringDictionary = {
78
webpack: "nativescript-dev-webpack"
89
};
910

1011
constructor(protected $projectData: IProjectData,
1112
protected $errors: IErrors,
1213
protected $options: IOptions) {
14+
super();
1315
this.$projectData.initializeProjectData();
1416
}
1517

@@ -22,15 +24,9 @@ export class BundleValidatorHelper implements IBundleValidatorHelper {
2224
this.$errors.fail(BundleValidatorMessages.MissingBundlePlugin);
2325
}
2426

25-
if (minSupportedVersion) {
26-
const currentVersion = bundlerVersionInDependencies || bundlerVersionInDevDependencies;
27-
const shouldSkipCheck = !semver.valid(currentVersion) && !semver.validRange(currentVersion);
28-
if (!shouldSkipCheck) {
29-
const isBundleSupported = semver.gte(semver.coerce(currentVersion), semver.coerce(minSupportedVersion));
30-
if (!isBundleSupported) {
31-
this.$errors.failWithoutHelp(util.format(BundleValidatorMessages.NotSupportedVersion, minSupportedVersion));
32-
}
33-
}
27+
const currentVersion = bundlerVersionInDependencies || bundlerVersionInDevDependencies;
28+
if (minSupportedVersion && this.isValidVersion(currentVersion) && !this.compareCoerceVersions(currentVersion, minSupportedVersion, semver.gte)) {
29+
this.$errors.failWithoutHelp(util.format(BundleValidatorMessages.NotSupportedVersion, minSupportedVersion));
3430
}
3531
}
3632
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
import * as semver from "semver";
3+
4+
export class VersionValidatorHelper {
5+
protected isValidVersion(version: string): string {
6+
return semver.valid(version) || semver.validRange(version);
7+
}
8+
9+
protected compareCoerceVersions(version: string, minVersion: string, comperator: Function): boolean {
10+
return comperator(semver.coerce(version), semver.coerce(minVersion));
11+
}
12+
}

lib/services/android-project-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,9 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
336336
gradleArgs.unshift("--debug");
337337
}
338338
if (buildConfig.release) {
339-
task = baseTask + "Release";
339+
task = `${baseTask}Release`;
340340
} else {
341-
task = baseTask + "Debug";
341+
task = `${baseTask}Debug`;
342342
}
343343

344344
gradleArgs.unshift(task);

lib/services/platform-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export class PlatformService extends EventEmitter implements IPlatformService {
257257
}
258258

259259
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) {
260+
if (platform && !this.$mobileHelper.isAndroidPlatform(platform) && aab) {
261261
this.$errors.failWithoutHelp("Option --aab is supported for Android platform only.");
262262
}
263263

test/services/android-project-service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const getDefautlBuildConfig = (): IBuildConfig => {
5151
};
5252
};
5353

54-
describe.only("androidDebugService", () => {
54+
describe("androidDebugService", () => {
5555
let injector: IInjector;
5656
let androidProjectService: IPlatformProjectService;
5757
let sandbox: sinon.SinonSandbox = null;

0 commit comments

Comments
 (0)