Skip to content

Commit c05d30e

Browse files
Fix specifiying --sdk on platform add
During adding of Android platform, users can specify targetSdk via `--sdk` command line option. This has been broken in previous commit. As our services should not rely on `$options`, sdk must be passed as parameter whenever it could be used. It turns out some common methods (addPlatform, preparePlatform) rely on platform specific data - sdk, provision, etc. In order to handle this without adding new arguments, introudce IPlatformSpecificData interface and use it in al methods where we have to pass some of the platform specific data required for preparing of the project.
1 parent f78004f commit c05d30e

24 files changed

+108
-90
lines changed

lib/commands/add-platform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class AddPlatformCommand implements ICommand {
99
}
1010

1111
public async execute(args: string[]): Promise<void> {
12-
await this.$platformService.addPlatforms(args, this.$options.platformTemplate, this.$projectData);
12+
await this.$platformService.addPlatforms(args, this.$options.platformTemplate, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk }, this.$options.frameworkPath);
1313
}
1414

1515
public async canExecute(args: string[]): Promise<boolean> {

lib/commands/appstore-upload.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ export class PublishIOS implements ICommand {
7171
};
7272
this.$logger.info("Building .ipa with the selected mobile provision and/or certificate.");
7373
// This is not very correct as if we build multiple targets we will try to sign all of them using the signing identity here.
74-
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, this.$options.provision);
74+
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
7575
await this.$platformService.buildPlatform(platform, iOSBuildConfig, this.$projectData);
7676
ipaFilePath = this.$platformService.lastOutputPath(platform, { isForDevice: iOSBuildConfig.buildForDevice }, this.$projectData);
7777
} else {
7878
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.");
79-
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, this.$options.provision);
79+
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
8080

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

lib/commands/build.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ export class BuildCommandBase {
33
protected $projectData: IProjectData,
44
protected $platformsData: IPlatformsData,
55
protected $platformService: IPlatformService) {
6-
this.$projectData.initializeProjectData();
7-
}
6+
this.$projectData.initializeProjectData();
7+
}
88

99
public async executeCore(args: string[]): Promise<void> {
1010
let platform = args[0].toLowerCase();
1111
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);
12+
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
1313
this.$options.clean = true;
1414
const buildConfig: IiOSBuildConfig = {
1515
buildForDevice: this.$options.forDevice,

lib/commands/clean-app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export class CleanAppCommandBase {
88
public async execute(args: string[]): Promise<void> {
99
let platform = args[0].toLowerCase();
1010
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
11-
return this.$platformService.cleanDestinationApp(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData);
11+
return this.$platformService.cleanDestinationApp(platform, appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
1212
}
1313
}
1414

lib/commands/debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
provision: this.$options.provision,
3232
teamId: this.$options.teamId
3333
};
34-
await this.$platformService.deployPlatform(this.$devicesService.platform, appFilesUpdaterOptions, deployOptions, this.$projectData, this.$options.provision);
34+
await this.$platformService.deployPlatform(this.$devicesService.platform, appFilesUpdaterOptions, deployOptions, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
3535
this.$config.debugLivesync = true;
3636
let applicationReloadAction = async (deviceAppData: Mobile.IDeviceAppData): Promise<void> => {
3737
let projectData: IProjectData = this.$injector.resolve("projectData");

lib/commands/deploy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export class DeployOnDeviceCommand implements ICommand {
77
private $projectData: IProjectData,
88
private $errors: IErrors,
99
private $mobileHelper: Mobile.IMobileHelper) {
10-
this.$projectData.initializeProjectData();
11-
}
10+
this.$projectData.initializeProjectData();
11+
}
1212

1313
public async execute(args: string[]): Promise<void> {
1414
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
@@ -27,7 +27,7 @@ export class DeployOnDeviceCommand implements ICommand {
2727
keyStorePassword: this.$options.keyStorePassword,
2828
keyStorePath: this.$options.keyStorePath
2929
};
30-
return this.$platformService.deployPlatform(args[0], appFilesUpdaterOptions, deployOptions, this.$projectData, this.$options.provision);
30+
return this.$platformService.deployPlatform(args[0], appFilesUpdaterOptions, deployOptions, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
3131
}
3232

3333
public async canExecute(args: string[]): Promise<boolean> {

lib/commands/emulate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class EmulateCommandBase {
2121
provision: this.$options.provision,
2222
teamId: this.$options.teamId
2323
};
24-
return this.$platformService.emulatePlatform(args[0], appFilesUpdaterOptions, emulateOptions, this.$projectData, this.$options.provision);
24+
return this.$platformService.emulatePlatform(args[0], appFilesUpdaterOptions, emulateOptions, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
2525
}
2626
}
2727

lib/commands/install.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class InstallCommand implements ICommand {
3131
const frameworkPackageData = this.$projectDataService.getNSValue(this.$projectData.projectDir, platformData.frameworkPackageName);
3232
if (frameworkPackageData && frameworkPackageData.version) {
3333
try {
34-
await this.$platformService.addPlatforms([`${platform}@${frameworkPackageData.version}`], this.$options.platformTemplate, this.$projectData);
34+
await this.$platformService.addPlatforms([`${platform}@${frameworkPackageData.version}`], this.$options.platformTemplate, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk }, this.$options.frameworkPath);
3535
} catch (err) {
3636
error = `${error}${EOL}${err}`;
3737
}

lib/commands/livesync.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class LivesyncCommand implements ICommand {
2828
teamId: this.$options.teamId
2929
};
3030

31-
await this.$platformService.deployPlatform(args[0], appFilesUpdaterOptions, deployOptions, this.$projectData, this.$options.provision);
31+
await this.$platformService.deployPlatform(args[0], appFilesUpdaterOptions, deployOptions, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
3232
return this.$usbLiveSyncService.liveSync(args[0], this.$projectData);
3333
}
3434

lib/commands/platform-clean.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class CleanCommand implements ICommand {
1010

1111
public async execute(args: string[]): Promise<void> {
1212
await this.$platformService.removePlatforms(args, this.$projectData);
13-
await this.$platformService.addPlatforms(args, this.$options.platformTemplate, this.$projectData);
13+
await this.$platformService.addPlatforms(args, this.$options.platformTemplate, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
1414
}
1515

1616
public async canExecute(args: string[]): Promise<boolean> {

lib/commands/prepare.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class PrepareCommand implements ICommand {
1010

1111
public async execute(args: string[]): Promise<void> {
1212
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
13-
await this.$platformService.preparePlatform(args[0], appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, this.$options.provision);
13+
await this.$platformService.preparePlatform(args[0], appFilesUpdaterOptions, this.$options.platformTemplate, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
1414
}
1515

1616
public async canExecute(args: string[]): Promise<boolean> {

lib/commands/run.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class RunCommandBase {
2222
keyStorePassword: this.$options.keyStorePassword,
2323
keyStorePath: this.$options.keyStorePath
2424
};
25-
await this.$platformService.deployPlatform(args[0], appFilesUpdaterOptions, deployOptions, this.$projectData, this.$options.provision);
25+
await this.$platformService.deployPlatform(args[0], appFilesUpdaterOptions, deployOptions, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
2626

2727
if (this.$options.bundle) {
2828
this.$options.watch = false;

lib/commands/update-platform.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class UpdatePlatformCommand implements ICommand {
99
}
1010

1111
public async execute(args: string[]): Promise<void> {
12-
await this.$platformService.updatePlatforms(args, this.$options.platformTemplate, this.$projectData);
12+
await this.$platformService.updatePlatforms(args, this.$options.platformTemplate, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
1313
}
1414

1515
public async canExecute(args: string[]): Promise<boolean> {

lib/commands/update.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ export class UpdateCommand implements ICommand {
8383
platforms = platforms.concat(packagePlatforms);
8484
if (args.length === 1) {
8585
for (let platform of platforms) {
86-
await this.$platformService.addPlatforms([platform + "@" + args[0]], this.$options.platformTemplate, this.$projectData);
86+
await this.$platformService.addPlatforms([platform + "@" + args[0]], this.$options.platformTemplate, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk }, this.$options.frameworkPath);
8787
}
8888

8989
await this.$pluginsService.add("tns-core-modules@" + args[0], this.$projectData);
9090
} else {
91-
await this.$platformService.addPlatforms(platforms, this.$options.platformTemplate, this.$projectData);
91+
await this.$platformService.addPlatforms(platforms, this.$options.platformTemplate, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk }, this.$options.frameworkPath);
9292
await this.$pluginsService.add("tns-core-modules", this.$projectData);
9393
}
9494

lib/definitions/platform.d.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
interface IPlatformService extends NodeJS.EventEmitter {
2-
addPlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData): Promise<void>;
2+
addPlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, platformSpecificData: IPlatformSpecificData, frameworkPath?: string): Promise<void>;
33

44
/**
55
* Gets list of all installed platforms (the ones for which <project dir>/platforms/<platform> exists).
@@ -30,7 +30,7 @@ interface IPlatformService extends NodeJS.EventEmitter {
3030
*/
3131
removePlatforms(platforms: string[], projectData: IProjectData): Promise<void>;
3232

33-
updatePlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData): Promise<void>;
33+
updatePlatforms(platforms: string[], platformTemplate: string, projectData: IProjectData, platformSpecificData: IPlatformSpecificData): Promise<void>;
3434

3535
/**
3636
* Ensures that the specified platform and its dependencies are installed.
@@ -41,10 +41,10 @@ interface IPlatformService extends NodeJS.EventEmitter {
4141
* @param {IAppFilesUpdaterOptions} appFilesUpdaterOptions Options needed to instantiate AppFilesUpdater class.
4242
* @param {string} platformTemplate The name of the platform template.
4343
* @param {IProjectData} projectData DTO with information about the project.
44-
* @param {any} provision UUID of the provisioning profile used in iOS project preparation.
44+
* @param {IPlatformSpecificData} platformSpecificData Platform specific data required for project preparation.
4545
* @returns {boolean} true indicates that the platform was prepared.
4646
*/
47-
preparePlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, provision: any): Promise<boolean>;
47+
preparePlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, platformSpecificData: IPlatformSpecificData): Promise<boolean>;
4848

4949
/**
5050
* Determines whether a build is necessary. A build is necessary when one of the following is true:
@@ -103,10 +103,10 @@ interface IPlatformService extends NodeJS.EventEmitter {
103103
* @param {IAppFilesUpdaterOptions} appFilesUpdaterOptions Options needed to instantiate AppFilesUpdater class.
104104
* @param {IDeployPlatformOptions} deployOptions Various options that can manage the deploy operation.
105105
* @param {IProjectData} projectData DTO with information about the project.
106-
* @param {any} provision UUID of the provisioning profile used in iOS project preparation.
106+
* @param {any} platformSpecificData Platform specific data required for project preparation.
107107
* @returns {void}
108108
*/
109-
deployPlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, deployOptions: IDeployPlatformOptions, projectData: IProjectData, provision: any): Promise<void>;
109+
deployPlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, deployOptions: IDeployPlatformOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData): Promise<void>;
110110

111111
/**
112112
* Runs the application on specified platform. Assumes that the application is already build and installed. Fails if this is not true.
@@ -123,12 +123,12 @@ interface IPlatformService extends NodeJS.EventEmitter {
123123
* @param {IAppFilesUpdaterOptions} appFilesUpdaterOptions Options needed to instantiate AppFilesUpdater class.
124124
* @param {IEmulatePlatformOptions} emulateOptions Various options that can manage the emulate operation.
125125
* @param {IProjectData} projectData DTO with information about the project.
126-
* @param {any} provision UUID of the provisioning profile used in iOS project preparation.
126+
* @param {any} platformSpecificData Platform specific data required for project preparation.
127127
* @returns {void}
128128
*/
129-
emulatePlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, emulateOptions: IEmulatePlatformOptions, projectData: IProjectData, provision: any): Promise<void>;
129+
emulatePlatform(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, emulateOptions: IEmulatePlatformOptions, projectData: IProjectData, platformSpecificData: IPlatformSpecificData): Promise<void>;
130130

131-
cleanDestinationApp(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData): Promise<void>;
131+
cleanDestinationApp(platform: string, appFilesUpdaterOptions: IAppFilesUpdaterOptions, platformTemplate: string, projectData: IProjectData, platformSpecificData: IPlatformSpecificData): Promise<void>;
132132
validatePlatformInstalled(platform: string, projectData: IProjectData): void;
133133
validatePlatform(platform: string, projectData: IProjectData): void;
134134

@@ -177,6 +177,21 @@ interface IPlatformService extends NodeJS.EventEmitter {
177177
trackProjectType(projectData: IProjectData): Promise<void>;
178178
}
179179

180+
/**
181+
* Platform specific data required for project preparation.
182+
*/
183+
interface IPlatformSpecificData {
184+
/**
185+
* UUID of the provisioning profile used in iOS project preparation.
186+
*/
187+
provision: any;
188+
189+
/**
190+
* Target SDK for Android.s
191+
*/
192+
sdk: string;
193+
}
194+
180195
interface IPlatformData {
181196
frameworkPackageName: string;
182197
platformProjectService: IPlatformProjectService;

lib/definitions/project.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ interface IPlatformProjectService extends NodeJS.EventEmitter {
152152
getPlatformData(projectData: IProjectData): IPlatformData;
153153
validate(projectData: IProjectData): Promise<void>;
154154
createProject(frameworkDir: string, frameworkVersion: string, projectData: IProjectData, pathToTemplate?: string): Promise<void>;
155-
interpolateData(projectData: IProjectData): Promise<void>;
156-
interpolateConfigurationFile(projectData: IProjectData, sdk?: string): Promise<void>;
155+
interpolateData(projectData: IProjectData, platformSpecificData: IPlatformSpecificData): Promise<void>;
156+
interpolateConfigurationFile(projectData: IProjectData, platformSpecificData: IPlatformSpecificData): Promise<void>;
157157

158158
/**
159159
* Executes additional actions after native project is created.
@@ -176,10 +176,10 @@ interface IPlatformProjectService extends NodeJS.EventEmitter {
176176
/**
177177
* Prepares images in Native project (for iOS).
178178
* @param {IProjectData} projectData DTO with information about the project.
179-
* @param {any} provision UUID of the provisioning profile used in iOS project preparation.
179+
* @param {any} platformSpecificData Platform specific data required for project preparation.
180180
* @returns {void}
181181
*/
182-
prepareProject(projectData: IProjectData, provision: any): Promise<void>;
182+
prepareProject(projectData: IProjectData, platformSpecificData: IPlatformSpecificData): Promise<void>;
183183

184184
/**
185185
* Prepares App_Resources in the native project by clearing data from other platform and applying platform specific rules.

lib/providers/livesync-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class LiveSyncProvider implements ILiveSyncProvider {
5353

5454
public async preparePlatformForSync(platform: string, provision: any, projectData: IProjectData): Promise<void> {
5555
const appFilesUpdaterOptions: IAppFilesUpdaterOptions = { bundle: this.$options.bundle, release: this.$options.release };
56-
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, projectData, provision);
56+
await this.$platformService.preparePlatform(platform, appFilesUpdaterOptions, this.$options.platformTemplate, projectData, { provision: provision, sdk: this.$options.sdk });
5757
}
5858

5959
public canExecuteFastSync(filePath: string, projectData: IProjectData, platform: string): boolean {

lib/services/android-project-service.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
183183
_.map(directoriesToClean, dir => this.$fs.deleteDirectory(dir));
184184
}
185185

186-
public async interpolateData(projectData: IProjectData): Promise<void> {
186+
public async interpolateData(projectData: IProjectData, platformSpecificData: IPlatformSpecificData): Promise<void> {
187187
// Interpolate the apilevel and package
188-
await this.interpolateConfigurationFile(projectData);
188+
await this.interpolateConfigurationFile(projectData, platformSpecificData);
189189

190190
let stringsFilePath = path.join(this.getAppResourcesDestinationDirectoryPath(projectData), 'values', 'strings.xml');
191191
shell.sed('-i', /__NAME__/, projectData.projectName, stringsFilePath);
@@ -204,10 +204,11 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
204204
}
205205
}
206206

207-
public async interpolateConfigurationFile(projectData: IProjectData, sdk?: string): Promise<void> {
207+
public async interpolateConfigurationFile(projectData: IProjectData, platformSpecificData: IPlatformSpecificData): Promise<void> {
208208
let manifestPath = this.getPlatformData(projectData).configurationFilePath;
209209
shell.sed('-i', /__PACKAGE__/, projectData.projectId, manifestPath);
210-
shell.sed('-i', /__APILEVEL__/, sdk || (await this.$androidToolsInfo.getToolsInfo()).compileSdkVersion.toString(), manifestPath);
210+
const sdk = (platformSpecificData && platformSpecificData.sdk) || (await this.$androidToolsInfo.getToolsInfo()).compileSdkVersion.toString();
211+
shell.sed('-i', /__APILEVEL__/, sdk, manifestPath);
211212
}
212213

213214
private getProjectNameFromId(projectData: IProjectData): string {

0 commit comments

Comments
 (0)