diff --git a/lib/commands/create-project.ts b/lib/commands/create-project.ts index 41a404d0b1..44c297fa8d 100644 --- a/lib/commands/create-project.ts +++ b/lib/commands/create-project.ts @@ -14,7 +14,7 @@ export class ProjectCommandParameter implements ICommandParameter { } if (value.toUpperCase() === "APP") { - this.$logger.warn("You cannot build aplications named 'app' in Xcode. Consider creating a project with different name."); + this.$logger.warn("You cannot build applications named 'app' in Xcode. Consider creating a project with different name."); } return this.$projectNameValidator.validate(value); diff --git a/lib/services/ios-project-service.ts b/lib/services/ios-project-service.ts index b15117a830..e6be63998e 100644 --- a/lib/services/ios-project-service.ts +++ b/lib/services/ios-project-service.ts @@ -349,8 +349,12 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ return path.join(this.platformData.projectRoot, "Podfile"); } - private get projectXcconfigFilePath(): string { - return path.join(this.platformData.appDestinationDirectoryPath, "build.xcconfig"); + private get pluginsDebugXcconfigFilePath(): string { + return path.join(this.platformData.projectRoot, "plugins-debug.xcconfig"); + } + + private get pluginsReleaseXcconfigFilePath(): string { + return path.join(this.platformData.projectRoot, "plugins-release.xcconfig"); } private replace(name: string): string { @@ -389,7 +393,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ this.prepareFrameworks(pluginPlatformsFolderPath, pluginData).wait(); this.prepareStaticLibs(pluginPlatformsFolderPath, pluginData).wait(); this.prepareCocoapods(pluginPlatformsFolderPath).wait(); - this.prepareXcconfigFile(pluginPlatformsFolderPath).wait(); }).future()(); } @@ -400,7 +403,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ this.removeFrameworks(pluginPlatformsFolderPath, pluginData).wait(); this.removeStaticLibs(pluginPlatformsFolderPath, pluginData).wait(); this.removeCocoapods(pluginPlatformsFolderPath).wait(); - this.removeXcconfigFile(pluginPlatformsFolderPath).wait(); }).future()(); } @@ -433,6 +435,8 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ this.executePodInstall().wait(); } + + this.regeneratePluginsXcconfigFile().wait(); }).future()(); } @@ -535,16 +539,6 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ }).future()(); } - private prepareXcconfigFile(pluginPlatformsFolderPath: string): IFuture { - return (() => { - let pluginXcconfigFilePath = path.join(pluginPlatformsFolderPath, "build.xcconfig"); - if(this.$fs.exists(pluginXcconfigFilePath).wait()) { - let contentToWrite = this.buildXcconfigContent(pluginXcconfigFilePath); - this.$fs.appendFile(this.projectXcconfigFilePath, contentToWrite).wait(); - } - }).future()(); - } - private removeFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData): IFuture { return (() => { let project = this.createPbxProj(); @@ -588,18 +582,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ } else { this.$fs.writeFile(this.projectPodFilePath, projectPodFileContent).wait(); } - } - }).future()(); - } - private removeXcconfigFile(pluginPlatformsFolderPath: string): IFuture { - return (() => { - let pluginXcconfigFilePath = path.join(pluginPlatformsFolderPath, "build.xcconfig"); - if(this.$fs.exists(pluginXcconfigFilePath).wait()) { - let projectXcconfigFileContent = this.$fs.readText(this.projectXcconfigFilePath).wait(); - let contentToRemove = this.buildXcconfigContent(pluginXcconfigFilePath); - projectXcconfigFileContent = helpers.stringReplaceAll(projectXcconfigFileContent, contentToRemove, ""); - this.$fs.writeFile(this.projectXcconfigFilePath, projectXcconfigFileContent).wait(); } }).future()(); } @@ -624,9 +607,38 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ this.$fs.writeFile(path.join(headersFolderPath, "module.modulemap"), modulemap).wait(); } - private buildXcconfigContent(xcconfigFilePath: string): string { - let relativePluginXcconfigFilePath = path.relative(path.dirname(this.projectXcconfigFilePath), xcconfigFilePath); - return `${os.EOL}#include "${relativePluginXcconfigFilePath}"${os.EOL}`; + private mergeXcconfigFiles(pluginFile: string, projectFile: string): IFuture { + return (() => { + if (!this.$fs.exists(projectFile).wait()) { + this.$fs.writeFile(projectFile, "").wait(); + } + + let mergeScript = `require 'xcodeproj'; Xcodeproj::Config.new('${projectFile}').merge(Xcodeproj::Config.new('${pluginFile}')).save_as(Pathname.new('${projectFile}'))`; + this.$childProcess.exec(`ruby -e "${mergeScript}"`).wait(); + }).future()(); + } + + private regeneratePluginsXcconfigFile(): IFuture { + return (() => { + this.$fs.deleteFile(this.pluginsDebugXcconfigFilePath).wait(); + this.$fs.deleteFile(this.pluginsReleaseXcconfigFilePath).wait(); + + let allPlugins: IPluginData[] = (this.$injector.resolve("pluginsService")).getAllInstalledPlugins().wait(); + for (let plugin of allPlugins) { + let pluginPlatformsFolderPath = plugin.pluginPlatformsFolderPath(IOSProjectService.IOS_PLATFORM_NAME); + let pluginXcconfigFilePath = path.join(pluginPlatformsFolderPath, "build.xcconfig"); + if (this.$fs.exists(pluginXcconfigFilePath).wait()) { + this.mergeXcconfigFiles(pluginXcconfigFilePath, this.pluginsDebugXcconfigFilePath).wait(); + this.mergeXcconfigFiles(pluginXcconfigFilePath, this.pluginsReleaseXcconfigFilePath).wait(); + } + } + + let podFolder = path.join(this.platformData.projectRoot, "Pods/Target Support Files/Pods/"); + if (this.$fs.exists(podFolder).wait()) { + this.mergeXcconfigFiles(path.join(this.platformData.projectRoot, "Pods/Target Support Files/Pods/Pods.debug.xcconfig"), this.pluginsDebugXcconfigFilePath).wait(); + this.mergeXcconfigFiles(path.join(this.platformData.projectRoot, "Pods/Target Support Files/Pods/Pods.release.xcconfig"), this.pluginsReleaseXcconfigFilePath).wait(); + } + }).future()(); } } diff --git a/lib/services/plugins-service.ts b/lib/services/plugins-service.ts index 3bf8998970..3b5370cbaf 100644 --- a/lib/services/plugins-service.ts +++ b/lib/services/plugins-service.ts @@ -201,7 +201,7 @@ export class PluginsService implements IPluginsService { public getAllInstalledPlugins(): IFuture { return (() => { - let nodeModules = this.getAllInstalledModules().wait(); + let nodeModules = this.getAllInstalledModules().wait().map(nodeModuleData => this.convertToPluginData(nodeModuleData)); return _.filter(nodeModules, nodeModuleData => nodeModuleData && nodeModuleData.isPlugin); }).future()(); }