Skip to content

Commit 6dcd254

Browse files
committed
Support xcconfig file from plugin - close #883
1 parent a58717e commit 6dcd254

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

lib/services/ios-project-service.ts

+35-1
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
309309
return path.join(this.platformData.projectRoot, "Podfile");
310310
}
311311

312+
private get projectXcconfigFilePath(): string {
313+
return path.join(this.platformData.appDestinationDirectoryPath, "build.xcconfig");
314+
}
315+
312316
private replace(name: string): string {
313317
if(_.startsWith(name, '"')) {
314318
name = name.substr(1, name.length-2);
@@ -344,6 +348,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
344348
let pluginPlatformsFolderPath = pluginData.pluginPlatformsFolderPath(IOSProjectService.IOS_PLATFORM_NAME);
345349
this.prepareFrameworks(pluginPlatformsFolderPath, pluginData).wait();
346350
this.prepareCocoapods(pluginPlatformsFolderPath, opts).wait();
351+
this.prepareXcconfigFile(pluginPlatformsFolderPath).wait();
347352
}).future<void>()();
348353
}
349354

@@ -352,6 +357,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
352357
let pluginPlatformsFolderPath = pluginData.pluginPlatformsFolderPath(IOSProjectService.IOS_PLATFORM_NAME);
353358
this.removeFrameworks(pluginPlatformsFolderPath, pluginData).wait();
354359
this.removeCocoapods(pluginPlatformsFolderPath).wait();
360+
this.removeXcconfigFile(pluginPlatformsFolderPath).wait();
355361
}).future<void>()();
356362
}
357363

@@ -405,7 +411,7 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
405411

406412
let packageType = this.$childProcess.exec(`/usr/libexec/PlistBuddy -c "Print :CFBundlePackageType" "${infoPlistPath}"`).wait().trim();
407413
if (packageType !== "FMWK") {
408-
this.$errors.failWithoutHelp("The bundle at %s does not appear to be a dynamic framework.", libraryPath);
414+
this.$errors.failWithoutHelp("The bundle at %s does not appear to be a framework.", libraryPath);
409415
}
410416
}).future<void>()();
411417
}
@@ -457,6 +463,17 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
457463
}).future<void>()();
458464
}
459465

466+
private prepareXcconfigFile(pluginPlatformsFolderPath: string): IFuture<void> {
467+
return (() => {
468+
let pluginXcconfigFilePath = path.join(pluginPlatformsFolderPath, "build.xcconfig");
469+
if(this.$fs.exists(pluginXcconfigFilePath).wait()) {
470+
let xcconfigContent = this.$fs.readText(pluginXcconfigFilePath).wait();
471+
let contentToWrite = this.buildXcconfigContent(pluginXcconfigFilePath, xcconfigContent);
472+
this.$fs.appendFile(this.projectXcconfigFilePath, contentToWrite).wait();
473+
}
474+
}).future<void>()();
475+
}
476+
460477
private removeFrameworks(pluginPlatformsFolderPath: string, pluginData: IPluginData): IFuture<void> {
461478
return (() => {
462479
let project = this.createPbxProj();
@@ -488,8 +505,25 @@ export class IOSProjectService extends projectServiceBaseLib.PlatformProjectServ
488505
}).future<void>()();
489506
}
490507

508+
private removeXcconfigFile(pluginPlatformsFolderPath: string): IFuture<void> {
509+
return (() => {
510+
let pluginXcconfigFilePath = path.join(pluginPlatformsFolderPath, "build.xcconfig");
511+
if(this.$fs.exists(pluginXcconfigFilePath).wait()) {
512+
let xcconfigContent = this.$fs.readText(pluginXcconfigFilePath).wait();
513+
let projectXcconfigFileContent = this.$fs.readText(this.projectXcconfigFilePath).wait();
514+
let contentToRemove = this.buildXcconfigContent(pluginXcconfigFilePath, xcconfigContent);
515+
projectXcconfigFileContent = helpers.stringReplaceAll(projectXcconfigFileContent, contentToRemove, "");
516+
this.$fs.writeFile(this.projectXcconfigFilePath, projectXcconfigFileContent).wait();
517+
}
518+
}).future<void>()();
519+
}
520+
491521
private buildPodfileContent(pluginPodFilePath: string, pluginPodFileContent: string): string {
492522
return `# Begin Podfile - ${pluginPodFilePath} ${os.EOL} ${pluginPodFileContent} ${os.EOL} # End Podfile ${os.EOL}`;
493523
}
524+
525+
private buildXcconfigContent(xcconfigFilePath: string, xcconfigFileContent: string): string {
526+
return `${os.EOL}// Begin xcconfig - ${xcconfigFilePath} ${os.EOL} ${xcconfigFileContent} ${os.EOL} // End xcconfig ${os.EOL}`;
527+
}
494528
}
495529
$injector.register("iOSProjectService", IOSProjectService);

0 commit comments

Comments
 (0)