Skip to content

Commit abbd34d

Browse files
committed
fix: no creation from empty dir
1 parent 0dc3d75 commit abbd34d

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ node_modules/
1717

1818
# build
1919
dist/
20+
21+
# custom
22+
shadcnext/

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "shadcnext",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "shadcn but for tailwind v4",
55
"license": "MIT",
66
"author": {

src/commands/create.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { appendFile } from "fs/promises"
1+
import { constants } from "fs"
2+
import { access, appendFile } from "fs/promises"
23
import { Command } from "commander"
34
import { execa } from "execa"
45
import ora from "ora"
@@ -10,15 +11,15 @@ export const create = new Command()
1011
.action(async () => {
1112
const spinner = ora("detecting package manager...").start()
1213

13-
const pm = (await detect()) as {
14+
let pm = (await detect()) as {
1415
name: string
1516
agent: string
1617
execute: string
1718
}
1819

1920
if (!pm) {
2021
spinner.fail("package manager not detected.")
21-
process.exit(1)
22+
pm = { name: "npm", agent: "npm", execute: "npx" }
2223
}
2324

2425
pm.execute =
@@ -32,14 +33,19 @@ export const create = new Command()
3233

3334
const tmpCwd = "shadcnext"
3435

35-
const { stdout: gitignore } = await execa("grep", [
36-
tmpCwd,
37-
".gitignore",
38-
]).catch(() => ({ stdout: "false" }))
36+
try {
37+
await access("package.json", constants.F_OK)
38+
const { stdout: gitignore } = await execa("grep", [
39+
tmpCwd,
40+
".gitignore",
41+
]).catch(() => ({ stdout: "false" }))
3942

40-
if (gitignore === "false") {
41-
spinner.info(`adding ${tmpCwd} to .gitignore...`)
42-
await appendFile(".gitignore", `\n${tmpCwd}/\n`)
43+
if (gitignore === "false") {
44+
spinner.info(`adding ${tmpCwd} to .gitignore...`)
45+
await appendFile(".gitignore", `\n${tmpCwd}/\n`)
46+
}
47+
} catch {
48+
spinner.info("new project detected.")
4349
}
4450

4551
await execa("rm", ["-rf", tmpCwd])

0 commit comments

Comments
 (0)