mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-06-24 13:15:45 +00:00
feat(shadcn): add support for src dir (#4729)
* feat(shadcn): add support for src dir * chore: add changesets
This commit is contained in:
@@ -2,4 +2,4 @@
|
||||
"shadcn": patch
|
||||
---
|
||||
|
||||
npx shadcn init
|
||||
add --src-dir
|
||||
@@ -1,5 +0,0 @@
|
||||
---
|
||||
"shadcn": patch
|
||||
---
|
||||
|
||||
fix theme values bug
|
||||
@@ -21,6 +21,7 @@ export const addOptionsSchema = z.object({
|
||||
all: z.boolean(),
|
||||
path: z.string().optional(),
|
||||
silent: z.boolean(),
|
||||
srcDir: z.boolean().optional(),
|
||||
})
|
||||
|
||||
export const add = new Command()
|
||||
@@ -40,6 +41,11 @@ export const add = new Command()
|
||||
.option("-a, --all", "add all available components", false)
|
||||
.option("-p, --path <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
|
||||
)
|
||||
.action(async (components, opts) => {
|
||||
try {
|
||||
const options = addOptionsSchema.parse({
|
||||
@@ -100,6 +106,7 @@ export const add = new Command()
|
||||
skipPreflight: false,
|
||||
silent: true,
|
||||
isNewProject: false,
|
||||
srcDir: options.srcDir,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -108,6 +115,7 @@ export const add = new Command()
|
||||
const { projectPath } = await createProject({
|
||||
cwd: options.cwd,
|
||||
force: options.overwrite,
|
||||
srcDir: options.srcDir,
|
||||
})
|
||||
if (!projectPath) {
|
||||
logger.break()
|
||||
@@ -123,6 +131,7 @@ export const add = new Command()
|
||||
skipPreflight: true,
|
||||
silent: true,
|
||||
isNewProject: true,
|
||||
srcDir: options.srcDir,
|
||||
})
|
||||
|
||||
shouldUpdateAppIndex =
|
||||
|
||||
@@ -32,6 +32,7 @@ export const initOptionsSchema = z.object({
|
||||
force: z.boolean(),
|
||||
silent: z.boolean(),
|
||||
isNewProject: z.boolean(),
|
||||
srcDir: z.boolean().optional(),
|
||||
})
|
||||
|
||||
export const init = new Command()
|
||||
@@ -50,6 +51,11 @@ export const init = new Command()
|
||||
process.cwd()
|
||||
)
|
||||
.option("-s, --silent", "mute output.", false)
|
||||
.option(
|
||||
"--src-dir",
|
||||
"use the src directory when creating a new project.",
|
||||
false
|
||||
)
|
||||
.action(async (components, opts) => {
|
||||
try {
|
||||
const options = initOptionsSchema.parse({
|
||||
|
||||
@@ -10,15 +10,20 @@ import prompts from "prompts"
|
||||
import { z } from "zod"
|
||||
|
||||
export async function createProject(
|
||||
options: Pick<z.infer<typeof initOptionsSchema>, "cwd" | "force">
|
||||
options: Pick<z.infer<typeof initOptionsSchema>, "cwd" | "force" | "srcDir">
|
||||
) {
|
||||
options = {
|
||||
srcDir: false,
|
||||
...options,
|
||||
}
|
||||
|
||||
if (!options.force) {
|
||||
const { proceed } = await prompts({
|
||||
type: "confirm",
|
||||
name: "proceed",
|
||||
message: `The path ${highlighter.info(
|
||||
options.cwd
|
||||
)} is empty. Would you like to start a new ${highlighter.info(
|
||||
)} is does not contain a package.json file. Would you like to start a new ${highlighter.info(
|
||||
"Next.js"
|
||||
)} project?`,
|
||||
initial: true,
|
||||
@@ -81,7 +86,7 @@ export async function createProject(
|
||||
"--eslint",
|
||||
"--typescript",
|
||||
"--app",
|
||||
"--no-src-dir",
|
||||
options.srcDir ? "--src-dir" : "--no-src-dir",
|
||||
"--no-import-alias",
|
||||
`--use-${packageManager}`,
|
||||
]
|
||||
@@ -97,7 +102,7 @@ export async function createProject(
|
||||
} catch (error) {
|
||||
logger.break()
|
||||
logger.error(
|
||||
`Something went wront creating a new Next.js project. Please try again.`
|
||||
`Something went wrong creating a new Next.js project. Please try again.`
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user