40
40
41
41
var chalk = require ( 'chalk' ) ;
42
42
43
- var currentNodeVersion = process . versions . node
43
+ var currentNodeVersion = process . versions . node ;
44
44
if ( currentNodeVersion . split ( '.' ) [ 0 ] < 4 ) {
45
45
console . error (
46
46
chalk . red (
47
- 'You are running Node ' + currentNodeVersion + '.\n' +
48
- 'Create React App requires Node 4 or higher. \n' +
49
- 'Please update your version of Node.'
47
+ 'You are running Node ' +
48
+ currentNodeVersion +
49
+ '.\n' +
50
+ 'Create React App requires Node 4 or higher. \n' +
51
+ 'Please update your version of Node.'
50
52
)
51
53
) ;
52
54
process . exit ( 1 ) ;
@@ -65,44 +67,78 @@ var program = commander
65
67
. version ( require ( './package.json' ) . version )
66
68
. arguments ( '<project-directory>' )
67
69
. usage ( chalk . green ( '<project-directory>' ) + ' [options]' )
68
- . action ( function ( name ) {
70
+ . action ( function ( name ) {
69
71
projectName = name ;
70
72
} )
71
73
. option ( '--verbose' , 'print additional logs' )
72
- . option ( '--scripts-version <alternative-package>' , 'use a non-standard version of react-scripts' )
74
+ . option (
75
+ '--scripts-version <alternative-package>' ,
76
+ 'use a non-standard version of react-scripts'
77
+ )
73
78
. allowUnknownOption ( )
74
- . on ( '--help' , function ( ) {
75
- console . log ( ' Only ' + chalk . green ( '<project-directory>' ) + ' is required.' ) ;
79
+ . on ( '--help' , function ( ) {
80
+ console . log (
81
+ ' Only ' + chalk . green ( '<project-directory>' ) + ' is required.'
82
+ ) ;
76
83
console . log ( ) ;
77
- console . log ( ' A custom ' + chalk . cyan ( '--scripts-version' ) + ' can be one of:' ) ;
84
+ console . log (
85
+ ' A custom ' + chalk . cyan ( '--scripts-version' ) + ' can be one of:'
86
+ ) ;
78
87
console . log ( ' - a specific npm version: ' + chalk . green ( '0.8.2' ) ) ;
79
- console . log ( ' - a custom fork published on npm: ' + chalk . green ( 'my-react-scripts' ) ) ;
80
- console . log ( ' - a .tgz archive: ' + chalk . green ( 'https://mysite.com/my-react-scripts-0.8.2.tgz' ) ) ;
81
- console . log ( ' It is not needed unless you specifically want to use a fork.' ) ;
88
+ console . log (
89
+ ' - a custom fork published on npm: ' +
90
+ chalk . green ( 'my-react-scripts' )
91
+ ) ;
92
+ console . log (
93
+ ' - a .tgz archive: ' +
94
+ chalk . green ( 'https://mysite.com/my-react-scripts-0.8.2.tgz' )
95
+ ) ;
96
+ console . log (
97
+ ' It is not needed unless you specifically want to use a fork.'
98
+ ) ;
82
99
console . log ( ) ;
83
- console . log ( ' If you have any problems, do not hesitate to file an issue:' ) ;
84
- console . log ( ' ' + chalk . cyan ( 'https://github.com/facebookincubator/create-react-app/issues/new' ) ) ;
100
+ console . log (
101
+ ' If you have any problems, do not hesitate to file an issue:'
102
+ ) ;
103
+ console . log (
104
+ ' ' +
105
+ chalk . cyan (
106
+ 'https://github.com/facebookincubator/create-react-app/issues/new'
107
+ )
108
+ ) ;
85
109
console . log ( ) ;
86
110
} )
87
111
. parse ( process . argv ) ;
88
112
89
113
if ( typeof projectName === 'undefined' ) {
90
114
console . error ( 'Please specify the project directory:' ) ;
91
- console . log ( ' ' + chalk . cyan ( program . name ( ) ) + chalk . green ( ' <project-directory>' ) ) ;
115
+ console . log (
116
+ ' ' + chalk . cyan ( program . name ( ) ) + chalk . green ( ' <project-directory>' )
117
+ ) ;
92
118
console . log ( ) ;
93
119
console . log ( 'For example:' ) ;
94
120
console . log ( ' ' + chalk . cyan ( program . name ( ) ) + chalk . green ( ' my-react-app' ) ) ;
95
121
console . log ( ) ;
96
- console . log ( 'Run ' + chalk . cyan ( program . name ( ) + ' --help' ) + ' to see all options.' ) ;
122
+ console . log (
123
+ 'Run ' + chalk . cyan ( program . name ( ) + ' --help' ) + ' to see all options.'
124
+ ) ;
97
125
process . exit ( 1 ) ;
98
126
}
99
127
100
128
var hiddenProgram = new commander . Command ( )
101
- . option ( '--internal-testing-template <path-to-template>' , '(internal usage only, DO NOT RELY ON THIS) ' +
102
- 'use a non-standard application template' )
103
- . parse ( process . argv )
129
+ . option (
130
+ '--internal-testing-template <path-to-template>' ,
131
+ '(internal usage only, DO NOT RELY ON THIS) ' +
132
+ 'use a non-standard application template'
133
+ )
134
+ . parse ( process . argv ) ;
104
135
105
- createApp ( projectName , program . verbose , program . scriptsVersion , hiddenProgram . internalTestingTemplate ) ;
136
+ createApp (
137
+ projectName ,
138
+ program . verbose ,
139
+ program . scriptsVersion ,
140
+ hiddenProgram . internalTestingTemplate
141
+ ) ;
106
142
107
143
function createApp ( name , verbose , version , template ) {
108
144
var root = path . resolve ( name ) ;
@@ -111,20 +147,22 @@ function createApp(name, verbose, version, template) {
111
147
checkAppName ( appName ) ;
112
148
fs . ensureDirSync ( name ) ;
113
149
if ( ! isSafeToCreateProjectIn ( root ) ) {
114
- console . log ( 'The directory ' + chalk . green ( name ) + ' contains files that could conflict.' ) ;
150
+ console . log (
151
+ 'The directory ' +
152
+ chalk . green ( name ) +
153
+ ' contains files that could conflict.'
154
+ ) ;
115
155
console . log ( 'Try using a new directory name.' ) ;
116
156
process . exit ( 1 ) ;
117
157
}
118
158
119
- console . log (
120
- 'Creating a new React app in ' + chalk . green ( root ) + '.'
121
- ) ;
159
+ console . log ( 'Creating a new React app in ' + chalk . green ( root ) + '.' ) ;
122
160
console . log ( ) ;
123
161
124
162
var packageJson = {
125
163
name : appName ,
126
164
version : '0.1.0' ,
127
- private : true ,
165
+ private : true
128
166
} ;
129
167
fs . writeFileSync (
130
168
path . join ( root , 'package.json' ) ,
@@ -142,7 +180,7 @@ function createApp(name, verbose, version, template) {
142
180
143
181
function shouldUseYarn ( ) {
144
182
try {
145
- execSync ( 'yarnpkg --version' , { stdio : 'ignore' } ) ;
183
+ execSync ( 'yarnpkg --version' , { stdio : 'ignore' } ) ;
146
184
return true ;
147
185
} catch ( e ) {
148
186
return false ;
@@ -154,7 +192,7 @@ function install(packageToInstall, verbose, callback) {
154
192
var args ;
155
193
if ( shouldUseYarn ( ) ) {
156
194
command = 'yarnpkg' ;
157
- args = [ 'add' , '--dev' , '--exact' , packageToInstall ] ;
195
+ args = [ 'add' , '--dev' , '--exact' , packageToInstall ] ;
158
196
} else {
159
197
command = 'npm' ;
160
198
args = [ 'install' , '--save-dev' , '--save-exact' , packageToInstall ] ;
@@ -164,7 +202,7 @@ function install(packageToInstall, verbose, callback) {
164
202
args . push ( '--verbose' ) ;
165
203
}
166
204
167
- var child = spawn ( command , args , { stdio : 'inherit' } ) ;
205
+ var child = spawn ( command , args , { stdio : 'inherit' } ) ;
168
206
child . on ( 'close' , function ( code ) {
169
207
callback ( code , command , args ) ;
170
208
} ) ;
@@ -235,8 +273,8 @@ function checkNodeVersion(packageName) {
235
273
console . error (
236
274
chalk . red (
237
275
'You are running Node %s.\n' +
238
- 'Create React App requires Node %s or higher. \n' +
239
- 'Please update your version of Node.'
276
+ 'Create React App requires Node %s or higher. \n' +
277
+ 'Please update your version of Node.'
240
278
) ,
241
279
process . version ,
242
280
packageJson . engines . node
@@ -254,15 +292,19 @@ function checkAppName(appName) {
254
292
if ( allDependencies . indexOf ( appName ) >= 0 ) {
255
293
console . error (
256
294
chalk . red (
257
- 'We cannot create a project called ' + chalk . green ( appName ) + ' because a dependency with the same name exists.\n' +
258
- 'Due to the way npm works, the following names are not allowed:\n\n'
295
+ 'We cannot create a project called ' +
296
+ chalk . green ( appName ) +
297
+ ' because a dependency with the same name exists.\n' +
298
+ 'Due to the way npm works, the following names are not allowed:\n\n'
259
299
) +
260
- chalk . cyan (
261
- allDependencies . map ( function ( depName ) {
262
- return ' ' + depName ;
263
- } ) . join ( '\n' )
264
- ) +
265
- chalk . red ( '\n\nPlease choose a different project name.' )
300
+ chalk . cyan (
301
+ allDependencies
302
+ . map ( function ( depName ) {
303
+ return ' ' + depName ;
304
+ } )
305
+ . join ( '\n' )
306
+ ) +
307
+ chalk . red ( '\n\nPlease choose a different project name.' )
266
308
) ;
267
309
process . exit ( 1 ) ;
268
310
}
@@ -273,10 +315,15 @@ function checkAppName(appName) {
273
315
// https://github.com/facebookincubator/create-react-app/pull/368#issuecomment-243446094
274
316
function isSafeToCreateProjectIn ( root ) {
275
317
var validFiles = [
276
- '.DS_Store' , 'Thumbs.db' , '.git' , '.gitignore' , '.idea' , 'README.md' , 'LICENSE'
318
+ '.DS_Store' ,
319
+ 'Thumbs.db' ,
320
+ '.git' ,
321
+ '.gitignore' ,
322
+ '.idea' ,
323
+ 'README.md' ,
324
+ 'LICENSE'
277
325
] ;
278
- return fs . readdirSync ( root )
279
- . every ( function ( file ) {
280
- return validFiles . indexOf ( file ) >= 0 ;
281
- } ) ;
326
+ return fs . readdirSync ( root ) . every ( function ( file ) {
327
+ return validFiles . indexOf ( file ) >= 0 ;
328
+ } ) ;
282
329
}
0 commit comments