Skip to content

Kddimitrov/add platform application identifier setting #3120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions lib/commands/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ export class DebugPlatformCommand extends ValidatePlatformCommandBase implements

const debugOptions = <IDebugOptions>_.cloneDeep(this.$options.argv);

const debugData = this.$debugDataService.createDebugData(this.$projectData, this.$options);

await this.$platformService.trackProjectType(this.$projectData);
const selectedDeviceForDebug = await this.getDeviceForDebug();
debugData.deviceIdentifier = selectedDeviceForDebug.deviceInfo.identifier;

const debugData = this.$debugDataService.createDebugData(this.$projectData, {device: selectedDeviceForDebug.deviceInfo.identifier});

if (this.$options.start) {
await this.$liveSyncService.printDebugInformation(await this.$debugService.debug(debugData, debugOptions));
Expand Down
10 changes: 10 additions & 0 deletions lib/definitions/livesync.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ interface IHasUseHotModuleReloadOption {
useHotModuleReload: boolean;
}

interface ILiveSyncEventData {
deviceIdentifier: string,
applicationIdentifier?: string,
projectDir: string,
syncedFiles?: string[],
error? : Error,
notification?: string,
isFullSync?: boolean
}

interface ILatestAppPackageInstalledSettings extends IDictionary<IDictionary<boolean>> { /* empty */ }

interface IIsEmulator {
Expand Down
17 changes: 8 additions & 9 deletions lib/definitions/plugins.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,39 @@ interface IPluginVariablesService {
/**
* Saves plugin variables in project package.json file.
* @param {IPluginData} pluginData for the plugin.
* @param {IProjectData} projectData DTO with information about the project.
* @param {string} projectDir: Specifies the directory of the project.
* @return {Promise<void>}
*/
savePluginVariablesInProjectFile(pluginData: IPluginData, projectData: IProjectData): Promise<void>;
savePluginVariablesInProjectFile(pluginData: IPluginData, projectDir: string): Promise<void>;

/**
* Removes plugin variables from project package.json file.
* @param {string} pluginName Name of the plugin.
* @param {IProjectData} projectData DTO with information about the project.
* @param {string} projectDir: Specifies the directory of the project.
* @return {void}
*/
removePluginVariablesFromProjectFile(pluginName: string, projectData: IProjectData): void;
removePluginVariablesFromProjectFile(pluginName: string, projectDir: string): void;

/**
* Replaces all plugin variables with their corresponding values.
* @param {IPluginData} pluginData for the plugin.
* @param {pluginConfigurationFilePath} pluginConfigurationFilePath for the plugin.
* @param {IProjectData} projectData DTO with information about the project.
* @param {string} projectDir: Specifies the directory of the project.
* @return {Promise<void>}
*/
interpolatePluginVariables(pluginData: IPluginData, pluginConfigurationFilePath: string, projectData: IProjectData): Promise<void>;
interpolatePluginVariables(pluginData: IPluginData, pluginConfigurationFilePath: string, projectDir: string): Promise<void>;

/**
* Replaces {nativescript.id} expression with the application identifier from package.json.
* @param {pluginConfigurationFilePath} pluginConfigurationFilePath for the plugin.
* @param {IProjectData} projectData DTO with information about the project.
* @return {void}
*/
interpolateAppIdentifier(pluginConfigurationFilePath: string, projectData: IProjectData): void;
interpolateAppIdentifier(pluginConfigurationFilePath: string, projectIdentifier: string): void;

/**
* Replaces both plugin variables and appIdentifier
*/
interpolate(pluginData: IPluginData, pluginConfigurationFilePath: string, projectData: IProjectData): Promise<void>;
interpolate(pluginData: IPluginData, pluginConfigurationFilePath: string, projectDir: string, projectIdentifier: string): Promise<void>;

/**
* Returns the
Expand Down
3 changes: 2 additions & 1 deletion lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ interface INsConfig {
interface IProjectData extends ICreateProjectData {
platformsDir: string;
projectFilePath: string;
projectId?: string;
projectId: string;
projectIdentifiers?: Mobile.IProjectIdentifier;
dependencies: any;
devDependencies: IStringDictionary;
appDirectoryPath: string;
Expand Down
10 changes: 9 additions & 1 deletion lib/helpers/livesync-command-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,15 @@ export class LiveSyncCommandHelper implements ILiveSyncCommandHelper {
};

await this.$platformService.deployPlatform(deployPlatformInfo);
await this.$platformService.startApplication(currentPlatform, runPlatformOptions, { appId: this.$projectData.projectId, projectName: this.$projectData.projectName });

await this.$platformService.startApplication(
currentPlatform,
runPlatformOptions,
{
appId: this.$projectData.projectIdentifiers[currentPlatform.toLowerCase()],
projectName: this.$projectData.projectName
}
);
await this.$platformService.trackProjectType(this.$projectData);
}
}
Expand Down
39 changes: 37 additions & 2 deletions lib/project-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as constants from "./constants";
import * as path from "path";
import { parseJson } from "./common/helpers";
import { EOL } from "os";
import { cache } from "./common/decorators";

interface IProjectType {
type: string;
Expand Down Expand Up @@ -35,7 +36,17 @@ export class ProjectData implements IProjectData {
public projectDir: string;
public platformsDir: string;
public projectFilePath: string;
public projectId: string;
public projectIdentifiers: Mobile.IProjectIdentifier;
get projectId(): string {
this.warnProjectId();
return this.projectIdentifiers.ios;
}
//just in case hook/extension modifies it.
set projectId(identifier: string) {
this.warnProjectId();
this.projectIdentifiers.ios = identifier;
this.projectIdentifiers.android = identifier;
}
public projectName: string;
public nsConfig: INsConfig;
public appDirectoryPath: string;
Expand Down Expand Up @@ -108,7 +119,7 @@ export class ProjectData implements IProjectData {
this.projectName = this.$projectHelper.sanitizeName(path.basename(projectDir));
this.platformsDir = path.join(projectDir, constants.PLATFORMS_DIR_NAME);
this.projectFilePath = projectFilePath;
this.projectId = nsData.id;
this.projectIdentifiers = this.initializeProjectIdentifiers(nsData.id);
this.dependencies = packageJsonData.dependencies;
this.devDependencies = packageJsonData.devDependencies;
this.projectType = this.getProjectType();
Expand Down Expand Up @@ -206,6 +217,25 @@ export class ProjectData implements IProjectData {
return path.resolve(projectDir, pathToResolve);
}

private initializeProjectIdentifiers(data: string | Mobile.IProjectIdentifier): Mobile.IProjectIdentifier {
let identifier: Mobile.IProjectIdentifier;
data = data || "";

if (typeof data === "string") {
identifier = {
android: data,
ios: data
};
} else {
Copy link
Contributor

@Plamen5kov Plamen5kov Oct 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the case when the android and ios package identifiers should be set to an empty string? Shouldn't we throw an error/warning here? (nvm, I got this is a default setting, but rename method)

identifier = {
android: data.android || "",
ios: data.ios || ""
};
}

return identifier;
}

private getProjectType(): string {
let detectedProjectType = _.find(ProjectData.PROJECT_TYPES, (projectType) => projectType.isDefaultProjectType).type;

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

return detectedProjectType;
}

@cache()
private warnProjectId(): void {
this.$logger.warnWithLabel("IProjectData.projectId is deprecated. Please use IProjectData.projectIdentifiers[platform].");
}
}
$injector.register("projectData", ProjectData);
17 changes: 9 additions & 8 deletions lib/services/android-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
}

public async validate(projectData: IProjectData, options: IOptions, notConfiguredEnvOptions?: INotConfiguredEnvOptions): Promise<IValidatePlatformOutput> {
this.validatePackageName(projectData.projectId);
this.validatePackageName(projectData.projectIdentifiers.android);
this.validateProjectName(projectData.projectName);

const checkEnvironmentRequirementsOutput = await this.$platformEnvironmentRequirements.checkEnvironmentRequirements({
Expand Down Expand Up @@ -269,16 +269,17 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
// will replace applicationId in app/App_Resources/Android/app.gradle if it has not been edited by the user
const appGradleContent = this.$fs.readText(projectData.appGradlePath);
if (appGradleContent.indexOf(constants.PACKAGE_PLACEHOLDER_NAME) !== -1) {
shell.sed('-i', new RegExp(constants.PACKAGE_PLACEHOLDER_NAME), projectData.projectId, projectData.appGradlePath);
//TODO: For compatibility with old templates. Once all templates are updated should delete.
shell.sed('-i', new RegExp(constants.PACKAGE_PLACEHOLDER_NAME), projectData.projectIdentifiers.android, projectData.appGradlePath);
}
} catch (e) {
this.$logger.warn(`\n${e}.\nCheck if you're using an outdated template and update it.`);
this.$logger.trace(`Templates updated and no need for replace in app.gradle.`);
}
}

public interpolateConfigurationFile(projectData: IProjectData, platformSpecificData: IPlatformSpecificData): void {
const manifestPath = this.getPlatformData(projectData).configurationFilePath;
shell.sed('-i', /__PACKAGE__/, projectData.projectId, manifestPath);
shell.sed('-i', /__PACKAGE__/, projectData.projectIdentifiers.android, manifestPath);
if (this.$androidToolsInfo.getToolsInfo().androidHomeEnvVar) {
const sdk = (platformSpecificData && platformSpecificData.sdk) || (this.$androidToolsInfo.getToolsInfo().compileSdkVersion || "").toString();
shell.sed('-i', /__APILEVEL__/, sdk, manifestPath);
Expand All @@ -287,8 +288,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject

private getProjectNameFromId(projectData: IProjectData): string {
let id: string;
if (projectData && projectData.projectId) {
const idParts = projectData.projectId.split(".");
if (projectData && projectData.projectIdentifiers && projectData.projectIdentifiers.android) {
const idParts = projectData.projectIdentifiers.android.split(".");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Plamen5kov(accidently deleted the comment) Yes there is validation for the identifier.

id = idParts[idParts.length - 1];
}

Expand Down Expand Up @@ -532,7 +533,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
const filesForInterpolation = this.$fs.enumerateFilesInDirectorySync(resourcesDestinationDirectoryPath, file => this.$fs.getFsStats(file).isDirectory() || path.extname(file) === constants.XML_FILE_EXTENSION) || [];
for (const file of filesForInterpolation) {
this.$logger.trace(`Interpolate data for plugin file: ${file}`);
await this.$pluginVariablesService.interpolate(pluginData, file, projectData);
await this.$pluginVariablesService.interpolate(pluginData, file, projectData.projectDir, projectData.projectIdentifiers.android);
}
}

Expand Down Expand Up @@ -642,7 +643,7 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject

public async cleanDeviceTempFolder(deviceIdentifier: string, projectData: IProjectData): Promise<void> {
const adb = this.$injector.resolve(DeviceAndroidDebugBridge, { identifier: deviceIdentifier });
const deviceRootPath = `${LiveSyncPaths.ANDROID_TMP_DIR_NAME}/${projectData.projectId}`;
const deviceRootPath = `${LiveSyncPaths.ANDROID_TMP_DIR_NAME}/${projectData.projectIdentifiers.android}`;
await adb.executeShellCommand(["rm", "-rf", deviceRootPath]);
}

Expand Down
7 changes: 6 additions & 1 deletion lib/services/debug-data-service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
export class DebugDataService implements IDebugDataService {
constructor(
private $devicesService: Mobile.IDevicesService
) { }
public createDebugData(projectData: IProjectData, options: IDeviceIdentifier): IDebugData {
const device = this.$devicesService.getDeviceByIdentifier(options.device);

return {
applicationIdentifier: projectData.projectId,
applicationIdentifier: projectData.projectIdentifiers[device.deviceInfo.platform.toLowerCase()],
projectDir: projectData.projectDir,
deviceIdentifier: options.device,
projectName: projectData.projectName
Expand Down
18 changes: 9 additions & 9 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
if (options && options.provision) {
plistTemplate += ` <key>provisioningProfiles</key>
<dict>
<key>${projectData.projectId}</key>
<key>${projectData.projectIdentifiers.ios}</key>
<string>${options.provision}</string>
</dict>`;
}
Expand Down Expand Up @@ -295,7 +295,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
if (options && options.provision) {
plistTemplate += ` <key>provisioningProfiles</key>
<dict>
<key>${projectData.projectId}</key>
<key>${projectData.projectIdentifiers.ios}</key>
<string>${options.provision}</string>
</dict>`;
}
Expand Down Expand Up @@ -512,7 +512,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ

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

this.$pluginVariablesService.interpolateAppIdentifier(this.getPlatformData(projectData).configurationFilePath, projectData);
this.$pluginVariablesService.interpolateAppIdentifier(this.getPlatformData(projectData).configurationFilePath, projectData.projectIdentifiers.ios);
}

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

makePatch(infoPlistPath);

if (projectData.projectId) {
if (projectData.projectIdentifiers && projectData.projectIdentifiers.ios) {
session.patch({
name: "CFBundleIdentifier from package.json nativescript.id",
read: () =>
Expand All @@ -850,13 +850,13 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>${projectData.projectId}</string>
<string>${projectData.projectIdentifiers.ios}</string>
</dict>
</plist>`
});
}

if (!buildOptions.release && projectData.projectId) {
if (!buildOptions.release && projectData.projectIdentifiers && projectData.projectIdentifiers.ios) {
session.patch({
name: "CFBundleURLTypes from package.json nativescript.id",
read: () =>
Expand All @@ -871,7 +871,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>${projectData.projectId.replace(/[^A-Za-z0-9]/g, "")}</string>
<string>${projectData.projectIdentifiers.ios.replace(/[^A-Za-z0-9]/g, "")}</string>
</array>
</dict>
</array>
Expand Down
2 changes: 1 addition & 1 deletion lib/services/itmstransporter-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class ITMSTransporterService implements IITMSTransporterService {
private async getBundleIdentifier(ipaFileFullPath?: string): Promise<string> {
if (!this._bundleIdentifier) {
if (!ipaFileFullPath) {
this._bundleIdentifier = this.$projectData.projectId;
this._bundleIdentifier = this.$projectData.projectIdentifiers.ios;
} else {
if (!this.$fs.exists(ipaFileFullPath) || path.extname(ipaFileFullPath) !== ".ipa") {
this.$errors.failWithoutHelp(`Cannot use specified ipa file ${ipaFileFullPath}. File either does not exist or is not an ipa file.`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class AndroidDeviceSocketsLiveSyncService extends AndroidDeviceLiveSyncSe
this.$fs.writeFile(pathToLiveSyncFile, "");
await this.device.fileSystem.putFile(pathToLiveSyncFile, this.getPathToLiveSyncFileOnDevice(deviceAppData.appIdentifier), deviceAppData.appIdentifier);
await this.device.applicationManager.startApplication({ appId: deviceAppData.appIdentifier, projectName: this.data.projectName, justLaunch: true });
await this.connectLivesyncTool(this.data.projectId);
await this.connectLivesyncTool(this.data.projectIdentifiers.android);
}

private getPathToLiveSyncFileOnDevice(appIdentifier: string): string {
Expand Down
10 changes: 6 additions & 4 deletions lib/services/livesync/ios-device-livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ export class IOSDeviceLiveSyncService extends DeviceLiveSyncServiceBase implemen
return true;
}

const appId = projectData.projectIdentifiers.ios;

if (this.device.isEmulator) {
await this.$iOSEmulatorServices.postDarwinNotification(this.$iOSNotification.getAttachRequest(projectData.projectId, this.device.deviceInfo.identifier), this.device.deviceInfo.identifier);
const port = await this.$iOSDebuggerPortService.getPort({ projectDir: projectData.projectDir, deviceId: this.device.deviceInfo.identifier, appId: projectData.projectId });
await this.$iOSEmulatorServices.postDarwinNotification(this.$iOSNotification.getAttachRequest(appId, this.device.deviceInfo.identifier), this.device.deviceInfo.identifier);
const port = await this.$iOSDebuggerPortService.getPort({ projectDir: projectData.projectDir, deviceId: this.device.deviceInfo.identifier, appId });
this.socket = await this.$iOSEmulatorServices.connectToPort({ port });
if (!this.socket) {
return false;
}
} else {
await this.$iOSSocketRequestExecutor.executeAttachRequest(this.device, constants.AWAIT_NOTIFICATION_TIMEOUT_SECONDS, projectData.projectId);
const port = await this.$iOSDebuggerPortService.getPort({ projectDir: projectData.projectDir, deviceId: this.device.deviceInfo.identifier, appId: projectData.projectId });
await this.$iOSSocketRequestExecutor.executeAttachRequest(this.device, constants.AWAIT_NOTIFICATION_TIMEOUT_SECONDS, appId);
const port = await this.$iOSDebuggerPortService.getPort({ projectDir: projectData.projectDir, deviceId: this.device.deviceInfo.identifier, appId });
this.socket = await this.device.connectToPort(port);
}

Expand Down
Loading