1- import { cp , mkdir } from "node:fs/promises" ;
21import path from "node:path" ;
3- import { fileURLToPath } from "node:url" ;
42import { runMain as _runMain , defineCommand } from "citty" ;
53import { consola } from "consola" ;
64import { colorize } from "consola/utils" ;
5+ import { downloadTemplate } from "giget" ;
76import { readPackageJSON , writePackageJSON } from "pkg-types" ;
87
98export const runMain = ( ) => _runMain ( mainCommand ) ;
@@ -19,37 +18,39 @@ const mainCommand = defineCommand({
1918 } ;
2019 } ,
2120 run : async ( ) => {
22- const projectName = await consola . prompt ( "Project Name" , {
21+ const projectName = await consola . prompt ( "Project Name? " , {
2322 type : "text" ,
24- default : "Babylon-App " ,
25- placeholder : "Babylon-App " ,
23+ default : "babylon-app " ,
24+ placeholder : "babylon-app " ,
2625 } ) ;
2726
28- const buildTool = await consola . prompt ( "Build Tools" , {
27+ const buildTool = await consola . prompt ( "Build Tools? " , {
2928 type : "select" ,
3029 options : [ { value : "vite" , label : "Vite" } ] ,
3130 } ) ;
3231
33- const language = await consola . prompt ( "Language" , {
32+ const language = await consola . prompt ( "Language? " , {
3433 type : "select" ,
3534 options : [
3635 { value : "ts" , label : `${ colorize ( "blue" , "TypeScript" ) } ` } ,
3736 { value : "js" , label : `${ colorize ( "yellow" , "JavaScript" ) } ` } ,
3837 ] ,
3938 } ) ;
4039
41- const templateDir = path . resolve (
42- fileURLToPath ( import . meta. url ) ,
43- "../.." ,
44- "templates" ,
45- `${ buildTool } -${ language } ` ,
46- ) ;
47-
48- const workingDir = process . cwd ( ) ;
49- const appDir = path . join ( workingDir , projectName ) ;
40+ const doInstall = await consola . prompt ( "Install Dependencies?" , {
41+ type : "confirm" ,
42+ initial : false ,
43+ } ) ;
5044
51- await mkdir ( appDir ) ;
52- await cp ( templateDir , appDir , { recursive : true } ) ;
45+ const githubRepoUrlBase = "gh:drumath2237/create-babylon-app/templates" ;
46+ const templateName = `${ buildTool } -${ language } ` ;
47+ const { dir : appDir } = await downloadTemplate (
48+ `${ githubRepoUrlBase } /${ templateName } ` ,
49+ {
50+ dir : projectName ,
51+ install : doInstall ,
52+ } ,
53+ ) ;
5354
5455 const packageJson = await readPackageJSON ( appDir ) ;
5556 if ( packageJson . name ) {
@@ -58,7 +59,8 @@ const mainCommand = defineCommand({
5859 await writePackageJSON ( jsonPath , packageJson ) ;
5960 }
6061
61- console . log ( "\nDone!" ) ;
62- console . log ( ` cd ${ projectName } \n` ) ;
62+ consola . log ( "\n" ) ;
63+ consola . success ( "Done!✨" ) ;
64+ consola . log ( ` cd ${ projectName } ` ) ;
6365 } ,
6466} ) ;
0 commit comments