shadcn-ui / ui

Beautifully designed components that you can copy and paste into your apps. Accessible. Customizable. Open Source.
https://ui.shadcn.com
MIT License
62.84k stars 3.53k forks source link

Add config.ts to let the CLI know about components path #369

Closed ahkhanjani closed 1 year ago

ahkhanjani commented 1 year ago

It's kind of painful to type the path on every component install. Sometimes the path is too long or there's a typo etc. A config file in the root directory could solve this issue. Something like this:

// shadcnui.config.ts

export default {
    components: "./src/components/ui/shadcn"
};

If the file exists the CLI shouldn't ask for a path.

shadcn commented 1 year ago

@ahkhanjani Yep we're looking into it in #245

albbus-stack commented 1 year ago

It should be a pretty straightforward change at the bottom of the cli index.ts:

async function promptForDestinationDir() {
  if (!fs.existsSync('./shadcnui.config.ts')) {
    const { dir } = await prompts([
      {
        type: "text",
        name: "dir",
        message: "Where would you like to install the component(s)?",
        initial: "./components/ui",
      },
    ])

    return dir
  }

  const config = require('./shadcnui.config.ts')

  return config.componentsPath
}

I don't really know how to parse a .config.ts file, this is just an idea.