diff --git a/packages/shadcn/src/commands/add.ts b/packages/shadcn/src/commands/add.ts index e2cc919418..08726092e2 100644 --- a/packages/shadcn/src/commands/add.ts +++ b/packages/shadcn/src/commands/add.ts @@ -29,7 +29,6 @@ export const addOptionsSchema = z.object({ all: z.boolean(), path: z.string().optional(), silent: z.boolean(), - srcDir: z.boolean().optional(), cssVariables: z.boolean(), }) @@ -47,15 +46,6 @@ export const add = new Command() .option("-a, --all", "add all available components", false) .option("-p, --path ", "the path to add the component to.") .option("-s, --silent", "mute output.", false) - .option( - "--src-dir", - "use the src directory when creating a new project.", - false - ) - .option( - "--no-src-dir", - "do not use the src directory when creating a new project." - ) .option("--css-variables", "use css variables for theming.", true) .option("--no-css-variables", "do not use css variables for theming.") .action(async (components, opts) => { @@ -177,10 +167,8 @@ export const add = new Command() skipPreflight: false, silent: options.silent && !hasNewRegistries, isNewProject: false, - srcDir: options.srcDir, cssVariables: options.cssVariables, installStyleIndex: shouldInstallStyleIndex, - baseColor: shouldInstallStyleIndex ? undefined : "neutral", components: options.components, }) initHasRun = true @@ -192,7 +180,6 @@ export const add = new Command() const { projectPath, template } = await createProject({ cwd: options.cwd, force: options.overwrite, - srcDir: options.srcDir, components: options.components, }) if (!projectPath) { @@ -213,10 +200,8 @@ export const add = new Command() skipPreflight: true, silent: !hasNewRegistries && options.silent, isNewProject: true, - srcDir: options.srcDir, cssVariables: options.cssVariables, installStyleIndex: shouldInstallStyleIndex, - baseColor: shouldInstallStyleIndex ? undefined : "neutral", components: options.components, }) initHasRun = true diff --git a/packages/shadcn/src/commands/create.ts b/packages/shadcn/src/commands/create.ts index 7a1a6e6cb0..5b00f71e4a 100644 --- a/packages/shadcn/src/commands/create.ts +++ b/packages/shadcn/src/commands/create.ts @@ -2,6 +2,7 @@ import path from "path" import { getRegistryItems } from "@/src/registry/api" import { configWithDefaults } from "@/src/registry/config" import { clearRegistryContext } from "@/src/registry/context" +import { templates } from "@/src/templates/index" import { addComponents } from "@/src/utils/add-components" import { handleError } from "@/src/utils/handle-error" import { highlighter } from "@/src/utils/highlighter" @@ -12,7 +13,6 @@ import { handlePresetOption, } from "@/src/utils/presets" import { ensureRegistriesInConfig } from "@/src/utils/registries" -import { templates } from "@/src/utils/templates/index" import { updateFiles } from "@/src/utils/updaters/update-files" import { Command } from "commander" import open from "open" @@ -35,15 +35,6 @@ export const create = new Command() "the working directory. defaults to the current directory.", process.cwd() ) - .option( - "--src-dir", - "use the src directory when creating a new project.", - false - ) - .option( - "--no-src-dir", - "do not use the src directory when creating a new project." - ) .option("-y, --yes", "skip confirmation prompt.", true) .option("--rtl", "enable RTL support.", false) .action(async (name, opts) => { @@ -146,9 +137,8 @@ export const create = new Command() process.exit(0) } - // Determine initUrl and baseColor based on preset type. + // Determine initUrl based on preset type. let initUrl: string - let baseColor: string if ("_isUrl" in presetResult) { // User provided a URL directly. @@ -157,11 +147,9 @@ export const create = new Command() url.searchParams.set("rtl", "true") } initUrl = url.toString() - baseColor = url.searchParams.get("baseColor") ?? "neutral" } else { // User selected a preset by name. initUrl = buildInitUrl(presetResult, opts.rtl) - baseColor = presetResult.baseColor } // Fetch the registry:base item to get its config. @@ -192,11 +180,9 @@ export const create = new Command() force: false, silent: false, isNewProject: true, - srcDir: opts.srcDir, cssVariables: true, rtl: opts.rtl, template, - baseColor, installStyleIndex: false, registryBaseConfig, skipPreflight: false, @@ -215,10 +201,11 @@ export const create = new Command() overwrite: true, }) - const templateFiles = - templates[template as keyof typeof templates]?.files ?? [] - if (templateFiles.length > 0) { - await updateFiles(templateFiles, config, { + const selectedTemplate = + templates[template as keyof typeof templates] + + if (selectedTemplate?.files?.length) { + await updateFiles(selectedTemplate.files, config, { overwrite: true, silent: true, }) @@ -226,9 +213,7 @@ export const create = new Command() } logger.log( - `${highlighter.success( - "Success!" - )} Project initialization completed.\nYou may now add components.` + `Project initialization completed.\nYou may now add components.` ) logger.break() } catch (error) { diff --git a/packages/shadcn/src/commands/init.ts b/packages/shadcn/src/commands/init.ts index 4f63dfcf0e..d0ab72ee33 100644 --- a/packages/shadcn/src/commands/init.ts +++ b/packages/shadcn/src/commands/init.ts @@ -8,9 +8,10 @@ import { } from "@/src/registry/api" import { buildUrlAndHeadersForRegistryItem } from "@/src/registry/builder" import { configWithDefaults } from "@/src/registry/config" -import { BASE_COLORS, BUILTIN_REGISTRIES } from "@/src/registry/constants" +import { BUILTIN_REGISTRIES } from "@/src/registry/constants" import { clearRegistryContext } from "@/src/registry/context" import { rawConfigSchema } from "@/src/schema" +import { templates } from "@/src/templates/index" import { addComponents } from "@/src/utils/add-components" import { createProject } from "@/src/utils/create-project" import { loadEnvFiles } from "@/src/utils/env-loader" @@ -38,7 +39,6 @@ import { } from "@/src/utils/get-project-info" import { handleError } from "@/src/utils/handle-error" import { highlighter } from "@/src/utils/highlighter" -import { initMonorepoProject } from "@/src/utils/init-monorepo" import { logger } from "@/src/utils/logger" import { buildInitUrl, @@ -47,8 +47,6 @@ import { } from "@/src/utils/presets" import { ensureRegistriesInConfig } from "@/src/utils/registries" import { spinner } from "@/src/utils/spinner" -import { templates } from "@/src/utils/templates/index" -import { updateTailwindContent } from "@/src/utils/updaters/update-tailwind-content" import { Command } from "commander" import deepmerge from "deepmerge" import fsExtra from "fs-extra" @@ -78,7 +76,6 @@ export const initOptionsSchema = z.object({ force: z.boolean(), silent: z.boolean(), isNewProject: z.boolean(), - srcDir: z.boolean().optional(), cssVariables: z.boolean(), rtl: z.boolean().optional(), template: z @@ -96,23 +93,6 @@ export const initOptionsSchema = z.object({ "Invalid template. Please use 'next', 'vite', 'start' or 'next-monorepo'.", } ), - baseColor: z - .string() - .optional() - .refine( - (val) => { - if (val) { - return BASE_COLORS.find((color) => color.name === val) - } - - return true - }, - { - message: `Invalid base color. Please use '${BASE_COLORS.map( - (color) => color.name - ).join("', '")}'`, - } - ), installStyleIndex: z.boolean(), // Config from registry:base item to merge into components.json. registryBaseConfig: rawConfigSchema.deepPartial().optional(), @@ -126,40 +106,47 @@ export const init = new Command() "-t, --template