@@ -15,20 +15,29 @@ import { z } from "zod"
15
15
const MONOREPO_TEMPLATE_URL =
16
16
"https://codeload.github.com/shadcn-ui/ui/tar.gz/main"
17
17
18
+ export const TEMPLATES = {
19
+ next : "next" ,
20
+ "next-monorepo" : "next-monorepo" ,
21
+ } as const
22
+
18
23
export async function createProject (
19
24
options : Pick <
20
25
z . infer < typeof initOptionsSchema > ,
21
- "cwd" | "force" | "srcDir" | "components"
26
+ "cwd" | "force" | "srcDir" | "components" | "template"
22
27
>
23
28
) {
24
29
options = {
25
30
srcDir : false ,
26
31
...options ,
27
32
}
28
33
29
- let projectType : "next" | "monorepo" = "next"
30
- let projectName : string = "my-app"
31
- let nextVersion = "canary"
34
+ let template : keyof typeof TEMPLATES =
35
+ options . template && TEMPLATES [ options . template as keyof typeof TEMPLATES ]
36
+ ? ( options . template as keyof typeof TEMPLATES )
37
+ : "next"
38
+ let projectName : string =
39
+ template === TEMPLATES . next ? "my-app" : "my-monorepo"
40
+ let nextVersion = "latest"
32
41
33
42
const isRemoteComponent =
34
43
options . components ?. length === 1 &&
@@ -45,6 +54,9 @@ export async function createProject(
45
54
} )
46
55
. parse ( result )
47
56
nextVersion = meta . nextVersion
57
+
58
+ // Force template to next for remote components.
59
+ template = TEMPLATES . next
48
60
} catch ( error ) {
49
61
logger . break ( )
50
62
handleError ( error )
@@ -54,14 +66,14 @@ export async function createProject(
54
66
if ( ! options . force ) {
55
67
const { type, name } = await prompts ( [
56
68
{
57
- type : "select" ,
69
+ type : options . template || isRemoteComponent ? null : "select" ,
58
70
name : "type" ,
59
71
message : `The path ${ highlighter . info (
60
72
options . cwd
61
73
) } does not contain a package.json file.\n Would you like to start a new project?`,
62
74
choices : [
63
75
{ title : "Next.js" , value : "next" } ,
64
- { title : "Next.js (Monorepo)" , value : "monorepo" } ,
76
+ { title : "Next.js (Monorepo)" , value : "next- monorepo" } ,
65
77
] ,
66
78
initial : 0 ,
67
79
} ,
@@ -78,7 +90,7 @@ export async function createProject(
78
90
} ,
79
91
] )
80
92
81
- projectType = type
93
+ template = type ?? template
82
94
projectName = name
83
95
}
84
96
@@ -113,7 +125,7 @@ export async function createProject(
113
125
process . exit ( 1 )
114
126
}
115
127
116
- if ( projectType === " next" ) {
128
+ if ( template === TEMPLATES . next ) {
117
129
await createNextProject ( projectPath , {
118
130
version : nextVersion ,
119
131
cwd : options . cwd ,
@@ -122,7 +134,7 @@ export async function createProject(
122
134
} )
123
135
}
124
136
125
- if ( projectType === " monorepo") {
137
+ if ( template === TEMPLATES [ "next- monorepo"] ) {
126
138
await createMonorepoProject ( projectPath , {
127
139
packageManager,
128
140
} )
@@ -131,7 +143,7 @@ export async function createProject(
131
143
return {
132
144
projectPath,
133
145
projectName,
134
- projectType ,
146
+ template ,
135
147
}
136
148
}
137
149
@@ -161,6 +173,7 @@ async function createNextProject(
161
173
162
174
if (
163
175
options . version . startsWith ( "15" ) ||
176
+ options . version . startsWith ( "latest" ) ||
164
177
options . version . startsWith ( "canary" )
165
178
) {
166
179
args . push ( "--turbopack" )
0 commit comments