From b40685050ddd6d0befda6d89988e11165a9cd34a Mon Sep 17 00:00:00 2001 From: shadcn Date: Mon, 2 Mar 2026 11:19:59 +0400 Subject: [PATCH] refactor: presets --- packages/shadcn/src/commands/add.ts | 10 +++--- packages/shadcn/src/commands/init.ts | 17 ++++----- packages/shadcn/src/preset/index.ts | 2 +- .../src/{utils => preset}/preset.test.ts | 0 .../shadcn/src/{utils => preset}/preset.ts | 35 +++++++++++++++---- .../src/{utils => preset}/presets.test.ts | 0 .../shadcn/src/{utils => preset}/presets.ts | 0 packages/shadcn/src/templates/index.ts | 2 +- packages/shadcn/src/utils/index.ts | 21 ----------- 9 files changed, 45 insertions(+), 42 deletions(-) rename packages/shadcn/src/{utils => preset}/preset.test.ts (100%) rename packages/shadcn/src/{utils => preset}/preset.ts (93%) rename packages/shadcn/src/{utils => preset}/presets.test.ts (100%) rename packages/shadcn/src/{utils => preset}/presets.ts (100%) diff --git a/packages/shadcn/src/commands/add.ts b/packages/shadcn/src/commands/add.ts index f6e39c1784..2bb8c0d195 100644 --- a/packages/shadcn/src/commands/add.ts +++ b/packages/shadcn/src/commands/add.ts @@ -1,6 +1,11 @@ import path from "path" import { runInit } from "@/src/commands/init" import { preFlightAdd } from "@/src/preflights/preflight-add" +import { + promptForBase, + promptForPreset, + resolveRegistryBaseConfig, +} from "@/src/preset/presets" import { getRegistryItems, getShadcnRegistryIndex } from "@/src/registry/api" import { DEPRECATED_COMPONENTS } from "@/src/registry/constants" import { clearRegistryContext } from "@/src/registry/context" @@ -18,11 +23,6 @@ import { getProjectInfo } from "@/src/utils/get-project-info" import { handleError } from "@/src/utils/handle-error" import { highlighter } from "@/src/utils/highlighter" import { logger } from "@/src/utils/logger" -import { - promptForBase, - promptForPreset, - resolveRegistryBaseConfig, -} from "@/src/utils/presets" import { ensureRegistriesInConfig } from "@/src/utils/registries" import { spinner } from "@/src/utils/spinner" import { updateAppIndex } from "@/src/utils/update-app-index" diff --git a/packages/shadcn/src/commands/init.ts b/packages/shadcn/src/commands/init.ts index 2dd4553b32..aa05688039 100644 --- a/packages/shadcn/src/commands/init.ts +++ b/packages/shadcn/src/commands/init.ts @@ -1,6 +1,14 @@ import { promises as fs } from "fs" import path from "path" import { preFlightInit } from "@/src/preflights/preflight-init" +import { decodePreset, isPresetCode } from "@/src/preset/preset" +import { + DEFAULT_PRESETS, + promptForBase, + promptForPreset, + resolveInitUrl, + resolveRegistryBaseConfig, +} from "@/src/preset/presets" import { getRegistryBaseColors, getRegistryStyles } from "@/src/registry/api" import { BUILTIN_REGISTRIES } from "@/src/registry/constants" import { clearRegistryContext } from "@/src/registry/context" @@ -45,14 +53,6 @@ import { import { handleError } from "@/src/utils/handle-error" import { highlighter } from "@/src/utils/highlighter" import { logger } from "@/src/utils/logger" -import { decodePreset, isPresetCode } from "@/src/utils/preset" -import { - DEFAULT_PRESETS, - promptForBase, - promptForPreset, - resolveInitUrl, - resolveRegistryBaseConfig, -} from "@/src/utils/presets" import { ensureRegistriesInConfig } from "@/src/utils/registries" import { spinner } from "@/src/utils/spinner" import { Command } from "commander" @@ -285,6 +285,7 @@ export const init = new Command() title: t.title, value, description: t.description, + disabled: options.monorepo && value === "laravel", })), }) diff --git a/packages/shadcn/src/preset/index.ts b/packages/shadcn/src/preset/index.ts index ec0009e928..9ea739cf83 100644 --- a/packages/shadcn/src/preset/index.ts +++ b/packages/shadcn/src/preset/index.ts @@ -20,4 +20,4 @@ export { generateRandomConfig, generateRandomPreset, type PresetConfig, -} from "../utils/preset" +} from "./preset" diff --git a/packages/shadcn/src/utils/preset.test.ts b/packages/shadcn/src/preset/preset.test.ts similarity index 100% rename from packages/shadcn/src/utils/preset.test.ts rename to packages/shadcn/src/preset/preset.test.ts diff --git a/packages/shadcn/src/utils/preset.ts b/packages/shadcn/src/preset/preset.ts similarity index 93% rename from packages/shadcn/src/utils/preset.ts rename to packages/shadcn/src/preset/preset.ts index cceb9ee13e..31deb6999a 100644 --- a/packages/shadcn/src/utils/preset.ts +++ b/packages/shadcn/src/preset/preset.ts @@ -11,7 +11,9 @@ // Value arrays — order matters for backward compat. Never reorder, only append. export const PRESET_BASES = ["radix", "base"] as const + export const PRESET_STYLES = ["nova", "vega", "maia", "lyra", "mira"] as const + export const PRESET_BASE_COLORS = [ "neutral", "stone", @@ -22,6 +24,7 @@ export const PRESET_BASE_COLORS = [ "mist", "taupe", ] as const + export const PRESET_THEMES = [ "neutral", "stone", @@ -49,6 +52,7 @@ export const PRESET_THEMES = [ "mist", "taupe", ] as const + export const PRESET_ICON_LIBRARIES = [ "lucide", "hugeicons", @@ -56,6 +60,7 @@ export const PRESET_ICON_LIBRARIES = [ "phosphor", "remixicon", ] as const + export const PRESET_FONTS = [ "inter", "noto-sans", @@ -72,7 +77,10 @@ export const PRESET_FONTS = [ "lora", "merriweather", "playfair-display", + "noto-serif", + "roboto-slab", ] as const + export const PRESET_RADII = [ "default", "none", @@ -80,6 +88,7 @@ export const PRESET_RADII = [ "medium", "large", ] as const + export const PRESET_MENU_ACCENTS = ["subtle", "bold"] as const export const PRESET_MENU_COLORS = ["default", "inverted"] as const @@ -159,8 +168,13 @@ export function encodePreset(config: Partial) { // Decode a preset code back into a PresetConfig. export function decodePreset(code: string): PresetConfig | null { - if (!code || code.length < 2) return null - if (code[0] !== VERSION_CHAR) return null + if (!code || code.length < 2) { + return null + } + + if (code[0] !== VERSION_CHAR) { + return null + } const bits = fromBase62(code.slice(1)) if (bits < 0) return null @@ -179,11 +193,20 @@ export function decodePreset(code: string): PresetConfig | null { // Check if a string looks like a preset code (version char + base62). export function isPresetCode(value: string) { - if (!value || value.length < 2 || value.length > 10) return false - if (value[0] !== VERSION_CHAR) return false - for (let i = 1; i < value.length; i++) { - if (BASE62.indexOf(value[i]) === -1) return false + if (!value || value.length < 2 || value.length > 10) { + return false } + + if (value[0] !== VERSION_CHAR) { + return false + } + + for (let i = 1; i < value.length; i++) { + if (BASE62.indexOf(value[i]) === -1) { + return false + } + } + return true } diff --git a/packages/shadcn/src/utils/presets.test.ts b/packages/shadcn/src/preset/presets.test.ts similarity index 100% rename from packages/shadcn/src/utils/presets.test.ts rename to packages/shadcn/src/preset/presets.test.ts diff --git a/packages/shadcn/src/utils/presets.ts b/packages/shadcn/src/preset/presets.ts similarity index 100% rename from packages/shadcn/src/utils/presets.ts rename to packages/shadcn/src/preset/presets.ts diff --git a/packages/shadcn/src/templates/index.ts b/packages/shadcn/src/templates/index.ts index 64efeadfce..84982ad94c 100644 --- a/packages/shadcn/src/templates/index.ts +++ b/packages/shadcn/src/templates/index.ts @@ -17,8 +17,8 @@ export const templates = { vite, start, "react-router": reactRouter, - laravel, astro, + laravel, } // Resolve a template key from a detected framework name. diff --git a/packages/shadcn/src/utils/index.ts b/packages/shadcn/src/utils/index.ts index 949a0c2d18..e76fb088cb 100644 --- a/packages/shadcn/src/utils/index.ts +++ b/packages/shadcn/src/utils/index.ts @@ -4,24 +4,3 @@ export { transformIcons } from "../utils/transformers/transform-icons" export { transformMenu } from "../utils/transformers/transform-menu" export { transformRender } from "../utils/transformers/transform-render" export { transformDirection } from "../utils/transformers/transform-rtl" -export { - PRESET_BASES, - PRESET_STYLES, - PRESET_BASE_COLORS, - PRESET_THEMES, - PRESET_ICON_LIBRARIES, - PRESET_FONTS, - PRESET_RADII, - PRESET_MENU_ACCENTS, - PRESET_MENU_COLORS, - DEFAULT_PRESET_CONFIG, - toBase62, - fromBase62, - encodePreset, - decodePreset, - isPresetCode, - isValidPreset, - generateRandomConfig, - generateRandomPreset, - type PresetConfig, -} from "../utils/preset"