Skip to content

Commit e57b1aa

Browse files
brnrdogfhammerschmidt
authored andcommitted
group Xote variants
1 parent bbe6965 commit e57b1aa

2 files changed

Lines changed: 48 additions & 12 deletions

File tree

‎src/NewProject.res‎

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,35 @@ let updateViteConfig = async () => {
8080
let newProjectMessage = "Create a new ReScript project"
8181

8282
let getTemplateOptions = () =>
83-
Templates.templates->Array.map(({name, displayName, shortDescription}) => {
83+
Templates.templates->Array.map(({name, displayName, shortDescription, _}) => {
8484
P.value: name,
8585
label: displayName,
8686
hint: shortDescription,
8787
})
8888

89+
let getVariantOptions = (variants: array<Templates.variant>) =>
90+
variants->Array.map(({name, displayName, shortDescription}) => {
91+
P.value: name,
92+
label: displayName,
93+
hint: shortDescription,
94+
})
95+
96+
let promptTemplateName = async () => {
97+
let selectedName = await P.select({
98+
message: "Select a template",
99+
options: getTemplateOptions(),
100+
})->P.resultOrRaise
101+
102+
switch Templates.templates->Array.find(template => template.name === selectedName) {
103+
| Some({variants: Some(variants)}) =>
104+
await P.select({
105+
message: "Select a variant",
106+
options: getVariantOptions(variants),
107+
})->P.resultOrRaise
108+
| _ => selectedName
109+
}
110+
}
111+
89112
let createProject = async (~templateName, ~projectName, ~versions) => {
90113
let templatePath = CraPaths.getTemplatePath(~templateName)
91114
let projectPath = Path.join2(Process.cwd(), projectName)
@@ -156,11 +179,7 @@ let createNewProject = async () => {
156179

157180
let templateName = switch commandLineArguments.templateName {
158181
| Some(templateName) => templateName
159-
| None =>
160-
await P.select({
161-
message: "Select a template",
162-
options: getTemplateOptions(),
163-
})->P.resultOrRaise
182+
| None => await promptTemplateName()
164183
}
165184

166185
let versions = useDefaultVersions

‎src/Templates.res‎

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
type variant = {
2+
name: string,
3+
displayName: string,
4+
shortDescription: string,
5+
}
6+
17
type t = {
28
name: string,
39
displayName: string,
410
shortDescription: string,
11+
variants: option<array<variant>>,
512
}
613

714
let basicTemplateName = "rescript-template-basic"
@@ -26,25 +33,35 @@ let templates = [
2633
name: viteTemplateName,
2734
displayName: "Vite",
2835
shortDescription: "Vite 8, React and Tailwind 4",
36+
variants: None,
2937
},
3038
{
3139
name: nextjsTemplateName,
3240
displayName: "Next.js",
3341
shortDescription: "Next.js 15 with static export and Tailwind 3",
42+
variants: None,
3443
},
3544
{
3645
name: xoteTemplateName,
3746
displayName: "Xote",
38-
shortDescription: "Xote with Vite, signals and Tailwind 4 (CSR)",
39-
},
40-
{
41-
name: xoteSsrTemplateName,
42-
displayName: "Xote SSR",
43-
shortDescription: "Xote with Vite, signals and Tailwind 4 (SSR)",
47+
shortDescription: "Xote with Vite, signals and Tailwind 4",
48+
variants: Some([
49+
{
50+
name: xoteTemplateName,
51+
displayName: "Client-Side Rendering (CSR)",
52+
shortDescription: "Vite, signals and Tailwind 4",
53+
},
54+
{
55+
name: xoteSsrTemplateName,
56+
displayName: "Server-Side Rendering (SSR)",
57+
shortDescription: "Vite SSR via Node server, signals and Tailwind 4",
58+
},
59+
]),
4460
},
4561
{
4662
name: basicTemplateName,
4763
displayName: "Basic",
4864
shortDescription: "Command line hello world app",
65+
variants: None,
4966
},
5067
]

0 commit comments

Comments
 (0)