1
1
#!/usr/bin/env node
2
2
import { fileURLToPath } from 'url'
3
3
import { dirname , join , resolve } from 'path'
4
- import { stat } from 'fs/promises'
5
4
import * as clack from '@clack/prompts'
6
5
import pc from 'picocolors'
7
6
import gradient from 'gradient-string'
8
- import { sleep , createProject , installDependencies } from '@mcp-tool-kit/shared'
7
+ import { sleep , createProject , installDependencies , fileExists } from '@mcp-tool-kit/shared'
9
8
10
9
const __filename = fileURLToPath ( import . meta. url )
11
10
const __dirname = dirname ( __filename )
@@ -49,7 +48,7 @@ const group = await clack.group(
49
48
message : 'Project template:' ,
50
49
options : [
51
50
{ value : 'standard' , label : pc . magenta ( 'Standard (recommended)' ) } ,
52
- // { value: 'custom', label: pc.blue('Custom') },
51
+ { value : 'custom' , label : pc . blue ( 'Custom' ) } ,
53
52
] ,
54
53
} ) ,
55
54
transports : ( ) => {
@@ -64,6 +63,23 @@ const group = await clack.group(
64
63
] ,
65
64
} )
66
65
} ,
66
+ plugins : ( { results } ) => {
67
+ if ( results . template !== 'custom' ) {
68
+ return Promise . resolve ( [ 'github-action' , 'vitest' , 'inspector' , 'style' , 'commitlint' , 'changelog' ] )
69
+ }
70
+ return clack . multiselect ( {
71
+ message : 'Project plugins:' ,
72
+ required : false ,
73
+ options : [
74
+ { value : 'github-action' , label : pc . magenta ( 'GitHub Action' ) } ,
75
+ { value : 'vitest' , label : pc . green ( 'Vitest' ) } ,
76
+ { value : 'inspector' , label : pc . blue ( 'Inspector' ) } ,
77
+ { value : 'style' , label : pc . white ( 'ESLint + Prettier + Lint-staged' ) } ,
78
+ { value : 'commitlint' , label : pc . gray ( 'Commitlint' ) } ,
79
+ { value : 'changelog' , label : pc . blueBright ( 'Changelog' ) } ,
80
+ ] ,
81
+ } )
82
+ } ,
67
83
install : ( ) =>
68
84
clack . confirm ( {
69
85
message : 'Do you want to install dependencies?' ,
@@ -80,18 +96,15 @@ const group = await clack.group(
80
96
const templatePath = join ( __dirname , '../template' , `${ group . type } -${ group . template } -${ group . language } ` )
81
97
const targetPath = resolve ( process . cwd ( ) , group . name as string )
82
98
83
- try {
84
- await stat ( templatePath )
85
- } catch {
99
+ if ( ! ( await fileExists ( templatePath ) ) ) {
86
100
clack . log . error ( `Template not found: ${ templatePath } ` )
87
101
process . exit ( 1 )
88
102
}
89
103
90
- try {
91
- await stat ( targetPath )
104
+ if ( await fileExists ( targetPath ) ) {
92
105
clack . log . error ( `Directory ${ group . name } already exists` )
93
106
process . exit ( 1 )
94
- } catch { }
107
+ }
95
108
96
109
{
97
110
const createSpinner = clack . spinner ( )
@@ -102,7 +115,7 @@ try {
102
115
projectName : group . name as string ,
103
116
year : new Date ( ) . getFullYear ( ) . toString ( ) ,
104
117
transports : group . transports as string [ ] ,
105
- plugins : [ ] ,
118
+ plugins : group . plugins as string [ ] ,
106
119
components : [ ] ,
107
120
} )
108
121
} catch ( error ) {
0 commit comments