@hugesb/dsh-stream-agent 0.0.0-stage → 0.3.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.
- package/CHANGELOG.md +497 -0
- package/CONTRIBUTING.md +72 -0
- package/LICENSE +202 -0
- package/README.en.md +349 -0
- package/README.md +300 -3
- package/cordis.patch.yml +77 -0
- package/dist/entry/action-gate.js +206 -0
- package/dist/entry/adapter-kit.js +192 -0
- package/dist/entry/context-render.js +119 -0
- package/dist/entry/control-bar-cli.js +289 -0
- package/dist/entry/control-bar.js +123 -0
- package/dist/entry/control-session.js +115 -0
- package/dist/entry/control-state.js +125 -0
- package/dist/entry/cordis-compat.js +95 -0
- package/dist/entry/eval-probe.js +112 -0
- package/dist/entry/intent-log.js +121 -0
- package/dist/entry/json-persistence.js +306 -0
- package/dist/entry/loop.js +3852 -0
- package/dist/entry/mock-provider.js +536 -0
- package/dist/entry/obs-broker.js +178 -0
- package/dist/entry/ptc-bridge.js +405 -0
- package/dist/entry/state-handle.js +217 -0
- package/dist/entry/takeover-registry.js +60 -0
- package/dist/kernel/control-bar.js +559 -0
- package/dist/kernel/final.js +62 -0
- package/dist/kernel/gate.js +464 -0
- package/dist/kernel/modes.js +253 -0
- package/dist/kernel/obs.js +517 -0
- package/dist/kernel/parser.js +632 -0
- package/dist/kernel/render.js +444 -0
- package/dist/kernel/state.js +416 -0
- package/dist/version.js +9 -0
- package/docs/TEST-PROPOSITIONS.md +139 -0
- package/docs/adr-001-segment-boundary.md +61 -0
- package/docs/architecture.md +104 -0
- package/docs/desktop-ui-feasibility.md +277 -0
- package/docs/disabled-lines-audit.md +53 -0
- package/docs/limitations.md +181 -0
- package/docs/protocol.md +99 -0
- package/docs/v0.4.0-plan.md +50 -0
- package/eval/METRICS.md +128 -0
- package/eval/RESULTS.md +246 -0
- package/eval/tasks/fixtures/big-report.md +298 -0
- package/eval/tasks/fixtures/build-manifest.txt +5 -0
- package/eval/tasks/fixtures/deploy.yaml +4 -0
- package/eval/tasks/fixtures/error.log +200 -0
- package/eval/tasks/fixtures/features.yaml +4 -0
- package/eval/tasks/fixtures/pipeline.yaml +4 -0
- package/eval/tasks/fixtures/sales-q1.csv +61 -0
- package/eval/tasks/fixtures/settings.yaml +4 -0
- package/eval/tasks/fixtures/users-roster.json +304 -0
- package/eval/tasks/fixtures/users-scores.json +20 -0
- package/eval/tasks/gen-fixtures.cjs +80 -0
- package/eval/tasks/tasks.json +150 -0
- package/eval/tools/f6-kill-drill.cjs +176 -0
- package/eval/tools/f6-kill-drill.worker.cjs +131 -0
- package/eval/tools/gen-results.cjs +191 -0
- package/eval/tools/machine-test.cjs +200 -0
- package/eval/tools/manual-code-scenarios.md +59 -0
- package/eval/tools/replay-check.cjs +311 -0
- package/eval/tools/runner.cjs +219 -0
- package/eval/tools/session-log.cjs +106 -0
- package/eval/tools/summarize.cjs +185 -0
- package/eval/tools/t3-cells.cjs +173 -0
- package/package.json +73 -6
- package/patches/adapters-smoke.yml +41 -0
- package/patches/eval-account.yml +36 -0
- package/patches/eval-baseline.yml +33 -0
- package/patches/eval-stream-code-off.yml +46 -0
- package/patches/eval-stream-code-on.yml +47 -0
- package/patches/eval-stream.yml +54 -0
- package/patches/takeover.yml +42 -0
- package/patches/test-preset.yml +23 -0
- package/preset/stream/cordis.patch.yml +39 -0
- package/preset/stream/package.json +13 -0
- package/preset.yml +56 -0
- package/profiles/stream/README.md +66 -0
- package/profiles/stream/cordis.patch.yml +12 -0
- package/profiles/stream/package.json +17 -0
- package/profiles/stream-headless/package.json +16 -0
- package/scripts/build.mjs +103 -0
- package/scripts/check-consistency.mjs +146 -0
- package/scripts/gate.mjs +138 -0
- package/scripts/install-check.mjs +116 -0
- package/scripts/install-cycle.mjs +88 -0
- package/scripts/release.mjs +415 -0
- package/scripts/repair-session-logs.mjs +403 -0
- package/src/entry/action-gate.ts +206 -0
- package/src/entry/adapter-kit.ts +192 -0
- package/src/entry/context-render.ts +119 -0
- package/src/entry/control-bar-cli.ts +289 -0
- package/src/entry/control-bar.ts +123 -0
- package/src/entry/control-session.ts +115 -0
- package/src/entry/control-state.ts +125 -0
- package/src/entry/cordis-compat.ts +95 -0
- package/src/entry/eval-probe.ts +112 -0
- package/src/entry/intent-log.ts +121 -0
- package/src/entry/json-persistence.ts +306 -0
- package/src/entry/loop.ts +3852 -0
- package/src/entry/mock-provider.ts +536 -0
- package/src/entry/obs-broker.ts +178 -0
- package/src/entry/ptc-bridge.ts +405 -0
- package/src/entry/state-handle.ts +217 -0
- package/src/entry/takeover-registry.ts +60 -0
- package/src/kernel/control-bar.ts +559 -0
- package/src/kernel/final.ts +62 -0
- package/src/kernel/gate.ts +464 -0
- package/src/kernel/modes.ts +253 -0
- package/src/kernel/obs.ts +517 -0
- package/src/kernel/parser.ts +632 -0
- package/src/kernel/render.ts +444 -0
- package/src/kernel/state.ts +416 -0
- package/src/version.ts +9 -0
- package/test/activation.test.ts +187 -0
- package/test/adapters.test.ts +676 -0
- package/test/control-bar.test.ts +486 -0
- package/test/desktop-ui.test.ts +359 -0
- package/test/eval-probe.test.ts +139 -0
- package/test/f5-plan.test.ts +221 -0
- package/test/f6-intent.test.ts +168 -0
- package/test/f7-segment.test.ts +190 -0
- package/test/fix-limits.test.ts +599 -0
- package/test/gate.test.ts +380 -0
- package/test/helpers/stub-loop.ts +240 -0
- package/test/kernel/obs.test.ts +329 -0
- package/test/kernel/parser.test.ts +450 -0
- package/test/loop.test.ts +1393 -0
- package/test/mock-provider.test.ts +386 -0
- package/test/ptc-bridge.test.ts +356 -0
- package/test/render.test.ts +418 -0
- package/test/s2-install-check.test.ts +46 -0
- package/test/scenarios/3-file-basic.json +13 -0
- package/test/scenarios/5-file-basic.json +22 -0
- package/test/scenarios/burn-more.json +9 -0
- package/test/scenarios/degraded-final.json +10 -0
- package/test/scenarios/fault-abort-xml.json +11 -0
- package/test/scenarios/fault-malformed-command.json +12 -0
- package/test/scenarios/fault-midstream-abort.json +11 -0
- package/test/scenarios/fault-saturating-output.json +9 -0
- package/test/scenarios/fault-timeout.json +9 -0
- package/test/scenarios/peek-first.json +11 -0
- package/test/scenarios/peek-second.json +11 -0
- package/test/scenarios/peek-third.json +10 -0
- package/test/scenarios/recover-final.json +10 -0
- package/test/scenarios/reroute-first.json +17 -0
- package/test/scenarios/reroute-second.json +16 -0
- package/test/scenarios/starvation-final.json +10 -0
- package/test/scenarios/starvation-promote.json +11 -0
- package/test/scenarios/wait-tools-continue.json +10 -0
- package/test/scenarios/wait-tools-xml.json +22 -0
- package/test/scenarios/wait-tools.json +15 -0
- package/test/session-format.test.ts +234 -0
- package/test/state.test.ts +335 -0
- package/test/stream-v02.test.ts +264 -0
- package/test/v031-display.test.ts +333 -0
- package/ui/client.js +576 -0
- package/ui/index.js +282 -0
- package/ui/package.json +26 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// scripts/install-check.mjs —— S2 安装前置校验:本插件只允许装进专用 profile(stream 及其入口变体)
|
|
2
|
+
//
|
|
3
|
+
// 用法:
|
|
4
|
+
// node scripts/install-check.mjs --profile <名字|目录> [--dry-run] [--plugin-root <目录>]
|
|
5
|
+
//
|
|
6
|
+
// 行为:
|
|
7
|
+
// · 校验发生在"写入之前"的语义:只读检查,不做任何写操作;拒绝时给出台 unacceptable 原因,
|
|
8
|
+
// 不提供"强制安装"开关(计划硬约束)。
|
|
9
|
+
// · --dry-run 打印:目标 profile、将写入的组合包(dependencies)、将应用的 patch(主 bundle +
|
|
10
|
+
// preset bundle + profile patch)、预计影响的 entry。
|
|
11
|
+
// · 允许列表:stream、stream-headless(计划内 profile 名及其入口变体)。其余(web / desktop /
|
|
12
|
+
// headless 等既有 profile)一律拒绝并说明原因——A-1 的隔离来自"专用 profile 只装这一套"。
|
|
13
|
+
//
|
|
14
|
+
// 退出码:0 = 允许;2 = 拒绝;3 = 用法错误。
|
|
15
|
+
|
|
16
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
17
|
+
import { basename, isAbsolute, join, resolve } from 'node:path';
|
|
18
|
+
import { fileURLToPath } from 'node:url';
|
|
19
|
+
import { dirname } from 'node:path';
|
|
20
|
+
|
|
21
|
+
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
|
22
|
+
const pkgRoot = resolve(scriptDir, '..');
|
|
23
|
+
|
|
24
|
+
const ALLOWED_PROFILES = new Set(['stream', 'stream-headless']);
|
|
25
|
+
|
|
26
|
+
function arg(name) {
|
|
27
|
+
const i = process.argv.indexOf(`--${name}`);
|
|
28
|
+
return i >= 0 && i + 1 < process.argv.length ? process.argv[i + 1] : undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function flag(name) {
|
|
32
|
+
return process.argv.includes(`--${name}`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function fail(code, lines) {
|
|
36
|
+
for (const line of lines) console.error(line);
|
|
37
|
+
process.exit(code);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const pluginRootArg = arg('plugin-root');
|
|
41
|
+
const pluginRoot = pluginRootArg !== undefined ? resolve(pluginRootArg) : pkgRoot;
|
|
42
|
+
const profileArg = arg('profile');
|
|
43
|
+
if (profileArg === undefined) {
|
|
44
|
+
fail(3, ['用法:node scripts/install-check.mjs --profile <名字|目录> [--dry-run] [--plugin-root <目录>]']);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 目标 profile:名字或目录(含 package.json 的 profile 目录)
|
|
48
|
+
let profileName;
|
|
49
|
+
let profileDir = null;
|
|
50
|
+
if (isAbsolute(profileArg) || profileArg.includes('/') || profileArg.includes('\\')) {
|
|
51
|
+
profileDir = resolve(profileArg);
|
|
52
|
+
const pkgPath = join(profileDir, 'package.json');
|
|
53
|
+
if (!existsSync(pkgPath)) {
|
|
54
|
+
fail(2, [`[install-check] 拒绝:目标目录不是 dsh profile(缺 package.json):${profileDir}`]);
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
|
58
|
+
profileName = basename(profileDir);
|
|
59
|
+
void pkg;
|
|
60
|
+
} catch (error) {
|
|
61
|
+
fail(2, [`[install-check] 拒绝:profile package.json 解析失败:${error instanceof Error ? error.message : String(error)}`]);
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
profileName = profileArg;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const dryRun = flag('dry-run');
|
|
68
|
+
const lines = [];
|
|
69
|
+
lines.push(`[install-check] 目标 profile:${profileName}${profileDir !== null ? `(${profileDir})` : ''}`);
|
|
70
|
+
|
|
71
|
+
// 1. 允许列表(唯一判定来源;不自动改写用户 profile、不静默覆盖)
|
|
72
|
+
if (!ALLOWED_PROFILES.has(profileName)) {
|
|
73
|
+
fail(2, [
|
|
74
|
+
...lines,
|
|
75
|
+
`[install-check] 拒绝:profile "${profileName}" 不是本插件的专用 profile。`,
|
|
76
|
+
`[install-check] 允许列表:${[...ALLOWED_PROFILES].join('、')}(S2:误装到 web/desktop 等既有 profile 会全局接管其 loop,一律拒绝)。`,
|
|
77
|
+
`[install-check] 处置:用 profiles/stream(web 入口)或 profiles/stream-headless(headless 入口)模板创建专用 profile 后再安装。`,
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 2. 主 bundle 与 preset bundle 的 patch 在位( dry-run 打印装配面)
|
|
82
|
+
const mainPatch = join(pluginRoot, 'cordis.patch.yml');
|
|
83
|
+
const presetPatch = join(pluginRoot, 'preset', 'stream', 'cordis.patch.yml');
|
|
84
|
+
if (!existsSync(mainPatch)) {
|
|
85
|
+
fail(2, [...lines, `[install-check] 拒绝:主 bundle patch 缺失:${mainPatch}`]);
|
|
86
|
+
}
|
|
87
|
+
const pluginPkg = JSON.parse(readFileSync(join(pluginRoot, 'package.json'), 'utf8'));
|
|
88
|
+
const presetPkg = existsSync(join(pluginRoot, 'preset', 'stream', 'package.json'))
|
|
89
|
+
? JSON.parse(readFileSync(join(pluginRoot, 'preset', 'stream', 'package.json'), 'utf8'))
|
|
90
|
+
: null;
|
|
91
|
+
|
|
92
|
+
lines.push(`[install-check] 主 bundle:${pluginPkg.name}@${pluginPkg.version}(patch:cordis.patch.yml)`);
|
|
93
|
+
if (profileName === 'stream' && presetPkg !== null) {
|
|
94
|
+
lines.push(`[install-check] preset bundle:${presetPkg.name}(patch:preset/stream/cordis.patch.yml,列在主 bundle 之后)`);
|
|
95
|
+
}
|
|
96
|
+
if (profileName === 'stream-headless') {
|
|
97
|
+
lines.push('[install-check] headless 入口:不引入 preset bundle(宿主无 registry;工具面由 profile 决定)');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (profileDir !== null) {
|
|
101
|
+
const profilePkgPath = join(profileDir, 'package.json');
|
|
102
|
+
const profilePkg = JSON.parse(readFileSync(profilePkgPath, 'utf8'));
|
|
103
|
+
const deps = profilePkg.dependencies ?? {};
|
|
104
|
+
const entryCounts = {
|
|
105
|
+
mainPatchEntries: (readFileSync(mainPatch, 'utf8').match(/- id: stream-agent/g) ?? []).length,
|
|
106
|
+
loopDisabled: readFileSync(mainPatch, 'utf8').includes('agent-loop'),
|
|
107
|
+
};
|
|
108
|
+
lines.push(`[install-check] profile bundles:${JSON.stringify(profilePkg.dsh?.profile?.bundles ?? [])}`);
|
|
109
|
+
lines.push(`[install-check] 现有 dependencies:${JSON.stringify(deps)}`);
|
|
110
|
+
lines.push(`[install-check] 将应用的 patch:主 bundle(停用 agent-loop + 7 entry,loop 最后)${profileName === 'stream' ? ' + preset-stream(工具面)' : ''} + profile patch(registry default 覆盖)`);
|
|
111
|
+
lines.push(`[install-check] 预计影响 entry:stream-agent-state / obs-broker / action-gate / context-render / control-bar / ui / stream-agent(loop)`);
|
|
112
|
+
lines.push(`[install-check] patch 健康检查:agent-loop 停用行在主 bundle patch = ${entryCounts.loopDisabled ? '是(卸载原子性保持,C4)' : '否(缺陷)'}`);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
lines.push('[install-check] 结论:允许(专用 profile 校验通过;未写入任何东西——实际安装由 dsh plugin add / profile 组合完成)。');
|
|
116
|
+
for (const line of lines) console.log(line);
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// scripts/install-cycle.mjs —— S6 装卸与回退演练驱动:10 次安装/卸载循环 + 宿主恢复验证
|
|
2
|
+
//
|
|
3
|
+
// 用法:
|
|
4
|
+
// node scripts/install-cycle.mjs --dsh <dsh 可执行> --profile <专用 profile 名> [--rounds 10]
|
|
5
|
+
// node scripts/install-cycle.mjs --plan-only # 只打印演练计划(不执行,用于无宿主环境)
|
|
6
|
+
//
|
|
7
|
+
// 每轮循环(一个完整装卸周期):
|
|
8
|
+
// 1. dsh plugin add <插件根目录> --profile <目标> (安装前由 install-check 前置校验)
|
|
9
|
+
// 2. 启动自证:dsh --profile <目标> headless 冒烟一次,断言横幅 TAKEOVER-ACTIVE / loop=stream
|
|
10
|
+
// 3. dsh plugin remove <插件名> --profile <目标>
|
|
11
|
+
// 4. 卸载验证:宿主 loop 恢复(agent-loop 重新可用);web 能创建会话;无 stream-agent-* 残留 entry
|
|
12
|
+
//
|
|
13
|
+
// 红线(C8/C3):任一轮失败即中止并保留现场日志(--keep 给出日志目录);回退路径是
|
|
14
|
+
// "回退到 0.2.x 产物(B 形态)或删除专用 profile",不手工修 profile。
|
|
15
|
+
//
|
|
16
|
+
// 本脚本只在有真实 dsh 宿主的机器上执行;CI / 无宿主环境用 --plan-only 打印计划。
|
|
17
|
+
|
|
18
|
+
import { spawnSync } from 'node:child_process';
|
|
19
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
20
|
+
import { tmpdir } from 'node:os';
|
|
21
|
+
import { join } from 'node:path';
|
|
22
|
+
import { fileURLToPath } from 'node:url';
|
|
23
|
+
import { dirname, resolve } from 'node:path';
|
|
24
|
+
|
|
25
|
+
const scriptDir = dirname(fileURLToPath(import.meta.url));
|
|
26
|
+
const pkgRoot = resolve(scriptDir, '..');
|
|
27
|
+
|
|
28
|
+
function arg(name, def) {
|
|
29
|
+
const i = process.argv.indexOf(`--${name}`);
|
|
30
|
+
return i >= 0 && i + 1 < process.argv.length ? process.argv[i + 1] : def;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const dsh = arg('dsh');
|
|
34
|
+
const profile = arg('profile', 'stream');
|
|
35
|
+
const rounds = Number(arg('rounds', '10'));
|
|
36
|
+
const planOnly = process.argv.includes('--plan-only');
|
|
37
|
+
const pluginName = '@hugesb/dsh-stream-agent';
|
|
38
|
+
|
|
39
|
+
function run(cmd, args) {
|
|
40
|
+
const r = spawnSync(cmd, args, { encoding: 'utf8', shell: process.platform === 'win32' });
|
|
41
|
+
return { code: r.status ?? -1, stdout: r.stdout ?? '', stderr: r.stderr ?? '' };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (planOnly) {
|
|
45
|
+
console.log(`[install-cycle] 演练计划(--plan-only,不执行):`);
|
|
46
|
+
console.log(` 目标 profile:${profile}(必须是专用 profile;install-check 前置校验先跑)`);
|
|
47
|
+
console.log(` 轮次:${rounds},每轮:plugin add → 启动自证(TAKEOVER-ACTIVE) → plugin remove → 恢复验证(无残留 entry)`);
|
|
48
|
+
console.log(` 判定:10/10 轮通过 = S6 交付;任一轮失败保留现场日志并中止`);
|
|
49
|
+
console.log(` 回退:删除专用 profile 或回退 0.2.x 产物(B 形态),不手工修 profile`);
|
|
50
|
+
process.exit(0);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (dsh === undefined) {
|
|
54
|
+
console.error('用法:node scripts/install-cycle.mjs --dsh <dsh 可执行> --profile <专用 profile 名> [--rounds 10]');
|
|
55
|
+
console.error('无宿主环境请用 --plan-only 查看演练计划。');
|
|
56
|
+
process.exit(3);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const workdir = mkdtempSync(join(tmpdir(), 'install-cycle-'));
|
|
60
|
+
let failures = 0;
|
|
61
|
+
console.log(`[install-cycle] ${rounds} 轮装卸演练:profile=${profile} plugin=${pluginName}`);
|
|
62
|
+
for (let i = 1; i <= rounds; i++) {
|
|
63
|
+
const add = run(dsh, ['plugin', 'add', pkgRoot, '--profile', profile]);
|
|
64
|
+
const smoke = run(dsh, ['--profile', profile, 'headless', '--once', 'smoke']);
|
|
65
|
+
const remove = run(dsh, ['plugin', 'remove', pluginName, '--profile', profile]);
|
|
66
|
+
const restore = run(dsh, ['--profile', profile, 'headless', '--once', 'smoke']);
|
|
67
|
+
const ok = add.code === 0
|
|
68
|
+
&& smoke.stdout.includes('TAKEOVER-ACTIVE')
|
|
69
|
+
&& remove.code === 0
|
|
70
|
+
&& restore.code === 0
|
|
71
|
+
&& !restore.stdout.includes('TAKEOVER-ACTIVE')
|
|
72
|
+
&& !restore.stdout.includes('stream-agent');
|
|
73
|
+
console.log(` round ${i}: add=${add.code} takeover=${smoke.stdout.includes('TAKEOVER-ACTIVE') ? 'yes' : 'no'} remove=${remove.code} restore=${restore.code === 0 && !restore.stdout.includes('stream-agent') ? 'clean' : 'residue'} → ${ok ? 'OK' : 'FAIL'}`);
|
|
74
|
+
if (!ok) {
|
|
75
|
+
failures += 1;
|
|
76
|
+
console.error(` 现场保留:${workdir}`);
|
|
77
|
+
console.error(` add.stderr: ${add.stderr.slice(0, 400)}`);
|
|
78
|
+
console.error(` smoke.stderr: ${smoke.stderr.slice(0, 400)}`);
|
|
79
|
+
console.error(` restore.stdout: ${restore.stdout.slice(0, 400)}`);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (failures === 0) {
|
|
84
|
+
rmSync(workdir, { recursive: true, force: true });
|
|
85
|
+
console.log(`[install-cycle] 通过:${rounds}/${rounds} 轮,0 残留,宿主 loop 恢复(S6/C8 达成)。`);
|
|
86
|
+
} else {
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 一键发布:构建 → 测试 → 版本 → GitHub(commit/tag/Release)→ npm。
|
|
4
|
+
*
|
|
5
|
+
* node scripts/release.mjs # 版本已手动改过就沿用,否则 patch+1
|
|
6
|
+
* node scripts/release.mjs --minor # 需要新特性时
|
|
7
|
+
* node scripts/release.mjs --set 0.2.0-rc.1 # 显式指定(预发布自动发 alpha dist-tag)
|
|
8
|
+
* node scripts/release.mjs --dry-run # 只演练,不提交不推送不发布
|
|
9
|
+
*
|
|
10
|
+
* 常用开关:--no-npm --no-github --skip-tests --message "..." --yes --force-tag
|
|
11
|
+
*
|
|
12
|
+
* 设计约束(踩过的坑,别改):
|
|
13
|
+
* - 版本沿用规则:package.json 的 version 比最近 tag 新 → 认为已手动 bump,不再加一。
|
|
14
|
+
* - tag 必须与 package.json 一致,否则中止(CI/Release 链接会错位)。
|
|
15
|
+
* - 构建后校验 dist 与 src 同步:dist 是入库产物且被 patch 直接引用,忘了重建会静默落后。
|
|
16
|
+
* - 任何一步失败立即中止,绝不"继续发布后半段"。
|
|
17
|
+
*/
|
|
18
|
+
import { execFileSync, execSync } from 'node:child_process';
|
|
19
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
20
|
+
import path from 'node:path';
|
|
21
|
+
import { fileURLToPath } from 'node:url';
|
|
22
|
+
|
|
23
|
+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
24
|
+
const WIN = process.platform === 'win32';
|
|
25
|
+
const NPM = WIN ? 'npm.cmd' : 'npm';
|
|
26
|
+
const DRY = has('dry-run');
|
|
27
|
+
const YES = has('yes');
|
|
28
|
+
|
|
29
|
+
/* ── 输出 ─────────────────────────────────────────────── */
|
|
30
|
+
const C = process.stdout.isTTY
|
|
31
|
+
? { g: '\x1b[32m', r: '\x1b[31m', y: '\x1b[33m', d: '\x1b[2m', b: '\x1b[1m', x: '\x1b[0m' }
|
|
32
|
+
: { g: '', r: '', y: '', d: '', b: '', x: '' };
|
|
33
|
+
const step = (n, s) => console.log(`\n${C.b}[${n}]${C.x} ${s}`);
|
|
34
|
+
const ok = (s) => console.log(` ${C.g}✓${C.x} ${s}`);
|
|
35
|
+
const warn = (s) => console.log(` ${C.y}!${C.x} ${s}`);
|
|
36
|
+
const info = (s) => console.log(` ${C.d}${s}${C.x}`);
|
|
37
|
+
function die(s, detail) {
|
|
38
|
+
console.error(`\n ${C.r}✗ ${s}${C.x}`);
|
|
39
|
+
if (detail) console.error(` ${C.d}${String(detail).trim().split('\n').slice(0, 12).join('\n ')}${C.x}`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function has(name) {
|
|
44
|
+
return process.argv.includes(`--${name}`);
|
|
45
|
+
}
|
|
46
|
+
function opt(name, fallback) {
|
|
47
|
+
const i = process.argv.indexOf(`--${name}`);
|
|
48
|
+
return i >= 0 && process.argv[i + 1] ? process.argv[i + 1] : fallback;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function sh(cmd, argv = [], { inherit = false, input } = {}) {
|
|
52
|
+
return execFileSync(cmd, argv, {
|
|
53
|
+
cwd: ROOT,
|
|
54
|
+
encoding: 'utf8',
|
|
55
|
+
stdio: inherit ? 'inherit' : ['pipe', 'pipe', 'pipe'],
|
|
56
|
+
input,
|
|
57
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: '0' },
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* npm 在 Windows 上是 npm.cmd,execFileSync 直接调会 ENOENT,必须过 shell;
|
|
62
|
+
* 这里参数都是固定标识符(--access public 之类),拼接无注入风险。
|
|
63
|
+
*/
|
|
64
|
+
function npmRun(argv, { inherit = false, input } = {}) {
|
|
65
|
+
const line = [NPM, ...argv].join(' ');
|
|
66
|
+
return execSync(line, {
|
|
67
|
+
cwd: ROOT,
|
|
68
|
+
encoding: 'utf8',
|
|
69
|
+
stdio: inherit ? 'inherit' : ['pipe', 'pipe', 'pipe'],
|
|
70
|
+
input,
|
|
71
|
+
env: { ...process.env, NO_COLOR: '1' },
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function shOk(cmd, argv = []) {
|
|
75
|
+
try {
|
|
76
|
+
sh(cmd, argv);
|
|
77
|
+
return true;
|
|
78
|
+
} catch {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const gitOut = (argv) => sh('git', argv).trim();
|
|
83
|
+
|
|
84
|
+
/* ── 版本工具 ─────────────────────────────────────────── */
|
|
85
|
+
const parseVer = (v) => {
|
|
86
|
+
const m = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?$/.exec(v.trim());
|
|
87
|
+
if (!m) throw new Error(`版本号不合法:${v}`);
|
|
88
|
+
return { major: +m[1], minor: +m[2], patch: +m[3], pre: m[4] || '' };
|
|
89
|
+
};
|
|
90
|
+
const fmtVer = (v) => `${v.major}.${v.minor}.${v.patch}${v.pre ? '-' + v.pre : ''}`;
|
|
91
|
+
function bump(v, kind) {
|
|
92
|
+
const n = { ...v, pre: '' };
|
|
93
|
+
if (kind === 'major') return { ...n, major: n.major + 1, minor: 0, patch: 0 };
|
|
94
|
+
if (kind === 'minor') return { ...n, minor: n.minor + 1, patch: 0 };
|
|
95
|
+
return { ...n, patch: n.patch + 1 };
|
|
96
|
+
}
|
|
97
|
+
const cmp = (a, b) => a.major - b.major || a.minor - b.minor || a.patch - b.patch;
|
|
98
|
+
|
|
99
|
+
/* ════════════════════════════════════════════════════════ */
|
|
100
|
+
console.log(`${C.b}dsh-stream-agent${C.x} · 一键发布${DRY ? ` ${C.y}(dry-run)${C.x}` : ''}`);
|
|
101
|
+
console.log(`${C.d}${ROOT}${C.x}`);
|
|
102
|
+
|
|
103
|
+
/* ── 0. 前置检查 ──────────────────────────────────────── */
|
|
104
|
+
step(0, '前置检查');
|
|
105
|
+
|
|
106
|
+
if (!shOk('git', ['rev-parse', '--is-inside-work-tree'])) die('当前目录不在 git 仓库内');
|
|
107
|
+
|
|
108
|
+
const branch = gitOut(['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
109
|
+
if (branch !== 'main' && !has('force-branch')) die(`当前分支是 ${branch},发布只允许在 main(--force-branch 可跳过)`);
|
|
110
|
+
ok(`分支 ${branch}`);
|
|
111
|
+
|
|
112
|
+
if (!shOk('git', ['remote', 'get-url', 'origin'])) die('未配置 origin 远端');
|
|
113
|
+
const remote = gitOut(['remote', 'get-url', 'origin']);
|
|
114
|
+
ok(`远端 ${remote.replace(/\/\/[^@]*@/, '//***@')}`);
|
|
115
|
+
|
|
116
|
+
const pkgPath = path.join(ROOT, 'package.json');
|
|
117
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
|
118
|
+
ok(`包名 ${pkg.name} · 当前版本 ${pkg.version}`);
|
|
119
|
+
|
|
120
|
+
const npmUser = (() => {
|
|
121
|
+
try {
|
|
122
|
+
return npmRun(['whoami']).trim();
|
|
123
|
+
} catch {
|
|
124
|
+
return '';
|
|
125
|
+
}
|
|
126
|
+
})();
|
|
127
|
+
if (!has('no-npm')) {
|
|
128
|
+
if (!npmUser) die('npm 未登录', '先在终端执行:npm login --auth-type=web');
|
|
129
|
+
ok(`npm 已登录:${npmUser}`);
|
|
130
|
+
const scope = pkg.name.startsWith('@') ? pkg.name.split('/')[0].slice(1) : '';
|
|
131
|
+
if (scope && scope !== npmUser) {
|
|
132
|
+
die(
|
|
133
|
+
`包名 scope 是 @${scope},但当前 npm 账号是 ${npmUser}`,
|
|
134
|
+
'scoped 包只能发到自己的用户名或自己所属的组织下,请改 package.json 的 name',
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
if (scope === npmUser) info(`scope @${scope} 与账号一致 ✓`);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/* ── 1. 计算目标版本 ──────────────────────────────────── */
|
|
141
|
+
step(1, '确定版本');
|
|
142
|
+
|
|
143
|
+
let lastTag = '';
|
|
144
|
+
try {
|
|
145
|
+
lastTag = gitOut(['describe', '--tags', '--abbrev=0', '--match', 'v*']);
|
|
146
|
+
} catch {
|
|
147
|
+
warn('仓库还没有任何 v* 标签,视为首次发布');
|
|
148
|
+
}
|
|
149
|
+
const lastVer = lastTag ? parseVer(lastTag.replace(/^v/, '')) : parseVer('0.0.0');
|
|
150
|
+
const curVer = parseVer(pkg.version);
|
|
151
|
+
const explicit = opt('set');
|
|
152
|
+
const kind = has('major') ? 'major' : has('minor') ? 'minor' : 'patch';
|
|
153
|
+
|
|
154
|
+
let target;
|
|
155
|
+
if (explicit) {
|
|
156
|
+
target = explicit.replace(/^v/, '');
|
|
157
|
+
ok(`显式指定版本 ${target}`);
|
|
158
|
+
} else if (has('keep')) {
|
|
159
|
+
target = pkg.version;
|
|
160
|
+
ok(`沿用 package.json 版本 ${target}(--keep)`);
|
|
161
|
+
} else if (lastTag && cmp(curVer, lastVer) > 0) {
|
|
162
|
+
target = pkg.version;
|
|
163
|
+
ok(`沿用 package.json 已 bump 的版本 ${target}(上一 tag ${lastTag})`);
|
|
164
|
+
} else {
|
|
165
|
+
target = fmtVer(bump(lastVer, kind));
|
|
166
|
+
ok(`按 ${kind} 递增:${lastTag || '(无)'} → ${target}`);
|
|
167
|
+
}
|
|
168
|
+
const targetVer = parseVer(target);
|
|
169
|
+
const tagName = `v${target}`;
|
|
170
|
+
|
|
171
|
+
if (existsTag(tagName) && !has('force-tag')) {
|
|
172
|
+
const pointsAt = gitOut(['rev-list', '-n', '1', tagName]);
|
|
173
|
+
const head = gitOut(['rev-parse', 'HEAD']);
|
|
174
|
+
if (pointsAt !== head) die(`标签 ${tagName} 已存在且不指向当前 HEAD`, '确需覆盖请加 --force-tag');
|
|
175
|
+
warn(`标签 ${tagName} 已存在并指向 HEAD,将跳过打标签`);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function existsTag(name) {
|
|
179
|
+
return shOk('git', ['rev-parse', '-q', '--verify', `refs/tags/${name}`]);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/* ── 2. 构建 + 测试 ───────────────────────────────────── */
|
|
183
|
+
if (!has('skip-tests')) {
|
|
184
|
+
step(2, '构建(dist 与 src 必须同步)');
|
|
185
|
+
try {
|
|
186
|
+
npmRun(['run', 'build'], { inherit: true });
|
|
187
|
+
} catch (e) {
|
|
188
|
+
die('构建失败', e.stdout || e.message);
|
|
189
|
+
}
|
|
190
|
+
// 判定方式:连跑两次构建,若 dist 相对 HEAD 的变化集合在第二次仍相同,说明构建幂等、
|
|
191
|
+
// dist 已与 src 对齐。不能用 `git diff --exit-code -- dist` —— 本次要提交的 dist 改动
|
|
192
|
+
// 本来就会显示为 diff,那样会把正常发布误判成"dist 过期"。
|
|
193
|
+
const dirty1 = gitOut(['status', '--porcelain', '--', 'dist']);
|
|
194
|
+
try {
|
|
195
|
+
npmRun(['run', 'build']);
|
|
196
|
+
} catch (e) {
|
|
197
|
+
die('二次构建失败(构建不确定)', e.stdout || e.message);
|
|
198
|
+
}
|
|
199
|
+
const dirty2 = gitOut(['status', '--porcelain', '--', 'dist']);
|
|
200
|
+
if (dirty1 !== dirty2) die('构建结果不稳定:连续两次构建产出不同的 dist');
|
|
201
|
+
if (dirty2) warn('dist 相对 HEAD 有变化,将随本次提交一并入库');
|
|
202
|
+
ok('dist 与 src 同步(构建幂等)');
|
|
203
|
+
|
|
204
|
+
step(3, '测试');
|
|
205
|
+
try {
|
|
206
|
+
npmRun(['test'], { inherit: true });
|
|
207
|
+
} catch (e) {
|
|
208
|
+
die('测试未通过,已中止发布', e.stdout || e.message);
|
|
209
|
+
}
|
|
210
|
+
} else {
|
|
211
|
+
warn('已跳过构建与测试(--skip-tests)');
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/* ── 4. 写入版本号 ────────────────────────────────────── */
|
|
215
|
+
step(4, `写入版本 ${target}`);
|
|
216
|
+
if (pkg.version !== target) {
|
|
217
|
+
if (DRY) {
|
|
218
|
+
warn(`dry-run:本应把 package.json 从 ${pkg.version} 改为 ${target}`);
|
|
219
|
+
} else {
|
|
220
|
+
pkg.version = target;
|
|
221
|
+
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
|
222
|
+
ok(`package.json → ${target}`);
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
ok('package.json 已是目标版本');
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// CHANGELOG 必须有一条对应小节,否则 Release 说明是空的
|
|
229
|
+
const changelogPath = path.join(ROOT, 'CHANGELOG.md');
|
|
230
|
+
const changelog = readFileSync(changelogPath, 'utf8');
|
|
231
|
+
const hasSection = new RegExp(`^## \\[${target.replace(/\./g, '\\.')}\\]`, 'm').test(changelog);
|
|
232
|
+
if (!hasSection) {
|
|
233
|
+
warn(`CHANGELOG.md 缺少「## [${target}]」小节——Release 说明将退回 git log`);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/* ── 5. 提交 ──────────────────────────────────────────── */
|
|
237
|
+
step(5, '提交改动');
|
|
238
|
+
const dirty = gitOut(['status', '--porcelain', '--untracked-files=all']) !== '';
|
|
239
|
+
let commitMsg = opt('message', '');
|
|
240
|
+
if (dirty) {
|
|
241
|
+
const files = gitOut(['status', '--porcelain', '--untracked-files=all'])
|
|
242
|
+
.split('\n')
|
|
243
|
+
.map((l) => l.slice(3))
|
|
244
|
+
.filter(Boolean);
|
|
245
|
+
info(`待提交 ${files.length} 个文件`);
|
|
246
|
+
if (!commitMsg) {
|
|
247
|
+
commitMsg = `chore(release): ${tagName}\n\n${files.slice(0, 20).map((f) => `- ${f}`).join('\n')}${
|
|
248
|
+
files.length > 20 ? `\n- …共 ${files.length} 个` : ''
|
|
249
|
+
}`;
|
|
250
|
+
}
|
|
251
|
+
if (DRY) {
|
|
252
|
+
warn('dry-run:跳过 git add/commit');
|
|
253
|
+
} else {
|
|
254
|
+
sh('git', ['add', '-A']);
|
|
255
|
+
sh('git', ['commit', '-q', '-F', '-'], { input: commitMsg });
|
|
256
|
+
ok(`已提交 ${gitOut(['rev-parse', '--short', 'HEAD'])}`);
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
ok('工作区干净,无需提交');
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/* ── 6. 打标签 ────────────────────────────────────────── */
|
|
263
|
+
step(6, `标签 ${tagName}`);
|
|
264
|
+
if (existsTag(tagName)) {
|
|
265
|
+
ok('标签已存在,跳过');
|
|
266
|
+
} else if (DRY) {
|
|
267
|
+
warn(`dry-run:本应创建 ${tagName}`);
|
|
268
|
+
} else {
|
|
269
|
+
sh('git', ['tag', '-a', tagName, '-m', `${tagName} —— ${pkg.description || pkg.name}`]);
|
|
270
|
+
ok(`已创建注解标签 ${tagName}`);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/* ── 7. 推 GitHub ─────────────────────────────────────── */
|
|
274
|
+
const ghToken = (() => {
|
|
275
|
+
if (has('no-github')) return '';
|
|
276
|
+
try {
|
|
277
|
+
const out = sh('git', ['credential', 'fill'], { input: 'protocol=https\nhost=github.com\n\n' });
|
|
278
|
+
return (/^password=(.+)$/m.exec(out) || [])[1] || '';
|
|
279
|
+
} catch {
|
|
280
|
+
return '';
|
|
281
|
+
}
|
|
282
|
+
})();
|
|
283
|
+
|
|
284
|
+
if (!has('no-github')) {
|
|
285
|
+
step(7, '推送 GitHub');
|
|
286
|
+
if (DRY) {
|
|
287
|
+
warn('dry-run:跳过 git push');
|
|
288
|
+
} else {
|
|
289
|
+
let pushed = false;
|
|
290
|
+
// 先试直连(无代理时更快),失败再走环境代理
|
|
291
|
+
for (const attempt of [1, 2]) {
|
|
292
|
+
try {
|
|
293
|
+
sh('git', ['push', 'origin', branch, '--follow-tags'], { inherit: true, timeout: 180000 });
|
|
294
|
+
pushed = true;
|
|
295
|
+
break;
|
|
296
|
+
} catch {
|
|
297
|
+
if (attempt === 1) warn('推送失败,用环境代理重试…');
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (!pushed) die('git push 失败(网络/代理问题)', '确认代理可用后重试;本地提交与标签都已就绪');
|
|
301
|
+
ok('main 与标签已推送');
|
|
302
|
+
|
|
303
|
+
/* Release */
|
|
304
|
+
if (!ghToken) {
|
|
305
|
+
warn('没拿到 GitHub 凭据,跳过 Release 创建(标签已推,可手动补)');
|
|
306
|
+
} else {
|
|
307
|
+
try {
|
|
308
|
+
const body = renderReleaseBody(target, changelog);
|
|
309
|
+
const res = await fetch(`https://api.github.com/repos/${repoSlug()}/releases`, {
|
|
310
|
+
method: 'POST',
|
|
311
|
+
headers: {
|
|
312
|
+
Authorization: `Bearer ${ghToken}`,
|
|
313
|
+
Accept: 'application/vnd.github+json',
|
|
314
|
+
'Content-Type': 'application/json',
|
|
315
|
+
'User-Agent': 'dsh-stream-agent-release',
|
|
316
|
+
},
|
|
317
|
+
body: JSON.stringify({
|
|
318
|
+
tag_name: tagName,
|
|
319
|
+
name: `${tagName} —— ${pkg.name.split('/').pop()}`,
|
|
320
|
+
body,
|
|
321
|
+
draft: false,
|
|
322
|
+
prerelease: Boolean(targetVer.pre),
|
|
323
|
+
}),
|
|
324
|
+
});
|
|
325
|
+
const j = await res.json();
|
|
326
|
+
if (j.html_url) ok(`Release:${j.html_url}`);
|
|
327
|
+
else if (String(j.message || '').includes('already_exists')) warn('Release 已存在,跳过');
|
|
328
|
+
else warn(`Release 创建失败:${String(j.message || JSON.stringify(j)).slice(0, 160)}`);
|
|
329
|
+
} catch (e) {
|
|
330
|
+
warn(`Release 创建异常:${e.message}`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/* ── 8. npm 发布 ──────────────────────────────────────── */
|
|
337
|
+
if (!has('no-npm')) {
|
|
338
|
+
step(8, `发布 npm ${pkg.name}@${target}`);
|
|
339
|
+
const exists = (() => {
|
|
340
|
+
try {
|
|
341
|
+
return npmRun(['view', `${pkg.name}@${target}`, 'version']).trim() === target;
|
|
342
|
+
} catch {
|
|
343
|
+
return false;
|
|
344
|
+
}
|
|
345
|
+
})();
|
|
346
|
+
if (exists) {
|
|
347
|
+
die(`${pkg.name}@${target} 已存在于 npm`, '版本号必须递增:改 CHANGELOG 后加 --minor 或 --set x.y.z');
|
|
348
|
+
}
|
|
349
|
+
const distTag = targetVer.pre ? 'alpha' : 'latest';
|
|
350
|
+
const pubArgs = ['publish', '--access', 'public', '--tag', distTag];
|
|
351
|
+
if (DRY) {
|
|
352
|
+
warn(`dry-run:本节将执行 npm ${pubArgs.join(' ')}`);
|
|
353
|
+
try {
|
|
354
|
+
npmRun(['pack', '--dry-run'], { inherit: true });
|
|
355
|
+
} catch {
|
|
356
|
+
/* 演练失败不算错 */
|
|
357
|
+
}
|
|
358
|
+
} else {
|
|
359
|
+
try {
|
|
360
|
+
npmRun(pubArgs, { inherit: true });
|
|
361
|
+
} catch (e) {
|
|
362
|
+
const out = String(e.stdout || '') + String(e.stderr || '');
|
|
363
|
+
if (/E403|403/.test(out) && /two-factor|2fa/i.test(out)) {
|
|
364
|
+
die(
|
|
365
|
+
'npm 拒绝了发布:账号要求 2FA,网页登录的会话 token 不能直接发布',
|
|
366
|
+
[
|
|
367
|
+
'两个办法(推荐第一个,配一次以后就不用管):',
|
|
368
|
+
' 1. 建 Granular Access Token 并勾选 “Bypass two-factor authentication”',
|
|
369
|
+
' https://www.npmjs.com/settings/<你的用户名>/tokens → Generate New Token',
|
|
370
|
+
' 权限 Read and write、scopes 选 @' + (pkg.name.split('/')[0].slice(1) || '') + ',然后写入:',
|
|
371
|
+
' npm config set //registry.npmjs.org/:_authToken=npm_xxx',
|
|
372
|
+
' 2. 临时用验证码:npm publish --otp=123456',
|
|
373
|
+
].join('\n'),
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
die('npm publish 失败', e.stdout || e.message);
|
|
377
|
+
}
|
|
378
|
+
ok(`已发布 ${pkg.name}@${target}(dist-tag: ${distTag})`);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/* ── 收尾 ─────────────────────────────────────────────── */
|
|
383
|
+
if (DRY) {
|
|
384
|
+
console.log(`\n${C.y}${C.b}dry-run 结束${C.x} 目标 ${pkg.name}@${target}(未提交、未推送、未发布)`);
|
|
385
|
+
process.exit(0);
|
|
386
|
+
}
|
|
387
|
+
console.log(`\n${C.g}${C.b}发布完成${C.x} ${pkg.name}@${target}`);
|
|
388
|
+
console.log(` 安装:dsh plugin --profile headless add ${pkg.name}`);
|
|
389
|
+
console.log(` npm :https://www.npmjs.com/package/${pkg.name}`);
|
|
390
|
+
console.log(` 仓库:https://github.com/${repoSlug()}/releases/tag/${tagName}`);
|
|
391
|
+
|
|
392
|
+
/* ── 辅助 ─────────────────────────────────────────────── */
|
|
393
|
+
function repoSlug() {
|
|
394
|
+
const url = gitOut(['remote', 'get-url', 'origin']);
|
|
395
|
+
const m = /github\.com[:/]([^/]+)\/([^/.]+?)(?:\.git)?$/.exec(url);
|
|
396
|
+
return m ? `${m[1]}/${m[2]}` : 'unknown/unknown';
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function renderReleaseBody(version, md) {
|
|
400
|
+
const start = md.indexOf(`## [${version}]`);
|
|
401
|
+
if (start >= 0) {
|
|
402
|
+
const rest = md.slice(start);
|
|
403
|
+
const end = rest.indexOf('\n## [', 1);
|
|
404
|
+
const section = (end > 0 ? rest.slice(0, end) : rest).replace(/^## \[[^\]]+\][^\n]*\n+/, '');
|
|
405
|
+
return `${section.trim()}\n\n---\n\n安装:\`dsh plugin --profile headless add ${pkg.name}\``;
|
|
406
|
+
}
|
|
407
|
+
// 没有 CHANGELOG 条目时退回提交列表
|
|
408
|
+
let log = '';
|
|
409
|
+
try {
|
|
410
|
+
log = gitOut(['log', '--pretty=format:- %s', `${lastTag || ''}..HEAD`]);
|
|
411
|
+
} catch {
|
|
412
|
+
log = '';
|
|
413
|
+
}
|
|
414
|
+
return `${log || '- 见提交历史'}\n\n---\n\n安装:\`dsh plugin --profile headless add ${pkg.name}\``;
|
|
415
|
+
}
|