Skip to content

Commit 1814c4b

Browse files
committed
Add platform specific app identifier in package.json.
Rename projectId to projectIdentifiers. projectId is left as getter and setter to avoid breaking change in hooks and CLI extensions Fix ui tests for platform service and safeguard missing id. Remove breaking change from debug data. Use IProjectDefinition from mobile-cli-lib
1 parent 6522178 commit 1814c4b

24 files changed

+148
-67
lines changed

lib/commands/debug.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ export class DebugPlatformCommand implements ICommand {
2424
public async execute(args: string[]): Promise<void> {
2525
const debugOptions = <IDebugOptions>_.cloneDeep(this.$options.argv);
2626

27-
const debugData = this.$debugDataService.createDebugData(this.$projectData, this.$options);
28-
2927
await this.$platformService.trackProjectType(this.$projectData);
3028
const selectedDeviceForDebug = await this.getDeviceForDebug();
31-
debugData.deviceIdentifier = selectedDeviceForDebug.deviceInfo.identifier;
29+
30+
const debugData = this.$debugDataService.createDebugData(this.$projectData, {device: selectedDeviceForDebug.deviceInfo.identifier});
3231

3332
if (this.$options.start) {
3433
await this.$liveSyncService.printDebugInformation(await this.$debugService.debug(debugData, debugOptions));

lib/definitions/livesync.d.ts

+10
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ interface ILiveSyncInfo extends IProjectDir, IEnvOptions {
135135
clean?: boolean;
136136
}
137137

138+
interface ILivesyncEventData {
139+
deviceIdentifier: string,
140+
applicationIdentifier?: string,
141+
projectDir: string,
142+
syncedFiles?: Object
143+
error? : Error,
144+
notification?: string,
145+
isFullSync?: boolean
146+
}
147+
138148
interface ILatestAppPackageInstalledSettings extends IDictionary<IDictionary<boolean>> { /* empty */ }
139149

140150
interface IIsEmulator {

lib/definitions/plugins.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ interface IPluginVariablesService {
7777
* @param {IProjectData} projectData DTO with information about the project.
7878
* @return {void}
7979
*/
80-
interpolateAppIdentifier(pluginConfigurationFilePath: string, projectData: IProjectData): void;
80+
interpolateAppIdentifier(pluginConfigurationFilePath: string, projectIdentifier: string): void;
8181

8282
/**
8383
* Replaces both plugin variables and appIdentifier
8484
*/
85-
interpolate(pluginData: IPluginData, pluginConfigurationFilePath: string, projectData: IProjectData): Promise<void>;
85+
interpolate(pluginData: IPluginData, pluginConfigurationFilePath: string, projectData: IProjectData, projectIdentifier: string): Promise<void>;
8686

8787
/**
8888
* Returns the

lib/definitions/project.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ interface IProjectData extends IProjectDir {
5757
projectName: string;
5858
platformsDir: string;
5959
projectFilePath: string;
60-
projectId?: string;
60+
projectId: string;
61+
projectIdentifiers?: Mobile.IProjectIdentifier;
6162
dependencies: any;
6263
devDependencies: IStringDictionary;
6364
appDirectoryPath: string;

lib/project-data.ts

+35-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,16 @@ export class ProjectData implements IProjectData {
3030
public projectDir: string;
3131
public platformsDir: string;
3232
public projectFilePath: string;
33-
public projectId: string;
33+
public projectIdentifiers: Mobile.IProjectIdentifier;
34+
get projectId(): string {
35+
this.warnProjectId();
36+
return this.projectIdentifiers.ios;
37+
}
38+
set projectId(identifier: string) {
39+
this.warnProjectId();
40+
this.projectIdentifiers.ios = identifier;
41+
this.projectIdentifiers.android = identifier;
42+
}
3443
public projectName: string;
3544
public appDirectoryPath: string;
3645
public appResourcesDirectoryPath: string;
@@ -47,6 +56,7 @@ export class ProjectData implements IProjectData {
4756

4857
public initializeProjectData(projectDir?: string): void {
4958
projectDir = projectDir || this.$projectHelper.projectDir;
59+
5060
// If no project found, projectDir should be null
5161
if (projectDir) {
5262
const projectFilePath = path.join(projectDir, this.$staticConfig.PROJECT_FILE_NAME);
@@ -70,7 +80,7 @@ export class ProjectData implements IProjectData {
7080
this.projectFilePath = projectFilePath;
7181
this.appDirectoryPath = path.join(projectDir, constants.APP_FOLDER_NAME);
7282
this.appResourcesDirectoryPath = path.join(projectDir, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME);
73-
this.projectId = data.id;
83+
this.projectIdentifiers = this.getProjectIdentifiers(data.id);
7484
this.dependencies = fileContent.dependencies;
7585
this.devDependencies = fileContent.devDependencies;
7686
this.projectType = this.getProjectType();
@@ -87,6 +97,25 @@ export class ProjectData implements IProjectData {
8797
this.$errors.fail("No project found at or above '%s' and neither was a --path specified.", projectDir || this.$options.path || currentDir);
8898
}
8999

100+
private getProjectIdentifiers(data :any): Mobile.IProjectIdentifier {
101+
let identifier: Mobile.IProjectIdentifier;
102+
data = data || "";
103+
104+
if (typeof data === "string") {
105+
identifier = {
106+
android: data,
107+
ios: data
108+
};
109+
} else {
110+
identifier = {
111+
android: data.android || "",
112+
ios: data.ios || ""
113+
};
114+
}
115+
116+
return identifier;
117+
}
118+
90119
private getProjectType(): string {
91120
let detectedProjectType = _.find(ProjectData.PROJECT_TYPES, (projectType) => projectType.isDefaultProjectType).type;
92121

@@ -101,5 +130,9 @@ export class ProjectData implements IProjectData {
101130

102131
return detectedProjectType;
103132
}
133+
134+
private warnProjectId(): void {
135+
this.$logger.warnWithLabel("IProjectData.projectId is depricated. Please use IProjectData.projectIdentifiers[platform].");
136+
}
104137
}
105138
$injector.register("projectData", ProjectData);

lib/services/android-project-service.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
131131
}
132132

133133
public async validate(projectData: IProjectData): Promise<void> {
134-
this.validatePackageName(projectData.projectId);
134+
this.validatePackageName(projectData.projectIdentifiers.android);
135135
this.validateProjectName(projectData.projectName);
136136

137137
this.$androidToolsInfo.validateAndroidHomeEnvVariable({ showWarningsAsErrors: true });
@@ -254,16 +254,17 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
254254
// will replace applicationId in app/App_Resources/Android/app.gradle if it has not been edited by the user
255255
const userAppGradleFilePath = path.join(projectData.appResourcesDirectoryPath, this.$devicePlatformsConstants.Android, "app.gradle");
256256

257+
//TODO: kddimitrov: For compatability with old templates. Once all templates are updated should delete.
257258
try {
258-
shell.sed('-i', /__PACKAGE__/, projectData.projectId, userAppGradleFilePath);
259+
shell.sed('-i', /__PACKAGE__/, projectData.projectIdentifiers.android, userAppGradleFilePath);
259260
} catch (e) {
260-
this.$logger.warn(`\n${e}.\nCheck if you're using an outdated template and update it.`);
261+
// Ignore
261262
}
262263
}
263264

264265
public interpolateConfigurationFile(projectData: IProjectData, platformSpecificData: IPlatformSpecificData): void {
265266
const manifestPath = this.getPlatformData(projectData).configurationFilePath;
266-
shell.sed('-i', /__PACKAGE__/, projectData.projectId, manifestPath);
267+
shell.sed('-i', /__PACKAGE__/, projectData.projectIdentifiers.android, manifestPath);
267268
if (this.$androidToolsInfo.getToolsInfo().androidHomeEnvVar) {
268269
const sdk = (platformSpecificData && platformSpecificData.sdk) || (this.$androidToolsInfo.getToolsInfo().compileSdkVersion || "").toString();
269270
shell.sed('-i', /__APILEVEL__/, sdk, manifestPath);
@@ -272,8 +273,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
272273

273274
private getProjectNameFromId(projectData: IProjectData): string {
274275
let id: string;
275-
if (projectData && projectData.projectId) {
276-
const idParts = projectData.projectId.split(".");
276+
if (projectData && projectData.projectIdentifiers && projectData.projectIdentifiers.android) {
277+
const idParts = projectData.projectIdentifiers.android.split(".");
277278
id = idParts[idParts.length - 1];
278279
}
279280

@@ -427,7 +428,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
427428
const filesForInterpolation = this.$fs.enumerateFilesInDirectorySync(resourcesDestinationDirectoryPath, file => this.$fs.getFsStats(file).isDirectory() || path.extname(file) === constants.XML_FILE_EXTENSION) || [];
428429
for (const file of filesForInterpolation) {
429430
this.$logger.trace(`Interpolate data for plugin file: ${file}`);
430-
await this.$pluginVariablesService.interpolate(pluginData, file, projectData);
431+
await this.$pluginVariablesService.interpolate(pluginData, file, projectData, projectData.projectIdentifiers.android);
431432
}
432433
}
433434

@@ -534,7 +535,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
534535

535536
public async cleanDeviceTempFolder(deviceIdentifier: string, projectData: IProjectData): Promise<void> {
536537
const adb = this.$injector.resolve(DeviceAndroidDebugBridge, { identifier: deviceIdentifier });
537-
const deviceRootPath = `/data/local/tmp/${projectData.projectId}`;
538+
const deviceRootPath = `/data/local/tmp/${projectData.projectIdentifiers.android}`;
538539
await adb.executeShellCommand(["rm", "-rf", deviceRootPath]);
539540
}
540541

lib/services/debug-data-service.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
export class DebugDataService implements IDebugDataService {
2+
constructor(
3+
private $devicesService: Mobile.IDevicesService
4+
) { }
25
public createDebugData(projectData: IProjectData, options: IDeviceIdentifier): IDebugData {
6+
const device = this.$devicesService.getDeviceByIdentifier(options.device);
7+
38
return {
4-
applicationIdentifier: projectData.projectId,
9+
applicationIdentifier: projectData.projectIdentifiers[device.deviceInfo.platform.toLowerCase()],
510
projectDir: projectData.projectDir,
611
deviceIdentifier: options.device,
712
projectName: projectData.projectName

lib/services/ios-project-service.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
232232
if (options && options.provision) {
233233
plistTemplate += ` <key>provisioningProfiles</key>
234234
<dict>
235-
<key>${projectData.projectId}</key>
235+
<key>${projectData.projectIdentifiers.ios}</key>
236236
<string>${options.provision}</string>
237237
</dict>`;
238238
}
@@ -279,7 +279,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
279279
if (options && options.provision) {
280280
plistTemplate += ` <key>provisioningProfiles</key>
281281
<dict>
282-
<key>${projectData.projectId}</key>
282+
<key>${projectData.projectIdentifiers.ios}</key>
283283
<string>${options.provision}</string>
284284
</dict>`;
285285
}
@@ -491,7 +491,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
491491

492492
if (shouldUpdateXcode) {
493493
const pickStart = Date.now();
494-
const mobileprovision = mobileProvisionData || await this.$iOSProvisionService.pick(provision, projectData.projectId);
494+
const mobileprovision = mobileProvisionData || await this.$iOSProvisionService.pick(provision, projectData.projectIdentifiers.ios);
495495
const pickEnd = Date.now();
496496
this.$logger.trace("Searched and " + (mobileprovision ? "found" : "failed to find ") + " matching provisioning profile. (" + (pickEnd - pickStart) + "ms.)");
497497
if (!mobileprovision) {
@@ -755,7 +755,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
755755
await this.$pluginVariablesService.interpolatePluginVariables(pluginData, this.getPlatformData(projectData).configurationFilePath, projectData);
756756
}
757757

758-
this.$pluginVariablesService.interpolateAppIdentifier(this.getPlatformData(projectData).configurationFilePath, projectData);
758+
this.$pluginVariablesService.interpolateAppIdentifier(this.getPlatformData(projectData).configurationFilePath, projectData.projectIdentifiers.ios);
759759
}
760760

761761
private getInfoPlistPath(projectData: IProjectData): string {
@@ -818,7 +818,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
818818

819819
makePatch(infoPlistPath);
820820

821-
if (projectData.projectId) {
821+
if (projectData.projectIdentifiers && projectData.projectIdentifiers.ios) {
822822
session.patch({
823823
name: "CFBundleIdentifier from package.json nativescript.id",
824824
read: () =>
@@ -827,13 +827,13 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
827827
<plist version="1.0">
828828
<dict>
829829
<key>CFBundleIdentifier</key>
830-
<string>${projectData.projectId}</string>
830+
<string>${projectData.projectIdentifiers.ios}</string>
831831
</dict>
832832
</plist>`
833833
});
834834
}
835835

836-
if (!buildOptions.release && projectData.projectId) {
836+
if (!buildOptions.release && projectData.projectIdentifiers && projectData.projectIdentifiers.ios) {
837837
session.patch({
838838
name: "CFBundleURLTypes from package.json nativescript.id",
839839
read: () =>
@@ -848,7 +848,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
848848
<string>Editor</string>
849849
<key>CFBundleURLSchemes</key>
850850
<array>
851-
<string>${projectData.projectId.replace(/[^A-Za-z0-9]/g, "")}</string>
851+
<string>${projectData.projectIdentifiers.ios.replace(/[^A-Za-z0-9]/g, "")}</string>
852852
</array>
853853
</dict>
854854
</array>

lib/services/itmstransporter-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class ITMSTransporterService implements IITMSTransporterService {
110110
private async getBundleIdentifier(ipaFileFullPath?: string): Promise<string> {
111111
if (!this._bundleIdentifier) {
112112
if (!ipaFileFullPath) {
113-
this._bundleIdentifier = this.$projectData.projectId;
113+
this._bundleIdentifier = this.$projectData.projectIdentifiers.ios;
114114
} else {
115115
if (!this.$fs.exists(ipaFileFullPath) || path.extname(ipaFileFullPath) !== ".ipa") {
116116
this.$errors.failWithoutHelp(`Cannot use specified ipa file ${ipaFileFullPath}. File either does not exist or is not an ipa file.`);

lib/services/livesync/ios-device-livesync-service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export class IOSDeviceLiveSyncService extends DeviceLiveSyncServiceBase implemen
7070
return;
7171
}
7272

73-
if (await this.setupSocketIfNeeded(projectData.projectId)) {
73+
if (await this.setupSocketIfNeeded(projectData.projectIdentifiers.ios)) {
7474
await this.liveEdit(scriptFiles);
7575
await this.reloadPage(deviceAppData, otherFiles);
7676
} else {

lib/services/livesync/livesync-command-helper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
106106
};
107107

108108
await this.$platformService.deployPlatform(deployPlatformInfo);
109-
await this.$platformService.startApplication(currentPlatform, runPlatformOptions, this.$projectData.projectId);
109+
await this.$platformService.startApplication(currentPlatform, runPlatformOptions, this.$projectData.projectIdentifiers[currentPlatform.toLowerCase()]);
110110
this.$platformService.trackProjectType(this.$projectData);
111111
}
112112
}

0 commit comments

Comments
 (0)