Skip to content

Commit 6a8b796

Browse files
committed
feat: add custom template and plugins selection
1 parent 99cb7ed commit 6a8b796

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

.changeset/petite-mammals-own.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'create-mcp-kit': patch
3+
---
4+
5+
feat: add custom template and plugins selection

packages/create-mcp-kit/src/index.ts

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/usr/bin/env node
22
import { fileURLToPath } from 'url'
33
import { dirname, join, resolve } from 'path'
4-
import { stat } from 'fs/promises'
54
import * as clack from '@clack/prompts'
65
import pc from 'picocolors'
76
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'
98

109
const __filename = fileURLToPath(import.meta.url)
1110
const __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(
8096
const templatePath = join(__dirname, '../template', `${group.type}-${group.template}-${group.language}`)
8197
const 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

Comments
 (0)