@@ -21,7 +21,13 @@ import {
2121import { generateInfoPlist } from "./infoPlist.mjs" ;
2222import { generateLocalizations , getProductName } from "./localizations.mjs" ;
2323import { generatePrivacyManifest } from "./privacyManifest.mjs" ;
24- import { isObject , isString , projectPath , resolveResources } from "./utils.mjs" ;
24+ import {
25+ assertObject ,
26+ isObject ,
27+ isString ,
28+ projectPath ,
29+ resolveResources ,
30+ } from "./utils.mjs" ;
2531import {
2632 PRODUCT_DISPLAY_NAME ,
2733 PRODUCT_VERSION ,
@@ -30,6 +36,7 @@ import {
3036 applySwiftFlags ,
3137 applyUserHeaderSearchPaths ,
3238 configureBuildSchemes ,
39+ openXcodeProject ,
3340 overrideBuildSettings ,
3441} from "./xcode.mjs" ;
3542
@@ -272,9 +279,57 @@ export function generateProject(
272279 return project ;
273280}
274281
282+ /**
283+ * @param {string } projectRoot
284+ * @param {string } targetPlatform
285+ * @param {JSONObject } options
286+ * @returns {ProjectConfiguration }
287+ */
288+ export function makeProject ( projectRoot , targetPlatform , options , fs = nodefs ) {
289+ const project = generateProject ( projectRoot , targetPlatform , options , fs ) ;
290+
291+ /** @type {Record<string, Record<string, string | string[]>> } */
292+ const mods = {
293+ ReactTestApp : project . buildSettings ,
294+ ReactTestAppTests : project . testsBuildSettings ,
295+ ReactTestAppUITests : project . uitestsBuildSettings ,
296+ } ;
297+
298+ const pbxproj = openXcodeProject ( project . xcodeprojPath , fs ) ;
299+ for ( const target of pbxproj . targets ) {
300+ const { name : targetName } = target ;
301+ if ( typeof targetName !== "string" || ! ( targetName in mods ) ) {
302+ continue ;
303+ }
304+
305+ const targetBuildSettings = Object . entries ( mods [ targetName ] ) ;
306+ for ( const config of target . buildConfigurations ) {
307+ const { buildSettings } = config ;
308+ assertObject ( buildSettings , "target.buildConfigurations[].buildSettings" ) ;
309+
310+ for ( const [ setting , value ] of targetBuildSettings ) {
311+ if ( Array . isArray ( value ) ) {
312+ const origValue = buildSettings [ setting ] ?? [ "$(inherited)" ] ;
313+ if ( Array . isArray ( origValue ) ) {
314+ origValue . push ( ...value ) ;
315+ buildSettings [ setting ] = origValue ;
316+ } else {
317+ buildSettings [ setting ] = [ origValue , ...value ] . join ( " " ) ;
318+ }
319+ } else {
320+ buildSettings [ setting ] = value ;
321+ }
322+ }
323+ }
324+ }
325+ pbxproj . save ( ) ;
326+
327+ return project ;
328+ }
329+
275330if ( isMain ( import . meta. url ) ) {
276331 const [ , , projectRoot , platform , options ] = process . argv ;
277332 const user = typeof options === "string" ? JSON . parse ( options ) : { } ;
278- const project = generateProject ( projectRoot , platform , user ) ;
333+ const project = makeProject ( projectRoot , platform , user ) ;
279334 console . log ( JSON . stringify ( project , undefined , 2 ) ) ;
280335}
0 commit comments