Blog
Next.js Codebase Analysis <> create-next-app <> index.ts explained — Part 1.15

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

In the previous article, you will find code explanation about how — typecript or — javascript arguments via CLI are handled.

In this article, you will see how the “— es-lint” or “? Would you like to use ESLint? › No / Yes” is configured

You will find the code below in next.js/create-next-app/index.ts

if (
      // Check if there is an argument --es-lint passed
      !process.argv.includes('--eslint') &&
      !process.argv.includes('--no-eslint')
    ) {
      // If not, check the user preferences 
      // cached/stored using Conf npm package
      // Skip the prompt, if this package runs in CI
      // ciInfo is from https://www.npmjs.com/package/ci-info
      if (ciInfo.isCI) {
        program.eslint = getPrefOrDefault('eslint')
      } else {
        // styledEslint, you could just directly use blue from picocolors
        // in the message below
        const styledEslint = blue('ESLint')
        // This is the prompt configuration that shows you the EsList prompt
        // in the CLI
        const { eslint } = await prompts({
          onState: onPromptState,
          type: 'toggle',
          name: 'eslint',
          message: `Would you like to use ${styledEslint}?`,
          initial: getPrefOrDefault('eslint'),
          active: 'Yes',
          inactive: 'No',
        })
        // set the program and preferneces keys
        program.eslint = Boolean(eslint)
        preferences.eslint = Boolean(eslint)
      }
    }

Conclusion

To summarise the code snippet used in this article, check if there is an argument passed via the CLI for ESLint, if not, show a prompt and take user’s input. There’s a side effect that makes the prompt skip if ciInfo.isCI is true. https://www.npmjs.com/package/ci-info can be used to detect if your node program is executed on CI server

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:

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.

I am open to work on interesting projects. Send me an email at ramu.narasinga@gmail.com

My Github —  https://github.com/ramu-narasinga

My website —  https://ramunarasinga.com

My Youtube channel —  https://www.youtube.com/@ramu-narasinga

Learning platform —  https://thinkthroo.com

Codebase Architecture —  https://app.thinkthroo.com/architecture

Best practices —  https://app.thinkthroo.com/best-practices

Production-grade projects —  https://app.thinkthroo.com/production-grade-projects