Skip to content

Commit

Permalink
docs(www): add bun support for installation commands (#1445)
Browse files Browse the repository at this point in the history
* feat(www): add bun support for commands

* chore: remove changeset

---------

Co-authored-by: shadcn <[email protected]>
  • Loading branch information
rgodha24 and shadcn authored Sep 21, 2023
1 parent c0deeac commit 4f8d768
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
7 changes: 6 additions & 1 deletion apps/www/components/copy-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export function CopyNpmCommandButton({
}, [hasCopied])

const copyCommand = React.useCallback(
(value: string, pm: "npm" | "pnpm" | "yarn") => {
(value: string, pm: "npm" | "pnpm" | "yarn" | "bun") => {
copyToClipboardWithMeta(value, {
name: "copy_npm_command",
properties: {
Expand Down Expand Up @@ -199,6 +199,11 @@ export function CopyNpmCommandButton({
>
pnpm
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => copyCommand(commands.__bunCommand__, "bun")}
>
bun
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)
Expand Down
27 changes: 16 additions & 11 deletions apps/www/components/mdx-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ const components = {
className,
__rawString__,
__npmCommand__,
__pnpmCommand__,
__yarnCommand__,
__pnpmCommand__,
__bunCommand__,
__withMeta__,
__src__,
__event__,
Expand Down Expand Up @@ -201,16 +202,20 @@ const components = {
className={cn("absolute right-4 top-4", __withMeta__ && "top-16")}
/>
)}
{__npmCommand__ && __yarnCommand__ && __pnpmCommand__ && (
<CopyNpmCommandButton
commands={{
__npmCommand__,
__pnpmCommand__,
__yarnCommand__,
}}
className={cn("absolute right-4 top-4", __withMeta__ && "top-16")}
/>
)}
{__npmCommand__ &&
__yarnCommand__ &&
__pnpmCommand__ &&
__bunCommand__ && (
<CopyNpmCommandButton
commands={{
__npmCommand__,
__yarnCommand__,
__pnpmCommand__,
__bunCommand__,
}}
className={cn("absolute right-4 top-4", __withMeta__ && "top-16")}
/>
)}
</StyleWrapper>
)
},
Expand Down
6 changes: 6 additions & 0 deletions apps/www/lib/rehype-npm-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export function rehypeNpmCommand() {
"npm install",
"pnpm add"
)
node.properties["__bunCommand__"] = npmCommand.replace(
"npm install",
"bun add"
)
}

// npx create.
Expand All @@ -34,6 +38,7 @@ export function rehypeNpmCommand() {
"npx create-",
"pnpm create "
)
node.properties["__bunCommand__"] = npmCommand.replace("npx", "bunx")
}

// npx.
Expand All @@ -48,6 +53,7 @@ export function rehypeNpmCommand() {
"npx",
"pnpm dlx"
)
node.properties["__bunCommand__"] = npmCommand.replace("npx", "bunx")
}
})
}
Expand Down
1 change: 1 addition & 0 deletions apps/www/types/unist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ export interface NpmCommands {
__npmCommand__?: string
__yarnCommand__?: string
__pnpmCommand__?: string
__bunCommand__?: string
}

1 comment on commit 4f8d768

@vercel
Copy link

@vercel vercel bot commented on 4f8d768 Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./apps/www

example-playground.vercel.app
ui-shadcn-pro.vercel.app
ui-git-main-shadcn-pro.vercel.app
ui.shadcn.com

Please sign in to comment.