@yorha2b-lab/autodev 1.0.15 → 1.0.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yorha2b-lab/autodev",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "基于视觉大模型的前端(Umi+Antd)全自动 CRUD 代码生成器",
5
5
  "bin": {
6
6
  "autodev": "bin/autodev.js"
@@ -17,7 +17,7 @@ const watchPage = options => {
17
17
  const { createTaskQueue } = require('../core/task-queue') // 任务队列,控制并发
18
18
  const stringify = require('json-stringify-pretty-compact') // 格式化 JSON
19
19
  const { recognizePage, generateMock } = require('../services/llm.js') // AI 服务
20
- const { getConfig, copyHooks, copyComponents, getExistingMenus } = require('../utils/utils.js') // 工具函数
20
+ const { getConfig, copyTemplateDir, getExistingMenus } = require('../utils/utils.js') // 工具函数
21
21
 
22
22
  const config = getConfig()
23
23
 
@@ -37,8 +37,8 @@ const watchPage = options => {
37
37
 
38
38
  try {
39
39
  // 首次运行时复制 hooks 和 components 模板到目标项目
40
- copyHooks(options)
41
- copyComponents(options)
40
+ copyTemplateDir(options, 'hooks', config.hooksDir)
41
+ copyTemplateDir(options, 'components', config.componentsDir)
42
42
  } catch (error) {
43
43
  console.error('❌ 程序运行出错:', error)
44
44
  }
@@ -86,28 +86,24 @@ const generateSmartImports = (codeStr, hasTabs) => {
86
86
  }
87
87
 
88
88
  /**
89
- * 复制 hooks 模板到目标项目
89
+ * 复制模板目录到目标项目
90
90
  * @param {Object} options - 命令行选项
91
- * @param {string} hooksDir - hooks 目录路径(默认 'src/hooks')
91
+ * @param {string} templateSubDir - 模板子目录(如 'hooks'、'components')
92
+ * @param {string} targetSubDir - 目标子目录(如 'src/hooks'、'src/components')
92
93
  */
93
- const copyHooks = (options, hooksDir = 'src/hooks') => {
94
- const targetDir = path.join(process.cwd(), hooksDir)
95
- if (!fs.existsSync(targetDir)) fs.mkdirSync(targetDir, { recursive: true }) // 递归创建目录
96
- const hookDir = path.join(__dirname, `../../templates/${options.template}/hooks`)
97
- fs.readdirSync(hookDir).forEach(file => fs.copyFileSync(path.join(hookDir, file), path.join(targetDir, file)))
98
- }
99
-
100
- /**
101
- * 复制 components 模板到目标项目
102
- * @param {Object} options - 命令行选项
103
- * @param {string} componentsDir - components 目录路径(默认 'src/components')
104
- */
105
- const copyComponents = (options, componentsDir = 'src/components') => {
106
- const targetDir = path.join(process.cwd(), componentsDir)
107
- if (!fs.existsSync(targetDir)) fs.mkdirSync(targetDir, { recursive: true }) // 递归创建目录
108
- const componentsDirectory = path.join(__dirname, `../../templates/${options.template}/components`)
109
- fs.readdirSync(componentsDirectory).forEach(file => fs.copyFileSync(path.join(componentsDirectory, file), path.join(targetDir, file)))
94
+ const copyTemplateDir = (options, templateSubDir, targetSubDir) => {
95
+ const targetDir = path.join(process.cwd(), targetSubDir)
96
+ const sourceDir = path.join(__dirname, `../../templates/${options.template}/${templateSubDir}`)
97
+ if (!fs.existsSync(sourceDir)) return
98
+ fs.mkdirSync(targetDir, { recursive: true })
99
+ fs.readdirSync(sourceDir).forEach(file => {
100
+ const src = path.join(sourceDir, file)
101
+ const dest = path.join(targetDir, file)
102
+ if (!fs.existsSync(dest)) {
103
+ fs.copyFileSync(src, dest)
104
+ }
105
+ })
110
106
  }
111
107
 
112
108
  // 导出工具函数
113
- module.exports = { getConfig, copyHooks, cleanCode, copyComponents, getExistingMenus, generateSmartImports }
109
+ module.exports = { getConfig, copyHooks, cleanCode, copyComponents, getExistingMenus, copyTemplateDir, generateSmartImports }
@@ -1,5 +1,5 @@
1
1
  import { Table } from 'antd'
2
- import { useEffect } from 'react'
2
+ import { useRef, useEffect } from 'react'
3
3
  import { EditableRow, EditableCell } from './EditableCell'
4
4
 
5
5
  const components = {