From 97029f1af656cdd9169e46ced175c333e218ff09 Mon Sep 17 00:00:00 2001 From: Toma Nikolov Date: Fri, 7 Jul 2017 15:49:43 +0300 Subject: [PATCH] Fix CFBundleURLTypes merging. --- lib/services/ios-project-service.ts | 76 +++++++++++++---------------- package.json | 2 +- 2 files changed, 34 insertions(+), 44 deletions(-) diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index b46b6e89b7..b684faec92 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -6,7 +6,7 @@ import * as constants from "../constants"; import * as helpers from "../common/helpers"; import { attachAwaitDetach } from "../common/helpers"; import * as projectServiceBaseLib from "./platform-project-service-base"; -import { PlistSession } from "plist-merge-patch"; +import { PlistSession, Reporter } from "plist-merge-patch"; import { EOL } from "os"; import * as temp from "temp"; import * as plist from "plist"; @@ -723,7 +723,13 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f return; } - let session = new PlistSession({ log: (txt: string) => this.$logger.trace("Info.plist: " + txt) }); + const reporterTraceMessage = "Info.plist:"; + const reporter: Reporter = { + log: (txt: string) => this.$logger.trace(`${reporterTraceMessage} ${txt}`), + warn: (txt: string) => this.$logger.warn(`${reporterTraceMessage} ${txt}`) + }; + + let session = new PlistSession(reporter); let makePatch = (plistPath: string) => { if (!this.$fs.exists(plistPath)) { this.$logger.trace("No plist found at: " + plistPath); @@ -743,17 +749,7 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f makePatch(pluginInfoPlistPath); } - if (!buildOptions.release && projectData.projectId) { - const modifiedPlistContent = this.updateCFBundleURLSchemes(infoPlistPath, projectData); - - session.patch({ - name: "CFBundleURLTypes from Info.plist and required one for restarting application", - read: () => modifiedPlistContent - }); - - } else { - makePatch(infoPlistPath); - } + makePatch(infoPlistPath); if (projectData.projectId) { session.patch({ @@ -770,42 +766,36 @@ We will now place an empty obsolete compatability white screen LauncScreen.xib f }); } + if (!buildOptions.release && projectData.projectId) { + session.patch({ + name: "CFBundleURLTypes from package.json nativescript.id", + read: () => + ` + + + + CFBundleURLTypes + + + CFBundleTypeRole + Editor + CFBundleURLSchemes + + ${projectData.projectId.replace(/[^A-Za-z0-9]/g, "")} + + + + + ` + }); + } + let plistContent = session.build(); this.$logger.trace("Info.plist: Write to: " + this.getPlatformData(projectData).configurationFilePath); this.$fs.writeFile(this.getPlatformData(projectData).configurationFilePath, plistContent); } - private updateCFBundleURLSchemes(infoPlistPath: string, projectData: IProjectData): string { - // This code is required due to bug in session.patch logic which cannot merge values which are both arrays - it uses the second one directly. - // In our case we want to merge the values of CFBundleURLSchemes (which are arrays), which are in CFBundleURLTypes arrays. - let parsedPlist: any = plist.parse(this.$fs.readFile(infoPlistPath).toString()); - parsedPlist.CFBundleURLTypes = parsedPlist.CFBundleURLTypes || []; - - const appIdCfBundleUrlScheme = projectData.projectId.replace(/[^A-Za-z0-9]/g, ""); - - let hasAddedCFBundleURLSchemes = false; - - _.each(parsedPlist.CFBundleURLTypes, type => { - if (type.CFBundleURLSchemes) { - hasAddedCFBundleURLSchemes = true; - type.CFBundleURLSchemes.push(appIdCfBundleUrlScheme); - return false; - } - }); - - if (!hasAddedCFBundleURLSchemes) { - parsedPlist.CFBundleURLTypes.push( - { - CFBundleURLSchemes: [appIdCfBundleUrlScheme] - } - ); - } - - const newPlistContent = plist.build(parsedPlist); - return newPlistContent; - } - private getAllInstalledPlugins(projectData: IProjectData): Promise { return (this.$injector.resolve("pluginsService")).getAllInstalledPlugins(projectData); } diff --git a/package.json b/package.json index cd710a0686..49a25c7cea 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "osenv": "0.1.3", "pbxproj-dom": "1.0.11", "plist": "1.1.0", - "plist-merge-patch": "0.0.9", + "plist-merge-patch": "0.1.0", "plistlib": "0.2.1", "progress-stream": "1.1.1", "properties-parser": "0.2.3",