@yorha2b-lab/autodev 1.0.17 → 1.0.18

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
@@ -23,13 +23,24 @@ program
23
23
  .action(() => {
24
24
  const tplConfig = path.resolve(__dirname, '../config.js')
25
25
  const tplEnv = path.resolve(__dirname, '../.env.example')
26
- fs.copyFileSync(tplEnv, path.join(process.cwd(), '.env'))
27
- fs.copyFileSync(tplConfig, path.join(process.cwd(), 'config.js'))
26
+ const targetEnv = path.join(process.cwd(), '.env')
27
+ const targetConfig = path.join(process.cwd(), 'config.js')
28
28
  fs.mkdirSync(path.join(process.cwd(), 'swagger'), { 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
+ if (fs.existsSync(targetEnv)) {
32
+ console.log(chalk.yellow('🤖 Pod 042: [警告] 终端已存在 .env 文件,跳过生成以免覆盖数据。'));
33
+ } else {
34
+ fs.copyFileSync(tplEnv, targetEnv);
35
+ console.log(chalk.green('🤖 Pod 042: [报告] .env 存储完毕。'));
36
+ }
37
+ if (fs.existsSync(targetConfig)) {
38
+ console.log(chalk.yellow('🤖 Pod 042: [警告] 终端已存在 config.js 文件,跳过生成以免覆盖数据。'));
39
+ } else {
40
+ fs.copyFileSync(tplConfig, targetConfig)
41
+ console.log(chalk.green('🤖 Pod 042: [报告] config.js 存储完毕。'));
42
+ }
31
43
  console.log(chalk.cyan('📡 Operator 6O: 呼叫 2B,环境配置文件已下发至本地终端!'))
32
- console.log(chalk.green('🤖 Pod 042: [报告] config.js 与 .env 存储完毕。'))
33
44
  })
34
45
 
35
46
  program
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yorha2b-lab/autodev",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "description": "基于视觉大模型的前端(Umi+Antd)全自动 CRUD 代码生成器",
5
5
  "bin": {
6
6
  "autodev": "bin/autodev.js"
@@ -35,7 +35,7 @@ const watchApi = () => {
35
35
  const regex = new RegExp(`(dataIndex|name)\\s*:\\s*['"]${oldField}['"]`, 'g')
36
36
  resourceStr = resourceStr.replace(regex, `$1: '${newField}'`)
37
37
  })
38
- fs.writeFileSync(path.join(`./${config.pagesDir}/${fileName}/resource.js`), resourceStr.replace(/"(\w+)":/g, '$1:').replace(/"/g, "'"))
38
+ fs.writeFileSync(path.join(`./${config.pagesDir}/${fileName}/resource.js`), resourceStr)
39
39
  const endTime = Date.now()
40
40
  //fs.unlinkSync(filePath)
41
41
  spinner.succeed(chalk.green(`🤖 Pod 153: [肯定] 字段对齐协议执行完毕:耗时 ${(endTime - startTime) / 1000} 秒。9S 的骇客任务很顺利。`))
@@ -88,15 +88,13 @@ const watchPage = options => {
88
88
  const mockDir = path.join(process.cwd(), 'mock')
89
89
  const fileName = path.basename(filePath, path.extname(filePath))
90
90
  const targetDir = path.join(process.cwd(), config.pagesDir, fileName)
91
-
91
+ const spinner = ora(chalk.cyan(`🤖 Pod 042: [报告] 捕获到新的视觉图像 [${fileName}],开始执行构筑程序...`))
92
+ spinner.start()
92
93
  try {
93
94
  // 创建必要的目录
94
95
  if (!fs.existsSync(mockDir)) fs.mkdirSync(mockDir, { recursive: true })
95
96
  if (!fs.existsSync(targetDir)) fs.mkdirSync(targetDir, { recursive: true })
96
97
 
97
- const spinner = ora(chalk.cyan(`🤖 Pod 042: [报告] 捕获到新的视觉图像 [${fileName}],开始执行构筑程序...`))
98
- spinner.start()
99
-
100
98
  // 1. 识别页面结构(调用视觉大模型)
101
99
  const pageConfig = await recognizePage(pagePrompt, filePath)
102
100
 
@@ -124,7 +122,7 @@ const watchPage = options => {
124
122
  //fs.unlinkSync(filePath) // 可选:处理完成后删除截图
125
123
  spinner.succeed(chalk.green(`🤖 Pod 042: [报告] 模块 [${fileName}] 物理装配完成!耗时 ${(endTime - startTime) / 1000} 秒`))
126
124
  } catch (error) {
127
- console.log(chalk.red(`🤖 Pod 042: [警告] 模块 [${fileName}] 构筑失败。原因:${error}`))
125
+ spinner.fail(chalk.red(`🤖 Pod 042: [警告] 模块 [${fileName}] 构筑失败。原因:${error}`))
128
126
  }
129
127
  })
130
128
  })
@@ -18,10 +18,10 @@ const watchPart = () => {
18
18
  })
19
19
 
20
20
  watcher.on('add', async filePath => {
21
+ const spinner = ora(chalk.cyan(`🤖 Pod 042: [报告] 捕获到新的视觉图像,开始执行构筑程序...`))
22
+ spinner.start()
21
23
  try {
22
24
  const startTime = Date.now()
23
- const spinner = ora(chalk.cyan(`🤖 Pod 042: [报告] 捕获到新的视觉图像,开始执行构筑程序...`))
24
- spinner.start()
25
25
  const partPrompt = require('../prompts/watch-part.js')
26
26
  const pageConfig = await recognizePage(partPrompt, filePath)
27
27
  const optionDict = pageConfig.optionDict || {}
@@ -42,7 +42,7 @@ const watchPart = () => {
42
42
  const endTime = Date.now()
43
43
  spinner.succeed(`🤖 Pod 042: [报告] 识别程序结束!耗时 ${(endTime - startTime) / 1000} 秒\n================\n\n${finalResult}\n\n================`)
44
44
  } catch (error) {
45
- console.log(chalk.red(`🤖 Pod 042: [警告] 识别程序失败。原因:${error}`))
45
+ spinner.fail(chalk.red(`🤖 Pod 042: [警告] 识别程序失败。原因:${error}`))
46
46
  } finally {
47
47
  if (fs.existsSync(filePath)) {
48
48
  fs.unlinkSync(filePath)
@@ -55,6 +55,10 @@ const askAI = async (model, messages, retryCount = 0) => {
55
55
  // 使用 JSON5 解析(支持单引号、注释等非标准 JSON)
56
56
  return JSON5.parse(match ? match[0] : raw)
57
57
  } catch (err) {
58
+ const isAuthError = err.message.includes('401') || err.message.includes('402');
59
+ if (isAuthError) {
60
+ throw new Error('[系统警告] YoRHa 司令部拒绝访问:API Key 无效或额度耗尽,请检查!');
61
+ }
58
62
  console.warn(chalk.yellow(`[系统警告] 神经云网络连接不稳,正在尝试重新链接... (第 ${retryCount + 1} 次重试)`), err.message)
59
63
  return askAI(model, messages, retryCount + 1)
60
64
  }
@@ -105,7 +109,7 @@ module.exports = {
105
109
  role: 'user',
106
110
  content: [
107
111
  { type: 'text', text: prompt },
108
- { type: 'image_url', image_url: { url: `data:image/png;base64,${base64Image}` } }
112
+ { type: 'image_url', image_url: { url: `data:image/jpeg;base64,${base64Image}` } }
109
113
  ]
110
114
  }
111
115
  ]
@@ -79,7 +79,7 @@ const generateSmartImports = (codeStr, hasTabs) => {
79
79
  `import { ${hasTabs ? 'tabs, ' : ''}columns, formItems, modalItems } from './resource'`,
80
80
  ...usedHooks.map(hook => `import { ${hook} } from '../../hooks/${hook}'`),
81
81
  ...usedComps.map(comp => `import { ${comp} } from '../../components/${comp}'`),
82
- usedAntd.length && `import { Form,${usedAntd.join(', ')} } from 'antd'`
82
+ usedAntd.length && `import { Form, ${usedAntd.join(', ')} } from 'antd'`
83
83
  ].sort((a, b) => a.length - b.length) // 按长度排序(短的在前)
84
84
 
85
85
  return imports.filter(Boolean).join('\n') // 过滤空值并拼接
@@ -100,7 +100,7 @@ const copyTemplateDir = (options, templateSubDir, targetSubDir) => {
100
100
  const src = path.join(sourceDir, file)
101
101
  const dest = path.join(targetDir, file)
102
102
  if (!fs.existsSync(dest)) {
103
- fs.copyFileSync(src, dest)
103
+ fs.cpSync(src, dest, { recursive: true })
104
104
  }
105
105
  })
106
106
  }
@@ -29,7 +29,7 @@ export const MySearchForm = ({ form, search, loading, labelCol, setSearch, formI
29
29
 
30
30
  useEffect(() => {
31
31
  if (Object.values(initialValues).length > 0) {
32
- const entries = Object.entries(initialValues).map(([key, value]) => [
32
+ const entries = Object.entries(initialValues).filter(([key]) => formItems.some(item => item.name === key)).map(([key, value]) => [
33
33
  key,
34
34
  formItems.find(item => item.name === key)?.type?.includes('date') ? value?.split(dateSeparator)?.map(item => dayjs(item)) : value
35
35
  ])