1919
2020const path = require ( 'node:path' ) ;
2121const fs = require ( 'node:fs' ) ;
22- const { CordovaError, events } = require ( 'cordova-common' ) ;
22+ const { ConfigParser , CordovaError, events, xmlHelpers } = require ( 'cordova-common' ) ;
2323const xcode = require ( 'xcode' ) ;
2424const pkg = require ( '../package' ) ;
2525
@@ -31,10 +31,11 @@ const ROOT = path.join(__dirname, '..');
3131 * @param {string } project_path Path to your new Cordova iOS project
3232 * @param {string } package_name Package name, following reverse-domain style convention
3333 * @param {string } project_name Project name
34- * @param {{ link: boolean, customTemplate: string } } opts Project creation options
34+ * @param {{ customTemplate: string } } opts Project creation options
35+ * @param {ConfigParser } root_config The application config.xml
3536 * @returns {Promise<void> } resolves when the project has been created
3637 */
37- exports . createProject = async ( project_path , package_name , project_name , opts ) => {
38+ exports . createProject = async ( project_path , package_name , project_name , opts , root_config ) => {
3839 package_name = package_name || 'my.cordova.project' ;
3940 project_name = project_name || 'CordovaExample' ;
4041
@@ -56,7 +57,7 @@ exports.createProject = async (project_path, package_name, project_name, opts) =
5657 } ,
5758 options : {
5859 templatePath : opts . customTemplate || path . join ( ROOT , 'templates' , 'project' ) ,
59- linkLib : ! ! opts . link
60+ rootConfig : root_config
6061 }
6162 } ) . create ( ) ;
6263
@@ -73,6 +74,7 @@ class ProjectCreator {
7374 this . provideCordovaJs ( ) ;
7475 this . provideBuildScripts ( ) ;
7576 this . updateProjectSettings ( ) ;
77+ this . updatePlatformConfigFile ( ) ;
7678 }
7779
7880 provideProjectTemplate ( ) {
@@ -97,6 +99,17 @@ class ProjectCreator {
9799 fs . cpSync ( srcScriptsDir , destScriptsDir , { recursive : true } ) ;
98100 }
99101
102+ updatePlatformConfigFile ( ) {
103+ const defaultXmlPath = this . projectPath ( 'cordova' , 'defaults.xml' ) ;
104+ const configXmlPath = this . projectPath ( 'App' , 'config.xml' ) ;
105+
106+ fs . cpSync ( defaultXmlPath , configXmlPath ) ;
107+
108+ const config = new ConfigParser ( configXmlPath ) ;
109+ xmlHelpers . mergeXml ( this . options . rootConfig . doc . getroot ( ) , config . doc . getroot ( ) , 'ios' , /* clobber= */ true ) ;
110+ config . write ( ) ;
111+ }
112+
100113 updateProjectSettings ( ) {
101114 const projectPath = this . projectPath ( 'App.xcodeproj' , 'project.pbxproj' ) ;
102115 const xcodeproj = xcode . project ( projectPath ) ;
@@ -105,6 +118,11 @@ class ProjectCreator {
105118 xcodeproj . updateBuildProperty ( 'PRODUCT_NAME' , `"${ this . project . name } "` , null , 'App' ) ;
106119 xcodeproj . updateBuildProperty ( 'PRODUCT_BUNDLE_IDENTIFIER' , `"${ this . project . id } "` , null , 'App' ) ;
107120
121+ const deploymentTarget = this . options . rootConfig . getPreference ( 'deployment-target' , 'ios' ) ;
122+ if ( deploymentTarget ) {
123+ xcodeproj . updateBuildProperty ( 'IPHONEOS_DEPLOYMENT_TARGET' , deploymentTarget ) ;
124+ }
125+
108126 // Update the CordovaLib Swift package reference path
109127 const pkgRefs = xcodeproj . hash . project . objects . XCLocalSwiftPackageReference ;
110128 if ( pkgRefs ) {
0 commit comments