1
+ // @ts -check
2
+
1
3
'use strict' ;
4
+
2
5
const chalk = require ( 'chalk' ) ;
3
6
const path = require ( 'path' ) ;
4
7
const childProcess = require ( 'child_process' ) ;
@@ -10,7 +13,14 @@ const {
10
13
} = require ( '../generator-common' ) ;
11
14
12
15
const macOSDir = 'macos' ;
16
+ const oldProjectName = 'HelloWorld' ;
13
17
18
+ /**
19
+ * @param {string } srcRootPath
20
+ * @param {string } destPath
21
+ * @param {string } newProjectName
22
+ * @param {{ overwrite?: boolean } } options
23
+ */
14
24
function copyProjectTemplateAndReplace (
15
25
srcRootPath ,
16
26
destPath ,
@@ -29,29 +39,23 @@ function copyProjectTemplateAndReplace(
29
39
throw new Error ( 'Need a project name' ) ;
30
40
}
31
41
32
- const projectNameMacOS = newProjectName + '-macOS' ;
33
- const projectNameIOS = newProjectName ;
34
- const xcodeProjName = newProjectName + '.xcodeproj' ;
35
- const schemeNameMacOS = newProjectName + '-macOS.xcscheme' ;
36
- const schemeNameIOS = newProjectName + '.xcscheme' ;
37
-
38
42
createDir ( path . join ( destPath , macOSDir ) ) ;
39
- createDir ( path . join ( destPath , macOSDir , projectNameIOS ) ) ;
40
- createDir ( path . join ( destPath , macOSDir , projectNameMacOS ) ) ;
41
- createDir ( path . join ( destPath , macOSDir , xcodeProjName ) ) ;
42
- createDir ( path . join ( destPath , macOSDir , xcodeProjName , 'xcshareddata' ) ) ;
43
- createDir ( path . join ( destPath , macOSDir , xcodeProjName , 'xcshareddata/xcschemes' ) ) ;
43
+ createDir ( path . join ( destPath , srcDirPath ( newProjectName , 'iOS' ) ) ) ;
44
+ createDir ( path . join ( destPath , srcDirPath ( newProjectName , 'macOS' ) ) ) ;
45
+ createDir ( path . join ( destPath , xcodeprojPath ( newProjectName ) ) ) ;
46
+ createDir ( path . join ( destPath , schemesPath ( newProjectName ) ) ) ;
44
47
45
48
const templateVars = {
46
- 'HelloWorld' : newProjectName ,
49
+ [ oldProjectName ] : newProjectName ,
47
50
} ;
48
51
49
52
[
50
- { from : path . join ( srcRootPath , 'macos/HelloWorld' ) , to : path . join ( macOSDir , projectNameIOS ) } ,
51
- { from : path . join ( srcRootPath , 'macos/HelloWorld-macOS' ) , to : path . join ( macOSDir , projectNameMacOS ) } ,
52
- { from : path . join ( srcRootPath , 'macos/HelloWorld.xcodeproj' ) , to : path . join ( macOSDir , xcodeProjName ) } ,
53
- { from : path . join ( srcRootPath , 'macos/xcschemes/HelloWorld-macOS.xcscheme' ) , to : path . join ( macOSDir , xcodeProjName , 'xcshareddata/xcschemes' , schemeNameMacOS ) } ,
54
- { from : path . join ( srcRootPath , 'macos/xcschemes/HelloWorld.xcscheme' ) , to : path . join ( macOSDir , xcodeProjName , 'xcshareddata/xcschemes' , schemeNameIOS ) } ,
53
+ { from : path . join ( srcRootPath , macOSDir , 'Podfile' ) , to : path . join ( macOSDir , 'Podfile' ) } ,
54
+ { from : path . join ( srcRootPath , srcDirPath ( oldProjectName , 'iOS' ) ) , to : srcDirPath ( newProjectName , 'iOS' ) } ,
55
+ { from : path . join ( srcRootPath , srcDirPath ( oldProjectName , 'macOS' ) ) , to : srcDirPath ( newProjectName , 'macOS' ) } ,
56
+ { from : path . join ( srcRootPath , pbxprojPath ( oldProjectName ) ) , to : pbxprojPath ( newProjectName ) } ,
57
+ { from : path . join ( srcRootPath , schemePath ( oldProjectName , 'iOS' ) ) , to : schemePath ( newProjectName , 'iOS' ) } ,
58
+ { from : path . join ( srcRootPath , schemePath ( oldProjectName , 'macOS' ) ) , to : schemePath ( newProjectName , 'macOS' ) } ,
55
59
] . forEach ( ( mapping ) => copyAndReplaceAll ( mapping . from , destPath , mapping . to , templateVars , options . overwrite ) ) ;
56
60
57
61
[
@@ -61,14 +65,70 @@ function copyProjectTemplateAndReplace(
61
65
62
66
console . log ( `
63
67
${ chalk . blue ( `Run instructions for ${ chalk . bold ( 'macOS' ) } ` ) } :
68
+ • cd macos && pod install && cd ..
64
69
• npx react-native run-macos
65
70
${ chalk . dim ( '- or -' ) }
66
- • Open ${ macOSDir } / ${ xcodeProjName } in Xcode or run "xed -b ${ macOSDir } "
71
+ • Open ${ xcworkspacePath ( newProjectName ) } in Xcode or run "xed -b ${ macOSDir } "
67
72
• yarn start:macos
68
73
• Hit the Run button
69
74
` ) ;
70
75
}
71
76
77
+ /**
78
+ * @param {string } basename
79
+ * @param {"iOS" | "macOS" } platform
80
+ */
81
+ function projectName ( basename , platform ) {
82
+ return basename + '-' + platform ;
83
+ }
84
+
85
+ /**
86
+ * @param {string } basename
87
+ * @param {"iOS" | "macOS" } platform
88
+ */
89
+ function srcDirPath ( basename , platform ) {
90
+ return path . join ( macOSDir , projectName ( basename , platform ) ) ;
91
+ }
92
+
93
+ /**
94
+ * @param {string } basename
95
+ */
96
+ function xcodeprojPath ( basename ) {
97
+ return path . join ( macOSDir , basename + '.xcodeproj' ) ;
98
+ }
99
+
100
+ /**
101
+ * @param {string } basename
102
+ */
103
+ function xcworkspacePath ( basename ) {
104
+ return path . join ( macOSDir , basename + '.xcworkspace' ) ;
105
+ }
106
+
107
+ /**
108
+ * @param {string } basename
109
+ */
110
+ function pbxprojPath ( basename ) {
111
+ return path . join ( xcodeprojPath ( basename ) , 'project.pbxproj' ) ;
112
+ }
113
+
114
+ /**
115
+ * @param {string } basename
116
+ */
117
+ function schemesPath ( basename ) {
118
+ return path . join ( xcodeprojPath ( basename ) , 'xcshareddata' , 'xcschemes' ) ;
119
+ }
120
+
121
+ /**
122
+ * @param {string } basename
123
+ * @param {"iOS" | "macOS" } platform
124
+ */
125
+ function schemePath ( basename , platform ) {
126
+ return path . join ( schemesPath ( basename ) , projectName ( basename , platform ) + '.xcscheme' ) ;
127
+ }
128
+
129
+ /**
130
+ * @param {{ verbose?: boolean }= } options
131
+ */
72
132
function installDependencies ( options ) {
73
133
const cwd = process . cwd ( ) ;
74
134
@@ -80,6 +140,8 @@ function installDependencies(options) {
80
140
81
141
// Install dependencies using correct package manager
82
142
const isYarn = fs . existsSync ( path . join ( cwd , 'yarn.lock' ) ) ;
143
+
144
+ /** @type {{ stdio?: 'inherit' } } */
83
145
const execOptions = options && options . verbose ? { stdio : 'inherit' } : { } ;
84
146
childProcess . execSync ( isYarn ? 'yarn' : 'npm i' , execOptions ) ;
85
147
}
0 commit comments