Logo

dev-resources.site

for different kinds of informations.

shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 2.7

Published at
7/5/2024
Categories
javascript
opensource
nextjs
shadcnui
Author
ramunarasinga
Author
13 person written this
ramunarasinga
open
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 2.7

I wanted to find out how shadcn-ui CLI works. In this article, I discuss the code used to build the shadcn-ui/ui CLI.

In part 2.6, we looked at function getTsConfigAliasPrefix that returns the alias used in paths in your project’s ts-config.json.

Let’s move on to the next line of code.

At L84, it is a simple check that returns null if any of the projectType or tailwindCssFile or tsConfigAliasPrefix does not exist.

Let’s learn more about isTypescriptProject(cwd)

const isTsx = await isTypeScriptProject(cwd)
Enter fullscreen mode Exit fullscreen mode

isTypescriptProject is a function imported from ui/packages/cli/src/utils/get-project-info.ts and this function checks if the cwd (current working directory) has a tsconfig.json file.

export async function isTypeScriptProject(cwd: string) {
  // Check if cwd has a tsconfig.json file.
  return pathExists(path.resolve(cwd, "tsconfig.json"))
}
Enter fullscreen mode Exit fullscreen mode

pathExists

pathExists is a function imported from fs-extra

import fs, { pathExists } from "fs-extra"
Enter fullscreen mode Exit fullscreen mode

Conclusion:

To check if a project uses TypeScript, you could do the same thing that shadcn-ui/ui CLI package does. That is, check if tsconfig.json path exists in the given cwd using pathExists function provided by fs-extra.

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: [email protected]

Learn the best practices used in open source.

References:

  1. https://github.com/shadcn-ui/ui/blob/main/packages/cli/src/utils/get-project-info.ts#L84C3-L88C47
  2. https://github.com/shadcn-ui/ui/blob/main/packages/cli/src/utils/get-project-info.ts#L174
  3. https://github.com/shadcn-ui/ui/blob/main/packages/cli/src/utils/get-project-info.ts#L10
  4. https://www.npmjs.com/package/fs-extra
shadcnui Article's
30 articles in total
Favicon
Color Highlighting for Tailwind CSS Variables in VS Code
Favicon
Shadcn UI Theme generator, with OKLCH colors and ancient sacred geometry.
Favicon
Next.js Starter Kit: Build Fast & Secure Apps with Auth, Payments & More!
Favicon
Comparing the copyToClipboard implementations in Shadcn-ui/ui and Codehike.
Favicon
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 3.1
Favicon
Comparison of file and component structures among Shadcn-ui, Plane.so and Gitroom.
Favicon
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 3.0
Favicon
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 2.15
Favicon
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 2.14
Favicon
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 2.13
Favicon
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 2.12
Favicon
Create File Upload UI in Next.js with Shadcn UI
Favicon
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 2.11
Favicon
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 2.10
Favicon
How to Use Icons in Shadcn UI with Next.js
Favicon
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 2.9
Favicon
Next.js with Shadcn UI Progress Bar Example
Favicon
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 2.7
Favicon
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 2.5
Favicon
How to Use Scroll Area in Next.js with Shadcn UI
Favicon
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 2.4
Favicon
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 2.3
Favicon
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 2.2
Favicon
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 2.0
Favicon
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 2.1
Favicon
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 1.1
Favicon
shadcn-ui/ui codebase analysis: How does shadcn-ui CLI work? β€” Part 1.0
Favicon
shadcn-ui/ui codebase analysis: How is β€œBlocks” page built β€” Part 5
Favicon
Next.js Image File Upload and Preview with shadcn/ui
Favicon
shadcn-ui/ui codebase analysis: How is β€œBlocks” page built β€” Part 3

Featured ones: