Skip to content

Commit edac99a

Browse files
author
Ramu Narasinga
committed
added comments for part 1.1
1 parent 976e6e0 commit edac99a

File tree

8 files changed

+35
-4
lines changed

8 files changed

+35
-4
lines changed

create-next-app/dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

create-next-app/index.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ const onPromptState = (state: {
3636
}
3737
}
3838

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.
3944
const program = new Commander.Command(packageJson.name)
4045
.version(packageJson.version)
4146
.arguments('<project-directory>')
@@ -160,8 +165,15 @@ const packageManager = !!program.useNpm
160165
: getPkgManager()
161166

162167
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.
163171
const conf = new Conf({ projectName: 'create-next-app' })
164172

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.
165177
if (program.resetPreferences) {
166178
conf.clear()
167179
console.log(`Preferences reset successfully`)
@@ -498,21 +510,40 @@ async function notifyUpdate(): Promise<void> {
498510
}
499511

500512
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
502517
.catch(async (reason) => {
503518
console.log()
519+
// Log explains installation is aborted
520+
// How often do you log when you encounter failure?
504521
console.log('Aborting installation.')
522+
523+
// This is specifically looking for command prop
524+
// Specificity matters when it comes to error logging
505525
if (reason.command) {
506526
console.log(` ${cyan(reason.command)} has failed.`)
507527
} else {
528+
// There is a catchall as well
529+
// Nice!
508530
console.log(
509531
red('Unexpected error. Please report it as a bug:') + '\n',
510532
reason
511533
)
512534
}
513535
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?
515542
await notifyUpdate()
516543

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
517548
process.exit(1)
518549
})
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

create-next-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"author": "Next.js Team <[email protected]>",
1616
"license": "MIT",
1717
"bin": {
18-
"create-tthroo-app": "./dist/index.js"
18+
"create-my-app": "./dist/index.js"
1919
},
2020
"files": [
2121
"dist"

0 commit comments

Comments
 (0)