@yorha2b-lab/autodev 1.0.24 → 1.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/README_EN.md +194 -0
- package/bin/autodev.js +2 -2
- package/package.json +1 -1
- package/src/commands/watch-api.js +5 -5
- package/src/prompts/watch-api.js +6 -5
- package/src/services/llm.js +4 -4
- package/templates/react/components/index.js +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Auto CRUD Copilot
|
|
2
2
|
|
|
3
|
+
[English](./README_EN.md) | 简体中文
|
|
4
|
+
|
|
3
5
|
[](https://www.npmjs.com/package/@yorha2b-lab/autodev)
|
|
4
6
|
[](https://www.npmjs.com/package/@yorha2b-lab/autodev)
|
|
5
7
|
[](https://github.com/yorha2b-lab/auto-crud-copilot/stargazers)
|
|
@@ -12,7 +14,7 @@
|
|
|
12
14
|
|
|
13
15
|
拒绝重复劳动!为什么你需要 Auto CRUD Copilot?
|
|
14
16
|
告别手写 Table/Form:截图即代码,提升你的开发效率,告别烦人的复制粘贴。
|
|
15
|
-
拒绝接口联调痛苦:自动读取
|
|
17
|
+
拒绝接口联调痛苦:自动读取 Response,AI 帮你抹平前后端字段命名差异。
|
|
16
18
|
架构解耦:核心逻辑与 UI 框架分离,React/Vue/Angular 均可适配。
|
|
17
19
|
|
|
18
20
|
## ✨ 特性
|
|
@@ -21,7 +23,7 @@
|
|
|
21
23
|
- 🔧 **智能生成**: 支持React、Vue、Angular等多种前端框架模板
|
|
22
24
|
- 📊 **表格组件**: 自动生成可编辑、可排序、可筛选的数据表格
|
|
23
25
|
- 📝 **表单组件**: 智能生成搜索表单和模态框表单
|
|
24
|
-
- 🔌 **API对齐**: 自动对齐
|
|
26
|
+
- 🔌 **API对齐**: 自动对齐Response接口与前端字段映射
|
|
25
27
|
- 🎨 **UI组件**: 支持多种UI组件类型(输入框、选择器、日期等)
|
|
26
28
|
- 📱 **响应式**: 生成的代码支持响应式布局
|
|
27
29
|
|
|
@@ -70,7 +72,6 @@ autodev watch:part
|
|
|
70
72
|
3. **对齐API字段**
|
|
71
73
|
|
|
72
74
|
```bash
|
|
73
|
-
# 将Swagger文档放入swagger目录
|
|
74
75
|
autodev watch:api
|
|
75
76
|
```
|
|
76
77
|
|
|
@@ -97,7 +98,7 @@ autodev watch:part -t vue
|
|
|
97
98
|
|
|
98
99
|
### watch:api 命令
|
|
99
100
|
|
|
100
|
-
监听 `
|
|
101
|
+
监听 `response` 目录下的与模块同名的json文件,自动对齐真实接口字段。
|
|
101
102
|
|
|
102
103
|
```bash
|
|
103
104
|
autodev watch:api
|
|
@@ -109,7 +110,7 @@ autodev watch:api
|
|
|
109
110
|
your-project/
|
|
110
111
|
├── screenShot/ # 页面截图目录
|
|
111
112
|
├── screenPart/ # 组件截图目录
|
|
112
|
-
├──
|
|
113
|
+
├── response/ # Response目录
|
|
113
114
|
├── mock/ # 生成的Mock数据
|
|
114
115
|
├── src/
|
|
115
116
|
│ ├── pages/ # 生成的页面代码
|
package/README_EN.md
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# Auto CRUD Copilot
|
|
2
|
+
|
|
3
|
+
English | [简体中文](./README.md)
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@yorha2b-lab/autodev)
|
|
6
|
+
[](https://www.npmjs.com/package/@yorha2b-lab/autodev)
|
|
7
|
+
[](https://github.com/yorha2b-lab/auto-crud-copilot/stargazers)
|
|
8
|
+
[](https://github.com/yorha2b-lab/auto-crud-copilot/blob/main/LICENSE)
|
|
9
|
+
|
|
10
|
+
An AI-powered frontend CRUD code generator based on vision models (Umi+Antd) 🚀
|
|
11
|
+
|
|
12
|
+
<video src="https://github.com/user-attachments/assets/6d42fce1-c815-482b-8c6a-4a3b9415ba47.mp4" controls="controls" muted="muted" style="max-width: 100%; display: block; margin: 20px auto;">
|
|
13
|
+
</video>
|
|
14
|
+
|
|
15
|
+
Say goodbye to repetitive work! Why do you need Auto CRUD Copilot?
|
|
16
|
+
Stop writing Tables/Forms manually: Screenshot to code, boost your development efficiency, and say goodbye to tedious copy-paste.
|
|
17
|
+
Eliminate API integration pain: Automatically read Response data, and let AI help you bridge frontend-backend field naming differences.
|
|
18
|
+
Decoupled architecture: Core logic separated from UI frameworks, supporting React/Vue/Angular.
|
|
19
|
+
|
|
20
|
+
## ✨ Features
|
|
21
|
+
|
|
22
|
+
- 🖼️ **Visual Recognition**: Automatically recognize page structures from screenshots and generate corresponding CRUD code
|
|
23
|
+
- 🔧 **Smart Generation**: Support multiple frontend framework templates including React, Vue, and Angular
|
|
24
|
+
- 📊 **Table Components**: Automatically generate editable, sortable, and filterable data tables
|
|
25
|
+
- 📝 **Form Components**: Intelligently generate search forms and modal forms
|
|
26
|
+
- 🔌 **API Alignment**: Automatically align Response interfaces with frontend field mappings
|
|
27
|
+
- 🎨 **UI Components**: Support various UI component types (input, select, date picker, etc.)
|
|
28
|
+
- 📱 **Responsive**: Generated code supports responsive layout
|
|
29
|
+
|
|
30
|
+
## 🚀 Quick Start
|
|
31
|
+
|
|
32
|
+
### Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install -g @yorha2b-lab/autodev
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Environment Setup
|
|
39
|
+
|
|
40
|
+
Quick start
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
autodev init
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Create a `.env` file and configure the following environment variables:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# AI Model API Configuration
|
|
50
|
+
API_KEY=your_api_key_here
|
|
51
|
+
BASE_URL=your_api_base_url_here
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
🚗 **Get API Key**: [Alibaba Cloud Bailian Console](https://bailian.console.aliyun.com/cn-beijing?tab=doc#/doc/)
|
|
55
|
+
|
|
56
|
+
### Basic Usage
|
|
57
|
+
|
|
58
|
+
1. **Generate Complete CRUD Pages**
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Put page screenshots in the screenShot directory
|
|
62
|
+
autodev watch:page
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
2. **Generate Partial UI Components**
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
# Put component screenshots in the screenPart directory
|
|
69
|
+
autodev watch:part
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
3. **Align API Fields**
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
autodev watch:api
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## 📖 Detailed Usage Guide
|
|
79
|
+
|
|
80
|
+
### watch:page Command
|
|
81
|
+
|
|
82
|
+
Monitor screenshot files in the `screenShot` directory and automatically generate complete CRUD pages.
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
autodev watch:page -t react
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Parameters:
|
|
89
|
+
- `-t, --template <type>`: Specify frontend framework template, default is `react`
|
|
90
|
+
|
|
91
|
+
### watch:part Command
|
|
92
|
+
|
|
93
|
+
Monitor screenshot files in the `screenPart` directory and automatically generate partial UI components.
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
autodev watch:part -t vue
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### watch:api Command
|
|
100
|
+
|
|
101
|
+
Monitor JSON files in the `response` directory (named after modules) and automatically align real API fields.
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
autodev watch:api
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## 📁 Project Structure
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
your-project/
|
|
111
|
+
├── screenShot/ # Page screenshot directory
|
|
112
|
+
├── screenPart/ # Component screenshot directory
|
|
113
|
+
├── response/ # Response directory
|
|
114
|
+
├── mock/ # Generated Mock data
|
|
115
|
+
├── src/
|
|
116
|
+
│ ├── pages/ # Generated page code
|
|
117
|
+
│ ├── components/ # Generated component code
|
|
118
|
+
│ ├── hooks/ # Generated Hook code
|
|
119
|
+
└── config.js # Configuration file
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## ⚙️ Configuration
|
|
123
|
+
|
|
124
|
+
You can configure the following options in `config.js`:
|
|
125
|
+
|
|
126
|
+
```javascript
|
|
127
|
+
module.exports = {
|
|
128
|
+
// Whether to generate Mock data
|
|
129
|
+
needMock: false,
|
|
130
|
+
|
|
131
|
+
// AI model types to use
|
|
132
|
+
visionModel: 'qwen3.5-plus',
|
|
133
|
+
textModel: 'qwen-turbo',
|
|
134
|
+
|
|
135
|
+
// Target project directory paths
|
|
136
|
+
hooksDir: 'src/hooks',
|
|
137
|
+
pagesDir: 'src/pages',
|
|
138
|
+
utilsDir: 'src/utils',
|
|
139
|
+
componentsDir: 'src/components',
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 🎯 Supported UI Components
|
|
144
|
+
|
|
145
|
+
- Input
|
|
146
|
+
- InputNumber
|
|
147
|
+
- Select
|
|
148
|
+
- Radio
|
|
149
|
+
- Checkbox
|
|
150
|
+
- DatePicker
|
|
151
|
+
- RangePicker
|
|
152
|
+
- Cascader
|
|
153
|
+
- AutoComplete
|
|
154
|
+
- TextArea
|
|
155
|
+
- Upload
|
|
156
|
+
|
|
157
|
+
## 🤝 Contributing
|
|
158
|
+
|
|
159
|
+
Contributions are welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) to learn how to participate in project development.
|
|
160
|
+
|
|
161
|
+
## 📄 License
|
|
162
|
+
|
|
163
|
+
This project is licensed under the [MIT](LICENSE) license.
|
|
164
|
+
|
|
165
|
+
## 🙏 Acknowledgments
|
|
166
|
+
|
|
167
|
+
Thanks to the following open-source projects:
|
|
168
|
+
|
|
169
|
+
- [OpenAI](https://openai.com/) - Providing powerful AI capabilities
|
|
170
|
+
- [Ant Design](https://ant.design/) - Excellent enterprise-level UI design language
|
|
171
|
+
- [UmiJS](https://umijs.org/) - Enterprise-level frontend application framework
|
|
172
|
+
|
|
173
|
+
## 📞 Contact
|
|
174
|
+
|
|
175
|
+
If you have any questions or suggestions, feel free to submit an [Issue](https://github.com/yorha2b-lab/auto-crud-copilot/issues).
|
|
176
|
+
|
|
177
|
+
## 🛠️ FAQ
|
|
178
|
+
|
|
179
|
+
**Q: Is this tool free?**
|
|
180
|
+
A: The tool itself is open-source and free, but the AI models it calls (such as GPT-4v, Qwen-VL) may require you to configure your own API Key. We recommend using cost-effective models like Alibaba Cloud's Qwen-VL.
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## ⚖️ Disclaimer
|
|
185
|
+
|
|
186
|
+
Auto CRUD Copilot is a **fan-made, non-commercial, open-source tool**.
|
|
187
|
+
|
|
188
|
+
- The themes, names (YoRHa, 2B, etc.), and catchphrases included in this project are inspired by **NieR:Automata**, which is a trademark and copyright of **Square Enix Co., Ltd. / PlatinumGames Inc.**
|
|
189
|
+
- This project is not affiliated with, endorsed by, or representative of Square Enix in any way.
|
|
190
|
+
- Please support the original masterpiece: [NieR:Automata Official Site](https://nierautomata.square-enix-games.com/).
|
|
191
|
+
|
|
192
|
+
**Glory to Mankind.**
|
|
193
|
+
|
|
194
|
+
⭐ If this project helps you, please give it a Star to show your support!
|
package/bin/autodev.js
CHANGED
|
@@ -25,7 +25,7 @@ program
|
|
|
25
25
|
const tplEnv = path.resolve(__dirname, '../.env.example')
|
|
26
26
|
const targetEnv = path.join(process.cwd(), '.env')
|
|
27
27
|
const targetConfig = path.join(process.cwd(), 'config.js')
|
|
28
|
-
fs.mkdirSync(path.join(process.cwd(), '
|
|
28
|
+
fs.mkdirSync(path.join(process.cwd(), 'response'), { recursive: true })
|
|
29
29
|
fs.mkdirSync(path.join(process.cwd(), 'screenShot'), { recursive: true })
|
|
30
30
|
fs.mkdirSync(path.join(process.cwd(), 'screenPart'), { recursive: true })
|
|
31
31
|
if (fs.existsSync(targetEnv)) {
|
|
@@ -61,7 +61,7 @@ program
|
|
|
61
61
|
|
|
62
62
|
program
|
|
63
63
|
.command('watch:api')
|
|
64
|
-
.description('监听
|
|
64
|
+
.description('监听 Response,自动对齐真实接口字段')
|
|
65
65
|
.action(() => {
|
|
66
66
|
const watchApi = require('../src/commands/watch-api')
|
|
67
67
|
watchApi()
|
package/package.json
CHANGED
|
@@ -7,11 +7,11 @@ const chokidar = require('chokidar')
|
|
|
7
7
|
const watchApi = () => {
|
|
8
8
|
|
|
9
9
|
const { getConfig } = require('../utils/utils.js')
|
|
10
|
-
const {
|
|
10
|
+
const { alignResponseFields } = require('../services/llm.js')
|
|
11
11
|
|
|
12
12
|
const config = getConfig()
|
|
13
13
|
|
|
14
|
-
const watcher = chokidar.watch('./
|
|
14
|
+
const watcher = chokidar.watch('./response', {
|
|
15
15
|
persistent: true,
|
|
16
16
|
ignored: /(^|[\/\\])\../,
|
|
17
17
|
awaitWriteFinish: {
|
|
@@ -23,13 +23,13 @@ const watchApi = () => {
|
|
|
23
23
|
watcher.on('add', async filePath => {
|
|
24
24
|
const startTime = Date.now()
|
|
25
25
|
const fileName = path.basename(filePath, path.extname(filePath))
|
|
26
|
-
const spinner = ora(chalk.cyan(`🤖 Pod 153: [报告] 侦测到未知的
|
|
26
|
+
const spinner = ora(chalk.cyan(`🤖 Pod 153: [报告] 侦测到未知的 Response 数据源 [${fileName}],开始进行语义对齐...`))
|
|
27
27
|
spinner.start()
|
|
28
28
|
|
|
29
29
|
try {
|
|
30
|
-
const
|
|
30
|
+
const responseStr = fs.readFileSync(filePath, 'utf8')
|
|
31
31
|
let resourceStr = fs.readFileSync(`./${config.pagesDir}/${fileName}/resource.js`, 'utf8')
|
|
32
|
-
const result = await
|
|
32
|
+
const result = await alignResponseFields(responseStr, resourceStr)
|
|
33
33
|
Object.entries(result).forEach(([oldField, newField]) => {
|
|
34
34
|
if (oldField === newField) return
|
|
35
35
|
const regex = new RegExp(`(dataIndex|name)\\s*:\\s*['"]${oldField}['"]`, 'g')
|
package/src/prompts/watch-api.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
module.exports = (
|
|
2
|
-
|
|
1
|
+
module.exports = (responseStr, resourceStr) => `
|
|
2
|
+
responseStr: ${responseStr}
|
|
3
3
|
resourceStr: ${resourceStr}
|
|
4
4
|
resourceStr是前端目前猜测的字段名列表(请从resourceStr中提取dataIndex和name),
|
|
5
|
-
|
|
5
|
+
responseStr是后端的真实响应。
|
|
6
6
|
请比对两者,找出现有前端字段名应该被替换为哪个真实的后端字段名。
|
|
7
7
|
匹配规则: 1.完全相同 2.下划线/驼峰转换 3.语义相似。
|
|
8
|
-
请只输出一个JSON对象, Key为前端猜测的旧名字, Value为
|
|
8
|
+
请只输出一个JSON对象, Key为前端猜测的旧名字, Value为Response里的真实新名字。
|
|
9
9
|
例如:{"key_1": "key1"}
|
|
10
10
|
如果没有找到对应的,请不要包含在结果中。
|
|
11
|
-
|
|
11
|
+
注意:⚠️⚠️如果有语义相近的两个字段优先取中文字段,比如"createByName"和"createBy",则取"createByName"
|
|
12
|
+
。`.trim()
|
package/src/services/llm.js
CHANGED
|
@@ -117,12 +117,12 @@ module.exports = {
|
|
|
117
117
|
},
|
|
118
118
|
|
|
119
119
|
/**
|
|
120
|
-
* 对齐
|
|
121
|
-
* @param {string}
|
|
120
|
+
* 对齐 Response 接口字段与前端字段
|
|
121
|
+
* @param {string} responseStr - 真实接口响应数据
|
|
122
122
|
* @param {string} resourceStr - 前端 resource.js 内容
|
|
123
123
|
* @returns {Object} 字段映射对象 { oldName: newName }
|
|
124
124
|
*/
|
|
125
|
-
|
|
125
|
+
alignResponseFields: async (responseStr, resourceStr) => {
|
|
126
126
|
const config = getConfig()
|
|
127
127
|
const apiPrompt = require('../prompts/watch-api.js')
|
|
128
128
|
const { API_DESIGNER } = require('../prompts/system.js')
|
|
@@ -130,7 +130,7 @@ module.exports = {
|
|
|
130
130
|
config.textModel,
|
|
131
131
|
[
|
|
132
132
|
{ role: 'system', content: API_DESIGNER },
|
|
133
|
-
{ role: 'user', content: apiPrompt(
|
|
133
|
+
{ role: 'user', content: apiPrompt(responseStr, resourceStr) }
|
|
134
134
|
]
|
|
135
135
|
)
|
|
136
136
|
}
|