Skip to content

Commit a008db1

Browse files
Allow local builds when {N} CLI is required as a library (#2574)
* 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 * Rebase onto master * Fix tns init * Fix ios-project-service tests * Respect ios-specific options when building
1 parent 1cffefb commit a008db1

File tree

76 files changed

+1696
-1286
lines changed

Some content is hidden

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

76 files changed

+1696
-1286
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

+23-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
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: IiOSBuildConfig = {
15+
buildForDevice: this.$options.forDevice,
16+
projectDir: this.$options.path,
17+
clean: this.$options.clean,
18+
teamId: this.$options.teamId,
19+
device: this.$options.device,
20+
provision: this.$options.provision,
21+
release: this.$options.release
22+
};
23+
await this.$platformService.buildPlatform(platform, buildConfig, this.$projectData);
1124
if (this.$options.copyTo) {
12-
this.$platformService.copyLastOutput(platform, this.$options.copyTo, { isForDevice: this.$options.forDevice });
25+
this.$platformService.copyLastOutput(platform, this.$options.copyTo, { isForDevice: this.$options.forDevice }, this.$projectData);
1326
}
1427
}
1528
}
@@ -18,17 +31,18 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
1831
public allowedParameters: ICommandParameter[] = [];
1932

2033
constructor(protected $options: IOptions,
34+
$projectData: IProjectData,
2135
$platformsData: IPlatformsData,
2236
$platformService: IPlatformService) {
23-
super($options, $platformsData, $platformService);
37+
super($options, $projectData, $platformsData, $platformService);
2438
}
2539

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

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

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

4054
constructor(protected $options: IOptions,
55+
$projectData: IProjectData,
4156
$platformsData: IPlatformsData,
4257
private $errors: IErrors,
4358
$platformService: IPlatformService) {
44-
super($options, $platformsData, $platformService);
59+
super($options, $projectData, $platformsData, $platformService);
4560
}
4661

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

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

+25-9
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,29 @@
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+
provision: this.$options.provision,
32+
teamId: this.$options.teamId
33+
};
34+
await this.$platformService.deployPlatform(this.$devicesService.platform, appFilesUpdaterOptions, deployOptions, this.$projectData, this.$options.provision);
2135
this.$config.debugLivesync = true;
2236
let applicationReloadAction = async (deviceAppData: Mobile.IDeviceAppData): Promise<void> => {
2337
let projectData: IProjectData = this.$injector.resolve("projectData");
@@ -31,9 +45,9 @@
3145

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

34-
await this.debugService.debug();
48+
await this.debugService.debug(this.$projectData);
3549
};
36-
return this.$usbLiveSyncService.liveSync(this.$devicesService.platform, applicationReloadAction);
50+
return this.$usbLiveSyncService.liveSync(this.$devicesService.platform, this.$projectData, applicationReloadAction);
3751
}
3852

3953
public async canExecute(args: string[]): Promise<boolean> {
@@ -64,13 +78,14 @@ export class DebugIOSCommand extends DebugPlatformCommand {
6478
$usbLiveSyncService: ILiveSyncService,
6579
$platformService: IPlatformService,
6680
$options: IOptions,
81+
$projectData: IProjectData,
6782
$platformsData: IPlatformsData) {
6883

69-
super($iOSDebugService, $devicesService, $injector, $logger, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $options, $platformsData);
84+
super($iOSDebugService, $devicesService, $injector, $logger, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $projectData, $options, $platformsData);
7085
}
7186

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

@@ -86,13 +101,14 @@ export class DebugAndroidCommand extends DebugPlatformCommand {
86101
$usbLiveSyncService: ILiveSyncService,
87102
$platformService: IPlatformService,
88103
$options: IOptions,
104+
$projectData: IProjectData,
89105
$platformsData: IPlatformsData) {
90106

91-
super($androidDebugService, $devicesService, $injector, $logger, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $options, $platformsData);
107+
super($androidDebugService, $devicesService, $injector, $logger, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $projectData, $options, $platformsData);
92108
}
93109

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

lib/commands/deploy.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,26 @@ 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+
provision: this.$options.provision,
24+
teamId: this.$options.teamId
25+
};
26+
return this.$platformService.deployPlatform(args[0], appFilesUpdaterOptions, deployOptions, this.$projectData, this.$options.provision);
1227
}
1328

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

27-
return this.$platformService.validateOptions(args[0]);
42+
return this.$platformService.validateOptions(this.$options.provision, this.$projectData, args[0]);
2843
}
2944
}
3045

lib/commands/emulate.ts

+29-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,38 @@
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+
provision: this.$options.provision,
22+
teamId: this.$options.teamId
23+
};
24+
return this.$platformService.emulatePlatform(args[0], appFilesUpdaterOptions, emulateOptions, this.$projectData, this.$options.provision);
625
}
726
}
827

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

12-
constructor($platformService: IPlatformService,
31+
constructor($options: IOptions,
32+
$projectData: IProjectData,
33+
$platformService: IPlatformService,
1334
private $platformsData: IPlatformsData) {
14-
super($platformService);
35+
super($options, $projectData, $platformService);
1536
}
1637

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

2445
export class EmulateAndroidCommand extends EmulateCommandBase implements ICommand {
25-
constructor($platformService: IPlatformService,
46+
constructor($options: IOptions,
47+
$projectData: IProjectData,
48+
$platformService: IPlatformService,
2649
private $platformsData: IPlatformsData) {
27-
super($platformService);
50+
super($options, $projectData, $platformService);
2851
}
2952

3053
public allowedParameters: ICommandParameter[] = [];

0 commit comments

Comments
 (0)