From c1e29824cd7a6809448e45b6b7fe8f7be71ecb0f Mon Sep 17 00:00:00 2001 From: shadcn Date: Mon, 6 Apr 2026 23:07:44 +0400 Subject: [PATCH 01/19] feat: add apply command --- .changeset/common-pears-accept.md | 5 + apps/v4/content/docs/(root)/cli.mdx | 78 ++++- packages/shadcn/README.md | 10 + packages/shadcn/src/commands/apply.test.ts | 47 +++ packages/shadcn/src/commands/apply.ts | 325 ++++++++++++++++++ packages/shadcn/src/commands/init.ts | 104 +++--- packages/shadcn/src/index.ts | 2 + .../shadcn/src/preflights/preflight-apply.ts | 74 ++++ packages/shadcn/src/preset/presets.ts | 49 ++- packages/shadcn/src/utils/file-helper.test.ts | 49 +++ packages/shadcn/src/utils/file-helper.ts | 37 ++ .../shadcn/src/utils/get-monorepo-info.ts | 11 +- packages/tests/src/tests/apply.test.ts | 263 ++++++++++++++ packages/tests/src/utils/helpers.ts | 3 + skills/shadcn/SKILL.md | 16 +- skills/shadcn/cli.md | 31 +- skills/shadcn/customization.md | 23 +- 17 files changed, 1010 insertions(+), 117 deletions(-) create mode 100644 .changeset/common-pears-accept.md create mode 100644 packages/shadcn/src/commands/apply.test.ts create mode 100644 packages/shadcn/src/commands/apply.ts create mode 100644 packages/shadcn/src/preflights/preflight-apply.ts create mode 100644 packages/shadcn/src/utils/file-helper.test.ts create mode 100644 packages/tests/src/tests/apply.test.ts diff --git a/.changeset/common-pears-accept.md b/.changeset/common-pears-accept.md new file mode 100644 index 000000000..c5662c64b --- /dev/null +++ b/.changeset/common-pears-accept.md @@ -0,0 +1,5 @@ +--- +"shadcn": minor +--- + +add shadcn apply command diff --git a/apps/v4/content/docs/(root)/cli.mdx b/apps/v4/content/docs/(root)/cli.mdx index 43374f872..95ac99eda 100644 --- a/apps/v4/content/docs/(root)/cli.mdx +++ b/apps/v4/content/docs/(root)/cli.mdx @@ -5,10 +5,12 @@ description: Use the shadcn CLI to add components to your project. ## init -Use the `init` command to initialize configuration and dependencies for a new project. +Use the `init` command to initialize configuration and dependencies for an existing project, or create a new project with `--name`. The `init` command installs dependencies, adds the `cn` util and configures CSS variables for the project. +For preset reapplication in an existing project, use [`apply`](#apply) when you want to overwrite preset-driven files and reinstall detected UI components. Use `init --force --no-reinstall` when you want to update config and CSS without reinstalling existing components. + ```bash npx shadcn@latest init ``` @@ -16,31 +18,31 @@ npx shadcn@latest init **Options** ```bash -Usage: shadcn init [options] [components...] +Usage: shadcn init|create [options] [components...] initialize your project and install dependencies Arguments: - components name, url or local path to component + components names, url or local path to component Options: -t, --template