Skip to content

Commit 64b2f1a

Browse files
authored
feat(shadcn): add experimental docs (#4820)
* feat(shadcn): add cli docs * chore: add changeset * fix: tests
1 parent f4ca57a commit 64b2f1a

6 files changed

Lines changed: 24 additions & 0 deletions

File tree

.changeset/small-foxes-destroy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"shadcn": patch
3+
---
4+
5+
add docs support

apps/www/registry/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export const registryEntrySchema = z.object({
6262
category: z.string().optional(),
6363
subcategory: z.string().optional(),
6464
chunks: z.array(blockChunkSchema).optional(),
65+
docs: z.string().optional(),
6566
})
6667

6768
export const registrySchema = z.array(registryEntrySchema)

packages/shadcn/src/utils/add-components.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { type Config } from "@/src/utils/get-config"
22
import { handleError } from "@/src/utils/handle-error"
3+
import { logger } from "@/src/utils/logger"
34
import { registryResolveItemsTree } from "@/src/utils/registry"
45
import { spinner } from "@/src/utils/spinner"
56
import { updateCssVars } from "@/src/utils/updaters/update-css-vars"
@@ -48,4 +49,8 @@ export async function addComponents(
4849
overwrite: options.overwrite,
4950
silent: options.silent,
5051
})
52+
53+
if (tree.docs) {
54+
logger.info(tree.docs)
55+
}
5156
}

packages/shadcn/src/utils/registry/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,13 @@ export async function registryResolveItemsTree(
321321
cssVars = deepmerge(cssVars, item.cssVars ?? {})
322322
})
323323

324+
let docs = ""
325+
payload.forEach((item) => {
326+
if (item.docs) {
327+
docs += `${item.docs}\n`
328+
}
329+
})
330+
324331
return registryResolvedItemsTreeSchema.parse({
325332
dependencies: deepmerge.all(
326333
payload.map((item) => item.dependencies ?? [])
@@ -331,6 +338,7 @@ export async function registryResolveItemsTree(
331338
files: deepmerge.all(payload.map((item) => item.files ?? [])),
332339
tailwind,
333340
cssVars,
341+
docs,
334342
})
335343
} catch (error) {
336344
handleError(error)

packages/shadcn/src/utils/registry/schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const registryItemSchema = z.object({
4646
tailwind: registryItemTailwindSchema.optional(),
4747
cssVars: registryItemCssVarsSchema.optional(),
4848
meta: z.record(z.string(), z.any()).optional(),
49+
docs: z.string().optional(),
4950
})
5051

5152
export type RegistryItem = z.infer<typeof registryItemSchema>
@@ -82,4 +83,5 @@ export const registryResolvedItemsTreeSchema = registryItemSchema.pick({
8283
files: true,
8384
tailwind: true,
8485
cssVars: true,
86+
docs: true,
8587
})

packages/shadcn/test/utils/schema/__snapshots__/registry-resolve-items-tree.test.ts.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ exports[`registryResolveItemTree > should resolve index 1`] = `
2020
"tailwind-merge",
2121
],
2222
"devDependencies": [],
23+
"docs": "",
2324
"files": [
2425
{
2526
"content": ""use client"
@@ -93,6 +94,7 @@ exports[`registryResolveItemTree > should resolve items tree 1`] = `
9394
"@radix-ui/react-slot",
9495
],
9596
"devDependencies": [],
97+
"docs": "",
9698
"files": [
9799
{
98100
"content": "import * as React from "react"
@@ -171,6 +173,7 @@ exports[`registryResolveItemTree > should resolve multiple items tree 1`] = `
171173
"@radix-ui/react-dialog",
172174
],
173175
"devDependencies": [],
176+
"docs": "",
174177
"files": [
175178
{
176179
"content": "import * as React from "react"

0 commit comments

Comments
 (0)