@@ -21,7 +21,13 @@ import {
21
21
import { generateInfoPlist } from "./infoPlist.mjs" ;
22
22
import { generateLocalizations , getProductName } from "./localizations.mjs" ;
23
23
import { 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" ;
25
31
import {
26
32
PRODUCT_DISPLAY_NAME ,
27
33
PRODUCT_VERSION ,
@@ -30,6 +36,7 @@ import {
30
36
applySwiftFlags ,
31
37
applyUserHeaderSearchPaths ,
32
38
configureBuildSchemes ,
39
+ openXcodeProject ,
33
40
overrideBuildSettings ,
34
41
} from "./xcode.mjs" ;
35
42
@@ -272,9 +279,57 @@ export function generateProject(
272
279
return project ;
273
280
}
274
281
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
+
275
330
if ( isMain ( import . meta. url ) ) {
276
331
const [ , , projectRoot , platform , options ] = process . argv ;
277
332
const user = typeof options === "string" ? JSON . parse ( options ) : { } ;
278
- const project = generateProject ( projectRoot , platform , user ) ;
333
+ const project = makeProject ( projectRoot , platform , user ) ;
279
334
console . log ( JSON . stringify ( project , undefined , 2 ) ) ;
280
335
}
0 commit comments