@@ -37,11 +37,10 @@ const {logger, CLIError, getDefaultUserTerminal} = (() => {
37
37
} ) ( ) ;
38
38
39
39
/**
40
- * @param {string[] } _
41
- * @param {Record<string, unknown> } _ctx
42
40
* @param {Options } args
41
+ * @returns {{ xcodeProject: XcodeProject, scheme: string } }
43
42
*/
44
- function runMacOS ( _ , _ctx , args ) {
43
+ function parseArgs ( args ) {
45
44
if ( ! fs . existsSync ( args . projectPath ) ) {
46
45
throw new CLIError (
47
46
'macOS project folder not found. Are you sure this is a React Native project?' ,
@@ -78,6 +77,26 @@ function runMacOS(_, _ctx, args) {
78
77
} "${ chalk . bold ( xcodeProject . name ) } "`,
79
78
) ;
80
79
80
+ return { xcodeProject, scheme} ;
81
+ }
82
+
83
+ /**
84
+ * @param {string[] } _
85
+ * @param {Record<string, unknown> } _ctx
86
+ * @param {Options } args
87
+ */
88
+ function buildMacOS ( _ , _ctx , args ) {
89
+ const { xcodeProject, scheme} = parseArgs ( args ) ;
90
+ return buildProject ( xcodeProject , scheme , { ...args , packager : false } ) ;
91
+ }
92
+
93
+ /**
94
+ * @param {string[] } _
95
+ * @param {Record<string, unknown> } _ctx
96
+ * @param {Options } args
97
+ */
98
+ function runMacOS ( _ , _ctx , args ) {
99
+ const { xcodeProject, scheme} = parseArgs ( args ) ;
81
100
return run ( xcodeProject , scheme , args ) ;
82
101
}
83
102
@@ -113,7 +132,7 @@ async function run(xcodeProject, scheme, args) {
113
132
114
133
child_process . exec (
115
134
'open -b ' + bundleID + ' -a ' + '"' + appPath + '"' ,
116
- ( error , stdout , stderr ) => {
135
+ ( error , _stdout , stderr ) => {
117
136
if ( error ) {
118
137
logger . error ( 'Failed to launch the app' , stderr ) ;
119
138
} else {
@@ -272,58 +291,75 @@ function getProcessOptions({packager, terminal, port}) {
272
291
} ;
273
292
}
274
293
275
- module . exports = {
276
- name : 'run-macos' ,
277
- description : 'builds your app and starts it' ,
278
- func : runMacOS ,
279
- examples : [
280
- {
281
- desc : 'Run the macOS app' ,
282
- cmd : 'react-native run-macos' ,
283
- } ,
284
- ] ,
285
- options : [
286
- {
287
- name : '--configuration [string]' ,
288
- description :
289
- '[Deprecated] Explicitly set the scheme configuration to use' ,
290
- default : 'Debug' ,
291
- } ,
292
- {
293
- name : '--mode [string]' ,
294
- description :
295
- 'Explicitly set the scheme configuration to use, corresponds to `--configuration` in `xcodebuild` command, e.g. Debug, Release.' ,
296
- } ,
297
- {
298
- name : '--scheme [string]' ,
299
- description :
300
- 'Explicitly set Xcode scheme to use, corresponds to `--scheme` in `xcodebuild` command.' ,
301
- } ,
302
- {
303
- name : '--project-path [string]' ,
304
- description :
305
- 'Path relative to project root where the Xcode project ' +
306
- '(.xcodeproj) lives.' ,
307
- default : 'macos' ,
308
- } ,
309
- {
310
- name : '--no-packager' ,
311
- description : 'Do not launch packager while building' ,
312
- } ,
313
- {
314
- name : '--verbose' ,
315
- description : 'Do not use xcpretty even if installed' ,
316
- } ,
317
- {
318
- name : '--port [number]' ,
319
- default : process . env . RCT_METRO_PORT || 8081 ,
320
- parse : val => Number ( val ) ,
321
- } ,
322
- {
323
- name : '--terminal [string]' ,
324
- description :
325
- 'Launches the Metro Bundler in a new window using the specified terminal path.' ,
326
- default : getDefaultUserTerminal ,
327
- } ,
328
- ] ,
329
- } ;
294
+ const commonOptions = [
295
+ {
296
+ name : '--mode [string]' ,
297
+ description :
298
+ 'Explicitly set the scheme configuration to use, corresponds to `--configuration` in `xcodebuild` command, e.g. Debug, Release.' ,
299
+ } ,
300
+ {
301
+ name : '--scheme [string]' ,
302
+ description :
303
+ 'Explicitly set Xcode scheme to use, corresponds to `--scheme` in `xcodebuild` command.' ,
304
+ } ,
305
+ {
306
+ name : '--project-path [string]' ,
307
+ description :
308
+ 'Path relative to project root where the Xcode project (.xcodeproj) lives.' ,
309
+ default : 'macos' ,
310
+ } ,
311
+ {
312
+ name : '--verbose' ,
313
+ description : 'Do not use xcpretty even if installed' ,
314
+ } ,
315
+ ] ;
316
+
317
+ module . exports = [
318
+ {
319
+ name : 'build-macos' ,
320
+ description : 'builds your app' ,
321
+ func : buildMacOS ,
322
+ examples : [
323
+ {
324
+ desc : 'Build the macOS app' ,
325
+ cmd : 'react-native build-macos' ,
326
+ } ,
327
+ ] ,
328
+ options : commonOptions ,
329
+ } ,
330
+ {
331
+ name : 'run-macos' ,
332
+ description : 'builds your app and starts it' ,
333
+ func : runMacOS ,
334
+ examples : [
335
+ {
336
+ desc : 'Run the macOS app' ,
337
+ cmd : 'react-native run-macos' ,
338
+ } ,
339
+ ] ,
340
+ options : [
341
+ {
342
+ name : '--configuration [string]' ,
343
+ description :
344
+ '[Deprecated] Explicitly set the scheme configuration to use' ,
345
+ default : 'Debug' ,
346
+ } ,
347
+ ...commonOptions ,
348
+ {
349
+ name : '--no-packager' ,
350
+ description : 'Do not launch packager while building' ,
351
+ } ,
352
+ {
353
+ name : '--port [number]' ,
354
+ default : process . env . RCT_METRO_PORT || 8081 ,
355
+ parse : val => Number ( val ) ,
356
+ } ,
357
+ {
358
+ name : '--terminal [string]' ,
359
+ description :
360
+ 'Launches the Metro Bundler in a new window using the specified terminal path.' ,
361
+ default : getDefaultUserTerminal ,
362
+ } ,
363
+ ] ,
364
+ } ,
365
+ ] ;
0 commit comments