DEV Community

Ramu Narasinga
Ramu Narasinga

Posted on • Edited on

Next.js Codebase Analysis <> create-next-app <> index.ts explained - Part 1.10

In the previous article, I wrote about project name validation. In this article, let’s look at more code from index.ts

if (program.example === true) {
    console.error(
      'Please provide an example name or url, otherwise remove the example option.'
    )
    process.exit(1)
  }
Enter fullscreen mode Exit fullscreen mode

program.example reminds of accessing options passed in via the cli

example is an option as shown below:

// https://www.npmjs.com/package/commander#options
// -e
// https://github.com/vercel/next.js/tree/canary/packages/create-next-app#non-interactive
.option(
  '-e, --example [name]|[github-url]',
  `
    An example to bootstrap the app with. You can use an example name
    from the official Next.js repo or a GitHub URL. The URL can use
    any branch and/or subdirectory
  `
)
Enter fullscreen mode Exit fullscreen mode

Pass it as npx create-my-app -e, because it needs url when there is no url provided, the following error is thrown

example option

Conclusion:

As I look at the more lines of code, I see that there is safeguarding in place for options submitted, for example, for project name and now for example.

Take the user input and importantly validate it before proceeding further.

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.

If you have any questions, feel free to reach out to me at ramu.narasinga@gmail.com

Get free courses inspired by the best practices used in open source.

About me:

Website: https://ramunarasinga.com/

Linkedin: https://www.linkedin.com/in/ramu-narasinga-189361128/

Github: https://github.com/Ramu-Narasinga

Email: ramu.narasinga@gmail.com

Learn the best practices used in open source.

Top comments (0)