11import { readFile , writeFile } from 'node:fs/promises' ;
2+ import { basename } from 'node:path' ;
23import { cwd } from 'node:process' ;
34import { pathToFileURL } from 'node:url' ;
45import { x } from 'tinyexec' ;
@@ -7,10 +8,15 @@ import type { CommandContext } from '../context.ts';
78export async function init ( ctx : CommandContext ) {
89 const [ _name = '.' ] = ctx . args ;
910 const cwdUrl = pathToFileURL ( `${ cwd ( ) } /` ) ;
10- const name =
11- _name === '.' ? new URL ( '../' , cwdUrl ) . pathname . split ( '/' ) . filter ( Boolean ) . pop ( ) ! : _name ;
12- const dest = new URL ( './.temp/' , cwdUrl ) ;
13- for await ( const line of x ( 'pnpx' , [ 'giget@latest' , 'gh:bombshell-dev/template' , name ] ) ) {
11+ // `.` scaffolds into the current directory; otherwise clone into a new `./<name>/`.
12+ const inPlace = _name === '.' ;
13+ const name = inPlace ? basename ( cwd ( ) ) : _name ;
14+ const target = inPlace ? '.' : name ;
15+ const dest = inPlace ? cwdUrl : new URL ( `./${ name } /` , cwdUrl ) ;
16+ const gigetArgs = [ 'giget@latest' , 'gh:bombshell-dev/template' , target ] ;
17+ // `--force` lets the template extract into an existing (non-empty) directory.
18+ if ( inPlace ) gigetArgs . push ( '--force' ) ;
19+ for await ( const line of x ( 'pnpx' , gigetArgs ) ) {
1420 console . log ( line ) ;
1521 }
1622
0 commit comments