Skip to content

Commit c9dcae2

Browse files
author
Dimitar Kerezov
committed
Allow local builds when require("")d
Includes: * Get rid of $projectData dependency in services * Introduce new service for calling build when required as a library * Emit build output when necessary
1 parent 8110d11 commit c9dcae2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1645
-1267
lines changed

lib/commands/add-platform.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
export class AddPlatformCommand implements ICommand {
22
public allowedParameters: ICommandParameter[] = [];
33

4-
constructor(private $platformService: IPlatformService,
5-
private $errors: IErrors) { }
4+
constructor(private $options: IOptions,
5+
private $platformService: IPlatformService,
6+
private $projectData: IProjectData,
7+
private $errors: IErrors) {
8+
this.$projectData.initializeProjectData();
9+
}
610

711
public async execute(args: string[]): Promise<void> {
8-
await this.$platformService.addPlatforms(args);
12+
await this.$platformService.addPlatforms(args, this.$options.platformTemplate, this.$projectData);
913
}
1014

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

16-
_.each(args, arg => this.$platformService.validatePlatform(arg));
20+
_.each(args, arg => this.$platformService.validatePlatform(arg, this.$projectData));
1721

1822
return true;
1923
}

lib/commands/appstore-upload.ts

+17-8
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ export class PublishIOS implements ICommand {
1111
private $injector: IInjector,
1212
private $itmsTransporterService: IITMSTransporterService,
1313
private $logger: ILogger,
14+
private $projectData: IProjectData,
1415
private $options: IOptions,
1516
private $prompter: IPrompter,
16-
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants) { }
17+
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants) {
18+
this.$projectData.initializeProjectData();
19+
}
1720

1821
private get $platformsData(): IPlatformsData {
1922
return this.$injector.resolve("platformsData");
@@ -54,28 +57,34 @@ export class PublishIOS implements ICommand {
5457
if (!ipaFilePath) {
5558
let platform = this.$devicePlatformsConstants.iOS;
5659
// No .ipa path provided, build .ipa on out own.
60+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
5761
if (mobileProvisionIdentifier || codeSignIdentity) {
5862
let iOSBuildConfig: IiOSBuildConfig = {
63+
projectDir: this.$options.path,
64+
release: this.$options.release,
65+
device: this.$options.device,
66+
provision: this.$options.provision,
67+
teamId: this.$options.teamId,
5968
buildForDevice: true,
6069
mobileProvisionIdentifier,
6170
codeSignIdentity
6271
};
6372
this.$logger.info("Building .ipa with the selected mobile provision and/or certificate.");
6473
// This is not very correct as if we build multiple targets we will try to sign all of them using the signing identity here.
65-
await this.$platformService.preparePlatform(platform);
66-
await this.$platformService.buildPlatform(platform, iOSBuildConfig);
67-
ipaFilePath = this.$platformService.lastOutputPath(platform, { isForDevice: iOSBuildConfig.buildForDevice });
74+
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, this.$options.provision);
75+
await this.$platformService.buildPlatform(platform, iOSBuildConfig, this.$projectData);
76+
ipaFilePath = this.$platformService.lastOutputPath(platform, { isForDevice: iOSBuildConfig.buildForDevice }, this.$projectData);
6877
} else {
6978
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.");
70-
await this.$platformService.preparePlatform(platform);
79+
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, this.$options.provision);
7180

72-
let platformData = this.$platformsData.getPlatformData(platform);
81+
let platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
7382
let iOSProjectService = <IOSProjectService>platformData.platformProjectService;
7483

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

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

8190
ipaFilePath = exportPath;

lib/commands/build.ts

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
export class BuildCommandBase {
22
constructor(protected $options: IOptions,
3+
protected $projectData: IProjectData,
34
protected $platformsData: IPlatformsData,
4-
protected $platformService: IPlatformService) { }
5+
protected $platformService: IPlatformService) {
6+
this.$projectData.initializeProjectData();
7+
}
58

69
public async executeCore(args: string[]): Promise<void> {
710
let platform = args[0].toLowerCase();
8-
await this.$platformService.preparePlatform(platform);
11+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
12+
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, this.$options.provision);
913
this.$options.clean = true;
10-
await this.$platformService.buildPlatform(platform);
14+
const buildConfig: IBuildConfig = {
15+
buildForDevice: this.$options.forDevice,
16+
projectDir: this.$options.path,
17+
clean: this.$options.clean,
18+
release: this.$options.release
19+
};
20+
await this.$platformService.buildPlatform(platform, buildConfig, this.$projectData);
1121
if (this.$options.copyTo) {
12-
this.$platformService.copyLastOutput(platform, this.$options.copyTo, { isForDevice: this.$options.forDevice });
22+
this.$platformService.copyLastOutput(platform, this.$options.copyTo, { isForDevice: this.$options.forDevice }, this.$projectData);
1323
}
1424
}
1525
}
@@ -18,17 +28,18 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
1828
public allowedParameters: ICommandParameter[] = [];
1929

2030
constructor(protected $options: IOptions,
31+
$projectData: IProjectData,
2132
$platformsData: IPlatformsData,
2233
$platformService: IPlatformService) {
23-
super($options, $platformsData, $platformService);
34+
super($options, $projectData, $platformsData, $platformService);
2435
}
2536

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

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

@@ -38,10 +49,11 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
3849
public allowedParameters: ICommandParameter[] = [];
3950

4051
constructor(protected $options: IOptions,
52+
$projectData: IProjectData,
4153
$platformsData: IPlatformsData,
4254
private $errors: IErrors,
4355
$platformService: IPlatformService) {
44-
super($options, $platformsData, $platformService);
56+
super($options, $projectData, $platformsData, $platformService);
4557
}
4658

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

lib/commands/clean-app.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
export class CleanAppCommandBase {
22
constructor(protected $options: IOptions,
3-
private $platformService: IPlatformService) { }
3+
protected $projectData: IProjectData,
4+
private $platformService: IPlatformService) {
5+
this.$projectData.initializeProjectData();
6+
}
47

58
public async execute(args: string[]): Promise<void> {
69
let platform = args[0].toLowerCase();
7-
return this.$platformService.cleanDestinationApp(platform);
10+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
11+
return this.$platformService.cleanDestinationApp(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData);
812
}
913
}
1014

1115
export class CleanAppIosCommand extends CleanAppCommandBase implements ICommand {
1216
constructor(protected $options: IOptions,
1317
private $platformsData: IPlatformsData,
14-
$platformService: IPlatformService) {
15-
super($options, $platformService);
18+
$platformService: IPlatformService,
19+
$projectData: IProjectData) {
20+
super($options, $projectData, $platformService);
1621
}
1722

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

3035
constructor(protected $options: IOptions,
3136
private $platformsData: IPlatformsData,
32-
$platformService: IPlatformService) {
33-
super($options, $platformService);
37+
$platformService: IPlatformService,
38+
$projectData: IProjectData) {
39+
super($options, $projectData, $platformService);
3440
}
3541

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

lib/commands/debug.ts

+23-9
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,27 @@
99
private $config: IConfiguration,
1010
private $usbLiveSyncService: ILiveSyncService,
1111
protected $platformService: IPlatformService,
12+
protected $projectData: IProjectData,
1213
protected $options: IOptions,
13-
protected $platformsData: IPlatformsData) { }
14+
protected $platformsData: IPlatformsData) {
15+
this.$projectData.initializeProjectData();
16+
}
1417

1518
public async execute(args: string[]): Promise<void> {
1619
if (this.$options.start) {
17-
return this.debugService.debug();
20+
return this.debugService.debug(this.$projectData);
1821
}
1922

20-
await this.$platformService.deployPlatform(this.$devicesService.platform);
23+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
24+
const deployOptions: IDeployPlatformOptions = {
25+
clean: this.$options.clean,
26+
device: this.$options.device,
27+
emulator: this.$options.emulator,
28+
platformTemplate: this.$options.platformTemplate,
29+
projectDir: this.$options.path,
30+
release: this.$options.release
31+
};
32+
await this.$platformService.deployPlatform(this.$devicesService.platform, appFilesUpdaterOptions, deployOptions, this.$projectData, this.$options.provision);
2133
this.$config.debugLivesync = true;
2234
let applicationReloadAction = async (deviceAppData: Mobile.IDeviceAppData): Promise<void> => {
2335
let projectData: IProjectData = this.$injector.resolve("projectData");
@@ -31,9 +43,9 @@
3143

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

34-
await this.debugService.debug();
46+
await this.debugService.debug(this.$projectData);
3547
};
36-
return this.$usbLiveSyncService.liveSync(this.$devicesService.platform, applicationReloadAction);
48+
return this.$usbLiveSyncService.liveSync(this.$devicesService.platform, this.$projectData, applicationReloadAction);
3749
}
3850

3951
public async canExecute(args: string[]): Promise<boolean> {
@@ -64,13 +76,14 @@ export class DebugIOSCommand extends DebugPlatformCommand {
6476
$usbLiveSyncService: ILiveSyncService,
6577
$platformService: IPlatformService,
6678
$options: IOptions,
79+
$projectData: IProjectData,
6780
$platformsData: IPlatformsData) {
6881

69-
super($iOSDebugService, $devicesService, $injector, $logger, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $options, $platformsData);
82+
super($iOSDebugService, $devicesService, $injector, $logger, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $projectData, $options, $platformsData);
7083
}
7184

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

@@ -86,13 +99,14 @@ export class DebugAndroidCommand extends DebugPlatformCommand {
8699
$usbLiveSyncService: ILiveSyncService,
87100
$platformService: IPlatformService,
88101
$options: IOptions,
102+
$projectData: IProjectData,
89103
$platformsData: IPlatformsData) {
90104

91-
super($androidDebugService, $devicesService, $injector, $logger, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $options, $platformsData);
105+
super($androidDebugService, $devicesService, $injector, $logger, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $projectData, $options, $platformsData);
92106
}
93107

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

lib/commands/deploy.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,24 @@ export class DeployOnDeviceCommand implements ICommand {
44
constructor(private $platformService: IPlatformService,
55
private $platformCommandParameter: ICommandParameter,
66
private $options: IOptions,
7+
private $projectData: IProjectData,
78
private $errors: IErrors,
8-
private $mobileHelper: Mobile.IMobileHelper) { }
9+
private $mobileHelper: Mobile.IMobileHelper) {
10+
this.$projectData.initializeProjectData();
11+
}
912

1013
public async execute(args: string[]): Promise<void> {
11-
return this.$platformService.deployPlatform(args[0], true);
14+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
15+
const deployOptions: IDeployPlatformOptions = {
16+
clean: this.$options.clean,
17+
device: this.$options.device,
18+
projectDir: this.$options.path,
19+
emulator: this.$options.emulator,
20+
platformTemplate: this.$options.platformTemplate,
21+
release: this.$options.release,
22+
forceInstall: true
23+
};
24+
return this.$platformService.deployPlatform(args[0], appFilesUpdaterOptions, deployOptions, this.$projectData, this.$options.provision);
1225
}
1326

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

27-
return this.$platformService.validateOptions(args[0]);
40+
return this.$platformService.validateOptions(this.$options.provision, this.$projectData, args[0]);
2841
}
2942
}
3043

lib/commands/emulate.ts

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,36 @@
11
export class EmulateCommandBase {
2-
constructor(private $platformService: IPlatformService) { }
2+
constructor(private $options: IOptions,
3+
private $projectData: IProjectData,
4+
private $platformService: IPlatformService) {
5+
this.$projectData.initializeProjectData();
6+
}
37

48
public async executeCore(args: string[]): Promise<void> {
5-
return this.$platformService.emulatePlatform(args[0]);
9+
this.$options.emulator = true;
10+
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
11+
const emulateOptions: IEmulatePlatformOptions = {
12+
avd: this.$options.avd,
13+
clean: this.$options.clean,
14+
device: this.$options.device,
15+
release: this.$options.release,
16+
emulator: this.$options.emulator,
17+
projectDir: this.$options.path,
18+
justlaunch: this.$options.justlaunch,
19+
availableDevices: this.$options.availableDevices,
20+
platformTemplate: this.$options.platformTemplate
21+
};
22+
return this.$platformService.emulatePlatform(args[0], appFilesUpdaterOptions, emulateOptions, this.$projectData, this.$options.provision);
623
}
724
}
825

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

12-
constructor($platformService: IPlatformService,
29+
constructor($options: IOptions,
30+
$projectData: IProjectData,
31+
$platformService: IPlatformService,
1332
private $platformsData: IPlatformsData) {
14-
super($platformService);
33+
super($options, $projectData, $platformService);
1534
}
1635

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

2443
export class EmulateAndroidCommand extends EmulateCommandBase implements ICommand {
25-
constructor($platformService: IPlatformService,
44+
constructor($options: IOptions,
45+
$projectData: IProjectData,
46+
$platformService: IPlatformService,
2647
private $platformsData: IPlatformsData) {
27-
super($platformService);
48+
super($options, $projectData, $platformService);
2849
}
2950

3051
public allowedParameters: ICommandParameter[] = [];

0 commit comments

Comments
 (0)