@@ -3,13 +3,7 @@ import { createVanilla } from "./create-vanilla";
33import * as p from "@clack/prompts" ;
44import { cancelable , spinnerify } from "@solid-cli/utils/ui" ;
55import { createStart } from "./create-start" ;
6- import {
7- getTemplatesList ,
8- GIT_IGNORE ,
9- isValidTemplate ,
10- PROJECT_TYPES ,
11- ProjectType ,
12- } from "./utils/constants" ;
6+ import { getTemplatesList , GIT_IGNORE , isValidTemplate , PROJECT_TYPES , ProjectType } from "./utils/constants" ;
137import { detectPackageManager } from "@solid-cli/utils/package-manager" ;
148import { existsSync , writeFileSync } from "node:fs" ;
159import { join } from "node:path" ;
@@ -53,6 +47,11 @@ export const createSolid = (version: string) =>
5347 alias : "s" ,
5448 description : "Create a SolidStart project" ,
5549 } ,
50+ "v2" : {
51+ type : "boolean" ,
52+ required : false ,
53+ description : "Create a SolidStart v2 project" ,
54+ } ,
5655 "library" : {
5756 type : "boolean" ,
5857 required : false ,
@@ -87,12 +86,19 @@ export const createSolid = (version: string) =>
8786 vanilla,
8887 ts,
8988 js,
89+ v2,
9090 } ,
9191 } ) {
9292 // Show prompts for any unknown arguments
9393 let projectName = projectNamePositional ?? projectNameOptional ;
9494 let template = templatePositional ?? templateOptional ;
95- let projectType : ProjectType | undefined = solidstart ? "start" : ( vanilla ? "vanilla" : ( library ? "library" : undefined ) ) ;
95+ let projectType : ProjectType | undefined = solidstart
96+ ? "start"
97+ : vanilla
98+ ? "vanilla"
99+ : library
100+ ? "library"
101+ : undefined ;
96102 // False if user has selected ts, true if they have selected js, and undefined if they've done neither
97103 let useJS = ts ? ! ts : js ? js : undefined ;
98104 projectName ??= await cancelable (
@@ -108,10 +114,30 @@ export const createSolid = (version: string) =>
108114 } ) ) ,
109115 } ) ,
110116 ) ;
117+ if ( ! projectType ) return ;
118+
119+ let useV2 : string | undefined ;
120+ if ( projectType === "start" ) {
121+ useV2 = v2
122+ ? "v2"
123+ : await cancelable (
124+ p . select ( {
125+ message : "Which version of SolidStart?" ,
126+ initialValue : "v2" ,
127+ options : [
128+ { value : "v2" , label : "v2 (pre-release, recommended)" } ,
129+ { value : "v1" , label : "v1 (stable)" } ,
130+ ] ,
131+ } ) ,
132+ ) ;
133+ }
134+ const isV2 = useV2 === "v2" ;
135+
111136 // Don't offer javascript if `projectType` is library
112137 useJS ??= projectType === "library" ? false : ! ( await cancelable ( p . confirm ( { message : "Use Typescript?" } ) ) ) ;
113138
114- const template_opts = getTemplatesList ( projectType ) ;
139+ if ( ! projectType ) return ;
140+ const template_opts = getTemplatesList ( projectType , isV2 ) ;
115141 template ??= await cancelable (
116142 p . select ( {
117143 message : "Which template would you like to use?" ,
@@ -122,13 +148,15 @@ export const createSolid = (version: string) =>
122148 } ) ,
123149 ) ;
124150
151+ if ( ! template ) return ;
152+
125153 // Need to transpile if the user wants Jabascript, but their selected template isn't Javascript
126154 const transpileToJS = useJS && ! template . startsWith ( "js" ) ;
127- if ( projectType === "start" && isValidTemplate ( "start" , template ) ) {
155+ if ( projectType === "start" && isValidTemplate ( "start" , template , isV2 ) ) {
128156 await spinnerify ( {
129157 startText : "Creating project" ,
130158 finishText : "Project created 🎉" ,
131- fn : ( ) => createStart ( { template, destination : projectName } , transpileToJS ) ,
159+ fn : ( ) => createStart ( { template, destination : projectName } , transpileToJS , isV2 ) ,
132160 } ) ;
133161 } else if ( projectType === "library" && isValidTemplate ( "library" , template ) ) {
134162 await spinnerify ( {
@@ -142,8 +170,7 @@ export const createSolid = (version: string) =>
142170 finishText : "Project created 🎉" ,
143171 fn : ( ) => createVanilla ( { template, destination : projectName } , transpileToJS ) ,
144172 } ) ;
145- }
146- else {
173+ } else {
147174 p . log . error ( `Template ${ template } is not valid for project type ${ projectType } ` ) ;
148175 process . exit ( 0 ) ;
149176 }
@@ -154,7 +181,11 @@ export const createSolid = (version: string) =>
154181 if ( existsSync ( readmePath ) ) {
155182 const contents = ( await readFile ( readmePath ) ) . toString ( ) ;
156183 if ( ! contents . includes ( "This project was created with the [Solid CLI]" ) )
157- await writeFile ( readmePath , contents + "\n## This project was created with the [Solid CLI](https://github.com/solidjs-community/solid-cli)\n" )
184+ await writeFile (
185+ readmePath ,
186+ contents +
187+ "\n## This project was created with the [Solid CLI](https://github.com/solidjs-community/solid-cli)\n" ,
188+ ) ;
158189 }
159190 // Next steps..
160191 const pM = detectPackageManager ( ) ;
0 commit comments