faet: add support for laravel in init

This commit is contained in:
shadcn
2026-02-27 21:52:41 +04:00
parent 9dc307f7cc
commit 7e766f4714
6 changed files with 55 additions and 2 deletions

View File

@@ -89,7 +89,7 @@ export const init = new Command()
.argument("[components...]", "names, url or local path to component")
.option(
"-t, --template <template>",
"the template to use. (next, start, vite, react-router)"
"the template to use. (next, start, vite, react-router, laravel)"
)
.option("-b, --base <base>", "the component library to use. (radix, base)")
.option("--monorepo", "scaffold a monorepo project.")
@@ -284,6 +284,7 @@ export const init = new Command()
choices: Object.entries(templates).map(([value, t]) => ({
title: t.title,
value,
description: t.description,
})),
})
@@ -305,6 +306,23 @@ export const init = new Command()
}
}
// Laravel cannot be scaffolded — exit early with instructions.
if (options.template === "laravel" && !hasPackageJson) {
logger.break()
logger.log(
` Please create a new app with ${highlighter.info(
"laravel new --react"
)} first then run ${highlighter.info("shadcn init")}.`
)
logger.log(
` See ${highlighter.info(
"https://ui.shadcn.com/docs/installation/laravel"
)} for more information.`
)
logger.break()
process.exit(0)
}
// Prompt for monorepo if the template supports it (new projects only).
if (
options.monorepo === undefined &&

View File

@@ -102,7 +102,7 @@ export async function preFlightInit(
let tailwindSpinnerMessage = "Validating Tailwind CSS."
if (projectInfo.tailwindVersion === "v4") {
tailwindSpinnerMessage = `Validating Tailwind CSS config. Found ${highlighter.info(
tailwindSpinnerMessage = `Validating Tailwind CSS. Found ${highlighter.info(
"v4"
)}.`
}

View File

@@ -27,6 +27,7 @@ export interface TemplateInitOptions {
export interface TemplateConfig {
name: string
title: string
description?: string
defaultProjectName: string
// The template directory name (e.g. "next-app", "vite-app").
templateDir: string

View File

@@ -1,4 +1,5 @@
import { astro } from "./astro"
import { laravel } from "./laravel"
import { next } from "./next"
import { reactRouter } from "./react-router"
import { start } from "./start"
@@ -16,6 +17,7 @@ export const templates = {
vite,
start,
"react-router": reactRouter,
laravel,
astro,
}

View File

@@ -0,0 +1,31 @@
import { highlighter } from "@/src/utils/highlighter"
import { logger } from "@/src/utils/logger"
import { createTemplate } from "./create-template"
export const laravel = createTemplate({
name: "laravel",
title: "Laravel",
description: "Requires `laravel new`",
defaultProjectName: "laravel-app",
templateDir: "laravel-app",
frameworks: ["laravel"],
scaffold: async () => {
logger.break()
logger.log(
` Please create a new app with ${highlighter.info(
"laravel new --react"
)} first then run ${highlighter.info("shadcn init")}.`
)
logger.log(
` See ${highlighter.info(
"https://ui.shadcn.com/docs/installation/laravel"
)} for more information.`
)
logger.break()
process.exit(0)
},
create: async () => {
// Not used — scaffold exits early.
},
})

View File

@@ -44,6 +44,7 @@ export async function createProject(
choices: Object.entries(templates).map(([key, t]) => ({
title: t.title,
value: key,
description: t.description,
})),
initial: 0,
},