@@ -317,16 +317,6 @@ module.exports = class extends Generator {
317
317
this . log ( `${ chalk . green ( "create folder" ) } ${ this . answers . projectSlug } ` ) ;
318
318
mkdirp . sync ( this . answers . projectSlug ) ;
319
319
this . destinationRoot ( this . destinationPath ( this . answers . projectSlug ) ) ;
320
-
321
- // A ".yo-rc.json" file may have been created at the starting path during the prompting step
322
- if (
323
- this . fs . exists ( this . destinationPath ( path . join ( ".." , ".yo-rc.json" ) ) )
324
- ) {
325
- this . fs . move (
326
- this . destinationPath ( path . join ( ".." , ".yo-rc.json" ) ) ,
327
- this . destinationPath ( ".yo-rc.json" )
328
- ) ;
329
- }
330
320
}
331
321
}
332
322
@@ -434,23 +424,41 @@ module.exports = class extends Generator {
434
424
}
435
425
436
426
end ( ) {
427
+ // The ".yo-rc.json" file may have been created at the starting path during the prompting step and has to be moved
428
+ // to the generated project folder. It should be moved in the `end()` step because previous steps may use the
429
+ // ".yo-rc.json" file in its original path.
430
+ if (
431
+ ! this . fs . exists ( this . destinationPath ( ".yo-rc.json" ) ) &&
432
+ this . fs . exists ( this . destinationPath ( path . join ( ".." , ".yo-rc.json" ) ) )
433
+ ) {
434
+ this . fs . move (
435
+ this . destinationPath ( path . join ( ".." , ".yo-rc.json" ) ) ,
436
+ this . destinationPath ( ".yo-rc.json" )
437
+ ) ;
438
+ }
439
+
437
440
// Initialize git repository
438
441
this . spawnCommandSync ( "git" , [ "init" ] ) ;
439
442
440
- // Create initial commit if there is no commit yet
443
+ // If there is no commit yet, add all files to Git and create initial commit
441
444
if (
442
445
this . spawnCommandSync ( "git" , [ "rev-parse" , "--verify" , "HEAD" ] , {
443
446
stdio : "ignore"
444
447
} ) . status !== 0
445
448
) {
446
- this . spawnCommandSync ( "git" , [ "add" , "." ] ) ;
447
- this . log ( "Creating initial commit" ) ;
448
- this . spawnCommandSync ( "git" , [
449
- "commit" ,
450
- "--quiet" ,
451
- "--message" ,
452
- "Initial commit (generated by Sicarator)"
453
- ] ) ;
449
+ // Commit last file system changes (especially ".yo-rc.json" move) so that everything is added to Git
450
+ this . fs . commit ( [ ] , ( ) => {
451
+ this . log ( "Adding all generated files to Git" ) ;
452
+ this . spawnCommandSync ( "git" , [ "add" , "." ] ) ;
453
+
454
+ this . log ( "Creating initial commit" ) ;
455
+ this . spawnCommandSync ( "git" , [
456
+ "commit" ,
457
+ "--quiet" ,
458
+ "--message" ,
459
+ "Initial commit (generated by Sicarator)"
460
+ ] ) ;
461
+ } ) ;
454
462
}
455
463
}
456
464
} ;
0 commit comments