Skip to content

Commit 069e69f

Browse files
Merge pull request #3416 from NativeScript/kerezov/cloud-deploy-run
refactor: allow pass buildaction
2 parents 360b9c9 + 4a6af32 commit 069e69f

File tree

13 files changed

+257
-133
lines changed

13 files changed

+257
-133
lines changed

lib/bootstrap.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,12 @@ $injector.require("devicePathProvider", "./device-path-provider");
107107

108108
$injector.requireCommand("platform|clean", "./commands/platform-clean");
109109

110+
$injector.require("bundleValidatorHelper", "./helpers/bundle-validator-helper");
111+
$injector.require("liveSyncCommandHelper", "./helpers/livesync-command-helper");
112+
$injector.require("deployCommandHelper", "./helpers/deploy-command-helper");
113+
110114
$injector.requirePublicClass("localBuildService", "./services/local-build-service");
111115
$injector.requirePublicClass("liveSyncService", "./services/livesync/livesync-service");
112-
$injector.require("liveSyncCommandHelper", "./services/livesync/livesync-command-helper");
113116
$injector.require("androidLiveSyncService", "./services/livesync/android-livesync-service");
114117
$injector.require("iOSLiveSyncService", "./services/livesync/ios-livesync-service");
115118
$injector.require("usbLiveSyncService", "./services/livesync/livesync-service"); // The name is used in https://github.com/NativeScript/nativescript-dev-typescript

lib/commands/build.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
2-
import { BundleBase } from "./base-bundler";
32

4-
export class BuildCommandBase extends BundleBase {
3+
export class BuildCommandBase {
54
constructor(protected $options: IOptions,
65
protected $errors: IErrors,
76
protected $projectData: IProjectData,
87
protected $platformsData: IPlatformsData,
98
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
10-
protected $platformService: IPlatformService) {
11-
super($projectData, $errors, $options);
9+
protected $platformService: IPlatformService,
10+
private $bundleValidatorHelper: IBundleValidatorHelper) {
1211
this.$projectData.initializeProjectData();
1312
}
1413

@@ -50,7 +49,7 @@ export class BuildCommandBase extends BundleBase {
5049
this.$errors.fail(`Applications for platform ${platform} can not be built on this OS`);
5150
}
5251

53-
super.validateBundling();
52+
this.$bundleValidatorHelper.validate();
5453
}
5554
}
5655

@@ -62,8 +61,9 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
6261
$projectData: IProjectData,
6362
$platformsData: IPlatformsData,
6463
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
65-
$platformService: IPlatformService) {
66-
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService);
64+
$platformService: IPlatformService,
65+
$bundleValidatorHelper: IBundleValidatorHelper) {
66+
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper);
6767
}
6868

6969
public async execute(args: string[]): Promise<void> {
@@ -86,8 +86,9 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
8686
$projectData: IProjectData,
8787
$platformsData: IPlatformsData,
8888
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
89-
$platformService: IPlatformService) {
90-
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService);
89+
$platformService: IPlatformService,
90+
$bundleValidatorHelper: IBundleValidatorHelper) {
91+
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper);
9192
}
9293

9394
public async execute(args: string[]): Promise<void> {

lib/commands/debug.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ export class DebugPlatformCommand implements ICommand {
3838
await this.$devicesService.detectCurrentlyAttachedDevices({ shouldReturnImmediateResult: false, platform: this.platform });
3939

4040
await this.$liveSyncCommandHelper.executeLiveSyncOperation([selectedDeviceForDebug], this.platform, {
41-
[selectedDeviceForDebug.deviceInfo.identifier]: true
41+
[selectedDeviceForDebug.deviceInfo.identifier]: true,
42+
// This will default in the liveSyncCommandHelper
43+
buildPlatform: undefined
4244
});
4345
}
4446

lib/commands/deploy.ts

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,22 @@ export class DeployOnDeviceCommand implements ICommand {
77
private $platformCommandParameter: ICommandParameter,
88
private $options: IOptions,
99
private $projectData: IProjectData,
10+
private $deployCommandHelper: IDeployCommandHelper,
1011
private $errors: IErrors,
1112
private $mobileHelper: Mobile.IMobileHelper,
12-
private $platformsData: IPlatformsData) {
13+
private $platformsData: IPlatformsData,
14+
private $bundleValidatorHelper: IBundleValidatorHelper) {
1315
this.$projectData.initializeProjectData();
1416
}
1517

1618
public async execute(args: string[]): Promise<void> {
17-
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
18-
const deployOptions: IDeployPlatformOptions = {
19-
clean: this.$options.clean,
20-
device: this.$options.device,
21-
projectDir: this.$options.path,
22-
emulator: this.$options.emulator,
23-
platformTemplate: this.$options.platformTemplate,
24-
release: this.$options.release,
25-
forceInstall: true,
26-
provision: this.$options.provision,
27-
teamId: this.$options.teamId,
28-
keyStoreAlias: this.$options.keyStoreAlias,
29-
keyStoreAliasPassword: this.$options.keyStoreAliasPassword,
30-
keyStorePassword: this.$options.keyStorePassword,
31-
keyStorePath: this.$options.keyStorePath
32-
};
33-
34-
const deployPlatformInfo: IDeployPlatformInfo = {
35-
platform: args[0],
36-
appFilesUpdaterOptions,
37-
deployOptions,
38-
projectData: this.$projectData,
39-
config: this.$options,
40-
env: this.$options.env
41-
};
19+
const deployPlatformInfo = this.$deployCommandHelper.getDeployPlatformInfo(args[0]);
4220

4321
return this.$platformService.deployPlatform(deployPlatformInfo);
4422
}
4523

4624
public async canExecute(args: string[]): Promise<boolean> {
25+
this.$bundleValidatorHelper.validate();
4726
if (!args || !args.length || args.length > 1) {
4827
return false;
4928
}

lib/commands/run.ts

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
import { ERROR_NO_VALID_SUBCOMMAND_FORMAT } from "../common/constants";
22
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
33
import { cache } from "../common/decorators";
4-
import { BundleBase } from "./base-bundler";
54

6-
export class RunCommandBase extends BundleBase implements ICommand {
5+
export class RunCommandBase implements ICommand {
76

87
public platform: string;
9-
constructor(protected $platformService: IPlatformService,
10-
protected $projectData: IProjectData,
11-
protected $options: IOptions,
12-
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
13-
protected $errors: IErrors,
14-
protected $devicesService: Mobile.IDevicesService,
15-
protected $platformsData: IPlatformsData,
8+
constructor(private $projectData: IProjectData,
9+
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
10+
private $errors: IErrors,
1611
private $hostInfo: IHostInfo,
17-
private $liveSyncCommandHelper: ILiveSyncCommandHelper
18-
) {
19-
super($projectData, $errors, $options);
20-
}
12+
private $liveSyncCommandHelper: ILiveSyncCommandHelper) { }
2113

2214
public allowedParameters: ICommandParameter[] = [];
2315
public async execute(args: string[]): Promise<void> {
24-
return this.executeCore(args);
16+
return this.$liveSyncCommandHelper.executeCommandLiveSync(this.platform);
2517
}
2618

2719
public async canExecute(args: string[]): Promise<boolean> {
@@ -36,32 +28,10 @@ export class RunCommandBase extends BundleBase implements ICommand {
3628
this.platform = this.$devicePlatformsConstants.Android;
3729
}
3830

39-
const availablePlatforms = this.$liveSyncCommandHelper.getPlatformsForOperation(this.platform);
40-
for (const platform of availablePlatforms) {
41-
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
42-
const platformProjectService = platformData.platformProjectService;
43-
await platformProjectService.validate(this.$projectData);
44-
}
45-
46-
super.validateBundling();
31+
this.$liveSyncCommandHelper.validatePlatform(this.platform);
4732

4833
return true;
4934
}
50-
51-
public async executeCore(args: string[]): Promise<void> {
52-
await this.$devicesService.initialize({
53-
deviceId: this.$options.device,
54-
platform: this.platform,
55-
emulator: this.$options.emulator,
56-
skipDeviceDetectionInterval: true,
57-
skipInferPlatform: !this.platform
58-
});
59-
60-
await this.$devicesService.detectCurrentlyAttachedDevices({ shouldReturnImmediateResult: false, platform: this.platform });
61-
let devices = this.$devicesService.getDeviceInstances();
62-
devices = devices.filter(d => !this.platform || d.deviceInfo.platform.toLowerCase() === this.platform.toLowerCase());
63-
await this.$liveSyncCommandHelper.executeLiveSyncOperation(devices, this.platform);
64-
}
6535
}
6636

6737
$injector.registerCommand("run|*all", RunCommandBase);
@@ -80,9 +50,9 @@ export class RunIosCommand implements ICommand {
8050
return this.$devicePlatformsConstants.iOS;
8151
}
8252

83-
constructor(protected $platformsData: IPlatformsData,
84-
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
85-
protected $errors: IErrors,
53+
constructor(private $platformsData: IPlatformsData,
54+
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
55+
private $errors: IErrors,
8656
private $injector: IInjector,
8757
private $platformService: IPlatformService,
8858
private $projectData: IProjectData,
@@ -94,7 +64,7 @@ export class RunIosCommand implements ICommand {
9464
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
9565
}
9666

97-
return this.runCommand.executeCore(args);
67+
return this.runCommand.execute(args);
9868
}
9969

10070
public async canExecute(args: string[]): Promise<boolean> {
@@ -118,17 +88,17 @@ export class RunAndroidCommand implements ICommand {
11888
return this.$devicePlatformsConstants.Android;
11989
}
12090

121-
constructor(protected $platformsData: IPlatformsData,
122-
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
123-
protected $errors: IErrors,
91+
constructor(private $platformsData: IPlatformsData,
92+
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
93+
private $errors: IErrors,
12494
private $injector: IInjector,
12595
private $platformService: IPlatformService,
12696
private $projectData: IProjectData,
12797
private $options: IOptions) {
12898
}
12999

130100
public async execute(args: string[]): Promise<void> {
131-
return this.runCommand.executeCore(args);
101+
return this.runCommand.execute(args);
132102
}
133103

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

lib/declarations.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,3 +739,26 @@ interface IXcprojInfo {
739739
*/
740740
xcprojAvailable: boolean;
741741
}
742+
743+
/**
744+
* Describes helper used during execution of deploy commands.
745+
*/
746+
interface IDeployCommandHelper {
747+
/**
748+
* Retrieves data needed to execute deploy command.
749+
* @param {string} platform platform to which to deploy - could be android or ios.
750+
* @return {IDeployPlatformInfo} data needed to execute deploy command.
751+
*/
752+
getDeployPlatformInfo(platform: string): IDeployPlatformInfo;
753+
}
754+
755+
/**
756+
* Describes helper for validating bundling.
757+
*/
758+
interface IBundleValidatorHelper {
759+
/**
760+
* Validates bundling options.
761+
* @return {void}
762+
*/
763+
validate(): void;
764+
}

lib/definitions/livesync.d.ts

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,31 @@ interface IOptionalOutputPath {
7777
outputPath?: string;
7878
}
7979

80+
/**
81+
* Describes action used whenever building a project.
82+
*/
83+
interface IBuildAction {
84+
/**
85+
* @returns {Promise<string>} Path to build artifact (.ipa, .apk or .zip).
86+
*/
87+
(): Promise<string>;
88+
}
89+
90+
/**
91+
* Describes options that can be passed in order to specify the exact location of the built package.
92+
*/
93+
interface IOutputDirectoryOptions extends IPlatform {
94+
/**
95+
* Directory where the project is located.
96+
*/
97+
projectDir: string;
98+
99+
/**
100+
* Whether the build is for emulator or not.
101+
*/
102+
emulator?: boolean;
103+
}
104+
80105
/**
81106
* Describes information for LiveSync on a device.
82107
*/
@@ -88,9 +113,8 @@ interface ILiveSyncDeviceInfo extends IOptionalOutputPath, IOptionalDebuggingOpt
88113

89114
/**
90115
* Action that will rebuild the application. The action must return a Promise, which is resolved with at path to build artifact.
91-
* @returns {Promise<string>} Path to build artifact (.ipa, .apk or .zip).
92116
*/
93-
buildAction: () => Promise<string>;
117+
buildAction: IBuildAction;
94118

95119
/**
96120
* Whether to skip preparing the native platform.
@@ -357,14 +381,46 @@ interface IDevicePathProvider {
357381
getDeviceSyncZipPath(device: Mobile.IDevice): string;
358382
}
359383

384+
/**
385+
* Describes additional options, that can be passed to LiveSyncCommandHelper.
386+
*/
387+
interface ILiveSyncCommandHelperAdditionalOptions extends IBuildPlatformAction {
388+
/**
389+
* A map representing devices which have debugging enabled initially.
390+
*/
391+
deviceDebugMap?: IDictionary<boolean>;
392+
393+
/**
394+
* Returns the path to the directory where the build output may be found.
395+
* @param {IOutputDirectoryOptions} options Options that are used to determine the build output directory.
396+
* @returns {string} The build output directory.
397+
*/
398+
getOutputDirectory?(options: IOutputDirectoryOptions): string;
399+
}
400+
360401
interface ILiveSyncCommandHelper {
361402
/**
362403
* Method sets up configuration, before calling livesync and expects that devices are already discovered.
363404
* @param {Mobile.IDevice[]} devices List of discovered devices
364405
* @param {string} platform The platform for which the livesync will be ran
365-
* @param {IDictionary<boolean>} deviceDebugMap @optional A map representing devices which have debugging enabled initially.
406+
* @param {ILiveSyncCommandHelperAdditionalOptions} additionalOptions @optional Additional options to control LiveSync.
366407
* @returns {Promise<void>}
367408
*/
368-
executeLiveSyncOperation(devices: Mobile.IDevice[], platform: string, deviceDebugMap?: IDictionary<boolean>): Promise<void>;
409+
executeLiveSyncOperation(devices: Mobile.IDevice[], platform: string, additionalOptions?: ILiveSyncCommandHelperAdditionalOptions): Promise<void>;
369410
getPlatformsForOperation(platform: string): string[];
411+
412+
/**
413+
* Validates the given platform's data - bundle identifier, etc.
414+
* @param {string} platform The platform to be validated.
415+
* @return {Promise<void>}
416+
*/
417+
validatePlatform(platform: string): Promise<void>;
418+
419+
/**
420+
* Executes livesync operation. Meant to be called from within a command.
421+
* @param {string} platform @optional platform for whith to run the livesync operation
422+
* @param {ILiveSyncCommandHelperAdditionalOptions} additionalOptions @optional Additional options to control LiveSync.
423+
* @returns {Promise<void>}
424+
*/
425+
executeCommandLiveSync(platform?: string, additionalOptions?: ILiveSyncCommandHelperAdditionalOptions): Promise<void>;
370426
}

0 commit comments

Comments
 (0)