11#!/usr/bin/env node
22import { fileURLToPath } from 'url'
33import { dirname , join , resolve } from 'path'
4- import { stat } from 'fs/promises'
54import * as clack from '@clack/prompts'
65import pc from 'picocolors'
76import 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'
98
109const __filename = fileURLToPath ( import . meta. url )
1110const __dirname = dirname ( __filename )
@@ -49,7 +48,7 @@ const group = await clack.group(
4948 message : 'Project template:' ,
5049 options : [
5150 { value : 'standard' , label : pc . magenta ( 'Standard (recommended)' ) } ,
52- // { value: 'custom', label: pc.blue('Custom') },
51+ { value : 'custom' , label : pc . blue ( 'Custom' ) } ,
5352 ] ,
5453 } ) ,
5554 transports : ( ) => {
@@ -64,6 +63,23 @@ const group = await clack.group(
6463 ] ,
6564 } )
6665 } ,
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+ } ,
6783 install : ( ) =>
6884 clack . confirm ( {
6985 message : 'Do you want to install dependencies?' ,
@@ -80,18 +96,15 @@ const group = await clack.group(
8096const templatePath = join ( __dirname , '../template' , `${ group . type } -${ group . template } -${ group . language } ` )
8197const targetPath = resolve ( process . cwd ( ) , group . name as string )
8298
83- try {
84- await stat ( templatePath )
85- } catch {
99+ if ( ! ( await fileExists ( templatePath ) ) ) {
86100 clack . log . error ( `Template not found: ${ templatePath } ` )
87101 process . exit ( 1 )
88102}
89103
90- try {
91- await stat ( targetPath )
104+ if ( await fileExists ( targetPath ) ) {
92105 clack . log . error ( `Directory ${ group . name } already exists` )
93106 process . exit ( 1 )
94- } catch { }
107+ }
95108
96109{
97110 const createSpinner = clack . spinner ( )
@@ -102,7 +115,7 @@ try {
102115 projectName : group . name as string ,
103116 year : new Date ( ) . getFullYear ( ) . toString ( ) ,
104117 transports : group . transports as string [ ] ,
105- plugins : [ ] ,
118+ plugins : group . plugins as string [ ] ,
106119 components : [ ] ,
107120 } )
108121 } catch ( error ) {
0 commit comments