adspecs 0.1.20 → 0.1.21
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/.adspecs/templates/04-/345/211/215/347/253/257/345/212/237/350/203/275/350/256/276/350/256/241/346/250/241/346/235/277.md +1 -1
- package/.adspecs/templates/05-/345/220/216/347/253/257/344/273/273/345/212/241/346/270/205/345/215/225/346/250/241/346/235/277.md +613 -724
- package/.adspecs/templates/05b-/345/211/215/347/253/257/344/273/273/345/212/241/346/270/205/345/215/225/346/250/241/346/235/277.md +51 -51
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/.qoder-plugin/plugin.json +1 -1
- package/INSTALL.md +3 -3
- package/package.json +1 -1
- package/skills/adspecs-front-spec/SKILL.md +4 -4
- package/skills/adspecs-front-tasks/SKILL.md +213 -173
- package/skills/project-init/SKILL.md +93 -22
- package/src/commands/init.js +1 -1
- package/src/lib/dir-utils.js +28 -0
- package/src/lib/prompts.js +86 -5
- package/src/lib/report.js +20 -9
- package/src/lib/scaffolder.js +42 -9
|
@@ -302,7 +302,7 @@ questions: [
|
|
|
302
302
|
}
|
|
303
303
|
子目录决策 = {
|
|
304
304
|
conventions_decision: "update" | "skip", # docs 为 skip 且 40-project_conventions/ 有文件时
|
|
305
|
-
templates_decision: "
|
|
305
|
+
templates_decision: { "<文件名>": "replace" | "keep", ... }, # .adspecs 为 skip 且 templates/ 有文件时,逐文件确认
|
|
306
306
|
}
|
|
307
307
|
```
|
|
308
308
|
|
|
@@ -317,7 +317,7 @@ questions: [
|
|
|
317
317
|
}
|
|
318
318
|
子目录决策 = {
|
|
319
319
|
conventions_decision: "update" | "skip", # docs 为 skip 且 40-project_conventions/ 有文件时
|
|
320
|
-
templates_decision: "
|
|
320
|
+
templates_decision: { "<文件名>": "replace" | "keep", ... }, # .adspecs 为 skip 且 templates/ 有文件时,逐文件确认
|
|
321
321
|
}
|
|
322
322
|
```
|
|
323
323
|
|
|
@@ -334,7 +334,7 @@ questions: [
|
|
|
334
334
|
}
|
|
335
335
|
子目录决策 = {
|
|
336
336
|
conventions_decision: "update" | "skip", # docs 为 skip 且 40-project_conventions/ 有文件时
|
|
337
|
-
templates_decision: "
|
|
337
|
+
templates_decision: { "<文件名>": "replace" | "keep", ... }, # .adspecs 为 skip 且 templates/ 有文件时,逐文件确认
|
|
338
338
|
}
|
|
339
339
|
```
|
|
340
340
|
|
|
@@ -351,7 +351,7 @@ questions: [
|
|
|
351
351
|
}
|
|
352
352
|
子目录决策 = {
|
|
353
353
|
conventions_decision: "update" | "skip", # docs 为 skip 且 40-project_conventions/ 有文件时
|
|
354
|
-
templates_decision: "
|
|
354
|
+
templates_decision: { "<文件名>": "replace" | "keep", ... }, # .adspecs 为 skip 且 templates/ 有文件时,逐文件确认
|
|
355
355
|
}
|
|
356
356
|
固定技术栈:
|
|
357
357
|
FRONT_DEMO_SOURCE = "antd-front-demo" # Ant Design React(无需询问用户)
|
|
@@ -421,27 +421,79 @@ questions: [
|
|
|
421
421
|
- 记录子决策:`conventions_decision` = `"update"` | `"skip"`
|
|
422
422
|
- 如果 `40-project_conventions/` 不存在或仅包含空目录 → 跳过此检查,`conventions_decision` = `"skip"`
|
|
423
423
|
|
|
424
|
-
- **子目录更新检查(.adspecs/templates/)**:当 `.adspecs/` 已存在且 `.adspecs` 决策为 `skip`,且 `.adspecs/templates/`
|
|
425
|
-
|
|
424
|
+
- **子目录更新检查(.adspecs/templates/)**:当 `.adspecs/` 已存在且 `.adspecs` 决策为 `skip`,且 `.adspecs/templates/` 下已包含实际文件时,需**逐文件**询问用户是否替换模板文件(因用户可能在首次初始化后根据项目实际情况修改了模板内容):
|
|
425
|
+
|
|
426
|
+
**步骤 1:扫描目标目录已有模板文件**
|
|
427
|
+
- 列出 `$TARGET/.adspecs/templates/` 下所有 `.md` 文件
|
|
428
|
+
- 同时列出 `$PLUGIN_DIR/.adspecs/templates/` 下所有 `.md` 文件(插件根目录的最新模板)
|
|
429
|
+
- 计算两组文件集合:
|
|
430
|
+
- `existing_files`:目标目录中已有的模板文件名列表
|
|
431
|
+
- `new_files`:插件根目录中存在但目标目录中不存在的模板文件(需要新增)
|
|
432
|
+
- `common_files`:两边都存在的模板文件(需要逐一确认是否替换)
|
|
433
|
+
|
|
434
|
+
**步骤 2:先处理新增文件(无需确认)**
|
|
435
|
+
- 如果 `new_files` 非空 → 直接复制到目标目录,输出:`📦 模板新增:已添加 {N} 个新模板文件:{文件列表}`
|
|
436
|
+
- 如果 `new_files` 为空 → 不输出
|
|
437
|
+
|
|
438
|
+
**步骤 3:逐文件确认(批量询问)**
|
|
439
|
+
- 对 `common_files` 中的每个文件,使用 **AskUserQuestion** 工具批量询问(每次最多 4 个文件,因为 AskUserQuestion 最多支持 4 个问题,需要分多轮询问):
|
|
426
440
|
|
|
427
441
|
```
|
|
442
|
+
# 第 1 轮(文件 1~4)
|
|
428
443
|
questions: [
|
|
429
444
|
{
|
|
430
|
-
question: "
|
|
431
|
-
header: "
|
|
445
|
+
question: "模板文件 {文件名1} 已存在,是否使用最新版本替换?",
|
|
446
|
+
header: "{文件名1}",
|
|
447
|
+
options: [
|
|
448
|
+
{ label: "保留现有", description: "保留当前项目中的版本,不做修改(用户可能已按项目实际情况调整过)" },
|
|
449
|
+
{ label: "替换为最新", description: "使用插件根目录中的最新版本覆盖现有文件" }
|
|
450
|
+
],
|
|
451
|
+
multiSelect: false
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
question: "模板文件 {文件名2} 已存在,是否使用最新版本替换?",
|
|
455
|
+
header: "{文件名2}",
|
|
432
456
|
options: [
|
|
433
|
-
{ label: "
|
|
434
|
-
{ label: "
|
|
457
|
+
{ label: "保留现有", description: "保留当前项目中的版本,不做修改" },
|
|
458
|
+
{ label: "替换为最新", description: "使用插件根目录中的最新版本覆盖现有文件" }
|
|
459
|
+
],
|
|
460
|
+
multiSelect: false
|
|
461
|
+
},
|
|
462
|
+
... # 最多 4 个问题一轮
|
|
463
|
+
]
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
- 如果 `common_files` 数量超过 4 个,需要分多轮调用 AskUserQuestion,每轮最多 4 个文件
|
|
467
|
+
- 每轮询问结束后,将用户选择记录到 `templates_decision` 映射中
|
|
468
|
+
|
|
469
|
+
**步骤 4:提供批量快捷选项(可选)**
|
|
470
|
+
- 在首轮询问前,可先通过 AskUserQuestion 提供一个全局快捷选项:
|
|
471
|
+
|
|
472
|
+
```
|
|
473
|
+
questions: [
|
|
474
|
+
{
|
|
475
|
+
question: ".adspecs/templates/ 目录已存在且包含 {N} 个模板文件,是否需要逐文件确认?(选择"否"将统一保留现有文件)",
|
|
476
|
+
header: "批量确认",
|
|
477
|
+
options: [
|
|
478
|
+
{ label: "逐文件确认", description: "对每个已修改的模板文件逐一询问是否替换(推荐,用户可能已按项目情况调整过模板)" },
|
|
479
|
+
{ label: "全部保留现有", description: "保留所有现有模板文件不做修改(跳过逐文件确认)" },
|
|
480
|
+
{ label: "全部替换为最新", description: "使用插件根目录中的最新版本覆盖所有模板文件" }
|
|
435
481
|
],
|
|
436
482
|
multiSelect: false
|
|
437
483
|
}
|
|
438
484
|
]
|
|
439
485
|
```
|
|
440
486
|
|
|
441
|
-
-
|
|
442
|
-
-
|
|
487
|
+
- 如果用户选择"逐文件确认" → 执行步骤 3 的逐文件询问
|
|
488
|
+
- 如果用户选择"全部保留现有" → `templates_decision` 中所有文件标记为 `"keep"`
|
|
489
|
+
- 如果用户选择"全部替换为最新" → `templates_decision` 中所有文件标记为 `"replace"`
|
|
490
|
+
|
|
491
|
+
**步骤 5:记录子决策**
|
|
492
|
+
- 记录子决策映射:`templates_decision` = `{ "<文件名>": "replace" | "keep", ... }`
|
|
493
|
+
- 其中 `"replace"` 表示使用插件根目录最新版本覆盖,`"keep"` 表示保留目标目录现有版本
|
|
494
|
+
- 如果 `.adspecs/templates/` 不存在或仅包含空目录 → 跳过此检查,`templates_decision` = `{}`(空映射)
|
|
443
495
|
|
|
444
|
-
7. **输出初始化计划摘要**,包含项目信息(项目名称、项目短名称、公司名称、文件密级、项目目录)、初始化模式、前端技术栈(如适用)、每个区域的操作(创建 / 重新创建 / 跳过)、子目录更新决策(40-project_conventions/
|
|
496
|
+
7. **输出初始化计划摘要**,包含项目信息(项目名称、项目短名称、公司名称、文件密级、项目目录)、初始化模式、前端技术栈(如适用)、每个区域的操作(创建 / 重新创建 / 跳过)、子目录更新决策(40-project_conventions/ 的更新/跳过、templates/ 的逐文件确认结果:哪些文件将被替换、哪些将被保留)、feature.json/project.json 属性补全计划以及补充检查结果,等待用户确认后继续执行
|
|
445
497
|
|
|
446
498
|
## 工作流程
|
|
447
499
|
|
|
@@ -862,8 +914,7 @@ find "$TARGET/front-demo" -type f | wc -l
|
|
|
862
914
|
根据区域决策执行:
|
|
863
915
|
|
|
864
916
|
- `.adspecs` 决策为 `skip` → 输出 `⏭ 阶段 6 跳过:.adspecs/ 已存在,保留现有内容`,但需检查以下子决策和属性补全:
|
|
865
|
-
-
|
|
866
|
-
- 如果 `templates_decision` = `"skip"` → 不做额外处理
|
|
917
|
+
- 根据 `templates_decision` 逐文件映射执行模板更新(见下方"模板逐文件更新执行逻辑")
|
|
867
918
|
- 执行 **feature.json 与 project.json 属性补全检查**(见下方)
|
|
868
919
|
- 处理完子决策和属性补全后进入阶段 7
|
|
869
920
|
- `.adspecs` 决策为 `recreate` → 先备份已存在的 `feature.json` 和 `project.json`,然后执行 `rm -rf "$TARGET/.adspecs"`,按下方步骤完整重建,最后恢复备份文件并执行属性补全检查(见下方"feature.json 与 project.json 属性补全")
|
|
@@ -967,13 +1018,33 @@ find "$TARGET/.adspecs" -type f | wc -l
|
|
|
967
1018
|
- 无缺失时:`✅ 阶段 6:feature.json 属性完整,无需补全`
|
|
968
1019
|
- 文件不存在时:`✅ 阶段 6:feature.json 已从 references 创建`
|
|
969
1020
|
|
|
1021
|
+
#### 模板逐文件更新执行逻辑
|
|
1022
|
+
|
|
1023
|
+
当 `.adspecs` 决策为 `skip` 且 `templates_decision` 映射不为空时,按以下方式执行模板文件的逐文件更新:
|
|
1024
|
+
|
|
1025
|
+
1. **新增文件**:对于存在于 `$PLUGIN_DIR/.adspecs/templates/` 但不存在于 `$TARGET/.adspecs/templates/` 的文件,直接复制到目标目录
|
|
1026
|
+
2. **已有文件逐一处理**:对于 `templates_decision` 映射中的每个文件:
|
|
1027
|
+
- `"replace"` → 执行 `cp "$PLUGIN_DIR/.adspecs/templates/{文件名}" "$TARGET/.adspecs/templates/{文件名}"`,用最新版本覆盖
|
|
1028
|
+
- `"keep"` → 保留目标目录中的现有文件,不做任何操作
|
|
1029
|
+
3. **仅复制已标记为 replace 的文件**,不要使用通配符一次性覆盖整个 templates 目录
|
|
1030
|
+
|
|
1031
|
+
```bash
|
|
1032
|
+
# 示例:逐文件复制被标记为 replace 的模板
|
|
1033
|
+
for file in "${REPLACE_FILES[@]}"; do
|
|
1034
|
+
cp "$PLUGIN_DIR/.adspecs/templates/$file" "$TARGET/.adspecs/templates/$file"
|
|
1035
|
+
done
|
|
1036
|
+
|
|
1037
|
+
# 统计实际更新的模板文件数量
|
|
1038
|
+
echo "更新了 ${#REPLACE_FILES[@]} 个模板文件,保留了 ${#KEEP_FILES[@]} 个模板文件"
|
|
1039
|
+
```
|
|
1040
|
+
|
|
970
1041
|
完成后输出:
|
|
971
1042
|
|
|
972
1043
|
- 新建时:`✅ 阶段 6 完成:.adspecs/ 配置与脚本目录已复制({N} 个文件)`
|
|
973
1044
|
- 重建时:`🔄 阶段 6 完成:.adspecs/ 已重新复制({N} 个文件)`
|
|
974
1045
|
- 重建且有文件恢复时:`🔄 阶段 6 完成:.adspecs/ 已重新复制 + 🔧 feature.json/project.json 已恢复并补全属性`
|
|
975
1046
|
- 跳过时:`⏭ 阶段 6 跳过:.adspecs/ 已存在,保留现有内容`
|
|
976
|
-
-
|
|
1047
|
+
- 跳过但部分更新模板时:`⏭ 阶段 6 跳过:.adspecs/ 已存在 + 🔄 templates/ 已部分更新({N} 个文件替换,{M} 个文件保留)`
|
|
977
1048
|
- 跳过但属性补全时:`⏭ 阶段 6 跳过:.adspecs/ 已存在 + 🔧 feature.json/project.json 已补全缺失属性`
|
|
978
1049
|
|
|
979
1050
|
---
|
|
@@ -1101,7 +1172,7 @@ mkdir -p "$TARGET/.adspecs"
|
|
|
1101
1172
|
| 区域 | 状态 | 说明 |
|
|
1102
1173
|
| ------------------------- | --------------------------------- | -------------------------------------------------------------------------- |
|
|
1103
1174
|
| .adspecs/ | ✅ 已创建 / 🔄 已重建 / ⏭ 已跳过 | 插件配置、脚本、模板(extensions.yml、feature.json、templates/、scripts/) |
|
|
1104
|
-
| └ templates/ | 🔄
|
|
1175
|
+
| └ templates/ | 🔄 部分更新 / ⏭ 全部跳过 | .adspecs/ 跳过时,逐文件确认结果({N} 个替换,{M} 个保留) |
|
|
1105
1176
|
| └ feature.json | 🔧 已补全 / ✅ 已完整 / ✅ 已创建 | 属性补全检查(已有属性保留,缺失属性补充) |
|
|
1106
1177
|
| docs/ | ✅ 已创建 / 🔄 已重建 / ⏭ 已跳过 | 11 个骨架目录,40 仅创建空目录 |
|
|
1107
1178
|
| └ 40-project_conventions/ | 🔄 已更新 / ⏭ 已跳过 | docs/ 跳过时,40 子目录的更新决策 |
|
|
@@ -1114,7 +1185,7 @@ mkdir -p "$TARGET/.adspecs"
|
|
|
1114
1185
|
| 区域 | 状态 | 说明 |
|
|
1115
1186
|
| ------------------------- | --------------------------------- | -------------------------------------------------------------------------- |
|
|
1116
1187
|
| .adspecs/ | ✅ 已创建 / 🔄 已重建 / ⏭ 已跳过 | 插件配置、脚本、模板(extensions.yml、feature.json、templates/、scripts/) |
|
|
1117
|
-
| └ templates/ | 🔄
|
|
1188
|
+
| └ templates/ | 🔄 部分更新 / ⏭ 全部跳过 | .adspecs/ 跳过时,逐文件确认结果({N} 个替换,{M} 个保留) |
|
|
1118
1189
|
| └ feature.json | 🔧 已补全 / ✅ 已完整 / ✅ 已创建 | 属性补全检查(已有属性保留,缺失属性补充) |
|
|
1119
1190
|
| docs/ | ✅ 已创建 / 🔄 已重建 / ⏭ 已跳过 | 11 个骨架目录 + 40 从 references 复制 |
|
|
1120
1191
|
| └ 40-project_conventions/ | 🔄 已更新 / ⏭ 已跳过 | docs/ 跳过时,40 子目录的更新决策 |
|
|
@@ -1128,7 +1199,7 @@ mkdir -p "$TARGET/.adspecs"
|
|
|
1128
1199
|
| 区域 | 状态 | 说明 |
|
|
1129
1200
|
| ------------------------- | --------------------------------- | -------------------------------------------------------------------------- |
|
|
1130
1201
|
| .adspecs/ | ✅ 已创建 / 🔄 已重建 / ⏭ 已跳过 | 插件配置、脚本、模板(extensions.yml、feature.json、templates/、scripts/) |
|
|
1131
|
-
| └ templates/ | 🔄
|
|
1202
|
+
| └ templates/ | 🔄 部分更新 / ⏭ 全部跳过 | .adspecs/ 跳过时,逐文件确认结果({N} 个替换,{M} 个保留) |
|
|
1132
1203
|
| └ feature.json | 🔧 已补全 / ✅ 已完整 / ✅ 已创建 | 属性补全检查(已有属性保留,缺失属性补充) |
|
|
1133
1204
|
| docs/ | ✅ 已创建 / 🔄 已重建 / ⏭ 已跳过 | 11 个骨架目录 + 40 从 references 复制 |
|
|
1134
1205
|
| └ 40-project_conventions/ | 🔄 已更新 / ⏭ 已跳过 | docs/ 跳过时,40 子目录的更新决策 |
|
|
@@ -1144,7 +1215,7 @@ mkdir -p "$TARGET/.adspecs"
|
|
|
1144
1215
|
| 区域 | 状态 | 说明 |
|
|
1145
1216
|
| ------------------------- | --------------------------------- | -------------------------------------------------------------------------- |
|
|
1146
1217
|
| .adspecs/ | ✅ 已创建 / 🔄 已重建 / ⏭ 已跳过 | 插件配置、脚本、模板(extensions.yml、feature.json、templates/、scripts/) |
|
|
1147
|
-
| └ templates/ | 🔄
|
|
1218
|
+
| └ templates/ | 🔄 部分更新 / ⏭ 全部跳过 | .adspecs/ 跳过时,逐文件确认结果({N} 个替换,{M} 个保留) |
|
|
1148
1219
|
| └ feature.json | 🔧 已补全 / ✅ 已完整 / ✅ 已创建 | 属性补全检查(已有属性保留,缺失属性补充) |
|
|
1149
1220
|
| docs/ | ✅ 已创建 / 🔄 已重建 / ⏭ 已跳过 | 11 个骨架目录 + 40 按 Python+React 技术栈复制前后端规范 |
|
|
1150
1221
|
| └ 40-project_conventions/ | 🔄 已更新 / ⏭ 已跳过 | docs/ 跳过时,40 子目录的更新决策 |
|
|
@@ -1159,7 +1230,7 @@ mkdir -p "$TARGET/.adspecs"
|
|
|
1159
1230
|
|
|
1160
1231
|
- ✅ 已创建:目录原本不存在,新建完成
|
|
1161
1232
|
- 🔄 已重建:目录原本存在,按用户选择删除后重新创建
|
|
1162
|
-
- 🔄 已更新:父目录跳过,但子目录按用户选择使用 references
|
|
1233
|
+
- 🔄 已更新:父目录跳过,但子目录按用户选择使用 references 最新文件覆盖更新(templates/ 支持逐文件确认,部分文件可替换、部分保留)
|
|
1163
1234
|
- 🔧 已补全:已有文件属性与 references 对比后,补充缺失属性(已有属性不覆盖)
|
|
1164
1235
|
- ⏭ 已跳过:目录原本存在,按用户选择保留未动
|
|
1165
1236
|
|
|
@@ -1278,7 +1349,7 @@ mkdir -p "$TARGET/.adspecs"
|
|
|
1278
1349
|
- [ ] service/ 目录已创建/重建/跳过(仅完整/轻量模式)
|
|
1279
1350
|
- [ ] front-demo/ 已从 references 按技术栈选择复制/重建/跳过(经典/完整/轻量模式,排除 node_modules、.git、.vite)
|
|
1280
1351
|
- [ ] .adspecs/ 配置与脚本目录已从插件根目录完整复制/重建/跳过
|
|
1281
|
-
- [ ] .adspecs/templates/
|
|
1352
|
+
- [ ] .adspecs/templates/ 子目录逐文件更新检查已完成(.adspecs/ 跳过且模板目录已包含文件时,已通过 AskUserQuestion 逐文件确认替换/保留决策并按决策执行)
|
|
1282
1353
|
- [ ] feature.json 属性补全检查已完成(recreate/skip 时,已对比 references 初始版本并补全缺失属性,已有属性不覆盖)
|
|
1283
1354
|
- [ ] project.json 属性补全检查已完成(recreate/skip 时,已对比 references 初始版本并补全缺失属性)
|
|
1284
1355
|
- [ ] .adspecs/project.json 项目元数据文件已生成或更新
|
package/src/commands/init.js
CHANGED
|
@@ -51,7 +51,7 @@ module.exports = async function init(options) {
|
|
|
51
51
|
const decisions = await collectDecisions(areaStates, options);
|
|
52
52
|
|
|
53
53
|
// === Step 4: 收集子目录决策 ===
|
|
54
|
-
const subDecisions = await collectSubDecisions(decisions, targetDir, options);
|
|
54
|
+
const subDecisions = await collectSubDecisions(decisions, targetDir, pluginDir, options);
|
|
55
55
|
|
|
56
56
|
// === Step 5: 模式升级检测 ===
|
|
57
57
|
const modeUpgrade = detectModeUpgrade(decisions, info.mode, targetDir);
|
package/src/lib/dir-utils.js
CHANGED
|
@@ -125,9 +125,37 @@ function listSubdirs(dirPath) {
|
|
|
125
125
|
return entries.filter((e) => e.isDirectory()).map((e) => e.name);
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
+
/**
|
|
129
|
+
* 列出目录下的所有文件名(不递归)
|
|
130
|
+
*
|
|
131
|
+
* @param {string} dirPath - 目录绝对路径
|
|
132
|
+
* @returns {string[]} 文件名列表
|
|
133
|
+
*/
|
|
134
|
+
function listFiles(dirPath) {
|
|
135
|
+
if (!fs.existsSync(dirPath)) return [];
|
|
136
|
+
|
|
137
|
+
let stat;
|
|
138
|
+
try {
|
|
139
|
+
stat = fs.statSync(dirPath);
|
|
140
|
+
} catch {
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
143
|
+
if (!stat.isDirectory()) return [];
|
|
144
|
+
|
|
145
|
+
let entries;
|
|
146
|
+
try {
|
|
147
|
+
entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
148
|
+
} catch {
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return entries.filter((e) => e.isFile()).map((e) => e.name);
|
|
153
|
+
}
|
|
154
|
+
|
|
128
155
|
module.exports = {
|
|
129
156
|
hasAnyFile,
|
|
130
157
|
isEmptyDirectoryTree,
|
|
131
158
|
countFiles,
|
|
132
159
|
listSubdirs,
|
|
160
|
+
listFiles,
|
|
133
161
|
};
|
package/src/lib/prompts.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
const { input, select, confirm } = require('@inquirer/prompts');
|
|
6
|
-
const { hasAnyFile, isEmptyDirectoryTree } = require('./dir-utils');
|
|
6
|
+
const { hasAnyFile, isEmptyDirectoryTree, listFiles } = require('./dir-utils');
|
|
7
7
|
const { areaDisplayName } = require('./area-scanner');
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -220,8 +220,8 @@ async function askAreaDecision(areaName) {
|
|
|
220
220
|
* @param {object} options - CLI 选项
|
|
221
221
|
* @returns {Promise<object>} 子决策 { conventions, templates }
|
|
222
222
|
*/
|
|
223
|
-
async function collectSubDecisions(decisions, targetDir, options) {
|
|
224
|
-
const sub = { conventions: 'skip', templates:
|
|
223
|
+
async function collectSubDecisions(decisions, targetDir, pluginDir, options) {
|
|
224
|
+
const sub = { conventions: 'skip', templates: {} };
|
|
225
225
|
const nonInteractive = options.nonInteractive || false;
|
|
226
226
|
const force = options.force || false;
|
|
227
227
|
|
|
@@ -239,11 +239,12 @@ async function collectSubDecisions(decisions, targetDir, options) {
|
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
// templates_decision:.adspecs/ skip 且 templates/ 有文件
|
|
242
|
+
// templates_decision:.adspecs/ skip 且 templates/ 有文件 → 逐文件确认
|
|
243
243
|
if (decisions.adspecs === 'skip') {
|
|
244
244
|
const tmplDir = path.join(targetDir, '.adspecs/templates');
|
|
245
|
+
const pluginTmplDir = path.join(pluginDir, '.adspecs/templates');
|
|
245
246
|
if (fs.existsSync(tmplDir) && hasAnyFile(tmplDir)) {
|
|
246
|
-
sub.templates = await
|
|
247
|
+
sub.templates = await collectTemplatesDecision(tmplDir, pluginTmplDir);
|
|
247
248
|
}
|
|
248
249
|
}
|
|
249
250
|
|
|
@@ -266,6 +267,85 @@ async function askSubDecision(subDirName) {
|
|
|
266
267
|
});
|
|
267
268
|
}
|
|
268
269
|
|
|
270
|
+
/**
|
|
271
|
+
* 逐文件确认模板文件是否替换
|
|
272
|
+
*
|
|
273
|
+
* 扫描目标目录和插件根目录的模板文件,自动识别新增文件(直接复制),
|
|
274
|
+
* 对共有文件提供批量快捷选项 + 逐文件确认。
|
|
275
|
+
*
|
|
276
|
+
* @param {string} targetTmplDir - 目标项目 templates 目录
|
|
277
|
+
* @param {string} pluginTmplDir - 插件根目录 templates 目录
|
|
278
|
+
* @returns {Promise<Object<string, 'replace'|'keep'>>} 逐文件决策映射
|
|
279
|
+
*/
|
|
280
|
+
async function collectTemplatesDecision(targetTmplDir, pluginTmplDir) {
|
|
281
|
+
const targetFiles = listFiles(targetTmplDir).filter((f) => f.endsWith('.md'));
|
|
282
|
+
const pluginFiles = listFiles(pluginTmplDir).filter((f) => f.endsWith('.md'));
|
|
283
|
+
|
|
284
|
+
const targetSet = new Set(targetFiles);
|
|
285
|
+
const pluginSet = new Set(pluginFiles);
|
|
286
|
+
|
|
287
|
+
// 新增文件(插件有,目标没有)→ 直接复制,无需确认
|
|
288
|
+
const newFiles = pluginFiles.filter((f) => !targetSet.has(f));
|
|
289
|
+
// 共有文件 → 需要逐文件确认
|
|
290
|
+
const commonFiles = pluginFiles.filter((f) => targetSet.has(f));
|
|
291
|
+
|
|
292
|
+
if (commonFiles.length === 0) {
|
|
293
|
+
// 没有共有文件,无需确认
|
|
294
|
+
return {};
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// 批量快捷选项
|
|
298
|
+
const bulkChoice = await select({
|
|
299
|
+
message: `.adspecs/templates/ 目录已存在且包含 ${targetFiles.length} 个模板文件(其中 ${commonFiles.length} 个为已有,${newFiles.length} 个为新增),如何处理已有文件?`,
|
|
300
|
+
choices: [
|
|
301
|
+
{ name: '逐文件确认 — 对每个已有模板文件逐一询问是否替换(推荐)', value: 'ask-each' },
|
|
302
|
+
{ name: '全部保留现有 — 保留所有已有模板文件不做修改', value: 'keep-all' },
|
|
303
|
+
{ name: '全部替换为最新 — 使用插件根目录中的最新版本覆盖所有已有模板文件', value: 'replace-all' },
|
|
304
|
+
],
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
if (bulkChoice === 'keep-all') {
|
|
308
|
+
const decision = {};
|
|
309
|
+
for (const f of commonFiles) {
|
|
310
|
+
decision[f] = 'keep';
|
|
311
|
+
}
|
|
312
|
+
return decision;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (bulkChoice === 'replace-all') {
|
|
316
|
+
const decision = {};
|
|
317
|
+
for (const f of commonFiles) {
|
|
318
|
+
decision[f] = 'replace';
|
|
319
|
+
}
|
|
320
|
+
return decision;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// 逐文件询问(每批最多 4 个文件,避免 inquirer 单次问题过多)
|
|
324
|
+
const decision = {};
|
|
325
|
+
const BATCH_SIZE = 4;
|
|
326
|
+
for (let i = 0; i < commonFiles.length; i += BATCH_SIZE) {
|
|
327
|
+
const batch = commonFiles.slice(i, i + BATCH_SIZE);
|
|
328
|
+
const batchNum = Math.floor(i / BATCH_SIZE) + 1;
|
|
329
|
+
const totalBatches = Math.ceil(commonFiles.length / BATCH_SIZE);
|
|
330
|
+
|
|
331
|
+
console.log('');
|
|
332
|
+
console.log(`--- 模板文件确认(第 ${batchNum}/${totalBatches} 批,共 ${commonFiles.length} 个) ---`);
|
|
333
|
+
|
|
334
|
+
for (const file of batch) {
|
|
335
|
+
const choice = await select({
|
|
336
|
+
message: `模板文件 ${file} 已存在,是否使用最新版本替换?`,
|
|
337
|
+
choices: [
|
|
338
|
+
{ name: '保留现有 — 保留当前项目中的版本(用户可能已按项目实际情况调整过)', value: 'keep' },
|
|
339
|
+
{ name: '替换为最新 — 使用插件根目录中的最新版本覆盖现有文件', value: 'replace' },
|
|
340
|
+
],
|
|
341
|
+
});
|
|
342
|
+
decision[file] = choice;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return decision;
|
|
347
|
+
}
|
|
348
|
+
|
|
269
349
|
// ============================================================
|
|
270
350
|
// 模式升级检测
|
|
271
351
|
// ============================================================
|
|
@@ -340,6 +420,7 @@ module.exports = {
|
|
|
340
420
|
collectProjectInfo,
|
|
341
421
|
collectDecisions,
|
|
342
422
|
collectSubDecisions,
|
|
423
|
+
collectTemplatesDecision,
|
|
343
424
|
detectModeUpgrade,
|
|
344
425
|
confirmExecution,
|
|
345
426
|
askAreaDecision,
|
package/src/lib/report.js
CHANGED
|
@@ -91,10 +91,16 @@ function printPlanSummary(info, decisions, subDecisions, modeUpgrade, targetDir)
|
|
|
91
91
|
` ${chalk.gray('└')} 40-project_conventions/ ${chalk.gray('→')} ${decisionLabel(subDecisions.conventions)}`
|
|
92
92
|
);
|
|
93
93
|
}
|
|
94
|
-
if (areaKey === 'adspecs' && decision === 'skip'
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
);
|
|
94
|
+
if (areaKey === 'adspecs' && decision === 'skip') {
|
|
95
|
+
const tmplMap = subDecisions.templates || {};
|
|
96
|
+
const tmplEntries = Object.entries(tmplMap);
|
|
97
|
+
const replaceCount = tmplEntries.filter(([, v]) => v === 'replace').length;
|
|
98
|
+
const keepCount = tmplEntries.filter(([, v]) => v === 'keep').length;
|
|
99
|
+
if (replaceCount > 0 || keepCount > 0) {
|
|
100
|
+
console.log(
|
|
101
|
+
` ${chalk.gray('└')} templates/ ${chalk.gray('→')} 逐文件确认(${replaceCount} 个替换,${keepCount} 个保留)`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
98
104
|
}
|
|
99
105
|
}
|
|
100
106
|
|
|
@@ -153,10 +159,15 @@ function printFinalReport(report, info, decisions, subDecisions, modeUpgrade) {
|
|
|
153
159
|
const detail = stageDetail(stage);
|
|
154
160
|
console.log(` | ${stage.name} | ${icon} ${stage.status} | ${detail} |`);
|
|
155
161
|
|
|
156
|
-
// 子行:templates
|
|
157
|
-
if (stage.name === '.adspecs/' && stage.subDecisions) {
|
|
158
|
-
|
|
159
|
-
|
|
162
|
+
// 子行:templates/(逐文件确认结果)
|
|
163
|
+
if (stage.name === '.adspecs/' && stage.subDecisions && stage.subDecisions.templates) {
|
|
164
|
+
const tmpl = stage.subDecisions.templates;
|
|
165
|
+
if (typeof tmpl === 'object' && (tmpl.replaced > 0 || tmpl.kept > 0 || tmpl.added > 0)) {
|
|
166
|
+
const parts = [];
|
|
167
|
+
if (tmpl.added > 0) parts.push(`${tmpl.added} 个新增`);
|
|
168
|
+
if (tmpl.replaced > 0) parts.push(`${tmpl.replaced} 个替换`);
|
|
169
|
+
if (tmpl.kept > 0) parts.push(`${tmpl.kept} 个保留`);
|
|
170
|
+
console.log(` | ${chalk.gray('└ templates/')} | ${chalk.green('🔄')} 部分更新 | ${parts.join(',')} |`);
|
|
160
171
|
}
|
|
161
172
|
}
|
|
162
173
|
|
|
@@ -190,7 +201,7 @@ function printFinalReport(report, info, decisions, subDecisions, modeUpgrade) {
|
|
|
190
201
|
console.log(chalk.bold('状态说明:'));
|
|
191
202
|
console.log(' ✅ 已创建 — 目录原本不存在,新建完成');
|
|
192
203
|
console.log(' 🔄 已重建 — 目录原本存在,按用户选择删除后重新创建');
|
|
193
|
-
console.log(' 🔄 已更新 —
|
|
204
|
+
console.log(' 🔄 已更新 — 父目录跳过,但子目录按用户选择使用最新文件覆盖(templates/ 支持逐文件确认,部分替换部分保留)');
|
|
194
205
|
console.log(' 🔧 已补全 — 已有文件属性与 references 对比后,补充缺失属性');
|
|
195
206
|
console.log(' ⏭ 已跳过 — 目录原本存在,按用户选择保留未动');
|
|
196
207
|
console.log('');
|
package/src/lib/scaffolder.js
CHANGED
|
@@ -6,6 +6,7 @@ const { copyDirFiltered, removeDir, countFiles } = require('./copier');
|
|
|
6
6
|
const { generateReadme, generateWikiReadme, generateServiceReadme, DOCS_READMES } = require('./readme-gen');
|
|
7
7
|
const { mergeJsonFile, mergeProjectJson } = require('./json-merge');
|
|
8
8
|
const { generatePathsConfig } = require('./paths-defaults');
|
|
9
|
+
const { listFiles } = require('./dir-utils');
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* 脚手架核心
|
|
@@ -52,7 +53,7 @@ async function scaffold(opts) {
|
|
|
52
53
|
confidentiality,
|
|
53
54
|
modules,
|
|
54
55
|
decisions,
|
|
55
|
-
subDecisions = { conventions: 'skip', templates:
|
|
56
|
+
subDecisions = { conventions: 'skip', templates: {} },
|
|
56
57
|
modeUpgrade = { detected: false, emptyDirs: [] },
|
|
57
58
|
logger = () => {},
|
|
58
59
|
} = opts;
|
|
@@ -408,14 +409,46 @@ async function scaffoldAdspecs(targetDir, pluginDir, decision, subDecisions, log
|
|
|
408
409
|
if (decision === 'skip') {
|
|
409
410
|
logger(`⏭ 阶段 6 跳过:.adspecs/ 已存在,保留现有内容`);
|
|
410
411
|
|
|
411
|
-
// 子决策:templates
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
);
|
|
417
|
-
|
|
418
|
-
|
|
412
|
+
// 子决策:templates(逐文件确认)
|
|
413
|
+
const templatesDecision = subDecisions.templates || {};
|
|
414
|
+
const templatesMap = typeof templatesDecision === 'object' ? templatesDecision : {};
|
|
415
|
+
const replaceFiles = Object.entries(templatesMap)
|
|
416
|
+
.filter(([, v]) => v === 'replace')
|
|
417
|
+
.map(([k]) => k);
|
|
418
|
+
const keepFiles = Object.entries(templatesMap)
|
|
419
|
+
.filter(([, v]) => v === 'keep')
|
|
420
|
+
.map(([k]) => k);
|
|
421
|
+
|
|
422
|
+
// 新增文件(插件有但目标没有)→ 直接复制
|
|
423
|
+
const pluginTmplDir = path.join(pluginDir, '.adspecs/templates');
|
|
424
|
+
const targetTmplDir = path.join(adspecsDir, 'templates');
|
|
425
|
+
const targetFiles = new Set(listFiles(targetTmplDir));
|
|
426
|
+
const pluginFiles = listFiles(pluginTmplDir);
|
|
427
|
+
const newFiles = pluginFiles.filter((f) => !targetFiles.has(f));
|
|
428
|
+
|
|
429
|
+
let addedCount = 0;
|
|
430
|
+
for (const f of newFiles) {
|
|
431
|
+
fs.copyFileSync(path.join(pluginTmplDir, f), path.join(targetTmplDir, f));
|
|
432
|
+
addedCount++;
|
|
433
|
+
}
|
|
434
|
+
if (addedCount > 0) {
|
|
435
|
+
logger(`📦 模板新增:已添加 ${addedCount} 个新模板文件`);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// 逐文件替换
|
|
439
|
+
let replacedCount = 0;
|
|
440
|
+
for (const f of replaceFiles) {
|
|
441
|
+
const srcPath = path.join(pluginTmplDir, f);
|
|
442
|
+
const dstPath = path.join(targetTmplDir, f);
|
|
443
|
+
if (fs.existsSync(srcPath)) {
|
|
444
|
+
fs.copyFileSync(srcPath, dstPath);
|
|
445
|
+
replacedCount++;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
if (replacedCount > 0 || keepFiles.length > 0) {
|
|
450
|
+
logger(`🔄 阶段 6 补充更新:.adspecs/templates/ 已部分更新(${replacedCount} 个文件替换,${keepFiles.length} 个文件保留)`);
|
|
451
|
+
stage.subDecisions = { templates: { replaced: replacedCount, kept: keepFiles.length, added: addedCount } };
|
|
419
452
|
}
|
|
420
453
|
|
|
421
454
|
// 属性补全(无论是否更新 templates 都执行)
|