Skip to content

Commit 15afa23

Browse files
brnrdogclaude
andcommitted
Group Xote CSR and SSR under a single template with a variant prompt
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 27018c8 commit 15afa23

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
@@ -64,12 +64,35 @@ let updateRescriptJson = async (~projectName, ~versions: RescriptVersions.versio
6464
let newProjectMessage = "Create a new ReScript project"
6565

6666
let getTemplateOptions = () =>
67-
Templates.templates->Array.map(({name, displayName, shortDescription}) => {
67+
Templates.templates->Array.map(({name, displayName, shortDescription, _}) => {
6868
P.value: name,
6969
label: displayName,
7070
hint: shortDescription,
7171
})
7272

73+
let getVariantOptions = (variants: array<Templates.variant>) =>
74+
variants->Array.map(({name, displayName, shortDescription}) => {
75+
P.value: name,
76+
label: displayName,
77+
hint: shortDescription,
78+
})
79+
80+
let promptTemplateName = async () => {
81+
let selectedName = await P.select({
82+
message: "Select a template",
83+
options: getTemplateOptions(),
84+
})->P.resultOrRaise
85+
86+
switch Templates.templates->Array.find(template => template.name === selectedName) {
87+
| Some({variants: Some(variants)}) =>
88+
await P.select({
89+
message: "Select a variant",
90+
options: getVariantOptions(variants),
91+
})->P.resultOrRaise
92+
| _ => selectedName
93+
}
94+
}
95+
7396
let createProject = async (~templateName, ~projectName, ~versions) => {
7497
let templatePath = CraPaths.getTemplatePath(~templateName)
7598
let projectPath = Path.join2(Process.cwd(), projectName)
@@ -139,11 +162,7 @@ let createNewProject = async () => {
139162

140163
let templateName = switch commandLineArguments.templateName {
141164
| Some(templateName) => templateName
142-
| None =>
143-
await P.select({
144-
message: "Select a template",
145-
options: getTemplateOptions(),
146-
})->P.resultOrRaise
165+
| None => await promptTemplateName()
147166
}
148167

149168
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 7, 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)