@@ -11,7 +11,7 @@ const spawn = require('cross-spawn');
1111let projectName ;
1212
1313const allDeps = {
14- antdsite : '^0.0.4 ' ,
14+ antdsite : 'latest ' ,
1515 gatsby : '^2.13.39' ,
1616 react : '^16.8.0' ,
1717 'react-dom' : '^16.8.0'
@@ -29,7 +29,7 @@ const program = new commander.Command(packageJson.name)
2929 . version ( packageJson . version )
3030 . arguments ( '[project-directory]' )
3131 . usage ( `${ chalk . green ( '[project-directory]' ) } ` )
32- . action ( name => {
32+ . action ( ( name ) => {
3333 projectName = name ;
3434 } )
3535 . option ( '--use-npm' )
@@ -39,7 +39,7 @@ createApp(projectName, program.useNpm);
3939
4040function printValidationResults ( results ) {
4141 if ( typeof results !== 'undefined' ) {
42- results . forEach ( error => {
42+ results . forEach ( ( error ) => {
4343 console . error ( chalk . red ( ` * ${ error } ` ) ) ;
4444 } ) ;
4545 }
@@ -69,7 +69,7 @@ function checkAppName(appName) {
6969 `Due to the way npm works, the following names are not allowed:\n\n`
7070 ) +
7171 chalk . hex ( '#29CDFF' ) (
72- dependencies . map ( depName => ` ${ depName } ` ) . join ( '\n' )
72+ dependencies . map ( ( depName ) => ` ${ depName } ` ) . join ( '\n' )
7373 ) +
7474 chalk . red ( '\n\nPlease choose a different project name.' )
7575 ) ;
@@ -87,14 +87,14 @@ function shouldUseYarn() {
8787}
8888
8989function executeNodeScript ( { cwd, initScriptPath } , data , source ) {
90- return new Promise ( resolve => {
90+ return new Promise ( ( resolve ) => {
9191 const child = spawn (
9292 process . execPath ,
9393 [ '-e' , source , '--' , JSON . stringify ( data ) , initScriptPath ] ,
9494 { cwd, stdio : 'inherit' }
9595 ) ;
9696
97- child . on ( 'close' , code => {
97+ child . on ( 'close' , ( code ) => {
9898 if ( code !== 0 ) {
9999 return ;
100100 }
@@ -121,12 +121,13 @@ function isSafeToCreateProjectIn(root, name) {
121121
122122 const conflicts = fs
123123 . readdirSync ( root )
124- . filter ( file => ! validFiles . includes ( file ) )
124+ . filter ( ( file ) => ! validFiles . includes ( file ) )
125125 // IntelliJ IDEA creates module files before CRA is launched
126- . filter ( file => ! / \. i m l $ / . test ( file ) )
126+ . filter ( ( file ) => ! / \. i m l $ / . test ( file ) )
127127 // Don't treat log files from previous installation as conflicts
128128 . filter (
129- file => ! errorLogFilePatterns . some ( pattern => file . indexOf ( pattern ) === 0 )
129+ ( file ) =>
130+ ! errorLogFilePatterns . some ( ( pattern ) => file . indexOf ( pattern ) === 0 )
130131 ) ;
131132
132133 if ( conflicts . length > 0 ) {
@@ -147,8 +148,8 @@ function isSafeToCreateProjectIn(root, name) {
147148
148149 // Remove any remnant files from a previous installation
149150 const currentFiles = fs . readdirSync ( path . join ( root ) ) ;
150- currentFiles . forEach ( file => {
151- errorLogFilePatterns . forEach ( errorLogFilePattern => {
151+ currentFiles . forEach ( ( file ) => {
152+ errorLogFilePatterns . forEach ( ( errorLogFilePattern ) => {
152153 // This will catch `(npm-debug|yarn-error|yarn-debug).log*` files
153154 if ( file . indexOf ( errorLogFilePattern ) === 0 ) {
154155 fs . removeSync ( path . join ( root , file ) ) ;
@@ -158,13 +159,14 @@ function isSafeToCreateProjectIn(root, name) {
158159 return true ;
159160}
160161
161- function createApp ( name , useNpm ) {
162- const root = path . resolve ( name || './' ) ;
162+ function createApp ( name = './' , useNpm ) {
163+ const root = path . resolve ( name ) ;
163164 const appName = path . basename ( root ) ;
165+ const originalDirectory = process . cwd ( ) ;
164166
165167 checkAppName ( appName ) ;
166168 fs . ensureDirSync ( name ) ;
167- if ( ! isSafeToCreateProjectIn ( root , name ) ) {
169+ if ( ! isSafeToCreateProjectIn ( root , appName ) ) {
168170 process . exit ( 1 ) ;
169171 }
170172
@@ -228,21 +230,20 @@ function createApp(name, useNpm) {
228230 return pre . concat ( cur + '@' + allDeps [ cur ] ) ;
229231 } , [ ] ) ;
230232
231- run ( root , dependencies , useYarn , appName ) ;
233+ run ( root , dependencies , useYarn , appName , originalDirectory ) ;
232234}
233235
234- function run ( root , dependencies , useYarn , appName ) {
236+ function run ( root , dependencies , useYarn , appName , originalDirectory ) {
235237 console . log ( `Installing ${ chalk . hex ( '#29CDFF' ) ( dependencies . join ( ' ' ) ) } ...` ) ;
236238 install ( root , useYarn , dependencies ) . then ( ( ) => {
237239 const initScriptPath = path . resolve ( __dirname , 'init.js' ) ;
238- console . log ( initScriptPath ) ;
239240
240241 executeNodeScript (
241242 {
242243 cwd : process . cwd ( ) ,
243244 initScriptPath
244245 } ,
245- [ root , appName , useYarn ] ,
246+ [ root , appName , useYarn , originalDirectory ] ,
246247 `
247248 var init = require(process.argv[2]);
248249 init.apply(null, JSON.parse(process.argv[1]));
@@ -253,6 +254,7 @@ function run(root, dependencies, useYarn, appName) {
253254
254255function install ( root , useYarn , dependencies ) {
255256 return new Promise ( ( resolve , reject ) => {
257+ return resolve ( ) ;
256258 let command ;
257259 let args ;
258260 if ( useYarn ) {
@@ -280,7 +282,7 @@ function install(root, useYarn, dependencies) {
280282 }
281283
282284 const child = spawn ( command , args , { stdio : 'inherit' } ) ;
283- child . on ( 'close' , code => {
285+ child . on ( 'close' , ( code ) => {
284286 if ( code !== 0 ) {
285287 reject ( {
286288 command : `${ command } ${ args . join ( ' ' ) } `
0 commit comments