@@ -15,109 +15,117 @@ import { copyHermesXcframework } from './copyHermesXcframework.js';
1515
1616const buildOptions = getBuildOptions ( { platformName : 'ios' } ) ;
1717
18+ export const pluginBrownfieldIosPackageAction = async (
19+ args : BuildFlags ,
20+ apiSubset : Pick <
21+ PluginApi ,
22+ | 'getReactNativeVersion'
23+ | 'getProjectRoot'
24+ | 'getReactNativePath'
25+ | 'getFingerprintOptions'
26+ | 'getRemoteCacheProvider'
27+ | 'getUsePrebuiltRNCore'
28+ > ,
29+ pluginConfig ?: IOSProjectConfig ,
30+ ) => {
31+ intro ( 'Packaging iOS project' ) ;
32+
33+ // 1) Build the project
34+ const projectRoot = apiSubset . getProjectRoot ( ) ;
35+ const iosConfig = getValidProjectConfig ( 'ios' , projectRoot , pluginConfig ) ;
36+ const { derivedDataDir } = getBuildPaths ( 'ios' ) ;
37+
38+ const destination = args . destination ?? [
39+ genericDestinations . ios . device ,
40+ genericDestinations . ios . simulator ,
41+ ] ;
42+
43+ const buildFolder = args . buildFolder ?? derivedDataDir ;
44+ const configuration = args . configuration ?? 'Debug' ;
45+
46+ const { sourceDir } = iosConfig ;
47+
48+ const { scheme } = await createBuild ( {
49+ platformName : 'ios' ,
50+ projectConfig : iosConfig ,
51+ args : { ...args , destination, buildFolder } ,
52+ projectRoot,
53+ reactNativePath : apiSubset . getReactNativePath ( ) ,
54+ fingerprintOptions : apiSubset . getFingerprintOptions ( ) ,
55+ brownfield : true ,
56+ remoteCacheProvider : await apiSubset . getRemoteCacheProvider ( ) ,
57+ usePrebuiltRNCore : apiSubset . getUsePrebuiltRNCore ( ) ,
58+ } ) ;
59+
60+ // 2) Merge the .framework outputs of the framework target
61+ const productsPath = path . join ( buildFolder , 'Build' , 'Products' ) ;
62+ const { packageDir : frameworkTargetOutputDir } = getBuildPaths ( 'ios' ) ;
63+
64+ await mergeFrameworks ( {
65+ sourceDir,
66+ frameworkPaths : [
67+ path . join (
68+ productsPath ,
69+ `${ configuration } -iphoneos` ,
70+ `${ scheme } .framework` ,
71+ ) ,
72+ path . join (
73+ productsPath ,
74+ `${ configuration } -iphonesimulator` ,
75+ `${ scheme } .framework` ,
76+ ) ,
77+ ] ,
78+ outputPath : path . join ( frameworkTargetOutputDir , `${ scheme } .xcframework` ) ,
79+ } ) ;
80+
81+ // 3) Merge React Native Brownfield paths
82+ await mergeFrameworks ( {
83+ sourceDir,
84+ frameworkPaths : [
85+ path . join (
86+ productsPath ,
87+ `${ configuration } -iphoneos` ,
88+ 'ReactBrownfield' ,
89+ 'ReactBrownfield.framework' ,
90+ ) ,
91+ path . join (
92+ productsPath ,
93+ `${ configuration } -iphonesimulator` ,
94+ 'ReactBrownfield' ,
95+ 'ReactBrownfield.framework' ,
96+ ) ,
97+ ] ,
98+ outputPath : path . join (
99+ frameworkTargetOutputDir ,
100+ 'ReactBrownfield.xcframework' ,
101+ ) ,
102+ } ) ;
103+
104+ // 4) Copy hermes xcframework to the output path
105+ copyHermesXcframework ( {
106+ sourceDir,
107+ destinationDir : frameworkTargetOutputDir ,
108+ reactNativeVersion : apiSubset . getReactNativeVersion ( ) ,
109+ } ) ;
110+
111+ // 5) Inform the user
112+ logger . log (
113+ `XCFrameworks are available at: ${ colorLink (
114+ relativeToCwd ( frameworkTargetOutputDir ) ,
115+ ) } `,
116+ ) ;
117+
118+ outro ( 'Success 🎉.' ) ;
119+ } ;
120+
18121export const pluginBrownfieldIos =
19122 ( pluginConfig ?: IOSProjectConfig ) =>
20123 ( api : PluginApi ) : PluginOutput => {
21124 api . registerCommand ( {
22125 name : 'package:ios' ,
23126 description : 'Emit a .xcframework file from React Native code.' ,
24- action : async ( args : BuildFlags ) => {
25- intro ( 'Packaging iOS project' ) ;
26-
27- // 1) Build the project
28- const projectRoot = api . getProjectRoot ( ) ;
29- const iosConfig = getValidProjectConfig (
30- 'ios' ,
31- projectRoot ,
32- pluginConfig ,
33- ) ;
34- const { derivedDataDir } = getBuildPaths ( 'ios' ) ;
35-
36- const destination = args . destination ?? [
37- genericDestinations . ios . device ,
38- genericDestinations . ios . simulator ,
39- ] ;
40-
41- const buildFolder = args . buildFolder ?? derivedDataDir ;
42- const configuration = args . configuration ?? 'Debug' ;
43-
44- const { sourceDir } = iosConfig ;
45-
46- const { scheme } = await createBuild ( {
47- platformName : 'ios' ,
48- projectConfig : iosConfig ,
49- args : { ...args , destination, buildFolder } ,
50- projectRoot,
51- reactNativePath : api . getReactNativePath ( ) ,
52- fingerprintOptions : api . getFingerprintOptions ( ) ,
53- brownfield : true ,
54- remoteCacheProvider : await api . getRemoteCacheProvider ( ) ,
55- usePrebuiltRNCore : api . getUsePrebuiltRNCore ( ) ,
56- } ) ;
57-
58- // 2) Merge the .framework outputs of the framework target
59- const productsPath = path . join ( buildFolder , 'Build' , 'Products' ) ;
60- const { packageDir : frameworkTargetOutputDir } = getBuildPaths ( 'ios' ) ;
61-
62- await mergeFrameworks ( {
63- sourceDir,
64- frameworkPaths : [
65- path . join (
66- productsPath ,
67- `${ configuration } -iphoneos` ,
68- `${ scheme } .framework` ,
69- ) ,
70- path . join (
71- productsPath ,
72- `${ configuration } -iphonesimulator` ,
73- `${ scheme } .framework` ,
74- ) ,
75- ] ,
76- outputPath : path . join (
77- frameworkTargetOutputDir ,
78- `${ scheme } .xcframework` ,
79- ) ,
80- } ) ;
81-
82- // 3) Merge React Native Brownfield paths
83- await mergeFrameworks ( {
84- sourceDir,
85- frameworkPaths : [
86- path . join (
87- productsPath ,
88- `${ configuration } -iphoneos` ,
89- 'ReactBrownfield' ,
90- 'ReactBrownfield.framework' ,
91- ) ,
92- path . join (
93- productsPath ,
94- `${ configuration } -iphonesimulator` ,
95- 'ReactBrownfield' ,
96- 'ReactBrownfield.framework' ,
97- ) ,
98- ] ,
99- outputPath : path . join (
100- frameworkTargetOutputDir ,
101- 'ReactBrownfield.xcframework' ,
102- ) ,
103- } ) ;
104-
105- // 4) Copy hermes xcframework to the output path
106- copyHermesXcframework ( {
107- sourceDir,
108- destinationDir : frameworkTargetOutputDir ,
109- reactNativeVersion : api . getReactNativeVersion ( ) ,
110- } ) ;
111-
112- // 5) Inform the user
113- logger . log (
114- `XCFrameworks are available at: ${ colorLink (
115- relativeToCwd ( frameworkTargetOutputDir ) ,
116- ) } `,
117- ) ;
118-
119- outro ( 'Success 🎉.' ) ;
120- } ,
127+ action : ( args : BuildFlags ) =>
128+ pluginBrownfieldIosPackageAction ( args , api , pluginConfig ) ,
121129 options : buildOptions ,
122130 } ) ;
123131
0 commit comments