Skip to content

Commit 63ef7ef

Browse files
Introduce interface for localBuildService (#3128)
1 parent a5dd35b commit 63ef7ef

File tree

10 files changed

+33
-9
lines changed

10 files changed

+33
-9
lines changed

lib/bootstrap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ $injector.require("devicePathProvider", "./device-path-provider");
105105

106106
$injector.requireCommand("platform|clean", "./commands/platform-clean");
107107

108+
$injector.requirePublicClass("localBuildService", "./services/local-build-service");
108109
$injector.requirePublicClass("liveSyncService", "./services/livesync/livesync-service");
109110
$injector.require("liveSyncCommandHelper", "./services/livesync/livesync-command-helper");
110111
$injector.require("androidLiveSyncService", "./services/livesync/android-livesync-service");

lib/commands/build.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
2+
13
export class BuildCommandBase {
24
constructor(protected $options: IOptions,
35
protected $errors: IErrors,
@@ -82,7 +84,7 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
8284
public async canExecute(args: string[]): Promise<boolean> {
8385
super.validatePlatform(this.$devicePlatformsConstants.Android);
8486
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
85-
this.$errors.fail("When producing a release build, you need to specify all --key-store-* options.");
87+
this.$errors.fail(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
8688
}
8789

8890
const platformData = this.$platformsData.getPlatformData(this.$devicePlatformsConstants.Android, this.$projectData);

lib/commands/deploy.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
2+
13
export class DeployOnDeviceCommand implements ICommand {
24
public allowedParameters: ICommandParameter[] = [];
35

@@ -41,7 +43,7 @@ export class DeployOnDeviceCommand implements ICommand {
4143
}
4244

4345
if (this.$mobileHelper.isAndroidPlatform(args[0]) && this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
44-
this.$errors.fail("When producing a release build, you need to specify all --key-store-* options.");
46+
this.$errors.fail(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
4547
}
4648

4749
const platformData = this.$platformsData.getPlatformData(args[0], this.$projectData);

lib/commands/run.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ERROR_NO_VALID_SUBCOMMAND_FORMAT } from "../common/constants";
2+
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
23
import { cache } from "../common/decorators";
34

45
export class RunCommandBase implements ICommand {
@@ -137,7 +138,7 @@ export class RunAndroidCommand implements ICommand {
137138
}
138139

139140
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
140-
this.$errors.fail("When producing a release build, you need to specify all --key-store-* options.");
141+
this.$errors.fail(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
141142
}
142143
return this.$platformService.validateOptions(this.$options.provision, this.$options.teamId, this.$projectData, this.$platformsData.availablePlatforms.Android);
143144
}

lib/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export const DEBUGGER_DETACHED_EVENT_NAME = "debuggerDetached";
9191
export const VERSION_STRING = "version";
9292
export const INSPECTOR_CACHE_DIRNAME = "ios-inspector";
9393
export const POST_INSTALL_COMMAND_NAME = "post-install-cli";
94+
export const ANDROID_RELEASE_BUILD_ERROR_MESSAGE = "When producing a release build, you need to specify all --key-store-* options.";
9495

9596
export class DebugCommandErrors {
9697
public static UNABLE_TO_USE_FOR_DEVICE_AND_EMULATOR = "The options --for-device and --emulator cannot be used simultaneously. Please use only one of them.";

lib/definitions/project.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,20 @@ interface IiOSBuildConfig extends IBuildForDevice, IDeviceIdentifier, IProvision
155155
codeSignIdentity?: string;
156156
}
157157

158+
/**
159+
* Describes service used for building a project locally.
160+
*/
161+
interface ILocalBuildService {
162+
/**
163+
* Builds a project locally.
164+
* @param {string} platform Platform for which to build.
165+
* @param {IPlatformBuildData} platformBuildOptions Additional options for controlling the build.
166+
* @param {string} platformTemplate The name of the template.
167+
* @return {Promise<string>} Path to the build output.
168+
*/
169+
build(platform: string, platformBuildOptions: IPlatformBuildData, platformTemplate?: string): Promise<string>;
170+
}
171+
158172
interface IPlatformProjectService extends NodeJS.EventEmitter {
159173
getPlatformData(projectData: IProjectData): IPlatformData;
160174
validate(projectData: IProjectData): Promise<void>;

lib/nativescript-cli-lib-bootstrap.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ $injector.overrideAlreadyRequiredModule = true;
88
$injector.requirePublic("companionAppsService", "./common/appbuilder/services/livesync/companion-apps-service");
99
$injector.requirePublicClass("deviceEmitter", "./common/appbuilder/device-emitter");
1010
$injector.requirePublicClass("deviceLogProvider", "./common/appbuilder/device-log-provider");
11-
$injector.requirePublicClass("localBuildService", "./services/local-build-service");
1211

1312
// We need this because some services check if (!$options.justlaunch) to start the device log after some operation.
1413
// We don't want this behaviour when the CLI is required as library.

lib/options.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import * as commonOptionsLibPath from "./common/options";
22
import * as osenv from "osenv";
33
import * as path from "path";
44

5-
const OptionType = commonOptionsLibPath.OptionType;
6-
75
export class Options extends commonOptionsLibPath.OptionsBase {
86
constructor($errors: IErrors,
97
$staticConfig: IStaticConfig,

lib/services/local-build-service.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import { EventEmitter } from "events";
2-
import { BUILD_OUTPUT_EVENT_NAME } from "../constants";
2+
import { BUILD_OUTPUT_EVENT_NAME, ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
33
import { attachAwaitDetach } from "../common/helpers";
44

5-
export class LocalBuildService extends EventEmitter {
5+
export class LocalBuildService extends EventEmitter implements ILocalBuildService {
66
constructor(private $projectData: IProjectData,
7+
private $mobileHelper: Mobile.IMobileHelper,
8+
private $errors: IErrors,
79
private $platformService: IPlatformService) {
810
super();
911
}
1012

1113
public async build(platform: string, platformBuildOptions: IPlatformBuildData, platformTemplate?: string): Promise<string> {
14+
if (this.$mobileHelper.isAndroidPlatform(platform) && platformBuildOptions.release && (!platformBuildOptions.keyStorePath || !platformBuildOptions.keyStorePassword || !platformBuildOptions.keyStoreAlias || !platformBuildOptions.keyStoreAliasPassword)) {
15+
this.$errors.fail(ANDROID_RELEASE_BUILD_ERROR_MESSAGE);
16+
}
17+
1218
this.$projectData.initializeProjectData(platformBuildOptions.projectDir);
1319
await this.$platformService.preparePlatform(platform, platformBuildOptions, platformTemplate, this.$projectData, {
1420
provision: platformBuildOptions.provision,

0 commit comments

Comments
 (0)