Skip to content

Commit 00b80f7

Browse files
Fix several issues in @next version (#2591)
* Fix adding of invalid platform When user tries to add invalid platform, CLI should prints user-friendly message. Instead it fails that cannot read `getPlatformData` of `undefined`. The reason is a change in platforms-data `getPlatformsData` method. Fix it to return undefined when there's no platform specific data. This way the code will detect the invalid platform and will fail with user-friendly message. * 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. * Pass android specific options for emulate command In case you want to use `tns emulate android --release`, several android specific options should be passed and used by the service. Even when they are passed on the command line, we did not pass them to the service. Pass required options, so the release build will be successfully signed. * Fix livesync watch operations LiveSync provider that detects how to process the files, needs the projectData. However we had not passed it and the code fails. Pass the data wherever its needed. This fixes livesync operations.
1 parent 8f9c273 commit 00b80f7

28 files changed

+127
-105
lines changed

lib/commands/add-platform.ts

+1-1
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

+2-2
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

+3-3
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

+1-1
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

+1-1
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

+3-3
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

+6-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ export class EmulateCommandBase {
1919
availableDevices: this.$options.availableDevices,
2020
platformTemplate: this.$options.platformTemplate,
2121
provision: this.$options.provision,
22-
teamId: this.$options.teamId
22+
teamId: this.$options.teamId,
23+
keyStoreAlias: this.$options.keyStoreAlias,
24+
keyStoreAliasPassword: this.$options.keyStoreAliasPassword,
25+
keyStorePassword: this.$options.keyStorePassword,
26+
keyStorePath: this.$options.keyStorePath
2327
};
24-
return this.$platformService.emulatePlatform(args[0], appFilesUpdaterOptions, emulateOptions, this.$projectData, this.$options.provision);
28+
return this.$platformService.emulatePlatform(args[0], appFilesUpdaterOptions, emulateOptions, this.$projectData, { provision: this.$options.provision, sdk: this.$options.sdk });
2529
}
2630
}
2731

lib/commands/install.ts

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+2-2
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/declarations.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ interface INativeScriptDeviceLiveSyncService extends IDeviceLiveSyncServiceBase
6060
* @param {Mobile.IDeviceAppData} deviceAppData Information about the application and the device.
6161
* @param {Mobile.ILocalToDevicePathData[]} localToDevicePaths Object containing a mapping of file paths from the system to the device.
6262
* @param {boolean} forceExecuteFullSync If this is passed a full LiveSync is performed instead of an incremental one.
63-
* @param {string} projectId Project identifier - for example org.nativescript.livesync.
63+
* @param {IProjectData} projectData Project data.
6464
* @return {Promise<void>}
6565
*/
66-
refreshApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], forceExecuteFullSync: boolean, projectId: string): Promise<void>;
66+
refreshApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], forceExecuteFullSync: boolean, projectData: IProjectData): Promise<void>;
6767
/**
6868
* Removes specified files from a connected device
6969
* @param {string} appIdentifier Application identifier.
@@ -78,7 +78,7 @@ interface INativeScriptDeviceLiveSyncService extends IDeviceLiveSyncServiceBase
7878
interface IPlatformLiveSyncService {
7979
fullSync(projectData: IProjectData, postAction?: (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => Promise<void>): Promise<void>;
8080
partialSync(event: string, filePath: string, dispatcher: IFutureDispatcher, afterFileSyncAction: (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => Promise<void>, projectData: IProjectData): Promise<void>;
81-
refreshApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], isFullSync: boolean, projectId: string): Promise<void>;
81+
refreshApplication(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], isFullSync: boolean, projectData: IProjectData): Promise<void>;
8282
}
8383

8484
interface IBundle {

lib/definitions/platform.d.ts

+24-9
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

+4-4
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/platforms-data.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class PlatformsData implements IPlatformsData {
1515
}
1616

1717
public getPlatformData(platform: string, projectData: IProjectData): IPlatformData {
18-
return this.platformsData[platform.toLowerCase()].getPlatformData(projectData);
18+
return this.platformsData[platform.toLowerCase()] && this.platformsData[platform.toLowerCase()].getPlatformData(projectData);
1919
}
2020

2121
public get availablePlatforms(): any {

0 commit comments

Comments
 (0)