Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@
},
"devDependencies": {
"@antfu/ni": "^0.23.0",
"@create-uni/gui": "^0.0.7",
"@create-uni/info": "^0.1.8",
"@types/node": "^18.19.50",
"@uni-helper/eslint-config": "^0.2.0",
"bumpp": "^9.5.2",
"consola": "^3.3.3",
"create-uni": "^2.3.5",
"cross-env": "^7.0.3",
"eslint": "^9.10.0",
"lint-staged": "^15.2.10",
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
help: ['h', 'help'],
info: ['info', 'i'],
gui: ['gui', 'g'],
force: ['force', 'f'],
},
string: ['_'],
})
Expand Down Expand Up @@ -81,7 +82,7 @@
const pluginList = validatePlugins(argv.pluginList)
const moduleList = validateModules(argv.moduleList)

const shouldOverwrite = await askForceOverwrite(projectName)
const shouldOverwrite = argv.force ? true : await askForceOverwrite(projectName)

result = {
projectName,
Expand Down Expand Up @@ -263,7 +264,7 @@
init()
.catch((error) => {
outro(cancelMesssage)
console.log(error.message.includes('操作已取消') ? '' : error)

Check warning on line 267 in packages/core/src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
console.log(`🚀 遇到问题? 快速反馈:${green('https://github.com/uni-helper/create-uni/issues/new/choose')}`)

Check warning on line 268 in packages/core/src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
process.exit(0)
})
2 changes: 1 addition & 1 deletion packages/core/template/UI/skiyee/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"@skiyee/uni-ui": "^1.1.0"
},
"devDependencies": {
"@skiyee/ui-preset": "^0.0.7",
"@skiyee/ui-preset": "^0.0.8",
"@skiyee/ui-resolver": "^0.0.2"
}
}
2 changes: 1 addition & 1 deletion packages/core/template/config/lint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
},
"devDependencies": {
"@uni-helper/eslint-config": "^0.5.0",
"eslint": "^9.34.0"
"eslint": "^9.35.0"
}
}
2 changes: 1 addition & 1 deletion packages/core/template/config/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type-check": "vue-tsc --noEmit"
},
"devDependencies": {
"@types/node": "^24.3.0",
"@types/node": "^24.3.1",
"@vue/tsconfig": "^0.8.1",
"typescript": "^5.9.2",
"vue-tsc": "^3.0.6"
Expand Down
16 changes: 16 additions & 0 deletions packages/mcp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# @create-uni/mcp

create-uni的MCP(Model Context Protocol)服务,为AI助手提供创建uni-app项目的能力。

```json
{
"mcpServers": {
"create-uni": {
"command": "npx",
"args": [
"@create-uni/mcp"
]
}
}
}
```
6 changes: 6 additions & 0 deletions packages/mcp/bump.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// bump.config.ts
import { defineConfig } from 'bumpp'

export default defineConfig({
tag: 'mcp-v%s',
})
48 changes: 48 additions & 0 deletions packages/mcp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "@create-uni/mcp",
"type": "module",
"version": "0.1.0",
"packageManager": "pnpm@9.9.0",
"description": "create-uni的mcp服务",
"author": "FliPPeDround <flippedround@qq.com>",
"license": "MIT",
"funding": "https://afdian.com/a/flippedround",
"homepage": "https://github.com/uni-helper/create-uni#readme",
"repository": {
"directory": "packages/mcp",
"type": "git",
"url": "git+https://github.com/uni-helper/create-uni.git"
},
"bugs": "https://github.com/uni-helper/create-uni/issues",
"keywords": [
"uni",
"uni-app",
"create-uni",
"cli",
"vue",
"miniapp",
"create"
],
"sideEffects": false,
"bin": {
"create-uni-mcp": "./dist/outfile.cjs"
},
"files": [
"dist/outfile.cjs"
],
"scripts": {
"build": "tsup",
"dev": "tsup --watch",
"prepublishOnly": "nr build",
"inspect": "mcp-inspector",
"release": "bumpp",
"typecheck": "tsc --noEmit"
},
"devDependencies": {
"@modelcontextprotocol/inspector": "^0.16.6",
"@modelcontextprotocol/sdk": "^1.17.5",
"@types/cross-spawn": "^6.0.6",
"cross-spawn": "^7.0.6",
"zod": "3.25.68"
}
}
220 changes: 220 additions & 0 deletions packages/mcp/src/handlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js'
import type { CreateCustomOptions, CreateWithTemplateOptions } from './types.js'
import { sync } from 'cross-spawn'
import { canSkipEmptying } from './utils.js'

/**
* 构建命令行参数
*/
function buildCommandArgs(options: CreateCustomOptions & { templateType?: string }): string[] {
const args: string[] = []

// 项目名称
args.push(options.name)

// TypeScript支持
if (options.needsTypeScript) {
args.push('--ts')
}

// ESLint配置
if (options.needsEslint) {
args.push('-e')
}

// UI组件库
if (options.UIName) {
args.push('-u', options.UIName)
}

// 插件列表
if (options.pluginList?.length) {
options.pluginList.forEach((plugin) => {
args.push('-p', plugin)
})
}

// 模块列表
if (options.moduleList?.length) {
options.moduleList.forEach((module) => {
args.push('-m', module)
})
}

// 强制覆盖
if (options.force) {
args.push('-f')
}

// 模板类型(如果指定)
if (options.templateType) {
args.push('-t', options.templateType)
}

return args
}

/**
* 执行创建命令
*/
function executeCreateCommand(args: string[]): { success: boolean, error?: string } {
const [command, ...commandArgs] = ['npx', 'create-uni@latest', ...args]

const { error } = sync(command, commandArgs, { stdio: 'pipe' })

if (error) {
return { success: false, error: error.message }
}

return { success: true }
}

/**
* 检查目录是否可以创建项目
*/
function checkDirectory(name: string, force?: boolean): { canCreate: boolean, message?: string } {
if (!force) {
const canSkip = canSkipEmptying(name)
if (!canSkip) {
return {
canCreate: false,
message: `目标目录${name}非空,无法创建项目, 请使用 --force 强制覆盖`,
}
}
}

return { canCreate: true }
}

/**
* 使用预设模板创建项目
*/
export async function createWithTemplate(options: CreateWithTemplateOptions): Promise<CallToolResult> {
const { canCreate, message } = checkDirectory(options.name, options.force)

if (!canCreate) {
return {
content: [{
type: 'text',
text: message!,
}],
}
}

const args = buildCommandArgs({
name: options.name,
templateType: options.templateType,
force: options.force,
})

const result = executeCreateCommand(args)

if (!result.success) {
return {
content: [{
type: 'text',
text: `创建项目失败: ${result.error}`,
}],
}
}

const templateInfo = {
'vitesse': '由Uni Helper维护的快速启动模板',
'wot-starter': '由Wot UI提供的基于 vitesse-uni-app 的快速启动模板',
'wot-starter-retail': '基于Wot UI的 uni-app 零售行业模板',
'unisave': '拥抱 web 开发,拯救uniapp。适配所有 (app、mp、web) 平台',
'tmui32': '优质 Vue3 TS Pinia Vite 跨端组件库',
}[options.templateType] || options.templateType

return {
content: [{
type: 'text' as const,
text: `✅ 使用预设模板创建uni-app项目成功!

📁 项目路径: ${options.name}
🎯 模板类型: ${options.templateType}
📝 模板描述: ${templateInfo}

🚀 项目已创建完成,接下来可以:
1. cd ${options.name}
2. 安装依赖: pnpm install
3. 启动开发: pnpm dev
4. 访问 https://uni-helper.js.org/ 查看更多文档信息`,
}],
}
}

/**
* 使用自定义模板创建项目
*/
export async function createCustom(options: CreateCustomOptions): Promise<CallToolResult> {
const { canCreate, message } = checkDirectory(options.name, options.force)

if (!canCreate) {
return {
content: [{
type: 'text',
text: message!,
}],
}
}

const args = buildCommandArgs(options)
const result = executeCreateCommand(args)

if (!result.success) {
return {
content: [{
type: 'text',
text: `创建项目失败: ${result.error}`,
}],
}
}

const features = []
if (options.needsTypeScript)
features.push('✅ TypeScript支持')
if (options.needsEslint)
features.push('✅ ESLint代码规范')
if (options.UIName) {
const uiInfo = {
uni: 'UniApp官方组件库',
wot: '高颜值、轻量化的uni-app组件库',
nut: '京东风格的轻量级移动端组件库',
skiyee: '随心创造差异化',
uv: '多平台快速开发的UI框架',
ano: '轻量级、漂亮、快速的 UnoCSS 组件库',
}[options.UIName] || options.UIName
features.push(`✅ UI组件库: ${uiInfo}`)
}
if (options.pluginList?.length) {
features.push(`✅ 插件: ${options.pluginList.join(', ')}`)
}
if (options.moduleList?.length) {
const moduleDescriptions = {
pinia: 'Vue.js状态管理',
unocss: '原子级CSS引擎',
uniNetwork: '网络请求库',
uniUse: '组合式工具集',
uniPromises: 'Promise化API',
}
const moduleNames = options.moduleList.map(m => moduleDescriptions[m as keyof typeof moduleDescriptions] || m)
features.push(`✅ 模块: ${moduleNames.join(', ')}`)
}

return {
content: [{
type: 'text',
text: `✅ 创建uni-app项目成功!

📁 项目路径: ${options.name}
${features.length ? `\n🎯 已选择的功能:\n${features.join('\n')}` : ''}

🚀 项目已创建完成,接下来可以:
1. cd ${options.name}
2. 安装依赖: pnpm install
3. 启动开发: pnpm dev
4. 访问 https://uni-helper.js.org/ 查看更多文档信息`,
}],
}
}
Loading
Loading