@@ -36,6 +36,11 @@ const onPromptState = (state: {
36
36
}
37
37
}
38
38
39
+ // Commander is a package for CLI available here:
40
+ // https://www.npmjs.com/package/commander
41
+ // packageJson is from import on top of the file
42
+ // import packageJson from './package.json'
43
+ // I personally never had to import anything from package.json, I guess you can do it.
39
44
const program = new Commander . Command ( packageJson . name )
40
45
. version ( packageJson . version )
41
46
. arguments ( '<project-directory>' )
@@ -160,8 +165,15 @@ const packageManager = !!program.useNpm
160
165
: getPkgManager ( )
161
166
162
167
async function run ( ) : Promise < void > {
168
+
169
+ // a Conf object creation with projectName.
170
+ // We do not know what Conf does yet and it is okay.
163
171
const conf = new Conf ( { projectName : 'create-next-app' } )
164
172
173
+ // My first thought, where did the program come from?
174
+ // Let’s find out by looking outside the run() function.
175
+ // We skipped Conf class but the program variable cannot be skipped.
176
+ // I know for a fact it is a global variable.
165
177
if ( program . resetPreferences ) {
166
178
conf . clear ( )
167
179
console . log ( `Preferences reset successfully` )
@@ -498,21 +510,40 @@ async function notifyUpdate(): Promise<void> {
498
510
}
499
511
500
512
run ( )
501
- . then ( notifyUpdate )
513
+ . then ( notifyUpdate ) // On successful execution of run(), call notifyUpdate. Not sure what notifyUpdate does yet.
514
+ // you have a reason why catch failed,
515
+ // I tend to put error as variable name,
516
+ // It makes to label it as reason
502
517
. catch ( async ( reason ) => {
503
518
console . log ( )
519
+ // Log explains installation is aborted
520
+ // How often do you log when you encounter failure?
504
521
console . log ( 'Aborting installation.' )
522
+
523
+ // This is specifically looking for command prop
524
+ // Specificity matters when it comes to error logging
505
525
if ( reason . command ) {
506
526
console . log ( ` ${ cyan ( reason . command ) } has failed.` )
507
527
} else {
528
+ // There is a catchall as well
529
+ // Nice!
508
530
console . log (
509
531
red ( 'Unexpected error. Please report it as a bug:' ) + '\n' ,
510
532
reason
511
533
)
512
534
}
513
535
console . log ( )
514
-
536
+ // Notify update even when the installation is aborted
537
+ // This makes me wonder if it is worth writing .then()
538
+ // But promises do not execute if you don’t put .then()
539
+ // Learnt it the hard way that one time when I was calling a promise without .then() and
540
+ // started questioning my progamming abilities because I forgot to initailise a promise with .then()
541
+ // How often do you question your programming abilties?
515
542
await notifyUpdate ( )
516
543
544
+ // useful links:
545
+ // https://stackoverflow.com/questions/5266152/how-to-exit-in-node-js
546
+ // https://nodejs.org/api/process.html#process
547
+ // This exits the node process with a failure
517
548
process . exit ( 1 )
518
549
} )
0 commit comments