Skip to content

Commit

Permalink
feat: add support for adding devDependencies in the cli (#2419)
Browse files Browse the repository at this point in the history
* feat(cli): add support for install devDependencies

* chore: add changeset
  • Loading branch information
shadcn committed Jan 14, 2024
1 parent 8f3b28f commit 7640ef7
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/violet-roses-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"shadcn-ui": minor
---

add support for devDependencies
1 change: 1 addition & 0 deletions apps/www/registry/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const ui: Registry = [
files: ["ui/carousel.tsx"],
registryDependencies: ["button"],
dependencies: ["embla-carousel-react"],
devDependencies: ["embla-carousel"],
},
{
name: "checkbox",
Expand Down
1 change: 1 addition & 0 deletions apps/www/registry/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const registrySchema = z.array(
z.object({
name: z.string(),
dependencies: z.array(z.string()).optional(),
devDependencies: z.array(z.string()).optional(),
registryDependencies: z.array(z.string()).optional(),
files: z.array(z.string()),
type: z.enum([
Expand Down
18 changes: 17 additions & 1 deletion packages/cli/src/commands/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,10 @@ export const add = new Command()
await fs.writeFile(filePath, content)
}

const packageManager = await getPackageManager(cwd)

// Install dependencies.
if (item.dependencies?.length) {
const packageManager = await getPackageManager(cwd)
await execa(
packageManager,
[
Expand All @@ -194,6 +195,21 @@ export const add = new Command()
}
)
}

// Install devDependencies.
if (item.devDependencies?.length) {
await execa(
packageManager,
[
packageManager === "npm" ? "install" : "add",
"-D",
...item.devDependencies,
],
{
cwd,
}
)
}
}
spinner.succeed(`Done.`)
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/utils/registry/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as z from "zod"
export const registryItemSchema = z.object({
name: z.string(),
dependencies: z.array(z.string()).optional(),
devDependencies: z.array(z.string()).optional(),
registryDependencies: z.array(z.string()).optional(),
files: z.array(z.string()),
type: z.enum(["components:ui", "components:component", "components:example"]),
Expand Down

0 comments on commit 7640ef7

Please sign in to comment.