Skip to content

Commit 22f87d0

Browse files
fix init (#40)
* fix(init): correct clone destination * chore(changeset): update changeset --------- Co-authored-by: paul valladares <85648028+dreyfus92@users.noreply.github.com>
1 parent a65a254 commit 22f87d0

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

.changeset/fix-init-clone-dest.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@bomb.sh/tools": patch
3+
---
4+
5+
Fixes the `bsh init` command—it now points at the directory the template was actually cloned into.
6+
7+
`init` / `init .` now scaffolds into the current directory in-place and uses the current directory's basename as the project name.

src/commands/init.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { readFile, writeFile } from 'node:fs/promises';
2+
import { basename } from 'node:path';
23
import { cwd } from 'node:process';
34
import { pathToFileURL } from 'node:url';
45
import { x } from 'tinyexec';
@@ -7,10 +8,15 @@ import type { CommandContext } from '../context.ts';
78
export 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

Comments
 (0)