Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fix-init-clone-dest.md
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 10 additions & 4 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 `./<name>/`.
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);
}

Expand Down
Loading