1
- import { appendFile } from "fs/promises"
1
+ import { constants } from "fs"
2
+ import { access , appendFile } from "fs/promises"
2
3
import { Command } from "commander"
3
4
import { execa } from "execa"
4
5
import ora from "ora"
@@ -10,15 +11,15 @@ export const create = new Command()
10
11
. action ( async ( ) => {
11
12
const spinner = ora ( "detecting package manager..." ) . start ( )
12
13
13
- const pm = ( await detect ( ) ) as {
14
+ let pm = ( await detect ( ) ) as {
14
15
name : string
15
16
agent : string
16
17
execute : string
17
18
}
18
19
19
20
if ( ! pm ) {
20
21
spinner . fail ( "package manager not detected." )
21
- process . exit ( 1 )
22
+ pm = { name : "npm" , agent : "npm" , execute : "npx" }
22
23
}
23
24
24
25
pm . execute =
@@ -32,14 +33,19 @@ export const create = new Command()
32
33
33
34
const tmpCwd = "shadcnext"
34
35
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" } ) )
39
42
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." )
43
49
}
44
50
45
51
await execa ( "rm" , [ "-rf" , tmpCwd ] )
0 commit comments