1- import { existsSync } from "node:fs" ;
1+ import { existsSync , rmSync } from "node:fs" ;
2+ import { resolve } from "node:path" ;
23import { isCancel , log , spinner , text } from "@clack/prompts" ;
34import { downloadTemplate } from "giget" ;
45
@@ -23,14 +24,19 @@ async function fetchTemplate(targetDir: string): Promise<void> {
2324 process . exit ( 1 ) ;
2425 }
2526
26- await exec ( `git -C "${ targetDir } " init` ) ;
27+ const gitInit = await exec ( [ "git" , "init" ] , { cwd : targetDir } ) ;
28+
29+ if ( gitInit . exitCode !== 0 ) {
30+ log . warn ( "Could not initialize git repository" ) ;
31+ log . warn ( gitInit . stderr || "git init failed" ) ;
32+ }
2733}
2834
2935async function installDeps ( targetDir : string ) : Promise < void > {
3036 const s = spinner ( ) ;
3137 s . start ( "Installing dependencies..." ) ;
3238
33- const result = await exec ( `cd " ${ targetDir } " && bun install` ) ;
39+ const result = await exec ( [ "bun" , "install" ] , { cwd : targetDir } ) ;
3440
3541 if ( result . exitCode !== 0 ) {
3642 s . stop ( "Install failed" ) ;
@@ -62,7 +68,7 @@ export async function runScaffold(projectNameArg?: string): Promise<string> {
6268 }
6369
6470 const dirName = toKebabCase ( projectName as string ) ;
65- const targetDir = ` ${ process . cwd ( ) } / ${ dirName } ` ;
71+ const targetDir = resolve ( process . cwd ( ) , dirName ) ;
6672
6773 if ( existsSync ( targetDir ) ) {
6874 log . error ( `Directory "${ dirName } " already exists.` ) ;
@@ -75,7 +81,7 @@ export async function runScaffold(projectNameArg?: string): Promise<string> {
7581 await installDeps ( targetDir ) ;
7682
7783 // Remove the state file if it exists from the template
78- await exec ( `rm -f " ${ targetDir } / .setup-state.json"` ) ;
84+ rmSync ( resolve ( targetDir , " .setup-state.json") , { force : true } ) ;
7985
8086 log . success ( `Project created in ./${ dirName } ` ) ;
8187
0 commit comments