Skip to content

refactor: allow pass buildaction #3416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,12 @@ $injector.require("devicePathProvider", "./device-path-provider");

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

$injector.require("bundleValidatorHelper", "./helpers/bundle-validator-helper");
$injector.require("liveSyncCommandHelper", "./helpers/livesync-command-helper");
$injector.require("deployCommandHelper", "./helpers/deploy-command-helper");

$injector.requirePublicClass("localBuildService", "./services/local-build-service");
$injector.requirePublicClass("liveSyncService", "./services/livesync/livesync-service");
$injector.require("liveSyncCommandHelper", "./services/livesync/livesync-command-helper");
$injector.require("androidLiveSyncService", "./services/livesync/android-livesync-service");
$injector.require("iOSLiveSyncService", "./services/livesync/ios-livesync-service");
$injector.require("usbLiveSyncService", "./services/livesync/livesync-service"); // The name is used in https://github.com/NativeScript/nativescript-dev-typescript
Expand Down
19 changes: 10 additions & 9 deletions lib/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
import { BundleBase } from "./base-bundler";

export class BuildCommandBase extends BundleBase {
export class BuildCommandBase {
constructor(protected $options: IOptions,
protected $errors: IErrors,
protected $projectData: IProjectData,
protected $platformsData: IPlatformsData,
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
protected $platformService: IPlatformService) {
super($projectData, $errors, $options);
protected $platformService: IPlatformService,
private $bundleValidatorHelper: IBundleValidatorHelper) {
this.$projectData.initializeProjectData();
}

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

super.validateBundling();
this.$bundleValidatorHelper.validate();
}
}

Expand All @@ -62,8 +61,9 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
$projectData: IProjectData,
$platformsData: IPlatformsData,
$devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
$platformService: IPlatformService) {
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService);
$platformService: IPlatformService,
$bundleValidatorHelper: IBundleValidatorHelper) {
super($options, $errors, $projectData, $platformsData, $devicePlatformsConstants, $platformService, $bundleValidatorHelper);
}

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

public async execute(args: string[]): Promise<void> {
Expand Down
4 changes: 3 additions & 1 deletion lib/commands/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export class DebugPlatformCommand implements ICommand {
await this.$devicesService.detectCurrentlyAttachedDevices({ shouldReturnImmediateResult: false, platform: this.platform });

await this.$liveSyncCommandHelper.executeLiveSyncOperation([selectedDeviceForDebug], this.platform, {
[selectedDeviceForDebug.deviceInfo.identifier]: true
[selectedDeviceForDebug.deviceInfo.identifier]: true,
// This will default in the liveSyncCommandHelper
buildPlatform: undefined
});
}

Expand Down
31 changes: 5 additions & 26 deletions lib/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,22 @@ export class DeployOnDeviceCommand implements ICommand {
private $platformCommandParameter: ICommandParameter,
private $options: IOptions,
private $projectData: IProjectData,
private $deployCommandHelper: IDeployCommandHelper,
private $errors: IErrors,
private $mobileHelper: Mobile.IMobileHelper,
private $platformsData: IPlatformsData) {
private $platformsData: IPlatformsData,
private $bundleValidatorHelper: IBundleValidatorHelper) {
this.$projectData.initializeProjectData();
}

public async execute(args: string[]): Promise<void> {
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: !!this.$options.bundle, release: this.$options.release };
const deployOptions: IDeployPlatformOptions = {
clean: this.$options.clean,
device: this.$options.device,
projectDir: this.$options.path,
emulator: this.$options.emulator,
platformTemplate: this.$options.platformTemplate,
release: this.$options.release,
forceInstall: true,
provision: this.$options.provision,
teamId: this.$options.teamId,
keyStoreAlias: this.$options.keyStoreAlias,
keyStoreAliasPassword: this.$options.keyStoreAliasPassword,
keyStorePassword: this.$options.keyStorePassword,
keyStorePath: this.$options.keyStorePath
};

const deployPlatformInfo: IDeployPlatformInfo = {
platform: args[0],
appFilesUpdaterOptions,
deployOptions,
projectData: this.$projectData,
config: this.$options,
env: this.$options.env
};
const deployPlatformInfo = this.$deployCommandHelper.getDeployPlatformInfo(args[0]);

return this.$platformService.deployPlatform(deployPlatformInfo);
}

public async canExecute(args: string[]): Promise<boolean> {
this.$bundleValidatorHelper.validate();
if (!args || !args.length || args.length > 1) {
return false;
}
Expand Down
60 changes: 15 additions & 45 deletions lib/commands/run.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
import { ERROR_NO_VALID_SUBCOMMAND_FORMAT } from "../common/constants";
import { ANDROID_RELEASE_BUILD_ERROR_MESSAGE } from "../constants";
import { cache } from "../common/decorators";
import { BundleBase } from "./base-bundler";

export class RunCommandBase extends BundleBase implements ICommand {
export class RunCommandBase implements ICommand {

public platform: string;
constructor(protected $platformService: IPlatformService,
protected $projectData: IProjectData,
protected $options: IOptions,
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
protected $errors: IErrors,
protected $devicesService: Mobile.IDevicesService,
protected $platformsData: IPlatformsData,
constructor(private $projectData: IProjectData,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $errors: IErrors,
private $hostInfo: IHostInfo,
private $liveSyncCommandHelper: ILiveSyncCommandHelper
) {
super($projectData, $errors, $options);
}
private $liveSyncCommandHelper: ILiveSyncCommandHelper) { }

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

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

const availablePlatforms = this.$liveSyncCommandHelper.getPlatformsForOperation(this.platform);
for (const platform of availablePlatforms) {
const platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
const platformProjectService = platformData.platformProjectService;
await platformProjectService.validate(this.$projectData);
}

super.validateBundling();
this.$liveSyncCommandHelper.validatePlatform(this.platform);

return true;
}

public async executeCore(args: string[]): Promise<void> {
await this.$devicesService.initialize({
deviceId: this.$options.device,
platform: this.platform,
emulator: this.$options.emulator,
skipDeviceDetectionInterval: true,
skipInferPlatform: !this.platform
});

await this.$devicesService.detectCurrentlyAttachedDevices({ shouldReturnImmediateResult: false, platform: this.platform });
let devices = this.$devicesService.getDeviceInstances();
devices = devices.filter(d => !this.platform || d.deviceInfo.platform.toLowerCase() === this.platform.toLowerCase());
await this.$liveSyncCommandHelper.executeLiveSyncOperation(devices, this.platform);
}
}

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

constructor(protected $platformsData: IPlatformsData,
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
protected $errors: IErrors,
constructor(private $platformsData: IPlatformsData,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $errors: IErrors,
private $injector: IInjector,
private $platformService: IPlatformService,
private $projectData: IProjectData,
Expand All @@ -94,7 +64,7 @@ export class RunIosCommand implements ICommand {
this.$errors.fail(`Applications for platform ${this.$devicePlatformsConstants.iOS} can not be built on this OS`);
}

return this.runCommand.executeCore(args);
return this.runCommand.execute(args);
}

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

constructor(protected $platformsData: IPlatformsData,
protected $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
protected $errors: IErrors,
constructor(private $platformsData: IPlatformsData,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
private $errors: IErrors,
private $injector: IInjector,
private $platformService: IPlatformService,
private $projectData: IProjectData,
private $options: IOptions) {
}

public async execute(args: string[]): Promise<void> {
return this.runCommand.executeCore(args);
return this.runCommand.execute(args);
}

public async canExecute(args: string[]): Promise<boolean> {
Expand Down
23 changes: 23 additions & 0 deletions lib/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -739,3 +739,26 @@ interface IXcprojInfo {
*/
xcprojAvailable: boolean;
}

/**
* Describes helper used during execution of deploy commands.
*/
interface IDeployCommandHelper {
/**
* Retrieves data needed to execute deploy command.
* @param {string} platform platform to which to deploy - could be android or ios.
* @return {IDeployPlatformInfo} data needed to execute deploy command.
*/
getDeployPlatformInfo(platform: string): IDeployPlatformInfo;
}

/**
* Describes helper for validating bundling.
*/
interface IBundleValidatorHelper {
/**
* Validates bundling options.
* @return {void}
*/
validate(): void;
}
64 changes: 60 additions & 4 deletions lib/definitions/livesync.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,31 @@ interface IOptionalOutputPath {
outputPath?: string;
}

/**
* Describes action used whenever building a project.
*/
interface IBuildAction {
/**
* @returns {Promise<string>} Path to build artifact (.ipa, .apk or .zip).
*/
(): Promise<string>;
}

/**
* Describes options that can be passed in order to specify the exact location of the built package.
*/
interface IOutputDirectoryOptions extends IPlatform {
/**
* Directory where the project is located.
*/
projectDir: string;

/**
* Whether the build is for emulator or not.
*/
emulator?: boolean;
}

/**
* Describes information for LiveSync on a device.
*/
Expand All @@ -88,9 +113,8 @@ interface ILiveSyncDeviceInfo extends IOptionalOutputPath, IOptionalDebuggingOpt

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

/**
* Whether to skip preparing the native platform.
Expand Down Expand Up @@ -357,14 +381,46 @@ interface IDevicePathProvider {
getDeviceSyncZipPath(device: Mobile.IDevice): string;
}

/**
* Describes additional options, that can be passed to LiveSyncCommandHelper.
*/
interface ILiveSyncCommandHelperAdditionalOptions extends IBuildPlatformAction {
/**
* A map representing devices which have debugging enabled initially.
*/
deviceDebugMap?: IDictionary<boolean>;

/**
* Returns the path to the directory where the build output may be found.
* @param {IOutputDirectoryOptions} options Options that are used to determine the build output directory.
* @returns {string} The build output directory.
*/
getOutputDirectory?(options: IOutputDirectoryOptions): string;
}

interface ILiveSyncCommandHelper {
/**
* Method sets up configuration, before calling livesync and expects that devices are already discovered.
* @param {Mobile.IDevice[]} devices List of discovered devices
* @param {string} platform The platform for which the livesync will be ran
* @param {IDictionary<boolean>} deviceDebugMap @optional A map representing devices which have debugging enabled initially.
* @param {ILiveSyncCommandHelperAdditionalOptions} additionalOptions @optional Additional options to control LiveSync.
* @returns {Promise<void>}
*/
executeLiveSyncOperation(devices: Mobile.IDevice[], platform: string, deviceDebugMap?: IDictionary<boolean>): Promise<void>;
executeLiveSyncOperation(devices: Mobile.IDevice[], platform: string, additionalOptions?: ILiveSyncCommandHelperAdditionalOptions): Promise<void>;
getPlatformsForOperation(platform: string): string[];

/**
* Validates the given platform's data - bundle identifier, etc.
* @param {string} platform The platform to be validated.
* @return {Promise<void>}
*/
validatePlatform(platform: string): Promise<void>;

/**
* Executes livesync operation. Meant to be called from within a command.
* @param {string} platform @optional platform for whith to run the livesync operation
* @param {ILiveSyncCommandHelperAdditionalOptions} additionalOptions @optional Additional options to control LiveSync.
* @returns {Promise<void>}
*/
executeCommandLiveSync(platform?: string, additionalOptions?: ILiveSyncCommandHelperAdditionalOptions): Promise<void>;
}
Loading