Skip to content

Commit 002f8a0

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 Fix comments. Fix comments chore: send projectDir instead of projectData to PluginVariableService. chore: fix comments chore: fix tests
1 parent 6d88123 commit 002f8a0

26 files changed

+216
-125
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
@@ -161,6 +161,16 @@ interface ILiveSyncInfo extends IProjectDir, IEnvOptions, IBundle, IRelease, IOp
161161
clean?: boolean;
162162
}
163163

164+
interface ILiveSyncEventData {
165+
deviceIdentifier: string,
166+
applicationIdentifier?: string,
167+
projectDir: string,
168+
syncedFiles?: Object
169+
error? : Error,
170+
notification?: string,
171+
isFullSync?: boolean
172+
}
173+
164174
interface ILatestAppPackageInstalledSettings extends IDictionary<IDictionary<boolean>> { /* empty */ }
165175

166176
interface IIsEmulator {

lib/definitions/plugins.d.ts

+8-9
Original file line numberDiff line numberDiff line change
@@ -49,40 +49,39 @@ interface IPluginVariablesService {
4949
/**
5050
* Saves plugin variables in project package.json file.
5151
* @param {IPluginData} pluginData for the plugin.
52-
* @param {IProjectData} projectData DTO with information about the project.
52+
* @param {string} projectDir: Specifies the directory of the project.
5353
* @return {Promise<void>}
5454
*/
55-
savePluginVariablesInProjectFile(pluginData: IPluginData, projectData: IProjectData): Promise<void>;
55+
savePluginVariablesInProjectFile(pluginData: IPluginData, projectDir: string): Promise<void>;
5656

5757
/**
5858
* Removes plugin variables from project package.json file.
5959
* @param {string} pluginName Name of the plugin.
60-
* @param {IProjectData} projectData DTO with information about the project.
60+
* @param {string} projectDir: Specifies the directory of the project.
6161
* @return {void}
6262
*/
63-
removePluginVariablesFromProjectFile(pluginName: string, projectData: IProjectData): void;
63+
removePluginVariablesFromProjectFile(pluginName: string, projectDir: string): void;
6464

6565
/**
6666
* Replaces all plugin variables with their corresponding values.
6767
* @param {IPluginData} pluginData for the plugin.
6868
* @param {pluginConfigurationFilePath} pluginConfigurationFilePath for the plugin.
69-
* @param {IProjectData} projectData DTO with information about the project.
69+
* @param {string} projectDir: Specifies the directory of the project.
7070
* @return {Promise<void>}
7171
*/
72-
interpolatePluginVariables(pluginData: IPluginData, pluginConfigurationFilePath: string, projectData: IProjectData): Promise<void>;
72+
interpolatePluginVariables(pluginData: IPluginData, pluginConfigurationFilePath: string, projectDir: string): Promise<void>;
7373

7474
/**
7575
* Replaces {nativescript.id} expression with the application identifier from package.json.
7676
* @param {pluginConfigurationFilePath} pluginConfigurationFilePath for the plugin.
77-
* @param {IProjectData} projectData DTO with information about the project.
7877
* @return {void}
7978
*/
80-
interpolateAppIdentifier(pluginConfigurationFilePath: string, projectData: IProjectData): void;
79+
interpolateAppIdentifier(pluginConfigurationFilePath: string, projectIdentifier: string): void;
8180

8281
/**
8382
* Replaces both plugin variables and appIdentifier
8483
*/
85-
interpolate(pluginData: IPluginData, pluginConfigurationFilePath: string, projectData: IProjectData): Promise<void>;
84+
interpolate(pluginData: IPluginData, pluginConfigurationFilePath: string, projectDir: string, projectIdentifier: string): Promise<void>;
8685

8786
/**
8887
* Returns the

lib/definitions/project.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ interface INsConfig {
6969
interface IProjectData extends ICreateProjectData {
7070
platformsDir: string;
7171
projectFilePath: string;
72-
projectId?: string;
72+
projectId: string;
73+
projectIdentifiers?: Mobile.IProjectIdentifier;
7374
dependencies: any;
7475
devDependencies: IStringDictionary;
7576
appDirectoryPath: string;

lib/helpers/livesync-command-helper.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,14 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
152152
};
153153

154154
await this.$platformService.deployPlatform(deployPlatformInfo);
155-
await this.$platformService.startApplication(currentPlatform, runPlatformOptions, { appId: this.$projectData.projectId, projectName: this.$projectData.projectName });
155+
await this.$platformService.startApplication(
156+
currentPlatform,
157+
runPlatformOptions,
158+
{
159+
appId: this.$projectData.projectIdentifiers[currentPlatform.toLowerCase()],
160+
projectName: this.$projectData.projectName
161+
}
162+
);
156163
this.$platformService.trackProjectType(this.$projectData);
157164
}
158165
}

lib/project-data.ts

+37-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as constants from "./constants";
22
import * as path from "path";
33
import { parseJson } from "./common/helpers";
44
import { EOL } from "os";
5+
import { cache } from "./common/decorators";
56

67
interface IProjectType {
78
type: string;
@@ -35,7 +36,17 @@ export class ProjectData implements IProjectData {
3536
public projectDir: string;
3637
public platformsDir: string;
3738
public projectFilePath: string;
38-
public projectId: string;
39+
public projectIdentifiers: Mobile.IProjectIdentifier;
40+
get projectId(): string {
41+
this.warnProjectId();
42+
return this.projectIdentifiers.ios;
43+
}
44+
//just in case hook/extension modifies it.
45+
set projectId(identifier: string) {
46+
this.warnProjectId();
47+
this.projectIdentifiers.ios = identifier;
48+
this.projectIdentifiers.android = identifier;
49+
}
3950
public projectName: string;
4051
public nsConfig: INsConfig;
4152
public appDirectoryPath: string;
@@ -108,7 +119,7 @@ export class ProjectData implements IProjectData {
108119
this.projectName = this.$projectHelper.sanitizeName(path.basename(projectDir));
109120
this.platformsDir = path.join(projectDir, constants.PLATFORMS_DIR_NAME);
110121
this.projectFilePath = projectFilePath;
111-
this.projectId = nsData.id;
122+
this.projectIdentifiers = this.initializeProjectIdentifiers(nsData.id);
112123
this.dependencies = packageJsonData.dependencies;
113124
this.devDependencies = packageJsonData.devDependencies;
114125
this.projectType = this.getProjectType();
@@ -206,6 +217,25 @@ export class ProjectData implements IProjectData {
206217
return path.resolve(projectDir, pathToResolve);
207218
}
208219

220+
private initializeProjectIdentifiers(data: string | Mobile.IProjectIdentifier): Mobile.IProjectIdentifier {
221+
let identifier: Mobile.IProjectIdentifier;
222+
data = data || "";
223+
224+
if (typeof data === "string") {
225+
identifier = {
226+
android: data,
227+
ios: data
228+
};
229+
} else {
230+
identifier = {
231+
android: data.android || "",
232+
ios: data.ios || ""
233+
};
234+
}
235+
236+
return identifier;
237+
}
238+
209239
private getProjectType(): string {
210240
let detectedProjectType = _.find(ProjectData.PROJECT_TYPES, (projectType) => projectType.isDefaultProjectType).type;
211241

@@ -220,5 +250,10 @@ export class ProjectData implements IProjectData {
220250

221251
return detectedProjectType;
222252
}
253+
254+
@cache()
255+
private warnProjectId(): void {
256+
this.$logger.warnWithLabel("IProjectData.projectId is deprecated. Please use IProjectData.projectIdentifiers[platform].");
257+
}
223258
}
224259
$injector.register("projectData", ProjectData);

lib/services/android-project-service.ts

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

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

136136
await this.$platformEnvironmentRequirements.checkEnvironmentRequirements(this.getPlatformData(projectData).normalizedPlatformName);
@@ -256,15 +256,16 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
256256

257257
try {
258258
// will replace applicationId in app/App_Resources/Android/app.gradle if it has not been edited by the user
259-
shell.sed('-i', /__PACKAGE__/, projectData.projectId, projectData.appGradlePath);
259+
//TODO: For compatibility with old templates. Once all templates are updated should delete.
260+
shell.sed('-i', /__PACKAGE__/, projectData.projectIdentifiers.android, projectData.appGradlePath);
260261
} catch (e) {
261-
this.$logger.warn(`\n${e}.\nCheck if you're using an outdated template and update it.`);
262+
this.$logger.trace(`Templates updated and no need for replace in app.gradle.`);
262263
}
263264
}
264265

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

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

@@ -511,7 +512,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
511512
const filesForInterpolation = this.$fs.enumerateFilesInDirectorySync(resourcesDestinationDirectoryPath, file => this.$fs.getFsStats(file).isDirectory() || path.extname(file) === constants.XML_FILE_EXTENSION) || [];
512513
for (const file of filesForInterpolation) {
513514
this.$logger.trace(`Interpolate data for plugin file: ${file}`);
514-
await this.$pluginVariablesService.interpolate(pluginData, file, projectData);
515+
await this.$pluginVariablesService.interpolate(pluginData, file, projectData.projectDir, projectData.projectIdentifiers.android);
515516
}
516517
}
517518

@@ -618,7 +619,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
618619

619620
public async cleanDeviceTempFolder(deviceIdentifier: string, projectData: IProjectData): Promise<void> {
620621
const adb = this.$injector.resolve(DeviceAndroidDebugBridge, { identifier: deviceIdentifier });
621-
const deviceRootPath = `/data/local/tmp/${projectData.projectId}`;
622+
const deviceRootPath = `/data/local/tmp/${projectData.projectIdentifiers.android}`;
622623
await adb.executeShellCommand(["rm", "-rf", deviceRootPath]);
623624
}
624625

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
244244
if (options && options.provision) {
245245
plistTemplate += ` <key>provisioningProfiles</key>
246246
<dict>
247-
<key>${projectData.projectId}</key>
247+
<key>${projectData.projectIdentifiers.ios}</key>
248248
<string>${options.provision}</string>
249249
</dict>`;
250250
}
@@ -291,7 +291,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
291291
if (options && options.provision) {
292292
plistTemplate += ` <key>provisioningProfiles</key>
293293
<dict>
294-
<key>${projectData.projectId}</key>
294+
<key>${projectData.projectIdentifiers.ios}</key>
295295
<string>${options.provision}</string>
296296
</dict>`;
297297
}
@@ -499,7 +499,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
499499

500500
if (shouldUpdateXcode) {
501501
const pickStart = Date.now();
502-
const mobileprovision = mobileProvisionData || await this.$iOSProvisionService.pick(provision, projectData.projectId);
502+
const mobileprovision = mobileProvisionData || await this.$iOSProvisionService.pick(provision, projectData.projectIdentifiers.ios);
503503
const pickEnd = Date.now();
504504
this.$logger.trace("Searched and " + (mobileprovision ? "found" : "failed to find ") + " matching provisioning profile. (" + (pickEnd - pickStart) + "ms.)");
505505
if (!mobileprovision) {
@@ -764,10 +764,10 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
764764
await this.$iOSEntitlementsService.merge(projectData);
765765
await this.mergeProjectXcconfigFiles(release, projectData);
766766
for (const pluginData of await this.getAllInstalledPlugins(projectData)) {
767-
await this.$pluginVariablesService.interpolatePluginVariables(pluginData, this.getPlatformData(projectData).configurationFilePath, projectData);
767+
await this.$pluginVariablesService.interpolatePluginVariables(pluginData, this.getPlatformData(projectData).configurationFilePath, projectData.projectDir);
768768
}
769769

770-
this.$pluginVariablesService.interpolateAppIdentifier(this.getPlatformData(projectData).configurationFilePath, projectData);
770+
this.$pluginVariablesService.interpolateAppIdentifier(this.getPlatformData(projectData).configurationFilePath, projectData.projectIdentifiers.ios);
771771
}
772772

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

829829
makePatch(infoPlistPath);
830830

831-
if (projectData.projectId) {
831+
if (projectData.projectIdentifiers && projectData.projectIdentifiers.ios) {
832832
session.patch({
833833
name: "CFBundleIdentifier from package.json nativescript.id",
834834
read: () =>
@@ -837,13 +837,13 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
837837
<plist version="1.0">
838838
<dict>
839839
<key>CFBundleIdentifier</key>
840-
<string>${projectData.projectId}</string>
840+
<string>${projectData.projectIdentifiers.ios}</string>
841841
</dict>
842842
</plist>`
843843
});
844844
}
845845

846-
if (!buildOptions.release && projectData.projectId) {
846+
if (!buildOptions.release && projectData.projectIdentifiers && projectData.projectIdentifiers.ios) {
847847
session.patch({
848848
name: "CFBundleURLTypes from package.json nativescript.id",
849849
read: () =>
@@ -858,7 +858,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
858858
<string>Editor</string>
859859
<key>CFBundleURLSchemes</key>
860860
<array>
861-
<string>${projectData.projectId.replace(/[^A-Za-z0-9]/g, "")}</string>
861+
<string>${projectData.projectIdentifiers.ios.replace(/[^A-Za-z0-9]/g, "")}</string>
862862
</array>
863863
</dict>
864864
</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
@@ -67,7 +67,7 @@ export class IOSDeviceLiveSyncService extends DeviceLiveSyncServiceBase implemen
6767
return;
6868
}
6969

70-
if (await this.setupSocketIfNeeded(projectData.projectId)) {
70+
if (await this.setupSocketIfNeeded(projectData.projectIdentifiers.ios)) {
7171
await this.liveEdit(scriptFiles);
7272
await this.reloadPage(deviceAppData, otherFiles);
7373
} else {

0 commit comments

Comments
 (0)