create-component-template-cli 1.0.0 → 1.0.1

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.
Files changed (75) hide show
  1. package/.changeset/config.json +1 -1
  2. package/AGENTS.md +114 -0
  3. package/CHANGELOG.md +6 -0
  4. package/CLAUDE.md +19 -7
  5. package/README.md +40 -20
  6. package/bin/cli.mjs +38 -29
  7. package/docs/2026-05-11T10-04-44-/344/270/211/345/245/227/346/250/241/346/235/277/351/207/215/346/236/204/2026-05-11T10-04-44-/344/270/211/345/245/227/346/250/241/346/235/277/351/207/215/346/236/204-/346/200/235/350/267/257/346/226/207/346/241/243.md +167 -0
  8. package/docs/2026-05-11T10-04-44-/344/270/211/345/245/227/346/250/241/346/235/277/351/207/215/346/236/204/2026-05-11T10-04-44-/344/270/211/345/245/227/346/250/241/346/235/277/351/207/215/346/236/204-/346/200/273/347/273/223/346/226/207/346/241/243.md +80 -0
  9. package/docs/2026-05-11T10-04-44-/344/270/211/345/245/227/346/250/241/346/235/277/351/207/215/346/236/204/2026-05-11T10-04-44-/344/270/211/345/245/227/346/250/241/346/235/277/351/207/215/346/236/204-/350/256/276/350/256/241/346/226/271/346/241/210.md +477 -0
  10. package/package.json +1 -1
  11. package/plop-templates/general/data.ts.hbs +16 -0
  12. package/plop-templates/general/hook.ts.hbs +11 -0
  13. package/plop-templates/general/index.normal.vue.hbs +28 -0
  14. package/plop-templates/general/index.scss.hbs +5 -0
  15. package/plop-templates/general/index.setup.vue.hbs +20 -0
  16. package/plop-templates/{index.ts.hbs → general/index.ts.hbs} +2 -1
  17. package/plop-templates/general/typing.ts.hbs +13 -0
  18. package/plop-templates/multiple-pick/data.ts.hbs +20 -0
  19. package/plop-templates/multiple-pick/hook.ts.hbs +11 -0
  20. package/plop-templates/multiple-pick/index.normal.vue.hbs +37 -0
  21. package/plop-templates/multiple-pick/index.scss.hbs +5 -0
  22. package/plop-templates/multiple-pick/index.setup.vue.hbs +22 -0
  23. package/plop-templates/multiple-pick/index.ts.hbs +4 -0
  24. package/plop-templates/multiple-pick/typing.ts.hbs +13 -0
  25. package/plop-templates/single-pick/data.ts.hbs +16 -0
  26. package/plop-templates/single-pick/hook.ts.hbs +11 -0
  27. package/plop-templates/single-pick/index.normal.vue.hbs +36 -0
  28. package/plop-templates/single-pick/index.scss.hbs +5 -0
  29. package/plop-templates/single-pick/index.setup.vue.hbs +23 -0
  30. package/plop-templates/single-pick/index.ts.hbs +4 -0
  31. package/plop-templates/single-pick/typing.ts.hbs +13 -0
  32. package/plopfile.mjs +68 -59
  33. package/src/generate.mjs +101 -31
  34. package/tmp-output/GeneralNormalDemo/index.ts +4 -0
  35. package/tmp-output/GeneralNormalDemo/src/data.ts +16 -0
  36. package/tmp-output/GeneralNormalDemo/src/hook.ts +11 -0
  37. package/tmp-output/GeneralNormalDemo/src/index.scss +5 -0
  38. package/tmp-output/GeneralNormalDemo/src/index.vue +28 -0
  39. package/tmp-output/GeneralNormalDemo/src/typing.ts +13 -0
  40. package/tmp-output/GeneralSetupDemo/index.ts +4 -0
  41. package/tmp-output/GeneralSetupDemo/src/data.ts +16 -0
  42. package/tmp-output/GeneralSetupDemo/src/hook.ts +11 -0
  43. package/tmp-output/GeneralSetupDemo/src/index.scss +5 -0
  44. package/tmp-output/GeneralSetupDemo/src/index.vue +20 -0
  45. package/tmp-output/GeneralSetupDemo/src/typing.ts +13 -0
  46. package/tmp-output/MultiplePickNormalDemo/index.ts +4 -0
  47. package/tmp-output/MultiplePickNormalDemo/src/data.ts +20 -0
  48. package/tmp-output/MultiplePickNormalDemo/src/hook.ts +11 -0
  49. package/tmp-output/MultiplePickNormalDemo/src/index.scss +5 -0
  50. package/tmp-output/MultiplePickNormalDemo/src/index.vue +37 -0
  51. package/tmp-output/MultiplePickNormalDemo/src/typing.ts +13 -0
  52. package/tmp-output/MultiplePickSetupDemo/index.ts +4 -0
  53. package/tmp-output/MultiplePickSetupDemo/src/data.ts +20 -0
  54. package/tmp-output/MultiplePickSetupDemo/src/hook.ts +11 -0
  55. package/tmp-output/MultiplePickSetupDemo/src/index.scss +5 -0
  56. package/tmp-output/MultiplePickSetupDemo/src/index.vue +22 -0
  57. package/tmp-output/MultiplePickSetupDemo/src/typing.ts +13 -0
  58. package/tmp-output/SinglePickNormalDemo/index.ts +4 -0
  59. package/tmp-output/SinglePickNormalDemo/src/data.ts +16 -0
  60. package/tmp-output/SinglePickNormalDemo/src/hook.ts +11 -0
  61. package/tmp-output/SinglePickNormalDemo/src/index.scss +5 -0
  62. package/tmp-output/SinglePickNormalDemo/src/index.vue +36 -0
  63. package/tmp-output/SinglePickNormalDemo/src/typing.ts +13 -0
  64. package/tmp-output/SinglePickSetupDemo/index.ts +4 -0
  65. package/tmp-output/SinglePickSetupDemo/src/data.ts +16 -0
  66. package/tmp-output/SinglePickSetupDemo/src/hook.ts +11 -0
  67. package/tmp-output/SinglePickSetupDemo/src/index.scss +5 -0
  68. package/tmp-output/SinglePickSetupDemo/src/index.vue +23 -0
  69. package/tmp-output/SinglePickSetupDemo/src/typing.ts +13 -0
  70. package/plop-templates/data.ts.hbs +0 -7
  71. package/plop-templates/hook.ts.hbs +0 -29
  72. package/plop-templates/index.scss.hbs +0 -1
  73. package/plop-templates/index.setup.vue.hbs +0 -25
  74. package/plop-templates/index.vue.hbs +0 -38
  75. package/plop-templates/typing.ts.hbs +0 -14
@@ -5,7 +5,7 @@
5
5
  "fixed": [],
6
6
  "linked": [],
7
7
  "access": "restricted",
8
- "baseBranch": "master",
8
+ "baseBranch": "agent-cli",
9
9
  "updateInternalDependencies": "patch",
10
10
  "ignore": []
11
11
  }
package/AGENTS.md ADDED
@@ -0,0 +1,114 @@
1
+ # AGENTS.md
2
+
3
+ This file provides guidance to Codex (Codex.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ **create-vue-component-template** (CLI command: `cvct`) — a CLI scaffolding tool that generates Vue component directory structures with predefined templates. Published to npm as a global CLI utility.
8
+
9
+ ## Commands
10
+
11
+ ### Non-Interactive Mode (for agents/CI)
12
+
13
+ ```bash
14
+ # Generate a general business template with setup style
15
+ node bin/cli.mjs --name=MyComponent --rootPath=src/components/platform
16
+
17
+ # Generate a single-pick business template
18
+ node bin/cli.mjs --name=MyComponent --rootPath=src/components/platform --templateType=single-pick
19
+
20
+ # Generate a multiple-pick business template with defineComponent style
21
+ node bin/cli.mjs --name=MyComponent --rootPath=src/components/platform --templateType=multiple-pick --vueTemplateType=normal
22
+
23
+ # Overwrite existing directory
24
+ node bin/cli.mjs --name=MyComponent --rootPath=src/components/platform --collisionStrategy=overwrite
25
+
26
+ # Strict non-interactive (error if missing required args)
27
+ node bin/cli.mjs --name=MyComponent --rootPath=src/components/platform --nonInteractive
28
+
29
+ # Help & version
30
+ node bin/cli.mjs --help
31
+ node bin/cli.mjs --version
32
+ ```
33
+
34
+ ### Interactive Mode (for humans)
35
+
36
+ ```bash
37
+ # Run without args to enter plop interactive prompts
38
+ node bin/cli.mjs
39
+ ```
40
+
41
+ ### Version bump via changesets
42
+
43
+ ```bash
44
+ npx changeset # create a changeset
45
+ npx changeset version # consume changesets, bump package.json
46
+ ```
47
+
48
+ ## CLI Flags Reference
49
+
50
+ | Flag | Required | Default | Description |
51
+ |------|----------|---------|-------------|
52
+ | `--name` | Yes (non-interactive) | — | Component name, PascalCase (e.g. `MyTest`) |
53
+ | `--rootPath` | Yes (non-interactive) | — | Target directory (e.g. `src/components/platform`) |
54
+ | `--templateType` | No | `general` | `general` = 通用模板;`single-pick` = 产品组单选模板;`multiple-pick` = 产品组多选模板 |
55
+ | `--vueTemplateType` | No | `setup` | `setup` = `<script setup>`;`normal` = `defineComponent` |
56
+ | `--collisionStrategy` | No | `skip` | `skip` = error if exists; `overwrite` = delete & regenerate |
57
+ | `--nonInteractive` | No | false | Fail on missing args instead of prompting |
58
+ | `--help` / `-h` | No | — | Print help text |
59
+ | `--version` / `-v` | No | — | Print version |
60
+
61
+ ## Architecture
62
+
63
+ **Entry point:** `bin/cli.mjs` — dispatches to non-interactive mode (`src/generate.mjs`) when all required CLI args are provided, otherwise falls back to plop interactive mode.
64
+
65
+ **Core generation:** `src/generate.mjs` — `generateComponent({ name, rootPath, templateType, collisionStrategy })` — pure function that:
66
+ 1. Validates inputs
67
+ 2. Converts case (PascalCase, kebab-case via `change-case`)
68
+ 3. Detects directory collisions (skip or overwrite)
69
+ 4. Renders `plop-templates/*.hbs` templates and writes files
70
+ 5. Returns `{ success, files, componentName, targetFolder }` or `{ success: false, error }`
71
+
72
+ **Interactive mode:** `plopfile.mjs` — plop generator for human interactive use.
73
+
74
+ **Templates:** `plop-templates/*.hbs` — Handlebars-style template files.
75
+
76
+ ### Business Template Types
77
+
78
+ - **general**: 通用业务模板
79
+ - **single-pick**: 产品组单选模板
80
+ - **multiple-pick**: 产品组多选模板
81
+
82
+ ### Vue Template Styles
83
+
84
+ - **setup** (`index.setup.vue.hbs`): `<script setup>` 风格
85
+ - **normal** (`index.normal.vue.hbs`): `defineComponent` 风格
86
+
87
+ Regardless of Vue style, the generated file name remains `src/index.vue`.
88
+
89
+ ### Generated Component Structure
90
+
91
+ ```
92
+ {rootPath}/{ComponentName}/
93
+ ├── index.ts # Re-exports component and types
94
+ └── src/
95
+ ├── index.vue # Component template
96
+ ├── index.scss # Scoped styles
97
+ ├── typing.ts # Props interface + enums
98
+ ├── hook.ts # use{ComponentName}() composable
99
+ └── data.ts # Data arrays
100
+ ```
101
+
102
+ ### Template Variables
103
+
104
+ | Variable | Source | Example |
105
+ |----------|--------|---------|
106
+ | `{{componentName}}` | PascalCase of input name | `MyTest` |
107
+ | `{{class}}` | kebab-case of input name | `my-test` |
108
+ | `{{interfaceName}}` | Same as componentName | `MyTest` |
109
+
110
+ The `change-case` library handles all case conversions.
111
+
112
+ ## Versioning
113
+
114
+ Uses `@changesets/cli` for version management. Changeset access is `restricted` (private by default). Base branch is `master`.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # create-vue-component-template
2
2
 
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 添加三种业务组件模板
8
+
3
9
  ## 1.1.0
4
10
 
5
11
  ### Minor Changes
package/CLAUDE.md CHANGED
@@ -11,11 +11,14 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
11
11
  ### Non-Interactive Mode (for agents/CI)
12
12
 
13
13
  ```bash
14
- # Generate a setup-syntax component
14
+ # Generate a general business template with setup style
15
15
  node bin/cli.mjs --name=MyComponent --rootPath=src/components/platform
16
16
 
17
- # Generate a normal (defineComponent) component
18
- node bin/cli.mjs --name=MyComponent --rootPath=src/components/platform --templateType=normal
17
+ # Generate a single-pick business template
18
+ node bin/cli.mjs --name=MyComponent --rootPath=src/components/platform --templateType=single-pick
19
+
20
+ # Generate a multiple-pick business template with defineComponent style
21
+ node bin/cli.mjs --name=MyComponent --rootPath=src/components/platform --templateType=multiple-pick --vueTemplateType=normal
19
22
 
20
23
  # Overwrite existing directory
21
24
  node bin/cli.mjs --name=MyComponent --rootPath=src/components/platform --collisionStrategy=overwrite
@@ -48,7 +51,8 @@ npx changeset version # consume changesets, bump package.json
48
51
  |------|----------|---------|-------------|
49
52
  | `--name` | Yes (non-interactive) | — | Component name, PascalCase (e.g. `MyTest`) |
50
53
  | `--rootPath` | Yes (non-interactive) | — | Target directory (e.g. `src/components/platform`) |
51
- | `--templateType` | No | `setup` | `setup` = `<script setup>` + defineProps; `normal` = defineComponent + PropType |
54
+ | `--templateType` | No | `general` | `general` = 通用模板;`single-pick` = 产品组单选模板;`multiple-pick` = 产品组多选模板 |
55
+ | `--vueTemplateType` | No | `setup` | `setup` = `<script setup>`;`normal` = `defineComponent` |
52
56
  | `--collisionStrategy` | No | `skip` | `skip` = error if exists; `overwrite` = delete & regenerate |
53
57
  | `--nonInteractive` | No | false | Fail on missing args instead of prompting |
54
58
  | `--help` / `-h` | No | — | Print help text |
@@ -69,10 +73,18 @@ npx changeset version # consume changesets, bump package.json
69
73
 
70
74
  **Templates:** `plop-templates/*.hbs` — Handlebars-style template files.
71
75
 
72
- ### Two Template Modes
76
+ ### Business Template Types
77
+
78
+ - **general**: 通用业务模板
79
+ - **single-pick**: 产品组单选模板
80
+ - **multiple-pick**: 产品组多选模板
81
+
82
+ ### Vue Template Styles
83
+
84
+ - **setup** (`index.setup.vue.hbs`): `<script setup>` 风格
85
+ - **normal** (`index.normal.vue.hbs`): `defineComponent` 风格
73
86
 
74
- - **setup** (`index.setup.vue.hbs`): `<script setup>` + `defineProps<>()` + `defineOptions()`
75
- - **normal** (`index.vue.hbs`): `defineComponent` + `PropType` + `setup()` function
87
+ Regardless of Vue style, the generated file name remains `src/index.vue`.
76
88
 
77
89
  ### Generated Component Structure
78
90
 
package/README.md CHANGED
@@ -1,29 +1,49 @@
1
1
  # create-vue-component-template
2
2
 
3
- A CLI tool for creating standardized Vue 3 + TypeScript + Sass public component templates.
3
+ 一个用于快速创建 Vue 3 + TypeScript + Sass 组件骨架的 CLI 工具。
4
4
 
5
- ## USAGE
5
+ ## 用法
6
6
 
7
7
  ```bash
8
- # create a components via npm
9
- npm create-vue-component-template --rootPath src/components/platform
8
+ # 交互模式
9
+ node bin/cli.mjs
10
10
 
11
- # or
12
- npx create-vue-component-template --rootPath src/components/platform
11
+ # 非交互模式
12
+ node bin/cli.mjs --name=MyComponent --rootPath=src/components/platform
13
13
 
14
+ # 指定业务模板类型
15
+ node bin/cli.mjs --name=MyComponent --rootPath=src/components/platform --templateType=single-pick
16
+
17
+ # 指定 index.vue 的 Vue 风格
18
+ node bin/cli.mjs --name=MyComponent --rootPath=src/components/platform --templateType=multiple-pick --vueTemplateType=normal
14
19
  ```
15
20
 
16
- directory tree like this:
17
-
18
- .
19
- └── Demo/
20
- ├── src/
21
- │ ├── components/
22
- │ │ ├── aaa/
23
- │ │ ├── bbb/
24
- │ │ └── .../
25
- │ ├── data.ts
26
- │ ├── typing.ts
27
- │ ├── hooks.ts
28
- │ └── index.scss
29
- └── index.ts
21
+ ## 参数说明
22
+
23
+ | 参数 | 必填 | 默认值 | 说明 |
24
+ | --- | --- | --- | --- |
25
+ | `--name` | 是(非交互) | - | 组件名称,PascalCase |
26
+ | `--rootPath` | 是(非交互) | - | 输出目录 |
27
+ | `--templateType` | 否 | `general` | 业务模板类型:`general` / `single-pick` / `multiple-pick` |
28
+ | `--vueTemplateType` | 否 | `setup` | `index.vue` 的 Vue 风格:`setup` / `normal` |
29
+ | `--collisionStrategy` | 否 | `skip` | 目录冲突策略:`skip` / `overwrite` |
30
+ | `--nonInteractive` | 否 | `false` | 缺少必填参数时直接报错,不进入交互模式 |
31
+
32
+ ## 模板规则
33
+
34
+ 1. `templateType` 只控制业务模板类型。
35
+ 2. `vueTemplateType` 只控制 `index.vue` 的 Vue 写法。
36
+ 3. 无论选择哪种 Vue 风格,最终生成的文件名始终是 `src/index.vue`。
37
+
38
+ ## 生成目录结构
39
+
40
+ ```txt
41
+ {rootPath}/{ComponentName}/
42
+ ├── index.ts
43
+ └── src/
44
+ ├── index.vue
45
+ ├── index.scss
46
+ ├── typing.ts
47
+ ├── hook.ts
48
+ └── data.ts
49
+ ```
package/bin/cli.mjs CHANGED
@@ -16,46 +16,53 @@ function printVersion() {
16
16
 
17
17
  function printHelp() {
18
18
  console.log(`
19
- cvct Vue 组件模板生成器 (create-vue-component-template)
19
+ cvct - Vue 组件模板生成器 (create-vue-component-template)
20
20
 
21
21
  用法:
22
22
  cvct [选项]
23
23
 
24
24
  必填参数 (非交互模式):
25
- --name=<ComponentName> 组件名称,PascalCase 格式 (例: MyTest)
26
- --rootPath=<path> 组件生成路径 (例: src/components/platform)
25
+ --name=<ComponentName> 组件名称,PascalCase 格式 (例: MyTest)
26
+ --rootPath=<path> 组件生成路径 (例: src/components/platform)
27
27
 
28
28
  可选参数:
29
- --templateType=<type> 模板类型: setup (默认) | normal
30
- - setup: <script setup> + defineProps<> + defineOptions
31
- - normal: defineComponent + PropType + setup()
29
+ --templateType=<type> 业务模板类型: general (默认) | single-pick | multiple-pick
30
+ - general: 通用业务模板
31
+ - single-pick: 产品组单选模板
32
+ - multiple-pick: 产品组多选模板
32
33
 
33
- --collisionStrategy=<s> 目录碰撞策略: skip (默认) | overwrite
34
- - skip: 目录已存在时报错退出
35
- - overwrite: 删除旧目录后重新生成
34
+ --vueTemplateType=<type> index.vue 语法风格: setup (默认) | normal
35
+ - setup: <script setup> 风格
36
+ - normal: defineComponent 风格
37
+ - 注意: 最终生成文件名始终为 index.vue
36
38
 
37
- --nonInteractive 强制非交互模式,缺少必填参数时报错而非提示
39
+ --collisionStrategy=<s> 目录冲突策略: skip (默认) | overwrite
40
+ - skip: 目录已存在时直接报错退出
41
+ - overwrite: 删除旧目录后重新生成
38
42
 
39
- -h, --help 显示帮助信息
40
- -v, --version 显示版本号
43
+ --nonInteractive 强制非交互模式,缺少必填参数时直接报错
44
+
45
+ -h, --help 显示帮助信息
46
+ -v, --version 显示版本号
41
47
 
42
48
  非交互模式示例:
43
49
  cvct --name=MyTest --rootPath=src/components/platform
44
- cvct --name=MyTest --rootPath=src/components/platform --templateType=normal
50
+ cvct --name=MyTest --rootPath=src/components/platform --templateType=single-pick
51
+ cvct --name=MyTest --rootPath=src/components/platform --templateType=multiple-pick --vueTemplateType=normal
45
52
  cvct --name=MyTest --rootPath=src/components/platform --collisionStrategy=overwrite
46
53
 
47
54
  生成的目录结构:
48
55
  {rootPath}/{ComponentName}/
49
- ├── index.ts # 导出组件和类型
56
+ ├── index.ts
50
57
  └── src/
51
- ├── index.vue # 组件模板
52
- ├── index.scss # 样式
53
- ├── typing.ts # Props 接口 + 枚举
54
- ├── hook.ts # use{ComponentName}() composable
55
- └── data.ts # 数据数组
58
+ ├── index.vue
59
+ ├── index.scss
60
+ ├── typing.ts
61
+ ├── hook.ts
62
+ └── data.ts
56
63
 
57
64
  交互模式:
58
- 不带参数运行 cvct 将进入交互式提示界面 (plop)
65
+ 不带参数运行 cvct 将进入 plop 交互提示界面
59
66
  `);
60
67
  }
61
68
 
@@ -73,7 +80,7 @@ const hasAllRequired = argv.name && argv.rootPath;
73
80
  const nonInteractive = argv.nonInteractive;
74
81
 
75
82
  if (nonInteractive && !hasAllRequired) {
76
- console.error('错误:非交互模式需要 --name 和 --rootPath 参数');
83
+ console.error('错误:非交互模式需要同时传入 --name 和 --rootPath');
77
84
  console.error('运行 cvct --help 查看帮助');
78
85
  process.exit(1);
79
86
  }
@@ -82,7 +89,8 @@ if (hasAllRequired) {
82
89
  const result = generateComponent({
83
90
  name: argv.name,
84
91
  rootPath: argv.rootPath,
85
- templateType: argv.templateType || 'setup',
92
+ templateType: argv.templateType || 'general',
93
+ vueTemplateType: argv.vueTemplateType || 'setup',
86
94
  collisionStrategy: argv.collisionStrategy || 'skip',
87
95
  });
88
96
 
@@ -93,21 +101,22 @@ if (hasAllRequired) {
93
101
 
94
102
  console.log(`✓ 已生成组件: ${result.componentName}`);
95
103
  console.log(` 路径: ${result.targetFolder}`);
96
- result.files.forEach(f => console.log(` - ${f}`));
104
+ console.log(` 业务模板: ${result.templateType}`);
105
+ console.log(` Vue 风格: ${result.vueTemplateType}`);
106
+ result.files.forEach((file) => console.log(` - ${file}`));
97
107
  process.exit(0);
98
108
  }
99
109
 
100
- // Fallback: interactive mode via plop
101
110
  const { Plop, run } = await import('plop');
102
111
 
103
112
  Plop.prepare({
104
113
  configPath: path.join(__dirname, '../plopfile.mjs'),
105
- import: []
106
- }, env => {
107
- Plop.execute(env, (env) => {
114
+ import: [],
115
+ }, (env) => {
116
+ Plop.execute(env, (executeEnv) => {
108
117
  const options = {
109
- ...env,
110
- dest: process.cwd()
118
+ ...executeEnv,
119
+ dest: process.cwd(),
111
120
  };
112
121
  return run(options, undefined, true);
113
122
  });
@@ -0,0 +1,167 @@
1
+ # 三套业务模板重构思路文档
2
+
3
+ ## 1. 这次真正要解决的问题
4
+
5
+ 补充需求之后,问题已经不是“把 `setup/normal` 改成三种业务模板”。
6
+
7
+ 真正的问题是:
8
+
9
+ 1. 业务模板层需要扩展为三种
10
+ 2. Vue 写法层仍然保留两种
11
+ 3. 这两个层次不能继续混用一个参数语义
12
+
13
+ 也就是说,当前项目要从“单维模板选择”升级成“双维模板选择”。
14
+
15
+ ## 2. 为什么之前会容易混淆
16
+
17
+ 当前代码里,`templateType` 实际控制的是:
18
+
19
+ - `index.vue` 用 `setup`
20
+ - 或者 `index.vue` 用 `normal`
21
+
22
+ 这会让人自然以为 `templateType` 就是“模板类型”。
23
+
24
+ 但现在已经确认:
25
+
26
+ - `general` / `single-pick` / `multiple-pick` 才是业务模板类型
27
+ - `setup` / `normal` 只是 Vue 文件写法
28
+
29
+ 因此,之前的困惑本质上来自“参数命名承载了错误的业务语义”。
30
+
31
+ ## 3. 我对结构的重新判断
32
+
33
+ 重构后最合理的抽象应该是:
34
+
35
+ ### 第一层:业务模板目录
36
+
37
+ 这一层决定:
38
+
39
+ - `typing.ts`
40
+ - `hook.ts`
41
+ - `data.ts`
42
+ - `index.scss`
43
+ - `index.ts`
44
+ - 以及 `index.vue` 的业务语义部分
45
+
46
+ ### 第二层:Vue 风格分支
47
+
48
+ 这一层只决定:
49
+
50
+ - `index.vue` 采用 `setup`
51
+ - 还是 `defineComponent`
52
+
53
+ 所以目录结构不应该是:
54
+
55
+ ```txt
56
+ setup/
57
+ normal/
58
+ ```
59
+
60
+ 而应该是:
61
+
62
+ ```txt
63
+ general/
64
+ single-pick/
65
+ multiple-pick/
66
+ ```
67
+
68
+ 然后在每个业务目录下再放:
69
+
70
+ ```txt
71
+ index.setup.vue.hbs
72
+ index.normal.vue.hbs
73
+ ```
74
+
75
+ 但这里要注意:
76
+
77
+ ```txt
78
+ 上面这两个名字只是模板源文件名,
79
+ 最终生成到组件目录里的文件名仍然统一是 index.vue
80
+ ```
81
+
82
+ ## 4. 为什么这样拆最稳
83
+
84
+ 因为这符合差异的主次关系。
85
+
86
+ ### 主差异
87
+
88
+ 主差异是业务模板不同。
89
+
90
+ 这会影响整套模板资源的含义,所以它应该成为目录分层的第一优先级。
91
+
92
+ ### 次差异
93
+
94
+ 次差异是 `index.vue` 的 Vue 写法不同。
95
+
96
+ 这只影响单个文件,因此应该成为业务目录下的次级分支,而不是顶层结构。
97
+ 它影响的是“选哪份模板源文件”,不影响最终输出文件名。
98
+
99
+ ## 5. 参数层面的思考
100
+
101
+ 如果继续只保留一个 `templateType`,后面无非两种结果:
102
+
103
+ 1. `templateType` 既可能传业务值,又可能传 Vue 风格值
104
+ 2. 代码内部继续做大量兼容判断
105
+
106
+ 这两种都不利于长期维护。
107
+
108
+ 所以我更倾向于把参数拆开,例如:
109
+
110
+ - `templateType`
111
+ - `vueTemplateType`
112
+
113
+ 这样能直接把概念表达清楚。
114
+
115
+ ## 6. 兼容旧调用的思路
116
+
117
+ 这里不能简单粗暴地完全切断旧逻辑,因为现有项目已经支持:
118
+
119
+ ```bash
120
+ --templateType=setup
121
+ --templateType=normal
122
+ ```
123
+
124
+ 如果马上废弃,旧脚本会直接失效。
125
+
126
+ 所以更合适的迁移方式是:
127
+
128
+ 1. 新逻辑正式引入双维度参数
129
+ 2. 旧逻辑临时兼容
130
+ 3. 兼容时把旧值映射到:
131
+ - 业务模板默认 `general`
132
+ - Vue 风格沿用旧值
133
+
134
+ 这个映射是合理的,因为旧调用本来就没有表达业务模板差异。
135
+
136
+ ## 7. 对模板文件生成阶段的判断
137
+
138
+ 你前面说“各个类型模板文件先给我生成,文件内容参考现有文件”,这意味着后续实施阶段的重点不是一次性把业务逻辑填满,而是先把骨架建立完整。
139
+
140
+ 所以执行时更适合:
141
+
142
+ 1. 先复用现有模板为基础
143
+ 2. 再按三类业务语义做差异化改造
144
+ 3. 最后再接回生成器逻辑
145
+
146
+ 这样风险更低,也更容易验证。
147
+
148
+ ## 8. 最终思路结论
149
+
150
+ 这次最关键的思路不是“模板数量从 2 变成 3”,而是:
151
+
152
+ ```txt
153
+ 原来只有一个维度:
154
+ Vue 写法维度
155
+
156
+ 现在变成两个维度:
157
+ 业务模板维度 + Vue 写法维度
158
+ ```
159
+
160
+ 只要把这个抽象立住,后面的代码改造、目录设计、参数设计和测试方案都会自然顺下来。
161
+
162
+ 补充一个最终落地规则:
163
+
164
+ ```txt
165
+ 模板源文件可以区分 setup / normal,
166
+ 最终组件目录中只能生成统一的 index.vue
167
+ ```
@@ -0,0 +1,80 @@
1
+ # 三套业务模板重构总结文档
2
+
3
+ ## 1. 本轮已完成内容
4
+
5
+ 本轮工作已经从设计阶段进入实施阶段,完成了模板资源重构、生成逻辑重构和文档同步。
6
+
7
+ 本次实现后的核心定义如下:
8
+
9
+ 1. `templateType`
10
+ 业务模板类型:
11
+ - `general`
12
+ - `single-pick`
13
+ - `multiple-pick`
14
+
15
+ 2. `vueTemplateType`
16
+ Vue 语法风格:
17
+ - `setup`
18
+ - `normal`
19
+
20
+ ## 2. 本轮修订点
21
+
22
+ 相较于上一版方案,本轮主要修正了以下内容:
23
+
24
+ 1. 新建了三套业务模板目录
25
+ - `plop-templates/general/`
26
+ - `plop-templates/single-pick/`
27
+ - `plop-templates/multiple-pick/`
28
+
29
+ 2. 每套业务模板都补齐了两份 Vue 模板源文件
30
+ - `index.setup.vue.hbs`
31
+ - `index.normal.vue.hbs`
32
+
33
+ 3. 重构了 `src/generate.mjs`
34
+ 生成器现在同时支持业务模板类型与 Vue 风格两个维度。
35
+
36
+ 4. 重构了 `plopfile.mjs`
37
+ 交互模式现在可以分别选择业务模板类型与 Vue 风格。
38
+
39
+ 5. 重构了 `bin/cli.mjs`
40
+ CLI 参数说明已经切换到双维度模型。
41
+
42
+ 6. 同步更新了说明文档
43
+ 包括 `README.md`、`AGENTS.md`、`CLAUDE.md`。
44
+
45
+ 7. 保持了最终输出命名规则
46
+ `index.setup.vue.hbs` 与 `index.normal.vue.hbs` 只是模板源文件名,最终输出文件名始终是 `index.vue`。
47
+
48
+ ## 3. 当前版本结论
49
+
50
+ 当前代码结构已经能够准确表达这次需求,后续新增业务模板或新增 Vue 风格时都可以在现有结构上继续扩展。
51
+
52
+ 本次修订后的关键结论是:
53
+
54
+ ```txt
55
+ 业务模板类型决定整套模板语义,
56
+ Vue 风格只决定 index.vue 的模板来源。
57
+ ```
58
+
59
+ 并且:
60
+
61
+ ```txt
62
+ setup / normal 只影响模板选择,
63
+ 不影响最终输出文件名。
64
+ ```
65
+
66
+ ## 4. 仍未完成的部分
67
+
68
+ 1. 业务模板内容目前还是第一版骨架,后续可以继续补充更贴近真实业务的默认实现
69
+ 2. 还没有为交互模式和非交互模式补自动化测试
70
+ 3. 还需要通过命令行实际跑通 6 组组合验证
71
+ 4. 还需要最终确认生成文件名始终统一为 `index.vue`
72
+
73
+ ## 5. 下一步建议
74
+
75
+ 下一步直接执行闭环验证,建议顺序如下:
76
+
77
+ 1. 运行 6 组组合命令验证
78
+ 2. 检查每组输出目录结构
79
+ 3. 检查最终是否始终生成 `src/index.vue`
80
+ 4. 执行 `git add` 暂存本轮修改