Skip to content

Allow local builds when {N} CLI is required as a library #2574

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 5 commits into from
Mar 3, 2017
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
12 changes: 8 additions & 4 deletions lib/commands/add-platform.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
export class AddPlatformCommand implements ICommand {
public allowedParameters: ICommandParameter[] = [];

constructor(private $platformService: IPlatformService,
private $errors: IErrors) { }
constructor(private $options: IOptions,
private $platformService: IPlatformService,
private $projectData: IProjectData,
private $errors: IErrors) {
this.$projectData.initializeProjectData();
}

public async execute(args: string[]): Promise<void> {
await this.$platformService.addPlatforms(args);
await this.$platformService.addPlatforms(args, this.$options.platformTemplate, this.$projectData);
}

public async canExecute(args: string[]): Promise<boolean> {
if (!args || args.length === 0) {
this.$errors.fail("No platform specified. Please specify a platform to add");
}

_.each(args, arg => this.$platformService.validatePlatform(arg));
_.each(args, arg => this.$platformService.validatePlatform(arg, this.$projectData));

return true;
}
Expand Down
25 changes: 17 additions & 8 deletions lib/commands/appstore-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ export class PublishIOS implements ICommand {
private $injector: IInjector,
private $itmsTransporterService: IITMSTransporterService,
private $logger: ILogger,
private $projectData: IProjectData,
private $options: IOptions,
private $prompter: IPrompter,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants) { }
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants) {
this.$projectData.initializeProjectData();
}

private get $platformsData(): IPlatformsData {
return this.$injector.resolve("platformsData");
Expand Down Expand Up @@ -54,28 +57,34 @@ export class PublishIOS implements ICommand {
if (!ipaFilePath) {
let platform = this.$devicePlatformsConstants.iOS;
// No .ipa path provided, build .ipa on out own.
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
if (mobileProvisionIdentifier || codeSignIdentity) {
let iOSBuildConfig: IiOSBuildConfig = {
projectDir: this.$options.path,
release: this.$options.release,
device: this.$options.device,
provision: this.$options.provision,
teamId: this.$options.teamId,
buildForDevice: true,
mobileProvisionIdentifier,
codeSignIdentity
};
this.$logger.info("Building .ipa with the selected mobile provision and/or certificate.");
// This is not very correct as if we build multiple targets we will try to sign all of them using the signing identity here.
await this.$platformService.preparePlatform(platform);
await this.$platformService.buildPlatform(platform, iOSBuildConfig);
ipaFilePath = this.$platformService.lastOutputPath(platform, { isForDevice: iOSBuildConfig.buildForDevice });
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, this.$options.provision);
await this.$platformService.buildPlatform(platform, iOSBuildConfig, this.$projectData);
ipaFilePath = this.$platformService.lastOutputPath(platform, { isForDevice: iOSBuildConfig.buildForDevice }, this.$projectData);
} else {
this.$logger.info("No .ipa, mobile provision or certificate set. Perfect! Now we'll build .xcarchive and let Xcode pick the distribution certificate and provisioning profile for you when exporting .ipa for AppStore submission.");
await this.$platformService.preparePlatform(platform);
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, this.$options.provision);

let platformData = this.$platformsData.getPlatformData(platform);
let platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
let iOSProjectService = <IOSProjectService>platformData.platformProjectService;

let archivePath = await iOSProjectService.archive(platformData.projectRoot);
let archivePath = await iOSProjectService.archive(this.$projectData);
this.$logger.info("Archive at: " + archivePath);

let exportPath = await iOSProjectService.exportArchive({ archivePath, teamID });
let exportPath = await iOSProjectService.exportArchive(this.$projectData, { archivePath, teamID });
this.$logger.info("Export at: " + exportPath);

ipaFilePath = exportPath;
Expand Down
31 changes: 23 additions & 8 deletions lib/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
export class BuildCommandBase {
constructor(protected $options: IOptions,
protected $projectData: IProjectData,
protected $platformsData: IPlatformsData,
protected $platformService: IPlatformService) { }
protected $platformService: IPlatformService) {
this.$projectData.initializeProjectData();
}

public async executeCore(args: string[]): Promise<void> {
let platform = args[0].toLowerCase();
await this.$platformService.preparePlatform(platform);
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, this.$options.provision);
this.$options.clean = true;
await this.$platformService.buildPlatform(platform);
const buildConfig: IiOSBuildConfig = {
buildForDevice: this.$options.forDevice,
projectDir: this.$options.path,
clean: this.$options.clean,
teamId: this.$options.teamId,
device: this.$options.device,
provision: this.$options.provision,
release: this.$options.release
};
await this.$platformService.buildPlatform(platform, buildConfig, this.$projectData);
if (this.$options.copyTo) {
this.$platformService.copyLastOutput(platform, this.$options.copyTo, { isForDevice: this.$options.forDevice });
this.$platformService.copyLastOutput(platform, this.$options.copyTo, { isForDevice: this.$options.forDevice }, this.$projectData);
}
}
}
Expand All @@ -18,17 +31,18 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
public allowedParameters: ICommandParameter[] = [];

constructor(protected $options: IOptions,
$projectData: IProjectData,
$platformsData: IPlatformsData,
$platformService: IPlatformService) {
super($options, $platformsData, $platformService);
super($options, $projectData, $platformsData, $platformService);
}

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

public canExecute(args: string[]): Promise<boolean> {
return args.length === 0 && this.$platformService.validateOptions(this.$platformsData.availablePlatforms.iOS);
return args.length === 0 && this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.iOS);
}
}

Expand All @@ -38,10 +52,11 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
public allowedParameters: ICommandParameter[] = [];

constructor(protected $options: IOptions,
$projectData: IProjectData,
$platformsData: IPlatformsData,
private $errors: IErrors,
$platformService: IPlatformService) {
super($options, $platformsData, $platformService);
super($options, $projectData, $platformsData, $platformService);
}

public async execute(args: string[]): Promise<void> {
Expand All @@ -52,7 +67,7 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
this.$errors.fail("When producing a release build, you need to specify all --key-store-* options.");
}
return args.length === 0 && await this.$platformService.validateOptions(this.$platformsData.availablePlatforms.Android);
return args.length === 0 && await this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.Android);
}
}

Expand Down
18 changes: 12 additions & 6 deletions lib/commands/clean-app.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
export class CleanAppCommandBase {
constructor(protected $options: IOptions,
private $platformService: IPlatformService) { }
protected $projectData: IProjectData,
private $platformService: IPlatformService) {
this.$projectData.initializeProjectData();
}

public async execute(args: string[]): Promise<void> {
let platform = args[0].toLowerCase();
return this.$platformService.cleanDestinationApp(platform);
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
return this.$platformService.cleanDestinationApp(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData);
}
}

export class CleanAppIosCommand extends CleanAppCommandBase implements ICommand {
constructor(protected $options: IOptions,
private $platformsData: IPlatformsData,
$platformService: IPlatformService) {
super($options, $platformService);
$platformService: IPlatformService,
$projectData: IProjectData) {
super($options, $projectData, $platformService);
}

public allowedParameters: ICommandParameter[] = [];
Expand All @@ -29,8 +34,9 @@ export class CleanAppAndroidCommand extends CleanAppCommandBase implements IComm

constructor(protected $options: IOptions,
private $platformsData: IPlatformsData,
$platformService: IPlatformService) {
super($options, $platformService);
$platformService: IPlatformService,
$projectData: IProjectData) {
super($options, $projectData, $platformService);
}

public async execute(args: string[]): Promise<void> {
Expand Down
34 changes: 25 additions & 9 deletions lib/commands/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,29 @@
private $config: IConfiguration,
private $usbLiveSyncService: ILiveSyncService,
protected $platformService: IPlatformService,
protected $projectData: IProjectData,
protected $options: IOptions,
protected $platformsData: IPlatformsData) { }
protected $platformsData: IPlatformsData) {
this.$projectData.initializeProjectData();
}

public async execute(args: string[]): Promise<void> {
if (this.$options.start) {
return this.debugService.debug();
return this.debugService.debug(this.$projectData);
}

await this.$platformService.deployPlatform(this.$devicesService.platform);
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
const deployOptions: IDeployPlatformOptions = {
clean: this.$options.clean,
device: this.$options.device,
emulator: this.$options.emulator,
platformTemplate: this.$options.platformTemplate,
projectDir: this.$options.path,
release: this.$options.release,
provision: this.$options.provision,
teamId: this.$options.teamId
};
await this.$platformService.deployPlatform(this.$devicesService.platform, appFilesUpdaterOptions, deployOptions, this.$projectData, this.$options.provision);
this.$config.debugLivesync = true;
let applicationReloadAction = async (deviceAppData: Mobile.IDeviceAppData): Promise<void> => {
let projectData: IProjectData = this.$injector.resolve("projectData");
Expand All @@ -31,9 +45,9 @@

await deviceAppData.device.applicationManager.stopApplication(applicationId);

await this.debugService.debug();
await this.debugService.debug(this.$projectData);
};
return this.$usbLiveSyncService.liveSync(this.$devicesService.platform, applicationReloadAction);
return this.$usbLiveSyncService.liveSync(this.$devicesService.platform, this.$projectData, applicationReloadAction);
}

public async canExecute(args: string[]): Promise<boolean> {
Expand Down Expand Up @@ -64,13 +78,14 @@ export class DebugIOSCommand extends DebugPlatformCommand {
$usbLiveSyncService: ILiveSyncService,
$platformService: IPlatformService,
$options: IOptions,
$projectData: IProjectData,
$platformsData: IPlatformsData) {

super($iOSDebugService, $devicesService, $injector, $logger, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $options, $platformsData);
super($iOSDebugService, $devicesService, $injector, $logger, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $projectData, $options, $platformsData);
}

public async canExecute(args: string[]): Promise<boolean> {
return await super.canExecute(args) && await this.$platformService.validateOptions(this.$platformsData.availablePlatforms.iOS);
return await super.canExecute(args) && await this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.iOS);
}
}

Expand All @@ -86,13 +101,14 @@ export class DebugAndroidCommand extends DebugPlatformCommand {
$usbLiveSyncService: ILiveSyncService,
$platformService: IPlatformService,
$options: IOptions,
$projectData: IProjectData,
$platformsData: IPlatformsData) {

super($androidDebugService, $devicesService, $injector, $logger, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $options, $platformsData);
super($androidDebugService, $devicesService, $injector, $logger, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $projectData, $options, $platformsData);
}

public async canExecute(args: string[]): Promise<boolean> {
return await super.canExecute(args) && await this.$platformService.validateOptions(this.$platformsData.availablePlatforms.Android);
return await super.canExecute(args) && await this.$platformService.validateOptions(this.$options.provision, this.$projectData, this.$platformsData.availablePlatforms.Android);
}
}

Expand Down
21 changes: 18 additions & 3 deletions lib/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,26 @@ export class DeployOnDeviceCommand implements ICommand {
constructor(private $platformService: IPlatformService,
private $platformCommandParameter: ICommandParameter,
private $options: IOptions,
private $projectData: IProjectData,
private $errors: IErrors,
private $mobileHelper: Mobile.IMobileHelper) { }
private $mobileHelper: Mobile.IMobileHelper) {
this.$projectData.initializeProjectData();
}

public async execute(args: string[]): Promise<void> {
return this.$platformService.deployPlatform(args[0], true);
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
};
return this.$platformService.deployPlatform(args[0], appFilesUpdaterOptions, deployOptions, this.$projectData, this.$options.provision);
}

public async canExecute(args: string[]): Promise<boolean> {
Expand All @@ -24,7 +39,7 @@ export class DeployOnDeviceCommand implements ICommand {
this.$errors.fail("When producing a release build, you need to specify all --key-store-* options.");
}

return this.$platformService.validateOptions(args[0]);
return this.$platformService.validateOptions(this.$options.provision, this.$projectData, args[0]);
}
}

Expand Down
35 changes: 29 additions & 6 deletions lib/commands/emulate.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
export class EmulateCommandBase {
constructor(private $platformService: IPlatformService) { }
constructor(private $options: IOptions,
private $projectData: IProjectData,
private $platformService: IPlatformService) {
this.$projectData.initializeProjectData();
}

public async executeCore(args: string[]): Promise<void> {
return this.$platformService.emulatePlatform(args[0]);
this.$options.emulator = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I have not removed the $options dependency from all services I cannot guarantee that the code will run the same if I remove this.

const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
const emulateOptions: IEmulatePlatformOptions = {
avd: this.$options.avd,
clean: this.$options.clean,
device: this.$options.device,
release: this.$options.release,
emulator: this.$options.emulator,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of setting the value of this.$options.emulator to true, shouldn't we just set the emulator option here to true?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to reuse the variable 😇

projectDir: this.$options.path,
justlaunch: this.$options.justlaunch,
availableDevices: this.$options.availableDevices,
platformTemplate: this.$options.platformTemplate,
provision: this.$options.provision,
teamId: this.$options.teamId
};
return this.$platformService.emulatePlatform(args[0], appFilesUpdaterOptions, emulateOptions, this.$projectData, this.$options.provision);
}
}

export class EmulateIosCommand extends EmulateCommandBase implements ICommand {
public allowedParameters: ICommandParameter[] = [];

constructor($platformService: IPlatformService,
constructor($options: IOptions,
$projectData: IProjectData,
$platformService: IPlatformService,
private $platformsData: IPlatformsData) {
super($platformService);
super($options, $projectData, $platformService);
}

public async execute(args: string[]): Promise<void> {
Expand All @@ -22,9 +43,11 @@ export class EmulateIosCommand extends EmulateCommandBase implements ICommand {
$injector.registerCommand("emulate|ios", EmulateIosCommand);

export class EmulateAndroidCommand extends EmulateCommandBase implements ICommand {
constructor($platformService: IPlatformService,
constructor($options: IOptions,
$projectData: IProjectData,
$platformService: IPlatformService,
private $platformsData: IPlatformsData) {
super($platformService);
super($options, $projectData, $platformService);
}

public allowedParameters: ICommandParameter[] = [];
Expand Down
Loading