diff --git a/bin/nativescript.js b/bin/nativescript.js old mode 100644 new mode 100755 diff --git a/lib/definitions/project.d.ts b/lib/definitions/project.d.ts index c45de5fc97..fce8b05537 100644 --- a/lib/definitions/project.d.ts +++ b/lib/definitions/project.d.ts @@ -27,6 +27,7 @@ interface IPlatformProjectService { interpolateData(projectRoot: string): IFuture; afterCreateProject(projectRoot: string): IFuture; buildProject(projectRoot: string): IFuture; + prepareProject(): IFuture; isPlatformPrepared(projectRoot: string): IFuture; addLibrary(platformData: IPlatformData, libraryPath: string): IFuture; canUpdatePlatform(currentVersion: string, newVersion: string): IFuture; diff --git a/lib/services/android-project-service.ts b/lib/services/android-project-service.ts index 9dfb88947e..f013a2c560 100644 --- a/lib/services/android-project-service.ts +++ b/lib/services/android-project-service.ts @@ -273,6 +273,10 @@ class AndroidProjectService implements IPlatformProjectService { public getFrameworkFilesExtensions(): string[] { return [".jar", ".dat"]; } + + public prepareProject(): IFuture { + return (() => { }).future()(); + } private copy(projectRoot: string, frameworkDir: string, files: string, cpArg: string): IFuture { return (() => { diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index d0f1a5d9b5..9fa2fb8057 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -182,13 +182,11 @@ class IOSProjectService implements IPlatformProjectService { this.$fs.ensureDirectoryExists(targetPath).wait(); shell.cp("-R", libraryPath, targetPath); - var pbxProjPath = path.join(platformData.projectRoot, this.$projectData.projectName + ".xcodeproj", "project.pbxproj"); - var project = new xcode.project(pbxProjPath); - project.parseSync(); + let project = this.xcodeproj; project.addFramework(path.join(targetPath, frameworkName + ".framework"), { customFramework: true, embed: true }); project.updateBuildProperty("IPHONEOS_DEPLOYMENT_TARGET", "8.0"); - this.$fs.writeFile(pbxProjPath, project.writeSync()).wait(); + this.saveXcodeproj(project).wait(); this.$logger.info("The iOS Deployment Target is now 8.0 in order to support Cocoa Touch Frameworks."); }).future()(); } @@ -221,11 +219,58 @@ class IOSProjectService implements IPlatformProjectService { shell.cp("-R", path.join(cachedPackagePath, "*"), path.join(this.platformData.projectRoot, util.format("%s.xcodeproj", this.$projectData.projectName))); this.$logger.info("Copied from %s at %s.", cachedPackagePath, this.platformData.projectRoot); - var pbxprojFilePath = path.join(this.platformData.projectRoot, this.$projectData.projectName + IOSProjectService.XCODE_PROJECT_EXT_NAME, "project.pbxproj"); this.replaceFileContent(pbxprojFilePath).wait(); }).future()(); } + + public prepareProject(): IFuture { + return (() => { + let project = this.xcodeproj; + let resources = project.pbxGroupByName("Resources"); + let references = project.pbxFileReferenceSection(); + + let images = _(resources.children) + .map(resource => references[resource.value]) + .value(); + + let imageNames = _.map(images, image => image.name.replace(/\"/g, "")); + let currentImageNames = this.$fs.readDirectory(this.platformData.appResourcesDestinationDirectoryPath).wait(); + + this.$logger.trace("Images from xcode project"); + this.$logger.trace(imageNames); + this.$logger.trace("Current images from App_Resources"); + this.$logger.trace(currentImageNames); + + if(imageNames.length !== currentImageNames.length) { + let imagesToAdd = _.difference(currentImageNames, imageNames); + this.$logger.trace(`New images to add into xcode project: ${ imagesToAdd.length !== 0 ? imagesToAdd.join(", ") : "" }`); + _.each(imagesToAdd, image => project.addResourceFile(path.join(this.platformData.appResourcesDestinationDirectoryPath, image))); + + let imagesToRemove = _.difference(imageNames, currentImageNames); + this.$logger.trace(`Images to remove from xcode project: ${ imagesToRemove.length !== 0 ? imagesToRemove.join(", ") : "" }`); + _.each(imagesToRemove, image => project.removeResourceFile(path.join(this.platformData.appResourcesDestinationDirectoryPath, image))); + + this.saveXcodeproj(project).wait(); + } + + }).future()(); + } + + private get pbxProjPath(): string { + return path.join(this.platformData.projectRoot, this.$projectData.projectName + ".xcodeproj", "project.pbxproj"); + } + + private get xcodeproj(): any { + let project = new xcode.project(this.pbxProjPath); + project.parseSync(); + + return project; + } + + private saveXcodeproj(project: any): IFuture { + return this.$fs.writeFile(this.pbxProjPath, project.writeSync()); + } private buildPathToXcodeProjectFile(version: string): string { return path.join(this.$npmInstallationManager.getCachedPackagePath(this.platformData.frameworkPackageName, version), constants.PROJECT_FRAMEWORK_FOLDER_NAME, util.format("%s.xcodeproj", IOSProjectService.IOS_PROJECT_NAME_PLACEHOLDER), "project.pbxproj"); diff --git a/lib/services/platform-service.ts b/lib/services/platform-service.ts index bde1e242ce..b8ca5dba18 100644 --- a/lib/services/platform-service.ts +++ b/lib/services/platform-service.ts @@ -160,7 +160,8 @@ export class PlatformService implements IPlatformService { this.$fs.ensureDirectoryExists(platformData.appResourcesDestinationDirectoryPath).wait(); // Should be deleted var appResourcesDirectoryPath = path.join(platformData.appDestinationDirectoryPath, constants.APP_FOLDER_NAME, constants.APP_RESOURCES_FOLDER_NAME); if (this.$fs.exists(appResourcesDirectoryPath).wait()) { - shell.cp("-Rf", path.join(appResourcesDirectoryPath, platformData.normalizedPlatformName, "*"), platformData.appResourcesDestinationDirectoryPath); + this.$fs.deleteDirectory(platformData.appResourcesDestinationDirectoryPath).wait(); // Respect removed files + shell.cp("-R", path.join(appResourcesDirectoryPath, platformData.normalizedPlatformName, "*"), platformData.appResourcesDestinationDirectoryPath); this.$fs.deleteDirectory(appResourcesDirectoryPath).wait(); } @@ -178,6 +179,8 @@ export class PlatformService implements IPlatformService { } }); this.processPlatformSpecificFiles(platform, files).wait(); + + platformData.platformProjectService.prepareProject().wait(); // Process node_modules folder this.$pluginsService.ensureAllDependenciesAreInstalled().wait(); diff --git a/test/npm-support.ts b/test/npm-support.ts index d7a557f79e..39f62ef65c 100644 --- a/test/npm-support.ts +++ b/test/npm-support.ts @@ -19,6 +19,7 @@ import BroccoliBuilderLib = require("../lib/tools/broccoli/builder"); import NodeModulesTreeLib = require("../lib/tools/broccoli/trees/node-modules-tree"); import PluginsServiceLib = require("../lib/services/plugins-service"); import ChildProcessLib = require("../lib/common/child-process"); +import Future = require("fibers/future"); import path = require("path"); import temp = require("temp"); @@ -118,7 +119,10 @@ describe("Npm support tests", () => { appDestinationDirectoryPath: appDestinationFolderPath, appResourcesDestinationDirectoryPath: path.join(appDestinationFolderPath, "app", "App_Resources"), frameworkPackageName: "tns-android", - normalizedPlatformName: "Android" + normalizedPlatformName: "Android", + platformProjectService: { + prepareProject: () => Future.fromResult() + } } }; diff --git a/test/platform-service.ts b/test/platform-service.ts index ce2782d899..8642d78880 100644 --- a/test/platform-service.ts +++ b/test/platform-service.ts @@ -223,7 +223,10 @@ describe('Platform Service Tests', () => { return { appDestinationDirectoryPath: appDestFolderPath, appResourcesDestinationDirectoryPath: appResourcesFolderPath, - normalizedPlatformName: "iOS" + normalizedPlatformName: "iOS", + platformProjectService: { + prepareProject: () => Future.fromResult() + } } }; @@ -274,7 +277,10 @@ describe('Platform Service Tests', () => { return { appDestinationDirectoryPath: appDestFolderPath, appResourcesDestinationDirectoryPath: appResourcesFolderPath, - normalizedPlatformName: "Android" + normalizedPlatformName: "Android", + platformProjectService: { + prepareProject: () => Future.fromResult() + } } }; diff --git a/test/stubs.ts b/test/stubs.ts index a3b45db324..7cb8a456e0 100644 --- a/test/stubs.ts +++ b/test/stubs.ts @@ -276,8 +276,8 @@ export class PlatformProjectServiceStub implements IPlatformProjectService { afterCreateProject(projectRoot: string): IFuture { return Future.fromResult(); } - prepareProject(platformData: IPlatformData): IFuture { - return Future.fromResult(""); + prepareProject(): IFuture { + return Future.fromResult(); } buildProject(projectRoot: string): IFuture { return Future.fromResult();