In the previous article, I wrote about project.example option. In this article, let’s look at more code from index.ts
/** * Verify the project dir is empty or doesn't exist */ const root = path.resolve(resolvedProjectPath) const appName = path.basename(root) const folderExists = fs.existsSync(root) if (folderExists && !isFolderEmpty(root, appName)) { process.exit(1) }
Looking at the above code, the comment already was there. I did not add it. It just checks if the project directory and does not exist, otherwise processs exits.
I am surprised there is no console.log before process.exit.
I logged the root, appName, folderExists and built the project and ran the command npx create-my-app and the following were found.
Looks like these will be logged after the first prompt to provide your project name.
As we are progressing in understanding how create-next-app is written, this article explains another safe guarding technique against providing an existing folder or project name.
I shall write more about isFolderEmpty in the next article. I try not to overdo these analysis, my goal is to get better at programming everyday by reading some unknown code from opensource and take notes so I could apply these later in the future.
I am building a platform that explains best practices used in open source by elite programmers. Join the waitlist and I will send you the link to the tutorials once they are ready.
Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.