diff --git a/.changeset/metal-queens-hang.md b/.changeset/metal-queens-hang.md new file mode 100644 index 0000000000..8b2d3ef60d --- /dev/null +++ b/.changeset/metal-queens-hang.md @@ -0,0 +1,5 @@ +--- +"shadcn": patch +--- + +add --template flag diff --git a/packages/shadcn/src/commands/add.ts b/packages/shadcn/src/commands/add.ts index d4da6f8d70..0e260586e9 100644 --- a/packages/shadcn/src/commands/add.ts +++ b/packages/shadcn/src/commands/add.ts @@ -149,7 +149,7 @@ export const add = new Command() let shouldUpdateAppIndex = false if (errors[ERRORS.MISSING_DIR_OR_EMPTY_PROJECT]) { - const { projectPath, projectType } = await createProject({ + const { projectPath, template } = await createProject({ cwd: options.cwd, force: options.overwrite, srcDir: options.srcDir, @@ -161,7 +161,7 @@ export const add = new Command() } options.cwd = projectPath - if (projectType === "monorepo") { + if (template === "next-monorepo") { options.cwd = path.resolve(options.cwd, "apps/web") config = await getConfig(options.cwd) } else { diff --git a/packages/shadcn/src/commands/init.ts b/packages/shadcn/src/commands/init.ts index 85af1d7e99..cbbaff855d 100644 --- a/packages/shadcn/src/commands/init.ts +++ b/packages/shadcn/src/commands/init.ts @@ -3,7 +3,7 @@ import path from "path" import { preFlightInit } from "@/src/preflights/preflight-init" import { getRegistryBaseColors, getRegistryStyles } from "@/src/registry/api" import { addComponents } from "@/src/utils/add-components" -import { createProject } from "@/src/utils/create-project" +import { TEMPLATES, createProject } from "@/src/utils/create-project" import * as ERRORS from "@/src/utils/errors" import { DEFAULT_COMPONENTS, @@ -39,6 +39,20 @@ export const initOptionsSchema = z.object({ isNewProject: z.boolean(), srcDir: z.boolean().optional(), cssVariables: z.boolean(), + template: z + .string() + .optional() + .refine( + (val) => { + if (val) { + return TEMPLATES[val as keyof typeof TEMPLATES] + } + return true + }, + { + message: "Invalid template. Please use 'next' or 'next-monorepo'.", + } + ), }) export const init = new Command() @@ -48,6 +62,11 @@ export const init = new Command() "[components...]", "the components to add or a url to the component." ) + .option( + "-t, --template