dsh-git-push 3.0.0 → 3.1.0
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/README.md +76 -48
- package/cli.mjs +4 -3
- package/lib/app/apply.js +11 -9
- package/lib/app/command-registry.js +4 -2
- package/lib/app/handlers/http-constants.js +8 -0
- package/lib/app/handlers/preprocess.js +3 -6
- package/lib/app/handlers/repo-actions.js +0 -1
- package/lib/app/handlers/repos.js +137 -10
- package/lib/app/handlers/settings.js +34 -15
- package/lib/app/index.js +1 -1
- package/lib/app/inject-text.js +3 -18
- package/lib/app/schema.js +20 -10
- package/lib/app/settings-bridge.js +60 -8
- package/lib/app/tool-call.js +26 -22
- package/lib/cli/commands-vcs.mjs +35 -1
- package/lib/cli/shared.mjs +1 -1
- package/lib/client/index.js +11 -16
- package/lib/client-parts/git/account.js +21 -12
- package/lib/client-parts/git/actions.js +23 -77
- package/lib/client-parts/git/apply.js +8 -2
- package/lib/client-parts/git/browser.js +1 -1
- package/lib/client-parts/git/const.js +33 -1
- package/lib/client-parts/git/controller.js +175 -176
- package/lib/client-parts/git/icons.js +1 -1
- package/lib/client-parts/git/loader.js +1 -1
- package/lib/client-parts/git/npm.js +56 -37
- package/lib/client-parts/git/page.js +53 -1
- package/lib/client-parts/git/repo.js +8 -1
- package/lib/client-parts/git/settings.js +13 -1
- package/lib/client-parts/git/state.js +237 -0
- package/lib/client-parts/git/utils.js +1 -1
- package/lib/client.js +631 -312
- package/lib/commit-push/pre-commit-engine.js +584 -32
- package/lib/commit-push.js +63 -47
- package/lib/context/index.js +7 -5
- package/lib/core/config.js +1 -27
- package/lib/core/exec.js +2 -11
- package/lib/git/identity-rewrite.js +1 -1
- package/lib/git/index.js +1 -1
- package/lib/git/push.js +2 -17
- package/lib/git/repo-index.js +8 -3
- package/lib/npm/install.js +1 -1
- package/lib/npm/registry.js +2 -2
- package/lib/plugin/auto-push.js +3 -6
- package/lib/preprocess/providers.js +5 -1
- package/lib/self/index.js +1 -1
- package/package.json +4 -7
- package/skills/dev/dsh-git-push.md +9 -9
- package/skills/guide/guide-commit-push.md +11 -13
- package/skills/workflow/README.md +0 -1
- package/skills/workflow/task-completion-report.md +2 -2
- package/.auditignore +0 -30
- package/.gitignore +0 -43
- package/lib/BUGFIX-NOTES-2026-09-14.md +0 -278
- package/lib/app/schema-preprocess.js +0 -42
- package/lib/user-requirements.json +0 -15
- package/scripts/build-client.mjs +0 -133
- package/scripts/bump-version.mjs +0 -178
- package/scripts/check.mjs +0 -205
- package/scripts/doc-func.mjs +0 -212
- package/scripts/doc-tree.mjs +0 -458
- package/scripts/doc-version.mjs +0 -149
- package/scripts/local-registry.mjs +0 -38
- package/scripts/scan-version.mjs +0 -125
- package/scripts/version-source.mjs +0 -173
package/scripts/doc-version.mjs
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* dsh-git-push — 版本列表文档生成器(doc-version:版本表由**文件**权威生成,防手写版本记录漂移)
|
|
4
|
-
* dsh-skip-i18n: 用户可见文案硬编码为产品设计
|
|
5
|
-
*
|
|
6
|
-
* 分体式文档三兄弟之一(doc-tree 文件树 / doc-func 函数列表 / doc-version 版本列表)。
|
|
7
|
-
* 版本表数据源 = `docs/releases.json`(每版一行说明)+ 版本真源文件(package.json 等)
|
|
8
|
-
* + `version-metrics.json`(可选量化记录);**不读 git log**(2026-10-16 改,原因见
|
|
9
|
-
* version-source.mjs 的 buildReadmeVersionTable 注释)。
|
|
10
|
-
* 写入宿主 md(README 有 dshgp-version 标记块用 README,否则 docs/ 带块 md)。
|
|
11
|
-
* 复用 version-source.mjs 的 buildReadmeVersionTable(版本聚合逻辑单一事实源)。
|
|
12
|
-
*
|
|
13
|
-
* 用法:
|
|
14
|
-
* node scripts/doc-version.mjs gen [--root <项目根>] # 打印版本表文本
|
|
15
|
-
* node scripts/doc-version.mjs apply [--root <项目根>] # 写入宿主 md(自动探测)
|
|
16
|
-
* node scripts/doc-version.mjs check [--root <项目根>] # 比对宿主块与最新(漂移报错)
|
|
17
|
-
*/
|
|
18
|
-
import { readFileSync, writeFileSync, existsSync } from 'node:fs';
|
|
19
|
-
import { join, resolve, relative, basename, dirname } from 'node:path';
|
|
20
|
-
import { fileURLToPath } from 'node:url';
|
|
21
|
-
import { findMarkedHostMd } from './doc-tree.mjs';
|
|
22
|
-
import { buildReadmeVersionTable, detectVersionSource, projectVersionOf, readReleases, VERSION_SOURCES } from './version-source.mjs';
|
|
23
|
-
|
|
24
|
-
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
25
|
-
const MARKER = 'dshgp-version';
|
|
26
|
-
const MARK_START = `<!-- ${MARKER}:start -->`;
|
|
27
|
-
const MARK_END = `<!-- ${MARKER}:end -->`;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 版本源探测与读取**在 scripts/version-source.mjs**(版本表生成与版本源同源,避免两处各写一份)。
|
|
31
|
-
* 这里只做再导出,保持旧调用方的 import 路径不变。
|
|
32
|
-
*
|
|
33
|
-
* ⚠️ 2026-10-16 起:版本表**不再读 git log**(`detectVersionSource` 不再回退 'git-log')——
|
|
34
|
-
* 表内容由 `docs/releases.json` + 版本真源文件生成,普通提交不再动表、也不再逼人「为门禁升版本」。
|
|
35
|
-
*/
|
|
36
|
-
// 本地再导出(`export … from` 不产生本地绑定 ⇒ 必须先 import 再导出)
|
|
37
|
-
export { VERSION_SOURCES, detectVersionSource, projectVersionOf, readReleases };
|
|
38
|
-
|
|
39
|
-
/** 兼容旧调用:等价于"按项目类型识别后取版本号"。 */
|
|
40
|
-
export function packageVersionOf(root) {
|
|
41
|
-
return projectVersionOf(root, detectVersionSource(root));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** 生成版本列表 markdown(宿主块内容)——**纯文件驱动,不读 git log**。
|
|
45
|
-
* 行内容来自 buildReadmeVersionTable(docs/releases.json + 版本真源 + version-metrics.json)。 */
|
|
46
|
-
export function buildVersionListText(root, _opts = {}) {
|
|
47
|
-
const rows = buildReadmeVersionTable(root);
|
|
48
|
-
const source = detectVersionSource(root) || '(无版本源文件)';
|
|
49
|
-
const pkg = projectVersionOf(root);
|
|
50
|
-
return { text: `## 版本列表\n\n${rows.join('\n')}\n`, rows: rows.length - 2, source, packageVersion: pkg };
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/** 找宿主 md 内的 dshgp-version 标记块。 */
|
|
54
|
-
function findBlock(text) {
|
|
55
|
-
const s = text.indexOf(MARK_START);
|
|
56
|
-
const e = text.indexOf(MARK_END);
|
|
57
|
-
if (s === -1 || e === -1 || e <= s) return null;
|
|
58
|
-
return { start: s, end: e, content: text.slice(s + MARK_START.length, e) };
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** 替换/插入标记块。无块时追加到文件尾。 */
|
|
62
|
-
export function applyVersionBlock(text, newContent) {
|
|
63
|
-
const block = findBlock(text);
|
|
64
|
-
if (block) return text.slice(0, block.start) + MARK_START + '\n' + newContent + '\n' + MARK_END + text.slice(block.end + MARK_END.length);
|
|
65
|
-
return text.replace(/\s*$/, '\n') + `\n${MARK_START}\n${newContent}\n${MARK_END}\n`;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** 比对宿主块与最新版本表。返回 { ok, issues, latest }。 */
|
|
69
|
-
export function checkVersionDrift({ hostPath, root, versionSource = '' } = {}) {
|
|
70
|
-
const { text: latest, source } = buildVersionListText(root, { versionSource });
|
|
71
|
-
const host = existsSync(hostPath) ? readFileSync(hostPath, 'utf8') : '';
|
|
72
|
-
const block = findBlock(host);
|
|
73
|
-
const issues = [];
|
|
74
|
-
if (!block) issues.push({ type: 'no-block', msg: `${basename(hostPath)} 无版本列表标记块(${MARK_START} … ${MARK_END}),先 apply 生成` });
|
|
75
|
-
else if (block.content.trim() !== latest.trim()) issues.push({ type: 'drift', msg: `版本列表与期望内容不一致(来源:${source},运行 doc-version.mjs apply 更新)` });
|
|
76
|
-
return { ok: issues.length === 0, issues, latest, source };
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/* ─────────── CLI ─────────── */
|
|
80
|
-
|
|
81
|
-
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
82
|
-
const args = process.argv.slice(2);
|
|
83
|
-
const cmd = args[0];
|
|
84
|
-
const rootIdx = args.indexOf('--root');
|
|
85
|
-
const root = rootIdx !== -1 && args[rootIdx + 1] ? resolve(args[rootIdx + 1]) : ROOT;
|
|
86
|
-
// 版本来源可显式指定(package.json | git-log);不传则按项目类型自动识别(有 package.json 即 npm 项目)
|
|
87
|
-
const srcIdx = args.indexOf('--version-source');
|
|
88
|
-
const versionSource = srcIdx !== -1 && args[srcIdx + 1] ? String(args[srcIdx + 1]) : '';
|
|
89
|
-
if (versionSource && versionSource !== 'package.json') {
|
|
90
|
-
console.log(`❌ --version-source 只接受 package.json(版本表已改为文件驱动,不再支持 git-log),收到:${versionSource}`);
|
|
91
|
-
process.exit(1);
|
|
92
|
-
}
|
|
93
|
-
const host = findMarkedHostMd(root, MARKER);
|
|
94
|
-
const out = (msg) => console.log(msg);
|
|
95
|
-
|
|
96
|
-
if (cmd === 'gen') {
|
|
97
|
-
const r = buildVersionListText(root, { versionSource });
|
|
98
|
-
out(r.text);
|
|
99
|
-
out(`\n(${r.rows} 版本行;来源 ${r.source};apply 写入 ${relative(root, host) || 'README.md'})`);
|
|
100
|
-
process.exit(0);
|
|
101
|
-
}
|
|
102
|
-
if (cmd === 'apply') {
|
|
103
|
-
const r = buildVersionListText(root, { versionSource });
|
|
104
|
-
const hostText = existsSync(host) ? readFileSync(host, 'utf8') : '';
|
|
105
|
-
const force = args.includes('--force');
|
|
106
|
-
// ── 预演(dry-run):先看清"将写入几行、首行是什么",再决定落盘 ──
|
|
107
|
-
// 破坏性写入前必须能预演;`gen` 也能看内容,但 dry-run 额外报出目标文件与现有行数对比。
|
|
108
|
-
if (args.includes('--dry-run')) {
|
|
109
|
-
const curB = findBlock(hostText);
|
|
110
|
-
const curN = curB ? (curB.content.match(/^\|\s*\d+\.\d+\.\d+\s*\|/gm) || []).length : 0;
|
|
111
|
-
out(`[dry-run] 目标文件:${relative(root, host) || 'README.md'}`);
|
|
112
|
-
out(`[dry-run] 将写入:${r.rows} 版本行(来源 ${r.source});现有:${curN} 行`);
|
|
113
|
-
out(`[dry-run] 首行预览:${(r.text.split('\n').find((l) => /^\|\s*\d/.test(l)) || '(无数据行)').trim()}`);
|
|
114
|
-
out('[dry-run] 未做任何写入。');
|
|
115
|
-
process.exit(0);
|
|
116
|
-
}
|
|
117
|
-
// ── 安全闸(2026-10-10 真实事故:本工具静默把整张版本表清空)──
|
|
118
|
-
// 0 行的常见原因**不是**"项目真的没有版本",而是 git log 读不到(如本机 dubious ownership,
|
|
119
|
-
// git 直接拒绝该仓库)⇒ 此时必须拒绝写盘,绝不覆盖现有版本表。
|
|
120
|
-
if (!force && !(r.rows > 0)) {
|
|
121
|
-
out(`❌ 拒绝写盘:聚合出 0 条版本行(来源 ${r.source})——现有版本表保持不变,未做任何修改。`);
|
|
122
|
-
out(' 常见原因:git log 读不到该仓库(例如 dubious ownership 被 git 拒绝)。先执行:');
|
|
123
|
-
out(" git config --global --add safe.directory '*'");
|
|
124
|
-
out(' 再用 `node scripts/doc-version.mjs gen` 确认能输出真实版本行(非 0 行)后重试;');
|
|
125
|
-
out(' 确实要写空表时显式加 --force。');
|
|
126
|
-
process.exit(2);
|
|
127
|
-
}
|
|
128
|
-
// ── 骤减保护:新表行数少于现有表行数 ⇒ 疑似聚合来源异常(log 不完整/换源),同样拒绝写盘 ──
|
|
129
|
-
const curBlock = findBlock(hostText);
|
|
130
|
-
const curRows = curBlock ? (curBlock.content.match(/^\|\s*\d+\.\d+\.\d+\s*\|/gm) || []).length : 0;
|
|
131
|
-
if (!force && curRows > 0 && r.rows < curRows) {
|
|
132
|
-
out(`❌ 拒绝写盘:本次聚合 ${r.rows} 行 < 现有 ${curRows} 行(疑似聚合来源异常,如 git log 不完整或换源)。`);
|
|
133
|
-
out(' 现有版本表保持不变;确认要缩减请先备份,再显式加 --force。');
|
|
134
|
-
process.exit(2);
|
|
135
|
-
}
|
|
136
|
-
writeFileSync(host, applyVersionBlock(hostText, r.text), 'utf8');
|
|
137
|
-
out(`✅ 已写入版本列表 → ${relative(root, host) || 'README.md'}(${r.rows} 版本行;来源 ${r.source})`);
|
|
138
|
-
process.exit(0);
|
|
139
|
-
}
|
|
140
|
-
if (cmd === 'check') {
|
|
141
|
-
const r = checkVersionDrift({ hostPath: host, root, versionSource });
|
|
142
|
-
if (r.ok) { out(`✅ 版本列表一致(来源 ${r.source})`); process.exit(0); }
|
|
143
|
-
out('❌ 版本列表存在差异:');
|
|
144
|
-
for (const i of r.issues) out(' - ' + i.msg);
|
|
145
|
-
process.exit(1);
|
|
146
|
-
}
|
|
147
|
-
out('用法: node scripts/doc-version.mjs <gen|apply|check> [--root <项目根>] [--version-source package.json|git-log]');
|
|
148
|
-
process.exit(1);
|
|
149
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* 本地 npm registry 的命令行入口(实现在 `lib/npm/local-registry.js`)。
|
|
4
|
-
*
|
|
5
|
-
* 用途:把本机当"npm 网站"做**发布彩排**——publish → install → 加载公开面,全程不写公共 registry。
|
|
6
|
-
*
|
|
7
|
-
* 用法:
|
|
8
|
-
* node scripts/local-registry.mjs --selftest # 一条命令跑完整彩排(推荐)
|
|
9
|
-
* node scripts/local-registry.mjs --port=4873 # 前台起服务(Ctrl-C 结束)
|
|
10
|
-
*
|
|
11
|
-
* 要真发到公网请用 `npm_publish`(含发布前冒烟);这里只做彩排,结束即清理临时目录。
|
|
12
|
-
*/
|
|
13
|
-
import { fileURLToPath } from 'node:url';
|
|
14
|
-
import { startLocalRegistry, runLocalPreview } from '../lib/npm/local-registry.js';
|
|
15
|
-
|
|
16
|
-
const repo = fileURLToPath(new URL('..', import.meta.url));
|
|
17
|
-
const args = process.argv.slice(2);
|
|
18
|
-
|
|
19
|
-
if (args.includes('--selftest')) {
|
|
20
|
-
const r = await runLocalPreview({
|
|
21
|
-
dir: repo,
|
|
22
|
-
tag: 'beta',
|
|
23
|
-
// 只验包自己的公开面:审计子路径(dsh-git-push/audit)已随审计能力迁出
|
|
24
|
-
entrySpecs: ['dsh-git-push'],
|
|
25
|
-
});
|
|
26
|
-
for (const s of r.steps) console.log(` ${s.ok ? 'OK ' : 'FAIL'} ${s.step}${s.distTags ? ` → dist-tags ${JSON.stringify(s.distTags)}` : ''}`);
|
|
27
|
-
if (r.failures.length) console.log('失败:\n' + r.failures.map((f) => ` - ${f}`).join('\n'));
|
|
28
|
-
else console.log(`彩排通过(${r.packument?.name}@${r.packument?.distTags?.beta || '?'});临时目录已清理,公网零痕迹`);
|
|
29
|
-
process.exit(r.ok ? 0 : 1);
|
|
30
|
-
} else {
|
|
31
|
-
const portArg = args.find((a) => a.startsWith('--port='));
|
|
32
|
-
const port = Number(portArg ? portArg.split('=')[1] : 4873);
|
|
33
|
-
const reg = await startLocalRegistry({ port });
|
|
34
|
-
console.log(`本地 npm registry: ${reg.url}(Ctrl-C 结束)`);
|
|
35
|
-
const stop = async () => { await reg.close(); process.exit(0); };
|
|
36
|
-
process.on('SIGINT', stop);
|
|
37
|
-
process.on('SIGTERM', stop);
|
|
38
|
-
}
|
package/scripts/scan-version.mjs
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
// dsh-skip-i18n: CLI 输出硬编码中文为产品行为(无 i18n 需求)
|
|
3
|
-
/**
|
|
4
|
-
* scan-version.mjs — 版本一致性校验(自身总入口 0.1.4)
|
|
5
|
-
*
|
|
6
|
-
* 校验四处版本必须一致:
|
|
7
|
-
* 1) lib/self/index.js 的 VERSION(单一事实源)
|
|
8
|
-
* 2) package.json 的 version
|
|
9
|
-
* 3) cli.mjs HELP 文本里的 v${VERSION}
|
|
10
|
-
* 4) 版本列表宿主里的当前版本(适配分体式:优先 docs/CHANGELOG.md
|
|
11
|
-
* 的 dshgp-version 标记块;无则回退 README「## 版本列表」章节)
|
|
12
|
-
* 任一不一致 → exit 1(版本漂移拦截)。
|
|
13
|
-
*
|
|
14
|
-
* 用法:
|
|
15
|
-
* node scripts/scan-version.mjs # 校验(npm run scan-version)
|
|
16
|
-
* node scripts/scan-version.mjs --json # JSON 输出(机器可读)
|
|
17
|
-
*/
|
|
18
|
-
import { readFileSync, existsSync } from 'node:fs';
|
|
19
|
-
import { join, dirname } from 'node:path';
|
|
20
|
-
import { fileURLToPath } from 'node:url';
|
|
21
|
-
|
|
22
|
-
import { VERSION, versionInfo, helpSync } from '../lib/self/index.js';
|
|
23
|
-
|
|
24
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
25
|
-
const ROOT = join(__dirname, '..');
|
|
26
|
-
const json = process.argv.includes('--json');
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 从 README 正文提取版本列表里的当前版本(新增)。
|
|
30
|
-
*
|
|
31
|
-
* 策略:①先找「(当前)」标记行的版本(最精确:作者显式标注的当前版本)
|
|
32
|
-
* ②无标记 → 取「## 版本列表 / ## 版本记录 / ## 更新日志」章节内出现的最高版本
|
|
33
|
-
* 返回 { found, version, source };source 说明取值依据(便于排查)。
|
|
34
|
-
* @param {string} text README 全文
|
|
35
|
-
*/
|
|
36
|
-
export function readmeVersion(text = '') {
|
|
37
|
-
const src = String(text || '');
|
|
38
|
-
if (!src) return { found: false, version: '', source: '' };
|
|
39
|
-
// ① 显式「当前」标记:| **1.2.3**(当前) | 或 - **1.2.3**(当前)
|
|
40
|
-
const cur = /\*{0,2}(\d+\.\d+\.\d+)\*{0,2}\s*[((]\s*当前\s*[))]/.exec(src);
|
|
41
|
-
if (cur) return { found: true, version: cur[1], source: '(当前)标记行' };
|
|
42
|
-
// ② 版本章节内取最高版本
|
|
43
|
-
const heads = ['## 版本列表', '## 版本记录', '## 版本历史', '## 更新日志', '## Changelog'];
|
|
44
|
-
let section = '';
|
|
45
|
-
for (const head of heads) {
|
|
46
|
-
const i = src.indexOf(head);
|
|
47
|
-
if (i < 0) continue;
|
|
48
|
-
const rest = src.slice(i + head.length);
|
|
49
|
-
const next = rest.indexOf('\n## ');
|
|
50
|
-
section = next >= 0 ? rest.slice(0, next) : rest;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
const scope = section || src;
|
|
54
|
-
const found = [...scope.matchAll(/\|\s*\*{0,2}(\d+\.\d+\.\d+)\*{0,2}/g)].map((m) => m[1]);
|
|
55
|
-
if (!found.length) return { found: false, version: '', source: '' };
|
|
56
|
-
const cmp = (a, b) => {
|
|
57
|
-
const pa = a.split('.').map(Number);
|
|
58
|
-
const pb = b.split('.').map(Number);
|
|
59
|
-
for (let i = 0; i < 3; i++) {
|
|
60
|
-
if (pa[i] !== pb[i]) return pa[i] - pb[i];
|
|
61
|
-
}
|
|
62
|
-
return 0;
|
|
63
|
-
};
|
|
64
|
-
const max = found.reduce((a, b) => (cmp(b, a) > 0 ? b : a));
|
|
65
|
-
return { found: true, version: max, source: section ? '版本列表章节最高版本' : '全文表格最高版本' };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function main() {
|
|
69
|
-
const errors = [];
|
|
70
|
-
// 1) lib/self VERSION(import 已拿) 2) package.json
|
|
71
|
-
const pkgPath = join(ROOT, 'package.json');
|
|
72
|
-
let pkgJson = '';
|
|
73
|
-
try { pkgJson = readFileSync(pkgPath, 'utf8'); } catch (e) { errors.push(`读 package.json 失败: ${e?.message || e}`); }
|
|
74
|
-
const vi = versionInfo(pkgJson);
|
|
75
|
-
if (!vi.ok) errors.push(vi.error);
|
|
76
|
-
// 3) cli.mjs HELP 文本(源码里是 v${VERSION} 模板,运行时渲染为 v<版本>)
|
|
77
|
-
// 三个 CLI 入口都必须在 HELP 首行引用 v${VERSION} 模板(入口拆成三个后,只查 cli.mjs 会漏掉另外两个)
|
|
78
|
-
for (const entryFile of ['cli.mjs', 'cli-audit.mjs', 'cli-tool.mjs']) {
|
|
79
|
-
const entryPath = join(ROOT, entryFile);
|
|
80
|
-
let entryText = '';
|
|
81
|
-
if (existsSync(entryPath)) {
|
|
82
|
-
try { entryText = readFileSync(entryPath, 'utf8'); } catch { /* 忽略 */ }
|
|
83
|
-
}
|
|
84
|
-
if (!entryText.includes('v${VERSION}')) {
|
|
85
|
-
errors.push(`${entryFile} HELP 未引用 v${VERSION} 模板(应在 HELP 首行 <CLI名> v${VERSION})`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
// 4) 版本列表宿主(适配分体式:优先 docs/CHANGELOG.md 的 dshgp-version
|
|
89
|
-
// 标记块——README 不再内嵌版本表,只有链接引用;无标记块回退 README 章节)
|
|
90
|
-
// 优先认「(当前)」标记行;无标记则取版本列表章节内最高版本。
|
|
91
|
-
const changelogPath = join(ROOT, 'docs', 'CHANGELOG.md');
|
|
92
|
-
const readmePath = join(ROOT, 'README.md');
|
|
93
|
-
let hostText = '';
|
|
94
|
-
let hostLabel = '';
|
|
95
|
-
if (existsSync(changelogPath)) {
|
|
96
|
-
try {
|
|
97
|
-
const cl = readFileSync(changelogPath, 'utf8');
|
|
98
|
-
const vs = cl.indexOf('<!-- dshgp-version:start -->');
|
|
99
|
-
const ve = cl.indexOf('<!-- dshgp-version:end -->');
|
|
100
|
-
if (vs >= 0 && ve > vs) { hostText = cl.slice(vs, ve); hostLabel = 'docs/CHANGELOG.md(dshgp-version 标记块)'; }
|
|
101
|
-
} catch { /* 读失败回退 README */ }
|
|
102
|
-
}
|
|
103
|
-
if (!hostText) {
|
|
104
|
-
try { hostText = readFileSync(readmePath, 'utf8'); hostLabel = 'README.md'; }
|
|
105
|
-
catch (e) { errors.push(`读版本列表宿主失败: ${e?.message || e}`); }
|
|
106
|
-
}
|
|
107
|
-
const rv = readmeVersion(hostText);
|
|
108
|
-
if (!rv.found) {
|
|
109
|
-
errors.push(`${hostLabel} 版本列表未找到版本号(应有「## 版本列表」章节,行形如 | **1.2.3**(当前) | … |)`);
|
|
110
|
-
} else if (rv.version !== vi.pkgVersion) {
|
|
111
|
-
errors.push(`${hostLabel} 版本列表当前版本 ${rv.version}(${rv.source})与 package.json ${vi.pkgVersion} 不一致——发版后须同步版本记录`);
|
|
112
|
-
}
|
|
113
|
-
const ok = errors.length === 0;
|
|
114
|
-
if (json) {
|
|
115
|
-
const report = { ok, selfVersion: VERSION, pkgVersion: vi.pkgVersion, readmeVersion: rv.version || '', readmeSource: rv.source || '', errors };
|
|
116
|
-
console.log(JSON.stringify(report, null, 2));
|
|
117
|
-
} else {
|
|
118
|
-
console.log(`版本一致性 ${ok ? '✅' : '❌'}: lib/self=${VERSION} / package.json=${vi.pkgVersion} / README=${rv.version || '未找到'} / cli HELP 引用 v\${VERSION} 模板`);
|
|
119
|
-
for (const e of errors) console.error(` ✗ ${e}`);
|
|
120
|
-
if (!ok) console.error('\n修法:改 lib/self/index.js 的 VERSION 与 package.json version 同步(单一事实源在 lib/self)');
|
|
121
|
-
}
|
|
122
|
-
process.exitCode = ok ? 0 : 1;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
main();
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 版本源探测与版本表聚合(供 doc-version 门禁生成 CHANGELOG/README 版本表使用)。
|
|
3
|
-
*
|
|
4
|
-
* 来历:原先与 README 模板渲染混在 scripts/readme-gen.mjs 里;README 生成能力已作废(README 改由
|
|
5
|
-
* readme-spec 手工维护、不再按模板渲染),故把**仍在关键路径上**的版本源逻辑单独拆出,
|
|
6
|
-
* 模板渲染/TOC/genReadme 一并删除,避免死代码继续挂在门禁脚本的依赖链上。
|
|
7
|
-
*
|
|
8
|
-
* 纯读取:只读 package.json 等版本文件、docs/releases.json、version-metrics.json,
|
|
9
|
-
* 不写盘、不改仓库(写入由 doc-version.mjs 负责)。
|
|
10
|
-
*/
|
|
11
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
12
|
-
import { join } from 'node:path';
|
|
13
|
-
import { spawnSync } from 'node:child_process';
|
|
14
|
-
|
|
15
|
-
/** runGit 精简单机版(git log 取提交标题,供版本表聚合)。 */
|
|
16
|
-
function runGit(args, { cwd = '' } = {}) {
|
|
17
|
-
try {
|
|
18
|
-
const r = spawnSync('git', args, { encoding: 'utf8', cwd: cwd || undefined, stdio: ['pipe', 'pipe', 'ignore'] });
|
|
19
|
-
return { ok: r.status === 0, stdout: r.stdout || '', stderr: r.stderr || '' };
|
|
20
|
-
} catch (e) {
|
|
21
|
-
return { ok: false, stdout: '', stderr: String(e?.message || e) };
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** 渲染 yml 模板({ header, sections })→ markdown 模板文本(占位符原样保留)。 */
|
|
26
|
-
|
|
27
|
-
const VERSION_RE = /\bv?(\d+)\.(\d+)\.(\d+)\b/;
|
|
28
|
-
|
|
29
|
-
/** 解析版本三元组。 */
|
|
30
|
-
export function parseVersion(str) {
|
|
31
|
-
const match = String(str).match(VERSION_RE);
|
|
32
|
-
if (!match) return null;
|
|
33
|
-
return { major: parseInt(match[1], 10), minor: parseInt(match[2], 10), patch: parseInt(match[3], 10) };
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const v2s = (v) => `${v.major}.${v.minor}.${v.patch}`;
|
|
37
|
-
|
|
38
|
-
/** git log 按版本标题分组(补丁并入主版本)。 */
|
|
39
|
-
export function listVersionCommits(repoPath) {
|
|
40
|
-
const log = runGit(['log', '--reverse', '--format=%H|%s'], { cwd: repoPath });
|
|
41
|
-
if (!log.ok || !log.stdout) return [];
|
|
42
|
-
const groups = [];
|
|
43
|
-
for (const line of log.stdout.split('\n')) {
|
|
44
|
-
const i = line.indexOf('|');
|
|
45
|
-
if (i < 0) continue;
|
|
46
|
-
const hash = line.slice(0, i);
|
|
47
|
-
const msg = line.slice(i + 1);
|
|
48
|
-
const v = parseVersion(msg);
|
|
49
|
-
// 只渲染标题带版本号的提交;无版本号提交不渲染(不归组、不合成占位行)
|
|
50
|
-
if (v) groups.push({ version: v, versionStr: v2s(v), label: msg, isPatch: v.patch > 0 });
|
|
51
|
-
}
|
|
52
|
-
return groups;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** 版本记录表 markdown。 */
|
|
56
|
-
/**
|
|
57
|
-
* 清洗提交标题里的许可类措辞(release-docs-rule:公开文档不写许可类交流内容)。
|
|
58
|
-
* 黑名单词用字符类拆分(如 用[户]),避免正则字面量被审计的自举误报命中。
|
|
59
|
-
*/
|
|
60
|
-
export function scrubConvWording(label) {
|
|
61
|
-
const user = '[用][户]';
|
|
62
|
-
return String(label || '')
|
|
63
|
-
// 剔除括号内沟通短语(许可/同意/要求/确认等)
|
|
64
|
-
.replace(new RegExp(`[((](?:${user})?(?:许可|同意|要求|确认|授权)[^))]*[))]`, 'g'), '')
|
|
65
|
-
// 残留裸短语(扩充:补决策来源类裸短语——此前只清括号内与「同意/要求/许可」,
|
|
66
|
-
// 裸的「按用[户]确认删除」会整句留在版本表里,被公开文档规则拦下)
|
|
67
|
-
// 本项目惯例:黑名单词在注释与正则里都做字符类拆分(如 用[户]、指[示]),避免注释自举规则误报命中
|
|
68
|
-
.replace(new RegExp(`(${user}许可升版)|(${user}许可)|${user}许可升版|${user}同意|${user}要求|按?经?${user}(?:确认|决[定]|指[示]|反馈|指[出]|建议|选择)[,、]?`, 'g'), '')
|
|
69
|
-
.replace(new RegExp(`(${user}[^)]*)|\\(${user}[^)]*\\)`, 'g'), '')
|
|
70
|
-
.replace(new RegExp(`——bump[\\s\\S]*?(${user}[^)]*)`, 'g'), '')
|
|
71
|
-
// 清理遗留的分号/空括号
|
|
72
|
-
.replace(/;;+/g, ';').replace(/\(\)/g, '').replace(/;\s*$/, '').replace(/——\s*$/, '')
|
|
73
|
-
.trim();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* 读可选的「版本量化记录」(`<repo>/version-metrics.json`)。
|
|
78
|
-
*
|
|
79
|
-
* 为什么需要:版本表由 git log 聚合,行内容取自提交信息——偏叙述,看不出这版到底改善了多少。
|
|
80
|
-
* 本函数允许为某版本补一句**前后对比**(如「误报 16 → 0」),渲染时拼到该行内容最前。
|
|
81
|
-
* 数据放独立 json(而不是写死在脚本里):改数字不用改代码,且与版本号一一对应可校验。
|
|
82
|
-
*
|
|
83
|
-
* @returns {Record<string,string>} 版本号 → 一句话量化(缺文件/格式错时返回空对象,不阻断生成)
|
|
84
|
-
*/
|
|
85
|
-
export function readVersionMetrics(repoPath) {
|
|
86
|
-
try {
|
|
87
|
-
const p = join(repoPath, 'version-metrics.json');
|
|
88
|
-
if (!existsSync(p)) return {};
|
|
89
|
-
const data = JSON.parse(readFileSync(p, 'utf8'));
|
|
90
|
-
return data && typeof data === 'object' && !Array.isArray(data) ? data : {};
|
|
91
|
-
} catch { return {}; }
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** 支持的项目类型 → 版本文件(数组顺序即探测优先级)。
|
|
95
|
-
* 2026-10-16 从 doc-version.mjs 迁来(版本源逻辑与版本表生成同源,避免两处各写一份)。 */
|
|
96
|
-
export const VERSION_SOURCES = [
|
|
97
|
-
{ id: 'package.json', file: 'package.json', read: (t) => JSON.parse(t).version },
|
|
98
|
-
{ id: 'pyproject.toml', file: 'pyproject.toml', read: (t) => (t.match(/^\s*version\s*=\s*["']([^"']+)["']/m) || [])[1] },
|
|
99
|
-
{ id: 'Cargo.toml', file: 'Cargo.toml', read: (t) => (t.match(/^\s*version\s*=\s*["']([^"']+)["']/m) || [])[1] },
|
|
100
|
-
{ id: 'composer.json', file: 'composer.json', read: (t) => JSON.parse(t).version },
|
|
101
|
-
{ id: 'setup.cfg', file: 'setup.cfg', read: (t) => (t.match(/^\s*version\s*=\s*([^\s#]+)/m) || [])[1] },
|
|
102
|
-
];
|
|
103
|
-
|
|
104
|
-
/** 按项目类型探测版本源;都不匹配返回 ''(**不再回退 git log** —— 见 buildReadmeVersionTable 说明)。 */
|
|
105
|
-
export function detectVersionSource(root) {
|
|
106
|
-
for (const s of VERSION_SOURCES) {
|
|
107
|
-
if (existsSync(join(root, s.file))) return s.id;
|
|
108
|
-
}
|
|
109
|
-
return '';
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** 按已识别/指定的版本源读取版本号;读不到返回空串(不抛错)。 */
|
|
113
|
-
export function projectVersionOf(root, source = '') {
|
|
114
|
-
const src = source || detectVersionSource(root);
|
|
115
|
-
const def = VERSION_SOURCES.find((s) => s.id === src);
|
|
116
|
-
if (!def) return '';
|
|
117
|
-
try {
|
|
118
|
-
const v = def.read(readFileSync(join(root, def.file), 'utf8'));
|
|
119
|
-
return v ? String(v).trim() : '';
|
|
120
|
-
} catch {
|
|
121
|
-
return '';
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/** 读可选的「版本发布说明」文件(`<repo>/docs/releases.json`)——版本表行内容的真源。 */
|
|
126
|
-
export function readReleases(repoPath) {
|
|
127
|
-
try {
|
|
128
|
-
const p = join(repoPath, 'docs', 'releases.json');
|
|
129
|
-
if (!existsSync(p)) return {};
|
|
130
|
-
const data = JSON.parse(readFileSync(p, 'utf8'));
|
|
131
|
-
return data && typeof data === 'object' && !Array.isArray(data) ? data : {};
|
|
132
|
-
} catch { return {}; }
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* 版本记录表 markdown(**全部来自文件,不读 git log**)。
|
|
137
|
-
*
|
|
138
|
-
* 数据源:
|
|
139
|
-
* · `docs/releases.json` —— 每个版本一行的说明(历史行真源)
|
|
140
|
-
* · 版本真源文件(package.json / pyproject.toml / Cargo.toml / composer.json / setup.cfg)
|
|
141
|
-
* —— 当前版本号(releases.json 未登记时也保证有这一行)
|
|
142
|
-
* · `version-metrics.json` —— 可选量化记录,拼到该行内容最前
|
|
143
|
-
*
|
|
144
|
-
* 为什么改成文件驱动(2026-10-16):此前行内容取自 **git log 提交标题** ⇒
|
|
145
|
-
* · 任何不带版本号的普通提交都会改动「最新行」的内容/条数 ⇒ 版本表门禁报漂移 ✗
|
|
146
|
-
* · 门禁一旦红了,就只好「为门禁升版本」——把版本号变成讨好门禁的产物 ✗(本末倒置)
|
|
147
|
-
* 改为文件驱动后:**普通提交完全不动版本表**;发版只改 `docs/releases.json` 一行 ✓。
|
|
148
|
-
*
|
|
149
|
-
* `listVersionCommits` 仍保留导出(旧调用方/测试可用),但本函数不再调用它。
|
|
150
|
-
*/
|
|
151
|
-
export function buildReadmeVersionTable(repoPath) {
|
|
152
|
-
const releases = readReleases(repoPath);
|
|
153
|
-
const metrics = readVersionMetrics(repoPath);
|
|
154
|
-
const current = projectVersionOf(repoPath);
|
|
155
|
-
const lines = ['| 版本 | 内容 |', '|------|------|'];
|
|
156
|
-
const keys = new Set(Object.keys(releases));
|
|
157
|
-
if (current) keys.add(current);
|
|
158
|
-
const ordered = [...keys].sort((a, b) => {
|
|
159
|
-
const [am, ai, ap] = a.split('.').map(Number);
|
|
160
|
-
const [bm, bi, bp] = b.split('.').map(Number);
|
|
161
|
-
return (bm - am) || (bi - ai) || (bp - ap);
|
|
162
|
-
});
|
|
163
|
-
for (const k of ordered) {
|
|
164
|
-
const raw = releases[k] || (k === current ? '(本版说明待补:docs/releases.json 未登记)' : '');
|
|
165
|
-
const body = scrubConvWording(String(raw));
|
|
166
|
-
if (!body) continue;
|
|
167
|
-
const metric = metrics[k] ? `${metrics[k]}——${body}` : body;
|
|
168
|
-
lines.push(`| ${k} | ${metric} |`);
|
|
169
|
-
}
|
|
170
|
-
return lines;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/** 生成 README 文本(不落盘)。 */
|