Skip to content

Commit 2ff7349

Browse files
committed
Merge Info.plist from App_Resources and plugins into platforms/ios
1 parent 0c3ff13 commit 2ff7349

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

lib/services/ios-project-service.ts

+65-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as constants from "../constants";
1111
import * as helpers from "../common/helpers";
1212
import * as projectServiceBaseLib from "./platform-project-service-base";
1313
import Future = require("fibers/future");
14+
import { PlistSession } from "plist-merge-patch";
1415

1516
export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService {
1617
private static XCODE_PROJECT_EXT_NAME = ".xcodeproj";
@@ -350,12 +351,75 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
350351

351352
public prepareAppResources(appResourcesDirectoryPath: string): IFuture<void> {
352353
return (() => {
354+
let platformFolder = path.join(appResourcesDirectoryPath, this.platformData.normalizedPlatformName);
355+
var filterFile = (filename: string) => this.$fs.deleteFile(path.join(platformFolder, filename)).wait();
356+
357+
// These got copied but are not actually resources. They should be rather filterd before the copy in the first place but anyway, let's just delete them here.
358+
filterFile("Info.plist");
359+
// filterFile("Podfile");
360+
// filterFile("Entitlements.plist");
361+
353362
this.$fs.deleteDirectory(this.getAppResourcesDestinationDirectoryPath().wait()).wait();
354363
}).future<void>()();
355364
}
356365

357366
public processConfigurationFilesFromAppResources(): IFuture<void> {
358-
return Future.fromResult();
367+
return (() => {
368+
this.mergeInfoPlists().wait();
369+
}).future<void>()();
370+
}
371+
372+
private mergeInfoPlists(): IFuture<void> {
373+
return (() => {
374+
let projectDir = this.$projectData.projectDir;
375+
let infoPlistPath = path.join(projectDir, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME, this.platformData.normalizedPlatformName, "Info.plist");
376+
377+
if (!this.$fs.exists(infoPlistPath).wait()) {
378+
this.$logger.trace("Info.plist: No app/App_Resources/iOS/Info.plist found, falling back to pre-1.6.0 Info.plist behavior.");
379+
return;
380+
}
381+
382+
let session = new PlistSession({ log: (txt: string) => this.$logger.trace("Info.plist: " + txt) });
383+
let makePatch = (plistPath: string) => {
384+
if (!this.$fs.exists(plistPath).wait()) {
385+
return;
386+
}
387+
388+
session.patch({
389+
name: path.relative(projectDir, plistPath),
390+
read: () => this.$fs.readFile(plistPath).wait().toString()
391+
});
392+
}
393+
394+
let allPlugins: IPluginData[] = (<IPluginsService>this.$injector.resolve("pluginsService")).getAllInstalledPlugins().wait();
395+
for (let plugin of allPlugins) {
396+
let pluginInfoPlistPath = path.join(plugin.pluginPlatformsFolderPath(IOSProjectService.IOS_PLATFORM_NAME), "Info.plist");
397+
makePatch(pluginInfoPlistPath);
398+
}
399+
400+
makePatch(infoPlistPath);
401+
402+
if (this.$projectData.projectId) {
403+
session.patch({
404+
name: "CFBundleIdentifier from package.json nativescript.id",
405+
read: () =>
406+
`<?xml version="1.0" encoding="UTF-8"?>
407+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
408+
<plist version="1.0">
409+
<dict>
410+
<key>CFBundleIdentifier</key>
411+
<string>${ this.$projectData.projectId }</string>
412+
</dict>
413+
</plist>`
414+
});
415+
}
416+
417+
var plistContent = session.build();
418+
419+
this.$logger.trace("Info.plist: Write to: " + this.platformData.configurationFilePath);
420+
this.$fs.writeFile(this.platformData.configurationFilePath, plistContent).wait();
421+
422+
}).future<void>()();
359423
}
360424

361425
private get projectPodFilePath(): string {

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"open": "0.0.5",
5959
"osenv": "0.1.3",
6060
"plist": "1.1.0",
61+
"plist-merge-patch": "0.0.9",
6162
"plistlib": "0.2.1",
6263
"progress-stream": "1.1.1",
6364
"prompt": "https://github.com/Icenium/prompt/tarball/master",

0 commit comments

Comments
 (0)