Skip to content

Commit 5c1460a

Browse files
author
Dimitar Kerezov
committed
Get rid of $projectData dependency in services
1 parent b951cbf commit 5c1460a

Some content is hidden

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

70 files changed

+1279
-1132
lines changed

lib/commands/add-platform.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@ export class AddPlatformCommand implements ICommand {
33

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

811
public async execute(args: string[]): Promise<void> {
9-
await this.$platformService.addPlatforms(args, this.$options.platformTemplate);
12+
await this.$platformService.addPlatforms(args, this.$options.platformTemplate, this.$projectData);
1013
}
1114

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

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

1922
return true;
2023
}

lib/commands/appstore-upload.ts

+11-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");
@@ -68,20 +71,20 @@ export class PublishIOS implements ICommand {
6871
};
6972
this.$logger.info("Building .ipa with the selected mobile provision and/or certificate.");
7073
// This is not very correct as if we build multiple targets we will try to sign all of them using the signing identity here.
71-
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate);
72-
await this.$platformService.buildPlatform(platform, iOSBuildConfig);
73-
ipaFilePath = this.$platformService.lastOutputPath(platform, { isForDevice: iOSBuildConfig.buildForDevice });
74+
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData);
75+
await this.$platformService.buildPlatform(platform, iOSBuildConfig, this.$projectData);
76+
ipaFilePath = this.$platformService.lastOutputPath(platform, { isForDevice: iOSBuildConfig.buildForDevice }, this.$projectData);
7477
} else {
7578
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.");
76-
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate);
79+
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData);
7780

78-
let platformData = this.$platformsData.getPlatformData(platform);
81+
let platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
7982
let iOSProjectService = <IOSProjectService>platformData.platformProjectService;
8083

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

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

8790
ipaFilePath = exportPath;

lib/commands/build.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +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();
811
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
9-
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate);
12+
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData);
1013
this.$options.clean = true;
1114
const buildConfig: IBuildConfig = {
1215
buildForDevice: this.$options.forDevice,
1316
projectDir: this.$options.path,
1417
clean: this.$options.clean,
1518
release: this.$options.release
1619
};
17-
await this.$platformService.buildPlatform(platform, buildConfig);
20+
await this.$platformService.buildPlatform(platform, buildConfig, this.$projectData);
1821
if (this.$options.copyTo) {
19-
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);
2023
}
2124
}
2225
}
@@ -25,17 +28,18 @@ export class BuildIosCommand extends BuildCommandBase implements ICommand {
2528
public allowedParameters: ICommandParameter[] = [];
2629

2730
constructor(protected $options: IOptions,
31+
$projectData: IProjectData,
2832
$platformsData: IPlatformsData,
2933
$platformService: IPlatformService) {
30-
super($options, $platformsData, $platformService);
34+
super($options, $projectData, $platformsData, $platformService);
3135
}
3236

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

3741
public canExecute(args: string[]): Promise<boolean> {
38-
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);
3943
}
4044
}
4145

@@ -45,10 +49,11 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
4549
public allowedParameters: ICommandParameter[] = [];
4650

4751
constructor(protected $options: IOptions,
52+
$projectData: IProjectData,
4853
$platformsData: IPlatformsData,
4954
private $errors: IErrors,
5055
$platformService: IPlatformService) {
51-
super($options, $platformsData, $platformService);
56+
super($options, $projectData, $platformsData, $platformService);
5257
}
5358

5459
public async execute(args: string[]): Promise<void> {
@@ -59,7 +64,7 @@ export class BuildAndroidCommand extends BuildCommandBase implements ICommand {
5964
if (this.$options.release && (!this.$options.keyStorePath || !this.$options.keyStorePassword || !this.$options.keyStoreAlias || !this.$options.keyStoreAliasPassword)) {
6065
this.$errors.fail("When producing a release build, you need to specify all --key-store-* options.");
6166
}
62-
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);
6368
}
6469
}
6570

lib/commands/clean-app.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +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();
710
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
8-
return this.$platformService.cleanDestinationApp(platform, appFilesUpdaterOptions, this.$options.platformTemplate);
11+
return this.$platformService.cleanDestinationApp(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData);
912
}
1013
}
1114

1215
export class CleanAppIosCommand extends CleanAppCommandBase implements ICommand {
1316
constructor(protected $options: IOptions,
1417
private $platformsData: IPlatformsData,
15-
$platformService: IPlatformService) {
16-
super($options, $platformService);
18+
$platformService: IPlatformService,
19+
$projectData: IProjectData) {
20+
super($options, $projectData, $platformService);
1721
}
1822

1923
public allowedParameters: ICommandParameter[] = [];
@@ -30,8 +34,9 @@ export class CleanAppAndroidCommand extends CleanAppCommandBase implements IComm
3034

3135
constructor(protected $options: IOptions,
3236
private $platformsData: IPlatformsData,
33-
$platformService: IPlatformService) {
34-
super($options, $platformService);
37+
$platformService: IPlatformService,
38+
$projectData: IProjectData) {
39+
super($options, $projectData, $platformService);
3540
}
3641

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

lib/commands/debug.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
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

2023
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
@@ -26,7 +29,7 @@
2629
projectDir: this.$options.path,
2730
release: this.$options.release
2831
};
29-
await this.$platformService.deployPlatform(this.$devicesService.platform, appFilesUpdaterOptions, deployOptions);
32+
await this.$platformService.deployPlatform(this.$devicesService.platform, appFilesUpdaterOptions, deployOptions, this.$projectData);
3033
this.$config.debugLivesync = true;
3134
let applicationReloadAction = async (deviceAppData: Mobile.IDeviceAppData): Promise<void> => {
3235
let projectData: IProjectData = this.$injector.resolve("projectData");
@@ -40,9 +43,9 @@
4043

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

43-
await this.debugService.debug();
46+
await this.debugService.debug(this.$projectData);
4447
};
45-
return this.$usbLiveSyncService.liveSync(this.$devicesService.platform, applicationReloadAction);
48+
return this.$usbLiveSyncService.liveSync(this.$devicesService.platform, this.$projectData, applicationReloadAction);
4649
}
4750

4851
public async canExecute(args: string[]): Promise<boolean> {
@@ -73,13 +76,14 @@ export class DebugIOSCommand extends DebugPlatformCommand {
7376
$usbLiveSyncService: ILiveSyncService,
7477
$platformService: IPlatformService,
7578
$options: IOptions,
79+
$projectData: IProjectData,
7680
$platformsData: IPlatformsData) {
7781

78-
super($iOSDebugService, $devicesService, $injector, $logger, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $options, $platformsData);
82+
super($iOSDebugService, $devicesService, $injector, $logger, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $projectData, $options, $platformsData);
7983
}
8084

8185
public async canExecute(args: string[]): Promise<boolean> {
82-
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);
8387
}
8488
}
8589

@@ -95,13 +99,14 @@ export class DebugAndroidCommand extends DebugPlatformCommand {
9599
$usbLiveSyncService: ILiveSyncService,
96100
$platformService: IPlatformService,
97101
$options: IOptions,
102+
$projectData: IProjectData,
98103
$platformsData: IPlatformsData) {
99104

100-
super($androidDebugService, $devicesService, $injector, $logger, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $options, $platformsData);
105+
super($androidDebugService, $devicesService, $injector, $logger, $devicePlatformsConstants, $config, $usbLiveSyncService, $platformService, $projectData, $options, $platformsData);
101106
}
102107

103108
public async canExecute(args: string[]): Promise<boolean> {
104-
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);
105110
}
106111
}
107112

lib/commands/deploy.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ 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> {
1114
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
@@ -18,7 +21,7 @@ export class DeployOnDeviceCommand implements ICommand {
1821
release: this.$options.release,
1922
forceInstall: true
2023
};
21-
return this.$platformService.deployPlatform(args[0], appFilesUpdaterOptions, deployOptions);
24+
return this.$platformService.deployPlatform(args[0], appFilesUpdaterOptions, deployOptions, this.$projectData);
2225
}
2326

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

37-
return this.$platformService.validateOptions(args[0]);
40+
return this.$platformService.validateOptions(this.$options.provision, this.$projectData, args[0]);
3841
}
3942
}
4043

lib/commands/emulate.ts

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

58
public async executeCore(args: string[]): Promise<void> {
69
this.$options.emulator = true;
@@ -15,18 +18,19 @@ export class EmulateCommandBase {
1518
justlaunch: this.$options.justlaunch,
1619
availableDevices: this.$options.availableDevices,
1720
platformTemplate: this.$options.platformTemplate
18-
}
19-
return this.$platformService.emulatePlatform(args[0], appFilesUpdaterOptions, emulateOptions);
21+
};
22+
return this.$platformService.emulatePlatform(args[0], appFilesUpdaterOptions, emulateOptions, this.$projectData);
2023
}
2124
}
2225

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

2629
constructor($options: IOptions,
30+
$projectData: IProjectData,
2731
$platformService: IPlatformService,
2832
private $platformsData: IPlatformsData) {
29-
super($options, $platformService);
33+
super($options, $projectData, $platformService);
3034
}
3135

3236
public async execute(args: string[]): Promise<void> {
@@ -38,9 +42,10 @@ $injector.registerCommand("emulate|ios", EmulateIosCommand);
3842

3943
export class EmulateAndroidCommand extends EmulateCommandBase implements ICommand {
4044
constructor($options: IOptions,
45+
$projectData: IProjectData,
4146
$platformService: IPlatformService,
4247
private $platformsData: IPlatformsData) {
43-
super($options, $platformService);
48+
super($options, $projectData, $platformService);
4449
}
4550

4651
public allowedParameters: ICommandParameter[] = [];

lib/commands/install.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export class InstallCommand implements ICommand {
1313
private $logger: ILogger,
1414
private $fs: IFileSystem,
1515
private $stringParameter: ICommandParameter,
16-
private $npm: INodePackageManager) { }
16+
private $npm: INodePackageManager) {
17+
this.$projectData.initializeProjectData();
18+
}
1719

1820
public async execute(args: string[]): Promise<void> {
1921
return args[0] ? this.installModule(args[0]) : this.installProjectDependencies();
@@ -22,15 +24,15 @@ export class InstallCommand implements ICommand {
2224
private async installProjectDependencies(): Promise<void> {
2325
let error: string = "";
2426

25-
await this.$pluginsService.ensureAllDependenciesAreInstalled();
27+
await this.$pluginsService.ensureAllDependenciesAreInstalled(this.$projectData);
2628

2729
this.$projectDataService.initialize(this.$projectData.projectDir);
2830
for (let platform of this.$platformsData.platformsNames) {
29-
let platformData = this.$platformsData.getPlatformData(platform);
31+
let platformData = this.$platformsData.getPlatformData(platform, this.$projectData);
3032
let frameworkPackageData = this.$projectDataService.getValue(platformData.frameworkPackageName);
3133
if (frameworkPackageData && frameworkPackageData.version) {
3234
try {
33-
await this.$platformService.addPlatforms([`${platform}@${frameworkPackageData.version}`], this.$options.platformTemplate);
35+
await this.$platformService.addPlatforms([`${platform}@${frameworkPackageData.version}`], this.$options.platformTemplate, this.$projectData);
3436
} catch (err) {
3537
error = `${error}${EOL}${err}`;
3638
}

lib/commands/list-platforms.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ export class ListPlatformsCommand implements ICommand {
44
public allowedParameters: ICommandParameter[] = [];
55

66
constructor(private $platformService: IPlatformService,
7-
private $logger: ILogger) { }
7+
private $projectData: IProjectData,
8+
private $logger: ILogger) {
9+
this.$projectData.initializeProjectData();
10+
}
811

912
public async execute(args: string[]): Promise<void> {
10-
let installedPlatforms = this.$platformService.getInstalledPlatforms();
13+
let installedPlatforms = this.$platformService.getInstalledPlatforms(this.$projectData);
1114

1215
if (installedPlatforms.length > 0) {
13-
let preparedPlatforms = this.$platformService.getPreparedPlatforms();
16+
let preparedPlatforms = this.$platformService.getPreparedPlatforms(this.$projectData);
1417
if (preparedPlatforms.length > 0) {
1518
this.$logger.out("The project is prepared for: ", helpers.formatListOfNames(preparedPlatforms, "and"));
1619
} else {
@@ -19,7 +22,7 @@ export class ListPlatformsCommand implements ICommand {
1922

2023
this.$logger.out("Installed platforms: ", helpers.formatListOfNames(installedPlatforms, "and"));
2124
} else {
22-
let formattedPlatformsList = helpers.formatListOfNames(this.$platformService.getAvailablePlatforms(), "and");
25+
let formattedPlatformsList = helpers.formatListOfNames(this.$platformService.getAvailablePlatforms(this.$projectData), "and");
2326
this.$logger.out("Available platforms for this OS: ", formattedPlatformsList);
2427
this.$logger.out("No installed platforms found. Use $ tns platform add");
2528
}

0 commit comments

Comments
 (0)