@yorha2b-lab/autodev 1.0.12 → 1.0.14

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 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(' [Mission] ') + chalk.yellow('Generate Frontend CRUD: ') + chalk.cyan('Awaiting Command'))
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('✅ 已生成 config.js')
29
- console.log('✅ 已生成 .env')
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@yorha2b-lab/autodev",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "基于视觉大模型的前端(Umi+Antd)全自动 CRUD 代码生成器",
5
5
  "bin": {
6
6
  "autodev": "bin/autodev.js"
@@ -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
- console.log(`🚀 检测到新文件: ${fileName}, 开始识别...`)
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
- console.log(`识别完成:耗时 ${(endTime - startTime) / 1000} 秒`)
41
+ spinner.succeed(chalk.green(`🤖 Pod 153: [肯定] 字段对齐协议执行完毕:耗时 ${(endTime - startTime) / 1000} 秒。9S 的骇客任务很顺利。`))
39
42
  } catch (error) {
40
- console.error(`识别 ${fileName} 失败:`, error)
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('💾 所有排队的截图已处理完成,正在统一更新 menu 配置...')
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('✅ Menu 配置更新成功!')
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(`🚀 Pod 042: 开始处理排队任务: ${fileName}...`)
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(`🚀 开始生成 ${fileName} 的 Mock 数据...`)
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(`生成 ${fileName} 的 Mock 数据耗时: ${(Date.now() - startTime) / 1000} 秒`)
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(`✅ Pod 042: 模块 [${fileName}] 装配完成!耗时 ${(endTime - startTime) / 1000} 秒`)
125
+ spinner.succeed(chalk.green(`🤖 Pod 042: [报告] 模块 [${fileName}] 物理装配完成!耗时 ${(endTime - startTime) / 1000} 秒`))
124
126
  } catch (error) {
125
- console.error(`❌ 处理失败: ${filePath}`, error)
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
- console.log(`🚀 检测到新图片: 开始识别...`)
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,11 +40,13 @@ const watchPart = () => {
37
40
  })
38
41
  const finalResult = `${mainConfigStr}\n${optionsCodeStr}`
39
42
  const endTime = Date.now()
40
- console.log(`🎉 识别完成!耗时 ${(endTime - startTime) / 1000} 秒\n================\n\n${finalResult}\n\n================`)
43
+ spinner.succeed(`🤖 Pod 042: [报告] 识别程序结束!耗时 ${(endTime - startTime) / 1000} 秒\n================\n\n${finalResult}\n\n================`)
41
44
  } catch (error) {
42
- console.error('识别图片失败', error)
45
+ console.log(chalk.red(`🤖 Pod 042: [警告] 识别程序失败。原因:${error}`))
43
46
  } finally {
44
- fs.unlinkSync(filePath)
47
+ if (fs.existsSync(filePath)) {
48
+ fs.unlinkSync(filePath)
49
+ }
45
50
  }
46
51
  })
47
52
  }
@@ -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('AI 重试次数耗尽,请检查网络或图片')
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(`[解析失败,第 ${retryCount + 1} 次重试...]`, err.message)
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 { MinusCircleOutlined, PlusCircleOutlined } from '@ant-design/icons'
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 = '\GMT\,', onValuesChange }) => {
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
 
@@ -11,8 +11,11 @@ const components = {
11
11
 
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
+
15
+ const hasScrolled = useRef(false)
16
+
14
17
  const mergedColumns = columns.map(col => {
15
- if (!col.editable) {
18
+ if (!col.editType) {
16
19
  return col
17
20
  }
18
21
  return {
@@ -31,16 +34,21 @@ export const MyTable = ({ size, query, onSave, autoScroll, onChange, pagination,
31
34
  })
32
35
 
33
36
  useEffect(() => {
34
- /* if (query && autoScroll) {
35
- //如果需要可以在这里通过query来处理滚动到目标行的操作
36
- const trList = document.getElementsByClassName('ant-table-row')
37
- const index = 0 //根据query来计算索引
38
- const tr = trList[index]
39
- if (tr) {
40
- tr.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'nearest' })
41
- }
42
- } */
43
- }, [])
37
+ if (hasScrolled.current || !query || !autoScroll || !dataSource?.length) return
38
+ if (query && autoScroll && dataSource?.length > 0) {
39
+ const timer = setTimeout(() => {
40
+ const trList = document.getElementsByClassName('ant-table-row')
41
+ const tr = trList[Number(query.rowIndex)]
42
+ if (tr) {
43
+ tr.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' })
44
+ tr.style.transition = 'background-color 0.8s ease'
45
+ tr.style.backgroundColor = '#e6f4ff'
46
+ hasScrolled.current = true
47
+ }
48
+ }, 100)
49
+ return () => clearTimeout(timer)
50
+ }
51
+ }, [dataSource])
44
52
 
45
53
  return (
46
54
  <Table