Skip to content

Commit

Permalink
feat(shadcn): add experimental docs (#4820)
Browse files Browse the repository at this point in the history
* feat(shadcn): add cli docs

* chore: add changeset

* fix: tests
  • Loading branch information
shadcn authored Sep 12, 2024
1 parent f4ca57a commit 64b2f1a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-foxes-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"shadcn": patch
---

add docs support
1 change: 1 addition & 0 deletions apps/www/registry/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const registryEntrySchema = z.object({
category: z.string().optional(),
subcategory: z.string().optional(),
chunks: z.array(blockChunkSchema).optional(),
docs: z.string().optional(),
})

export const registrySchema = z.array(registryEntrySchema)
Expand Down
5 changes: 5 additions & 0 deletions packages/shadcn/src/utils/add-components.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type Config } from "@/src/utils/get-config"
import { handleError } from "@/src/utils/handle-error"
import { logger } from "@/src/utils/logger"
import { registryResolveItemsTree } from "@/src/utils/registry"
import { spinner } from "@/src/utils/spinner"
import { updateCssVars } from "@/src/utils/updaters/update-css-vars"
Expand Down Expand Up @@ -48,4 +49,8 @@ export async function addComponents(
overwrite: options.overwrite,
silent: options.silent,
})

if (tree.docs) {
logger.info(tree.docs)
}
}
8 changes: 8 additions & 0 deletions packages/shadcn/src/utils/registry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ export async function registryResolveItemsTree(
cssVars = deepmerge(cssVars, item.cssVars ?? {})
})

let docs = ""
payload.forEach((item) => {
if (item.docs) {
docs += `${item.docs}\n`
}
})

return registryResolvedItemsTreeSchema.parse({
dependencies: deepmerge.all(
payload.map((item) => item.dependencies ?? [])
Expand All @@ -331,6 +338,7 @@ export async function registryResolveItemsTree(
files: deepmerge.all(payload.map((item) => item.files ?? [])),
tailwind,
cssVars,
docs,
})
} catch (error) {
handleError(error)
Expand Down
2 changes: 2 additions & 0 deletions packages/shadcn/src/utils/registry/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const registryItemSchema = z.object({
tailwind: registryItemTailwindSchema.optional(),
cssVars: registryItemCssVarsSchema.optional(),
meta: z.record(z.string(), z.any()).optional(),
docs: z.string().optional(),
})

export type RegistryItem = z.infer<typeof registryItemSchema>
Expand Down Expand Up @@ -82,4 +83,5 @@ export const registryResolvedItemsTreeSchema = registryItemSchema.pick({
files: true,
tailwind: true,
cssVars: true,
docs: true,
})
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ exports[`registryResolveItemTree > should resolve index 1`] = `
"tailwind-merge",
],
"devDependencies": [],
"docs": "",
"files": [
{
"content": ""use client"
Expand Down Expand Up @@ -93,6 +94,7 @@ exports[`registryResolveItemTree > should resolve items tree 1`] = `
"@radix-ui/react-slot",
],
"devDependencies": [],
"docs": "",
"files": [
{
"content": "import * as React from "react"
Expand Down Expand Up @@ -171,6 +173,7 @@ exports[`registryResolveItemTree > should resolve multiple items tree 1`] = `
"@radix-ui/react-dialog",
],
"devDependencies": [],
"docs": "",
"files": [
{
"content": "import * as React from "react"
Expand Down

0 comments on commit 64b2f1a

Please sign in to comment.