@yorha2b-lab/autodev 1.0.12 → 1.0.13
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/bin/autodev.js +6 -4
- package/package.json +1 -1
- package/src/commands/watch-api.js +6 -3
- package/src/commands/watch-page.js +9 -7
- package/src/commands/watch-part.js +6 -3
- package/src/services/llm.js +3 -2
- package/templates/react/components/MyBaseForm.js +2 -2
- package/templates/react/components/MyModalForm.js +3 -2
- package/templates/react/components/MyTable.js +1 -1
package/bin/autodev.js
CHANGED
|
@@ -6,9 +6,11 @@ const figlet = require('figlet')
|
|
|
6
6
|
const { program } = require('commander')
|
|
7
7
|
|
|
8
8
|
console.log(chalk.cyan(figlet.textSync('AutoDev', { horizontalLayout: 'full' })))
|
|
9
|
-
console.log(chalk.gray('
|
|
9
|
+
console.log(chalk.gray('Booting System...'))
|
|
10
10
|
console.log(chalk.white(' [System] ') + chalk.green('YoRHa No.2 Type B Unit: ') + chalk.cyan('Online'))
|
|
11
|
-
console.log(chalk.white(' [
|
|
11
|
+
console.log(chalk.white(' [System] ') + chalk.green('Scanner Type 9S Unit: ') + chalk.cyan('Standby'))
|
|
12
|
+
console.log(chalk.white(' [Mission] ') + chalk.yellow('Frontend Architecture Construction: ') + chalk.cyan('Awaiting Command'))
|
|
13
|
+
console.log(chalk.white(' [Bunker] ') + chalk.magenta('Glory to mankind. (人类荣光永存)'))
|
|
12
14
|
console.log(chalk.gray('--------------------------------------------------\n'))
|
|
13
15
|
|
|
14
16
|
program.version('1.0.0').description('AI驱动的前端CRUD代码生成器')
|
|
@@ -25,8 +27,8 @@ program
|
|
|
25
27
|
fs.mkdirSync(path.join(process.cwd(), 'swagger'), { recursive: true })
|
|
26
28
|
fs.mkdirSync(path.join(process.cwd(), 'screenShot'), { recursive: true })
|
|
27
29
|
fs.mkdirSync(path.join(process.cwd(), 'screenPart'), { recursive: true })
|
|
28
|
-
console.log('
|
|
29
|
-
console.log('
|
|
30
|
+
console.log(chalk.cyan('📡 Operator 6O: 呼叫 2B,环境配置文件已下发至本地终端!'))
|
|
31
|
+
console.log(chalk.green('🤖 Pod 042: [报告] config.js 与 .env 存储完毕。'))
|
|
30
32
|
})
|
|
31
33
|
|
|
32
34
|
program
|
package/package.json
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
|
+
const ora = require('ora')
|
|
2
3
|
const path = require('path')
|
|
4
|
+
const chalk = require('chalk')
|
|
3
5
|
const chokidar = require('chokidar')
|
|
4
6
|
|
|
5
7
|
const watchApi = () => {
|
|
@@ -21,7 +23,8 @@ const watchApi = () => {
|
|
|
21
23
|
watcher.on('add', async filePath => {
|
|
22
24
|
const startTime = Date.now()
|
|
23
25
|
const fileName = path.basename(filePath, path.extname(filePath))
|
|
24
|
-
|
|
26
|
+
const spinner = ora(chalk.cyan(`🤖 Pod 153: [报告] 侦测到未知的 Swagger 数据源 [${fileName}],开始进行语义对齐...`))
|
|
27
|
+
spinner.start()
|
|
25
28
|
|
|
26
29
|
try {
|
|
27
30
|
const swaggerStr = fs.readFileSync(filePath, 'utf8')
|
|
@@ -35,9 +38,9 @@ const watchApi = () => {
|
|
|
35
38
|
fs.writeFileSync(path.join(`./${config.pagesDir}/${fileName}/resource.js`), resourceStr.replace(/"(\w+)":/g, '$1:').replace(/"/g, "'"))
|
|
36
39
|
const endTime = Date.now()
|
|
37
40
|
//fs.unlinkSync(filePath)
|
|
38
|
-
|
|
41
|
+
spinner.succeed(chalk.green(`🤖 Pod 153: [肯定] 字段对齐协议执行完毕:耗时 ${(endTime - startTime) / 1000} 秒。9S 的骇客任务很顺利。`))
|
|
39
42
|
} catch (error) {
|
|
40
|
-
console.
|
|
43
|
+
console.log(chalk.red(`🤖 Pod 153: [警告] 骇入 [${fileName}] 失败。接口数据遭遇强力防火墙:${error}`))
|
|
41
44
|
}
|
|
42
45
|
})
|
|
43
46
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
2
|
const ora = require('ora') // 命令行加载动画
|
|
3
3
|
const path = require('path')
|
|
4
|
+
const chalk = require('chalk')
|
|
5
|
+
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* 监听截图目录,自动生成 CRUD 页面
|
|
@@ -61,12 +63,12 @@ const watchPage = options => {
|
|
|
61
63
|
|
|
62
64
|
// 所有任务完成后统一更新菜单配置
|
|
63
65
|
queue.onIdle(() => {
|
|
64
|
-
console.log('
|
|
66
|
+
console.log(chalk.green('🤖 Pod 042: [报告] 所有排队的视觉数据已解析完毕,正在向 Bunker 同步 Menu 路由配置...'))
|
|
65
67
|
const constantDir = path.join(process.cwd(), config.utilsDir)
|
|
66
68
|
if (!fs.existsSync(constantDir)) fs.mkdirSync(constantDir, { recursive: true })
|
|
67
69
|
// 格式化菜单配置为 JS 代码
|
|
68
70
|
fs.writeFileSync(path.join(constantDir, 'constant.js'), `export const menus = ${stringify.default(menus, { indent: 4, maxLength: 50 })}`)
|
|
69
|
-
console.log('
|
|
71
|
+
console.log(chalk.green('🤖 Pod 042: [肯定] Menu 配置同步成功。'))
|
|
70
72
|
})
|
|
71
73
|
|
|
72
74
|
// 监听 screenShot 目录
|
|
@@ -92,7 +94,7 @@ const watchPage = options => {
|
|
|
92
94
|
if (!fs.existsSync(mockDir)) fs.mkdirSync(mockDir, { recursive: true })
|
|
93
95
|
if (!fs.existsSync(targetDir)) fs.mkdirSync(targetDir, { recursive: true })
|
|
94
96
|
|
|
95
|
-
const spinner = ora(
|
|
97
|
+
const spinner = ora(chalk.cyan(`🤖 Pod 042: [报告] 捕获到新的视觉图像 [${fileName}],开始执行构筑程序...`))
|
|
96
98
|
spinner.start()
|
|
97
99
|
|
|
98
100
|
// 1. 识别页面结构(调用视觉大模型)
|
|
@@ -111,18 +113,18 @@ const watchPage = options => {
|
|
|
111
113
|
|
|
112
114
|
// 5. 生成 Mock 数据(可选)
|
|
113
115
|
if (config.needMock) {
|
|
114
|
-
console.log(
|
|
116
|
+
console.log(chalk.yellow(`🧑💻 9S: 交给我吧 2B!正在骇入并伪造 [${fileName}] 的 Mock 数据...`))
|
|
115
117
|
const rawContent = await generateMock(pageConfig.table.columns, fileName)
|
|
116
118
|
// 格式化 Mock 数据
|
|
117
119
|
fs.writeFileSync(path.join(mockDir, `${fileName}.js`), `export default ${stringify.default(rawContent, { indent: 4, maxLength: 200 })}`.replaceAll(`"'`, `"`).replaceAll(`'"`, `"`))
|
|
118
|
-
console.log(
|
|
120
|
+
console.log(chalk.green(`🤖 Pod 042: [报告] Mock 数据注入完成,耗时: ${(Date.now() - startTime) / 1000} 秒`))
|
|
119
121
|
}
|
|
120
122
|
|
|
121
123
|
const endTime = Date.now()
|
|
122
124
|
//fs.unlinkSync(filePath) // 可选:处理完成后删除截图
|
|
123
|
-
spinner.succeed(
|
|
125
|
+
spinner.succeed(chalk.green(`🤖 Pod 042: [报告] 模块 [${fileName}] 物理装配完成!耗时 ${(endTime - startTime) / 1000} 秒`))
|
|
124
126
|
} catch (error) {
|
|
125
|
-
console.
|
|
127
|
+
console.log(chalk.red(`🤖 Pod 042: [警告] 模块 [${fileName}] 构筑失败。原因:${error}`))
|
|
126
128
|
}
|
|
127
129
|
})
|
|
128
130
|
})
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
|
+
const ora = require('ora')
|
|
3
|
+
const chalk = require('chalk')
|
|
2
4
|
const chokidar = require('chokidar')
|
|
3
5
|
const stringify = require('json-stringify-pretty-compact')
|
|
4
6
|
|
|
@@ -18,7 +20,8 @@ const watchPart = () => {
|
|
|
18
20
|
watcher.on('add', async filePath => {
|
|
19
21
|
try {
|
|
20
22
|
const startTime = Date.now()
|
|
21
|
-
|
|
23
|
+
const spinner = ora(chalk.cyan(`🤖 Pod 042: [报告] 捕获到新的视觉图像,开始执行构筑程序...`))
|
|
24
|
+
spinner.start()
|
|
22
25
|
const partPrompt = require('../prompts/watch-part.js')
|
|
23
26
|
const pageConfig = await recognizePage(partPrompt, filePath)
|
|
24
27
|
const optionDict = pageConfig.optionDict || {}
|
|
@@ -37,9 +40,9 @@ const watchPart = () => {
|
|
|
37
40
|
})
|
|
38
41
|
const finalResult = `${mainConfigStr}\n${optionsCodeStr}`
|
|
39
42
|
const endTime = Date.now()
|
|
40
|
-
|
|
43
|
+
spinner.succeed(`🤖 Pod 042: [报告] 识别程序结束!耗时 ${(endTime - startTime) / 1000} 秒\n================\n\n${finalResult}\n\n================`)
|
|
41
44
|
} catch (error) {
|
|
42
|
-
console.
|
|
45
|
+
console.log(chalk.red(`🤖 Pod 042: [警告] 识别程序失败。原因:${error}`))
|
|
43
46
|
} finally {
|
|
44
47
|
fs.unlinkSync(filePath)
|
|
45
48
|
}
|
package/src/services/llm.js
CHANGED
|
@@ -2,6 +2,7 @@ const fs = require('fs')
|
|
|
2
2
|
const path = require('path')
|
|
3
3
|
const JSON5 = require('json5')
|
|
4
4
|
const sharp = require('sharp') // 图片压缩库,用于处理截图
|
|
5
|
+
const chalk = require('chalk')
|
|
5
6
|
const OpenAI = require('openai')
|
|
6
7
|
const { getConfig } = require('../utils/utils.js')
|
|
7
8
|
|
|
@@ -32,7 +33,7 @@ const getOpenAI = () => {
|
|
|
32
33
|
*/
|
|
33
34
|
const askAI = async (model, messages, retryCount = 0) => {
|
|
34
35
|
// 最多重试 3 次,避免无限循环
|
|
35
|
-
if (retryCount > 3) throw new Error('
|
|
36
|
+
if (retryCount > 3) throw new Error('YoRHa 司令部连接中断:请检查网络状态或黑盒共鸣情况。')
|
|
36
37
|
|
|
37
38
|
try {
|
|
38
39
|
const openai = getOpenAI()
|
|
@@ -54,7 +55,7 @@ const askAI = async (model, messages, retryCount = 0) => {
|
|
|
54
55
|
// 使用 JSON5 解析(支持单引号、注释等非标准 JSON)
|
|
55
56
|
return JSON5.parse(match ? match[0] : raw)
|
|
56
57
|
} catch (err) {
|
|
57
|
-
console.warn(`[
|
|
58
|
+
console.warn(chalk.yellow(`[系统警告] 神经云网络连接不稳,正在尝试重新链接... (第 ${retryCount + 1} 次重试)`), err.message)
|
|
58
59
|
return askAI(model, messages, retryCount + 1)
|
|
59
60
|
}
|
|
60
61
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Form, Space } from 'antd'
|
|
2
1
|
import { formNode } from './index'
|
|
3
|
-
import {
|
|
2
|
+
import { Form, Space, Button } from 'antd'
|
|
3
|
+
import { PlusOutlined, PlusCircleOutlined, MinusCircleOutlined } from '@ant-design/icons'
|
|
4
4
|
|
|
5
5
|
export const MyBaseForm = ({ item, form }) => {
|
|
6
6
|
|
|
@@ -3,7 +3,7 @@ import { MyBaseForm } from './MyBaseForm'
|
|
|
3
3
|
import { useState, useEffect } from 'react'
|
|
4
4
|
import { Row, Col, Form, Modal, } from 'antd'
|
|
5
5
|
|
|
6
|
-
export const MyModalForm = ({ width, title, submit, record, visible, setModal, labelCol, formItems, wrapperCol, dateSeparator = '
|
|
6
|
+
export const MyModalForm = ({ width, title, submit, record, visible, setModal, labelCol, formItems, wrapperCol, dateSeparator = ',', onValuesChange }) => {
|
|
7
7
|
|
|
8
8
|
const [form] = Form.useForm()
|
|
9
9
|
const [pending, setPending] = useState(false)
|
|
@@ -30,8 +30,9 @@ export const MyModalForm = ({ width, title, submit, record, visible, setModal, l
|
|
|
30
30
|
setPending(false)
|
|
31
31
|
}
|
|
32
32
|
} catch (error) {
|
|
33
|
-
setPending(false)
|
|
34
33
|
console.log('表单校验失败:', error)
|
|
34
|
+
} finally {
|
|
35
|
+
setPending(false)
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
|
|
@@ -12,7 +12,7 @@ const components = {
|
|
|
12
12
|
export const MyTable = ({ size, query, onSave, autoScroll, onChange, pagination, rowClassName, columns = [], rowSelection, rowKey = 'id', loading = false, dataSource = [], editable = false, scroll = { x: 'max-content' }, ...restProps }) => {
|
|
13
13
|
|
|
14
14
|
const mergedColumns = columns.map(col => {
|
|
15
|
-
if (!col.
|
|
15
|
+
if (!col.editType) {
|
|
16
16
|
return col
|
|
17
17
|
}
|
|
18
18
|
return {
|