diff --git a/.changeset/fix-init-clone-dest.md b/.changeset/fix-init-clone-dest.md new file mode 100644 index 0000000..2ad67fb --- /dev/null +++ b/.changeset/fix-init-clone-dest.md @@ -0,0 +1,7 @@ +--- +"@bomb.sh/tools": patch +--- + +Fixes the `bsh init` command—it now points at the directory the template was actually cloned into. + +`init` / `init .` now scaffolds into the current directory in-place and uses the current directory's basename as the project name. diff --git a/src/commands/init.ts b/src/commands/init.ts index d183f9e..3ecbee6 100644 --- a/src/commands/init.ts +++ b/src/commands/init.ts @@ -1,4 +1,5 @@ import { readFile, writeFile } from 'node:fs/promises'; +import { basename } from 'node:path'; import { cwd } from 'node:process'; import { pathToFileURL } from 'node:url'; import { x } from 'tinyexec'; @@ -7,10 +8,15 @@ import type { CommandContext } from '../context.ts'; export async function init(ctx: CommandContext) { const [_name = '.'] = ctx.args; const cwdUrl = pathToFileURL(`${cwd()}/`); - const name = - _name === '.' ? new URL('../', cwdUrl).pathname.split('/').filter(Boolean).pop()! : _name; - const dest = new URL('./.temp/', cwdUrl); - for await (const line of x('pnpx', ['giget@latest', 'gh:bombshell-dev/template', name])) { + // `.` scaffolds into the current directory; otherwise clone into a new `.//`. + const inPlace = _name === '.'; + const name = inPlace ? basename(cwd()) : _name; + const target = inPlace ? '.' : name; + const dest = inPlace ? cwdUrl : new URL(`./${name}/`, cwdUrl); + const gigetArgs = ['giget@latest', 'gh:bombshell-dev/template', target]; + // `--force` lets the template extract into an existing (non-empty) directory. + if (inPlace) gigetArgs.push('--force'); + for await (const line of x('pnpx', gigetArgs)) { console.log(line); }