Skip to content

Merge Info.plist from App_Resources and plugins into platforms/ios #1369

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 1 commit into from
Jan 7, 2016
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
83 changes: 81 additions & 2 deletions lib/services/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as constants from "../constants";
import * as helpers from "../common/helpers";
import * as projectServiceBaseLib from "./platform-project-service-base";
import Future = require("fibers/future");
import { PlistSession } from "plist-merge-patch";

export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServiceBase implements IPlatformProjectService {
private static XCODE_PROJECT_EXT_NAME = ".xcodeproj";
Expand All @@ -33,7 +34,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
private $injector: IInjector,
$projectDataService: IProjectDataService,
private $prompter: IPrompter,
private $config: IConfiguration) {
private $config: IConfiguration,
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants) {
super($fs, $projectData, $projectDataService);
}

Expand Down Expand Up @@ -350,12 +352,89 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ

public prepareAppResources(appResourcesDirectoryPath: string): IFuture<void> {
return (() => {
let platformFolder = path.join(appResourcesDirectoryPath, this.platformData.normalizedPlatformName);
let filterFile = (filename: string) => this.$fs.deleteFile(path.join(platformFolder, filename)).wait();

filterFile(this.platformData.configurationFileName);

this.$fs.deleteDirectory(this.getAppResourcesDestinationDirectoryPath().wait()).wait();
}).future<void>()();
}

public processConfigurationFilesFromAppResources(): IFuture<void> {
return Future.fromResult();
return (() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

you can skip (() => ...:

public processConfigurationFilesFromAppResources(): IFuture<void> {
    return this.mergeInfoPlists();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should soon add Entitlements here. I prefer it stay this way.

Copy link
Contributor

Choose a reason for hiding this comment

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

fine, 😸

this.mergeInfoPlists().wait();
}).future<void>()();
}

private mergeInfoPlists(): IFuture<void> {
return (() => {
let projectDir = this.$projectData.projectDir;
let infoPlistPath = path.join(projectDir, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME, this.platformData.normalizedPlatformName, this.platformData.configurationFileName);

if (!this.$fs.exists(infoPlistPath).wait()) {
// The project is missing Info.plist, try to populate it from the project tempalte.
let projectTemplateService: IProjectTemplatesService = this.$injector.resolve("projectTemplatesService");
let defaultTemplatePath = projectTemplateService.defaultTemplatePath.wait();
let templateInfoPlist = path.join(defaultTemplatePath, constants.APP_RESOURCES_FOLDER_NAME, this.$devicePlatformsConstants.iOS, this.platformData.configurationFileName);
if (this.$fs.exists(templateInfoPlist).wait()) {
this.$logger.trace("Info.plist: app/App_Resources/iOS/Info.plist is missing. Upgrading the source of the project with one from the new project template. Copy " + templateInfoPlist + " to " + infoPlistPath);
try {
this.$fs.copyFile(templateInfoPlist, infoPlistPath).wait();
} catch(e) {
this.$logger.trace("Copying template's Info.plist failed. " + e);
}
} else {
this.$logger.trace("Info.plist: app/App_Resources/iOS/Info.plist is missing but the template " + templateInfoPlist + " is missing too, can not upgrade Info.plist.");
}
}

if (!this.$fs.exists(infoPlistPath).wait()) {
this.$logger.trace("Info.plist: No app/App_Resources/iOS/Info.plist found, falling back to pre-1.6.0 Info.plist behavior.");
return;
}

let session = new PlistSession({ log: (txt: string) => this.$logger.trace("Info.plist: " + txt) });
let makePatch = (plistPath: string) => {
if (!this.$fs.exists(plistPath).wait()) {
return;
}

session.patch({
name: path.relative(projectDir, plistPath),
read: () => this.$fs.readFile(plistPath).wait().toString()
});
};

let allPlugins: IPluginData[] = (<IPluginsService>this.$injector.resolve("pluginsService")).getAllInstalledPlugins().wait();
for (let plugin of allPlugins) {
let pluginInfoPlistPath = path.join(plugin.pluginPlatformsFolderPath(IOSProjectService.IOS_PLATFORM_NAME), this.platformData.configurationFileName);
makePatch(pluginInfoPlistPath);
}

makePatch(infoPlistPath);

if (this.$projectData.projectId) {
session.patch({
name: "CFBundleIdentifier from package.json nativescript.id",
read: () =>
`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>${ this.$projectData.projectId }</string>
</dict>
</plist>`
});
}

let plistContent = session.build();

this.$logger.trace("Info.plist: Write to: " + this.platformData.configurationFilePath);
this.$fs.writeFile(this.platformData.configurationFilePath, plistContent).wait();

}).future<void>()();
}

private get projectPodFilePath(): string {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"open": "0.0.5",
"osenv": "0.1.3",
"plist": "1.1.0",
"plist-merge-patch": "0.0.9",
"plistlib": "0.2.1",
"progress-stream": "1.1.1",
"prompt": "https://github.com/Icenium/prompt/tarball/master",
Expand Down
1 change: 1 addition & 0 deletions test/ios-project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function createTestInjector(projectPath: string, projectName: string): IInjector
testInjector.register("staticConfig", ConfigLib.StaticConfig);
testInjector.register("projectDataService", {});
testInjector.register("prompter", {});
testInjector.register("devicePlatformsConstants", { iOS: "iOS" });
return testInjector;
}

Expand Down