(
appName?: string,
options: Partial<CreateAppOptions> = {}
)
| 161 | } |
| 162 | |
| 163 | export async function createApp( |
| 164 | appName?: string, |
| 165 | options: Partial<CreateAppOptions> = {} |
| 166 | ): Promise<void> { |
| 167 | if (!appName) { |
| 168 | const res = await prompts({ |
| 169 | type: 'text', |
| 170 | name: 'name', |
| 171 | message: 'Please enter a directory name for the project:', |
| 172 | initial: 'formkit-app', |
| 173 | }) |
| 174 | appName = res.name as string |
| 175 | } |
| 176 | |
| 177 | const isEmpty = await isDirEmpty(resolve(cwd(), `./${appName}`)) |
| 178 | if (!isEmpty) { |
| 179 | error('Directory is not empty. Please choose a different name.') |
| 180 | } |
| 181 | |
| 182 | if (!options.framework) { |
| 183 | const res = await prompts({ |
| 184 | type: 'select', |
| 185 | name: 'framework', |
| 186 | message: 'What framework would you like to use?', |
| 187 | choices: [ |
| 188 | { title: 'Vite', value: 'vite' }, |
| 189 | { title: 'Nuxt', value: 'nuxt' }, |
| 190 | ], |
| 191 | initial: 1, |
| 192 | }) |
| 193 | options.framework = res.framework as 'vite' | 'nuxt' |
| 194 | } |
| 195 | |
| 196 | if (!options.lang && options.framework === 'vite') { |
| 197 | const res = await prompts({ |
| 198 | type: 'select', |
| 199 | name: 'lang', |
| 200 | message: 'What language should be used?', |
| 201 | choices: [ |
| 202 | { title: 'TypeScript', value: 'ts' }, |
| 203 | { title: 'JavaScript', value: 'js' }, |
| 204 | ], |
| 205 | initial: 1, |
| 206 | }) |
| 207 | options.lang = res.lang as 'ts' | 'js' |
| 208 | } |
| 209 | |
| 210 | if (!options.pro) { |
| 211 | const res = await prompts([ |
| 212 | { |
| 213 | type: 'toggle', |
| 214 | name: 'install_pro', |
| 215 | message: 'Would you like to install FormKit Pro?', |
| 216 | active: 'yes', |
| 217 | initial: true, |
| 218 | inactive: 'no', |
| 219 | }, |
| 220 | ]) |
no test coverage detected