@@ -16,9 +16,11 @@ import type {
1616 ApplePlatform ,
1717 Device ,
1818 ProjectConfig ,
19+ XcodeProjectInfo ,
1920} from '../../types/index.js' ;
2021import { getConfiguration } from '../../utils/getConfiguration.js' ;
2122import { getInfo } from '../../utils/getInfo.js' ;
23+ import type { PlatformSDK } from '../../utils/getPlatformInfo.js' ;
2224import {
2325 getDevicePlatformSDK ,
2426 getPlatformInfo ,
@@ -96,39 +98,13 @@ export const createRun = async (
9698 }
9799
98100 if ( platformName === 'macos' ) {
99- let appPath = args . binaryPath ;
100- const info = await getInfo ( xcodeProject , sourceDir ) ;
101- if ( ! info ) {
102- throw new RnefError ( 'Failed to get Xcode project information' ) ;
103- }
104- if ( ! appPath ) {
105- const scheme = await getScheme (
106- info . schemes ,
107- args . scheme ,
108- xcodeProject . name
109- ) ;
110- const configuration = await getConfiguration (
111- info . configurations ,
112- args . configuration
113- ) ;
114- await buildProject ( {
115- xcodeProject,
116- sourceDir,
117- platformName,
118- udid : undefined ,
119- scheme,
120- configuration,
121- args,
122- } ) ;
123- const buildSettings = await getBuildSettings (
124- xcodeProject ,
125- sourceDir ,
126- configuration ,
127- getSimulatorPlatformSDK ( platformName ) ,
128- scheme
129- ) ;
130- appPath = buildSettings . appPath ;
131- }
101+ const { appPath } = await buildApp ( {
102+ args,
103+ xcodeProject,
104+ sourceDir,
105+ platformName,
106+ platformSDK : getSimulatorPlatformSDK ( platformName ) ,
107+ } ) ;
132108 await runOnMac ( appPath ) ;
133109 outro ( 'Success 🎉.' ) ;
134110 return ;
@@ -142,30 +118,14 @@ export const createRun = async (
142118 args . scheme ,
143119 xcodeProject . name
144120 ) ;
145- let appPath = args . binaryPath ;
146- if ( ! appPath ) {
147- const configuration = await getConfiguration (
148- info . configurations ,
149- args . configuration
150- ) ;
151- await buildProject ( {
152- xcodeProject,
153- sourceDir,
154- platformName,
155- udid : undefined ,
156- scheme,
157- configuration,
158- args,
159- } ) ;
160- const buildSettings = await getBuildSettings (
161- xcodeProject ,
162- sourceDir ,
163- configuration ,
164- getSimulatorPlatformSDK ( platformName ) ,
165- scheme
166- ) ;
167- appPath = buildSettings . appPath ;
168- }
121+ const { appPath } = await buildApp ( {
122+ args,
123+ xcodeProject,
124+ sourceDir,
125+ platformName,
126+ platformSDK : getSimulatorPlatformSDK ( platformName ) ,
127+ selectedScheme : scheme ,
128+ } ) ;
169129 await runOnMacCatalyst ( appPath , scheme ) ;
170130 outro ( 'Success 🎉.' ) ;
171131 return ;
@@ -186,74 +146,24 @@ export const createRun = async (
186146 if ( device ) {
187147 cacheRecentDevice ( device , platformName ) ;
188148 if ( device . type === 'simulator' ) {
189- const info = await getInfo ( xcodeProject , sourceDir ) ;
190- if ( ! info ) {
191- throw new RnefError ( 'Failed to get Xcode project information' ) ;
192- }
193- const scheme = await getScheme (
194- info . schemes ,
195- args . scheme ,
196- xcodeProject . name
197- ) ;
198- const configuration = await getConfiguration (
199- info . configurations ,
200- args . configuration
201- ) ;
202- if ( ! args . binaryPath ) {
203- await buildProject ( {
204- xcodeProject,
205- sourceDir,
206- platformName,
207- udid : device . udid ,
208- scheme,
209- configuration,
210- args,
211- } ) ;
212- }
213- const buildSettings = await getBuildSettings (
149+ const { appPath, infoPlistPath } = await buildApp ( {
150+ args,
214151 xcodeProject,
215152 sourceDir,
216- configuration ,
217- getSimulatorPlatformSDK ( platformName ) ,
218- scheme
219- ) ;
220- const appPath = args . binaryPath ?? buildSettings . appPath ;
221- const infoPlistPath = buildSettings . infoPlistPath ;
153+ platformName,
154+ platformSDK : getSimulatorPlatformSDK ( platformName ) ,
155+ udid : device . udid ,
156+ } ) ;
222157 await runOnSimulator ( device , appPath , infoPlistPath ) ;
223158 } else if ( device . type === 'device' ) {
224- let appPath = args . binaryPath ;
225- if ( ! appPath ) {
226- const info = await getInfo ( xcodeProject , sourceDir ) ;
227- if ( ! info ) {
228- throw new RnefError ( 'Failed to get Xcode project information' ) ;
229- }
230- const scheme = await getScheme (
231- info . schemes ,
232- args . scheme ,
233- xcodeProject . name
234- ) ;
235- const configuration = await getConfiguration (
236- info . configurations ,
237- args . configuration
238- ) ;
239- await buildProject ( {
240- xcodeProject,
241- sourceDir,
242- platformName,
243- udid : device . udid ,
244- scheme,
245- configuration,
246- args,
247- } ) ;
248- const buildSettings = await getBuildSettings (
249- xcodeProject ,
250- sourceDir ,
251- configuration ,
252- getDevicePlatformSDK ( platformName ) ,
253- scheme
254- ) ;
255- appPath = buildSettings . appPath ;
256- }
159+ const { appPath } = await buildApp ( {
160+ args,
161+ xcodeProject,
162+ sourceDir,
163+ platformName,
164+ platformSDK : getDevicePlatformSDK ( platformName ) ,
165+ udid : device . udid ,
166+ } ) ;
257167 await runOnDevice ( device , appPath , sourceDir ) ;
258168 }
259169 outro ( 'Success 🎉.' ) ;
@@ -285,46 +195,77 @@ export const createRun = async (
285195 }
286196 }
287197 for ( const simulator of bootedSimulators ) {
288- const info = await getInfo ( xcodeProject , sourceDir ) ;
289- if ( ! info ) {
290- throw new RnefError ( 'Failed to get Xcode project information' ) ;
291- }
292- const scheme = await getScheme (
293- info . schemes ,
294- args . scheme ,
295- xcodeProject . name
296- ) ;
297- const configuration = await getConfiguration (
298- info . configurations ,
299- args . configuration
300- ) ;
301- if ( ! args . binaryPath ) {
302- await buildProject ( {
303- xcodeProject,
304- sourceDir,
305- platformName,
306- udid : simulator . udid ,
307- scheme,
308- configuration,
309- args,
310- } ) ;
311- }
312- const buildSettings = await getBuildSettings (
198+ const { appPath, infoPlistPath } = await buildApp ( {
199+ args,
313200 xcodeProject,
314201 sourceDir,
315- configuration ,
316- getSimulatorPlatformSDK ( platformName ) ,
317- scheme
318- ) ;
319- const appPath = args . binaryPath ?? buildSettings . appPath ;
320- const infoPlistPath = buildSettings . infoPlistPath ;
202+ platformName,
203+ platformSDK : getSimulatorPlatformSDK ( platformName ) ,
204+ udid : simulator . udid ,
205+ } ) ;
321206 await runOnSimulator ( simulator , appPath , infoPlistPath ) ;
322207 }
323208 }
324209
325210 outro ( 'Success 🎉.' ) ;
326211} ;
327212
213+ async function buildApp ( {
214+ args,
215+ xcodeProject,
216+ sourceDir,
217+ platformName,
218+ platformSDK,
219+ udid,
220+ selectedScheme,
221+ } : {
222+ args : RunFlags ;
223+ xcodeProject : XcodeProjectInfo ;
224+ sourceDir : string ;
225+ platformName : ApplePlatform ;
226+ platformSDK : PlatformSDK ;
227+ udid ?: string ;
228+ selectedScheme ?: string ;
229+ } ) {
230+ let appPath = args . binaryPath ;
231+ let infoPlistPath ;
232+ if ( ! appPath ) {
233+ const info = await getInfo ( xcodeProject , sourceDir ) ;
234+ if ( ! info ) {
235+ throw new RnefError ( 'Failed to get Xcode project information' ) ;
236+ }
237+ const scheme =
238+ selectedScheme ??
239+ ( await getScheme ( info . schemes , args . scheme , xcodeProject . name ) ) ;
240+ const configuration = await getConfiguration (
241+ info . configurations ,
242+ args . configuration
243+ ) ;
244+ await buildProject ( {
245+ xcodeProject,
246+ sourceDir,
247+ platformName,
248+ udid,
249+ scheme,
250+ configuration,
251+ args,
252+ } ) ;
253+ const buildSettings = await getBuildSettings (
254+ xcodeProject ,
255+ sourceDir ,
256+ configuration ,
257+ platformSDK ,
258+ scheme
259+ ) ;
260+ appPath = buildSettings . appPath ;
261+ infoPlistPath = buildSettings . infoPlistPath ;
262+ } else {
263+ // @todo Info.plist is hardcoded when reading from binaryPath
264+ infoPlistPath = path . join ( appPath , 'Info.plist' ) ;
265+ }
266+ return { appPath, infoPlistPath } ;
267+ }
268+
328269async function selectDevice ( devices : Device [ ] , args : RunFlags ) {
329270 let device ;
330271 if ( args . device ) {
0 commit comments