create-clis 0.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/LICENSE +21 -0
- package/README.md +113 -0
- package/README.zh-CN.md +113 -0
- package/assets/manifest.json +99 -0
- package/assets/template/.editorconfig +12 -0
- package/assets/template/.gitattributes +18 -0
- package/assets/template/.github/ISSUE_TEMPLATE/bug_report.yml +86 -0
- package/assets/template/.github/ISSUE_TEMPLATE/feature_request.yml +45 -0
- package/assets/template/.github/PULL_REQUEST_TEMPLATE.md +26 -0
- package/assets/template/.github/workflows/ci.yml +42 -0
- package/assets/template/.github/workflows/release.yml +65 -0
- package/assets/template/.gitignorerc.json +21 -0
- package/assets/template/.nvmrc +1 -0
- package/assets/template/.oxlintrc.json +52 -0
- package/assets/template/.prettierignore +11 -0
- package/assets/template/.prettierrc +11 -0
- package/assets/template/.releaserc.json +17 -0
- package/assets/template/.vscode/extensions.json +8 -0
- package/assets/template/.vscode/launch.json +13 -0
- package/assets/template/.vscode/settings.json +14 -0
- package/assets/template/AGENTS.md +25 -0
- package/assets/template/CODE_OF_CONDUCT.md +91 -0
- package/assets/template/CONTRIBUTING.md +85 -0
- package/assets/template/CONTRIBUTING.zh-CN.md +85 -0
- package/assets/template/LICENSE +21 -0
- package/assets/template/README.md +22 -0
- package/assets/template/README.zh-CN.md +22 -0
- package/assets/template/SECURITY.md +21 -0
- package/assets/template/_gitignore +409 -0
- package/assets/template/_npmrc +6 -0
- package/assets/template/bunfig.toml +16 -0
- package/assets/template/docs/README.md +30 -0
- package/assets/template/docs/adrs/README.md +7 -0
- package/assets/template/docs/designs/README.md +11 -0
- package/assets/template/docs/designs/tech-debt.md +22 -0
- package/assets/template/docs/development.md +59 -0
- package/assets/template/lefthook.yml +55 -0
- package/assets/template/package.json +38 -0
- package/assets/template/packages/{{NAME}}/CHANGELOG.md +3 -0
- package/assets/template/packages/{{NAME}}/LICENSE +21 -0
- package/assets/template/packages/{{NAME}}/README.md +33 -0
- package/assets/template/packages/{{NAME}}/README.zh-CN.md +33 -0
- package/assets/template/packages/{{NAME}}/docs/README.md +21 -0
- package/assets/template/packages/{{NAME}}/package.json +40 -0
- package/assets/template/packages/{{NAME}}/scripts/build.ts +82 -0
- package/assets/template/packages/{{NAME}}/scripts/verify-release.test.ts +214 -0
- package/assets/template/packages/{{NAME}}/scripts/verify-release.ts +152 -0
- package/assets/template/packages/{{NAME}}/src/index.ts +15 -0
- package/assets/template/packages/{{NAME}}/tsconfig.build.json +12 -0
- package/assets/template/packages/{{NAME}}/tsconfig.json +5 -0
- package/assets/template/packages/{{NAME}}-cli/CHANGELOG.md +3 -0
- package/assets/template/packages/{{NAME}}-cli/LICENSE +21 -0
- package/assets/template/packages/{{NAME}}-cli/README.md +35 -0
- package/assets/template/packages/{{NAME}}-cli/README.zh-CN.md +35 -0
- package/assets/template/packages/{{NAME}}-cli/bin/{{BIN_NAME}} +30 -0
- package/assets/template/packages/{{NAME}}-cli/bin/{{BIN_NAME}}.cmd +30 -0
- package/assets/template/packages/{{NAME}}-cli/bin/{{BIN_NAME}}.d.mts +23 -0
- package/assets/template/packages/{{NAME}}-cli/bin/{{BIN_NAME}}.mjs +212 -0
- package/assets/template/packages/{{NAME}}-cli/docs/README.md +21 -0
- package/assets/template/packages/{{NAME}}-cli/package.json +48 -0
- package/assets/template/packages/{{NAME}}-cli/scripts/release-artifact.ts +141 -0
- package/assets/template/packages/{{NAME}}-cli/scripts/release.fixtures.ts +70 -0
- package/assets/template/packages/{{NAME}}-cli/scripts/verify-release.test.ts +444 -0
- package/assets/template/packages/{{NAME}}-cli/scripts/verify-release.ts +72 -0
- package/assets/template/packages/{{NAME}}-cli/scripts/write-dist-manifest.test.ts +126 -0
- package/assets/template/packages/{{NAME}}-cli/scripts/write-dist-manifest.ts +81 -0
- package/assets/template/packages/{{NAME}}-cli/src/cli.ts +36 -0
- package/assets/template/packages/{{NAME}}-cli/tsconfig.json +4 -0
- package/assets/template/scripts/ci.ts +163 -0
- package/assets/template/scripts/install-git-hooks.mjs +122 -0
- package/assets/template/scripts/install-git-hooks.test.ts +418 -0
- package/assets/template/scripts/lib/git-env.ts +21 -0
- package/assets/template/scripts/lib/release-verify.ts +431 -0
- package/assets/template/scripts/lib/tmp-root.ts +17 -0
- package/assets/template/scripts/lib/workspace.test.ts +92 -0
- package/assets/template/scripts/lib/workspace.ts +100 -0
- package/assets/template/scripts/lint-doc-examples.test.ts +129 -0
- package/assets/template/scripts/lint-doc-examples.ts +249 -0
- package/assets/template/scripts/lint-doc-references.test.ts +158 -0
- package/assets/template/scripts/lint-doc-references.ts +308 -0
- package/assets/template/scripts/lint-doc-shared.ts +59 -0
- package/assets/template/scripts/lint-stray-backups.test.ts +53 -0
- package/assets/template/scripts/lint-stray-backups.ts +39 -0
- package/assets/template/scripts/npm-trust-guard.test.ts +253 -0
- package/assets/template/scripts/npm-trust-guard.ts +533 -0
- package/assets/template/scripts/safe-install.ts +39 -0
- package/assets/template/scripts/transcription/api-harness.ts +219 -0
- package/assets/template/scripts/transcription/compare.ts +421 -0
- package/assets/template/scripts/transcription/corpus.ts +208 -0
- package/assets/template/scripts/transcription/fixture.ts +290 -0
- package/assets/template/scripts/transcription/make-mutants.ts +425 -0
- package/assets/template/scripts/transcription/report.ts +86 -0
- package/assets/template/scripts/transcription/run-conformance.ts +344 -0
- package/assets/template/scripts/transcription/validate-coverage.test.ts +119 -0
- package/assets/template/scripts/transcription/validate-coverage.ts +144 -0
- package/assets/template/scripts/transcription/validate.ts +366 -0
- package/assets/template/tsconfig.json +46 -0
- package/assets/template/turbo.jsonc +60 -0
- package/bin/create-clis +35 -0
- package/bin/create-clis.cmd +32 -0
- package/bin/create-clis.mjs +219 -0
- package/dist/create-clis.js +87682 -0
- package/dist/manifest.json +7 -0
- package/package.json +57 -0
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 转写契约套件 · 语料手写校验层 (schema 的物化子集)。
|
|
3
|
+
*
|
|
4
|
+
* 职责: 对 loadCorpus 读入的单条 case 做结构校验 (cli 与 api 两类按 kind 分流), 返回可读
|
|
5
|
+
* 问题清单; 字段语义以 docs/sweep/protocol/conformance/corpus.schema.json 为准, 本层只为尽早给出
|
|
6
|
+
* 报错, 不复刻 schema 的全部约束。
|
|
7
|
+
*/
|
|
8
|
+
import { isAbsolute } from 'node:path';
|
|
9
|
+
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// 手写校验 (schema 的物化子集)
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
const asRecord = (value: unknown): Record<string, unknown> | null =>
|
|
15
|
+
typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
16
|
+
? (value as Record<string, unknown>)
|
|
17
|
+
: null;
|
|
18
|
+
|
|
19
|
+
const ID_PATTERN = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
|
20
|
+
const SPEC_REF_PATTERN = /^[A-Z]{2,4}-[0-9]+$/;
|
|
21
|
+
|
|
22
|
+
/** 相对路径判定: 非空、非绝对 (含 win 盘符)、不含反斜杠与 '..' 段 */
|
|
23
|
+
function isSafeRelPath(value: unknown): value is string {
|
|
24
|
+
if (typeof value !== 'string' || value === '') return false;
|
|
25
|
+
if (isAbsolute(value) || /^[a-zA-Z]:/.test(value)) return false;
|
|
26
|
+
if (value.includes('\\')) return false;
|
|
27
|
+
return !value.split('/').includes('..');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** 校验单条 fixture.projects 项 (抽出以压平嵌套深度; 报错文案与顺序与内联时一致) */
|
|
31
|
+
function validateProjectEntry(
|
|
32
|
+
item: unknown,
|
|
33
|
+
index: number,
|
|
34
|
+
problems: string[],
|
|
35
|
+
): void {
|
|
36
|
+
const project = asRecord(item);
|
|
37
|
+
if (project === null || !isSafeRelPath(project.dir)) {
|
|
38
|
+
problems.push(`fixture.projects[${index}].dir 须为相对路径`);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
for (const key of ['files', 'bytesPerFile'] as const) {
|
|
42
|
+
const value = project[key];
|
|
43
|
+
if (
|
|
44
|
+
value !== undefined &&
|
|
45
|
+
(!Number.isInteger(value) || (value as number) < 0)
|
|
46
|
+
) {
|
|
47
|
+
problems.push(`fixture.projects[${index}].${key} 须为非负整数`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function validateFixture(fixture: unknown, problems: string[]): void {
|
|
53
|
+
const record = asRecord(fixture);
|
|
54
|
+
if (record === null) {
|
|
55
|
+
problems.push('fixture 缺失或不是对象');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const projects = record.projects;
|
|
59
|
+
if (projects !== undefined) {
|
|
60
|
+
if (!Array.isArray(projects)) {
|
|
61
|
+
problems.push('fixture.projects 须为数组');
|
|
62
|
+
} else {
|
|
63
|
+
for (const [index, item] of projects.entries()) {
|
|
64
|
+
validateProjectEntry(item, index, problems);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const symlinks = record.symlinks;
|
|
69
|
+
if (symlinks !== undefined) {
|
|
70
|
+
if (!Array.isArray(symlinks)) {
|
|
71
|
+
problems.push('fixture.symlinks 须为数组');
|
|
72
|
+
} else {
|
|
73
|
+
for (const [index, item] of symlinks.entries()) {
|
|
74
|
+
const link = asRecord(item);
|
|
75
|
+
if (
|
|
76
|
+
link === null ||
|
|
77
|
+
!isSafeRelPath(link.at) ||
|
|
78
|
+
!isSafeRelPath(link.to)
|
|
79
|
+
) {
|
|
80
|
+
problems.push(`fixture.symlinks[${index}] 的 at / to 须为相对路径`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const unreadable = record.unreadable;
|
|
86
|
+
if (unreadable !== undefined) {
|
|
87
|
+
if (!Array.isArray(unreadable) || !unreadable.every(isSafeRelPath)) {
|
|
88
|
+
problems.push('fixture.unreadable 须为相对路径数组');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const readonly = record.readonly;
|
|
92
|
+
if (readonly !== undefined) {
|
|
93
|
+
if (!Array.isArray(readonly) || !readonly.every(isSafeRelPath)) {
|
|
94
|
+
problems.push('fixture.readonly 须为相对路径数组');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function validateSetup(setup: unknown, problems: string[]): void {
|
|
100
|
+
if (setup === undefined) return;
|
|
101
|
+
if (!Array.isArray(setup)) {
|
|
102
|
+
problems.push('setup 须为数组');
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
for (const [index, item] of setup.entries()) {
|
|
106
|
+
const step = asRecord(item);
|
|
107
|
+
const write = step === null ? null : asRecord(step.write);
|
|
108
|
+
if (
|
|
109
|
+
write === null ||
|
|
110
|
+
!isSafeRelPath(write.path) ||
|
|
111
|
+
typeof write.text !== 'string'
|
|
112
|
+
) {
|
|
113
|
+
problems.push(
|
|
114
|
+
`setup[${index}] 须为 { write: { path: 相对路径, text: 字符串 } }`,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function validateRun(run: unknown, problems: string[]): void {
|
|
121
|
+
const record = asRecord(run);
|
|
122
|
+
if (record === null) {
|
|
123
|
+
problems.push('run 缺失或不是对象');
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const argv = record.argv;
|
|
127
|
+
if (
|
|
128
|
+
argv !== undefined &&
|
|
129
|
+
(!Array.isArray(argv) || !argv.every((item) => typeof item === 'string'))
|
|
130
|
+
) {
|
|
131
|
+
problems.push('run.argv 须为字符串数组');
|
|
132
|
+
}
|
|
133
|
+
const env = record.env;
|
|
134
|
+
if (env !== undefined) {
|
|
135
|
+
const envRecord = asRecord(env);
|
|
136
|
+
if (
|
|
137
|
+
envRecord === null ||
|
|
138
|
+
!Object.values(envRecord).every((item) => typeof item === 'string')
|
|
139
|
+
) {
|
|
140
|
+
problems.push('run.env 须为字符串值对象');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (record.cwd !== undefined && !isSafeRelPath(record.cwd)) {
|
|
144
|
+
problems.push('run.cwd 须为相对路径');
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** fs 断言族校验 (cli 与 api 两面共用) */
|
|
149
|
+
function validateFs(fs: unknown, problems: string[]): void {
|
|
150
|
+
if (fs === undefined) return;
|
|
151
|
+
if (!Array.isArray(fs)) {
|
|
152
|
+
problems.push('expect.fs 须为数组');
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
for (const [index, item] of fs.entries()) {
|
|
156
|
+
const entry = asRecord(item);
|
|
157
|
+
const state = entry === null ? undefined : entry.state;
|
|
158
|
+
if (
|
|
159
|
+
entry === null ||
|
|
160
|
+
!isSafeRelPath(entry.path) ||
|
|
161
|
+
!['gone', 'exists', 'empty'].includes(String(state))
|
|
162
|
+
) {
|
|
163
|
+
problems.push(
|
|
164
|
+
`expect.fs[${index}] 须为 { path: 相对路径, state: gone|exists|empty }`,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function validateExpect(expect: unknown, problems: string[]): void {
|
|
171
|
+
const record = asRecord(expect);
|
|
172
|
+
if (record === null) {
|
|
173
|
+
problems.push('expect 缺失或不是对象');
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
for (const key of ['result', 'error', 'events'] as const) {
|
|
177
|
+
if (record[key] !== undefined) {
|
|
178
|
+
problems.push(`expect.${key} 仅 api case 可用 (本 case 为 cli)`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (!Number.isInteger(record.exitCode)) {
|
|
182
|
+
problems.push('expect.exitCode 须为整数 (cli case 必填)');
|
|
183
|
+
}
|
|
184
|
+
if (
|
|
185
|
+
record.stdoutExact !== undefined &&
|
|
186
|
+
typeof record.stdoutExact !== 'string'
|
|
187
|
+
) {
|
|
188
|
+
problems.push('expect.stdoutExact 须为字符串');
|
|
189
|
+
}
|
|
190
|
+
for (const key of [
|
|
191
|
+
'stdoutContains',
|
|
192
|
+
'stdoutMustNotContain',
|
|
193
|
+
'stderrContains',
|
|
194
|
+
'stderrMustNotContain',
|
|
195
|
+
] as const) {
|
|
196
|
+
const value = record[key];
|
|
197
|
+
if (
|
|
198
|
+
value !== undefined &&
|
|
199
|
+
(!Array.isArray(value) ||
|
|
200
|
+
!value.every((item) => typeof item === 'string'))
|
|
201
|
+
) {
|
|
202
|
+
problems.push(`expect.${key} 须为字符串数组`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
validateFs(record.fs, problems);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** 环境增量校验 (api case 顶层 env; 与 run.env 同形态) */
|
|
209
|
+
function validateEnv(env: unknown, problems: string[]): void {
|
|
210
|
+
if (env === undefined) return;
|
|
211
|
+
const record = asRecord(env);
|
|
212
|
+
if (
|
|
213
|
+
record === null ||
|
|
214
|
+
!Object.values(record).every((item) => typeof item === 'string')
|
|
215
|
+
) {
|
|
216
|
+
problems.push('env 须为字符串值对象');
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** steps 校验 (api case): 每步恰为创建步 (call.export) 或方法步 (call.on + call.method) */
|
|
221
|
+
function validateSteps(steps: unknown, problems: string[]): void {
|
|
222
|
+
if (!Array.isArray(steps) || steps.length === 0) {
|
|
223
|
+
problems.push('steps 须为非空数组 (api case)');
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
for (const [index, item] of steps.entries()) {
|
|
227
|
+
const step = asRecord(item);
|
|
228
|
+
const call = step === null ? null : asRecord(step.call);
|
|
229
|
+
if (step === null || call === null) {
|
|
230
|
+
problems.push(`steps[${index}] 须为 { call: { ... } }`);
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
const hasExport = typeof call.export === 'string' && call.export !== '';
|
|
234
|
+
const hasOn = typeof call.on === 'string' && call.on !== '';
|
|
235
|
+
const hasMethod = typeof call.method === 'string' && call.method !== '';
|
|
236
|
+
if (!(hasExport !== (hasOn && hasMethod)) || hasOn !== hasMethod) {
|
|
237
|
+
problems.push(
|
|
238
|
+
`steps[${index}].call 须恰为创建步 (export) 或方法步 (on + method)`,
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
if (hasExport && step.collectEvents === true) {
|
|
242
|
+
problems.push(`steps[${index}]: 创建步不支持 collectEvents (仅方法步)`);
|
|
243
|
+
}
|
|
244
|
+
if (
|
|
245
|
+
step.as !== undefined &&
|
|
246
|
+
(typeof step.as !== 'string' || step.as === '')
|
|
247
|
+
) {
|
|
248
|
+
problems.push(`steps[${index}].as 须为非空字符串`);
|
|
249
|
+
}
|
|
250
|
+
if (call.args !== undefined && !Array.isArray(call.args)) {
|
|
251
|
+
problems.push(`steps[${index}].call.args 须为数组`);
|
|
252
|
+
}
|
|
253
|
+
if (
|
|
254
|
+
step.collectEvents !== undefined &&
|
|
255
|
+
typeof step.collectEvents !== 'boolean'
|
|
256
|
+
) {
|
|
257
|
+
problems.push(`steps[${index}].collectEvents 须为布尔`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/** api case 断言族校验: result (恰含 exact / subset 之一) / error (code 必填) / events / fs */
|
|
263
|
+
function validateApiExpect(expect: unknown, problems: string[]): void {
|
|
264
|
+
const record = asRecord(expect);
|
|
265
|
+
if (record === null) {
|
|
266
|
+
problems.push('expect 缺失或不是对象');
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
for (const key of [
|
|
270
|
+
'exitCode',
|
|
271
|
+
'stdoutExact',
|
|
272
|
+
'stdoutContains',
|
|
273
|
+
'stdoutMustNotContain',
|
|
274
|
+
'stderrContains',
|
|
275
|
+
'stderrMustNotContain',
|
|
276
|
+
] as const) {
|
|
277
|
+
if (record[key] !== undefined) {
|
|
278
|
+
problems.push(`expect.${key} 仅 cli case 可用 (本 case 为 api)`);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const result = record.result;
|
|
282
|
+
if (result !== undefined) {
|
|
283
|
+
const shape = asRecord(result);
|
|
284
|
+
const hasExact = shape !== null && 'exact' in shape;
|
|
285
|
+
const hasSubset = shape !== null && 'subset' in shape;
|
|
286
|
+
if (shape === null || hasExact === hasSubset) {
|
|
287
|
+
problems.push('expect.result 须恰含 exact 或 subset 之一');
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const error = record.error;
|
|
291
|
+
if (error !== undefined) {
|
|
292
|
+
const shape = asRecord(error);
|
|
293
|
+
if (shape === null || typeof shape.code !== 'string' || shape.code === '') {
|
|
294
|
+
problems.push('expect.error 须含非空字符串 code');
|
|
295
|
+
} else if (shape.name !== undefined && typeof shape.name !== 'string') {
|
|
296
|
+
problems.push('expect.error.name 须为字符串');
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const events = record.events;
|
|
300
|
+
if (events !== undefined) {
|
|
301
|
+
const shape = asRecord(events);
|
|
302
|
+
if (shape === null) {
|
|
303
|
+
problems.push('expect.events 须为对象');
|
|
304
|
+
} else {
|
|
305
|
+
if (shape.lastIs !== undefined && typeof shape.lastIs !== 'string') {
|
|
306
|
+
problems.push('expect.events.lastIs 须为字符串');
|
|
307
|
+
}
|
|
308
|
+
if (
|
|
309
|
+
shape.mustInclude !== undefined &&
|
|
310
|
+
(!Array.isArray(shape.mustInclude) ||
|
|
311
|
+
!shape.mustInclude.every((item) => typeof item === 'string'))
|
|
312
|
+
) {
|
|
313
|
+
problems.push('expect.events.mustInclude 须为字符串数组');
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
validateFs(record.fs, problems);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** 校验单条 case (按 kind 分流); 返回问题清单 (空数组即通过) */
|
|
321
|
+
export function validateCase(data: unknown): string[] {
|
|
322
|
+
const problems: string[] = [];
|
|
323
|
+
const record = asRecord(data);
|
|
324
|
+
if (record === null) return ['case 顶层须为 JSON 对象'];
|
|
325
|
+
|
|
326
|
+
if (typeof record.id !== 'string' || !ID_PATTERN.test(record.id)) {
|
|
327
|
+
problems.push('id 缺失或不合 kebab-case 形态 (小写字母数字与 -)');
|
|
328
|
+
}
|
|
329
|
+
const refs = record.specRefs;
|
|
330
|
+
if (
|
|
331
|
+
!Array.isArray(refs) ||
|
|
332
|
+
refs.length === 0 ||
|
|
333
|
+
!refs.every(
|
|
334
|
+
(item) => typeof item === 'string' && SPEC_REF_PATTERN.test(item),
|
|
335
|
+
)
|
|
336
|
+
) {
|
|
337
|
+
problems.push(
|
|
338
|
+
'specRefs 须为非空数组, 元素为条款编号形态 (如 BC-03 / OF-01 / EC-02)',
|
|
339
|
+
);
|
|
340
|
+
}
|
|
341
|
+
const kind = record.kind ?? 'cli';
|
|
342
|
+
if (kind !== 'cli' && kind !== 'api') {
|
|
343
|
+
problems.push('kind 须为 "cli" 或 "api"');
|
|
344
|
+
return problems;
|
|
345
|
+
}
|
|
346
|
+
validateFixture(record.fixture, problems);
|
|
347
|
+
validateSetup(record.setup, problems);
|
|
348
|
+
if (kind === 'api') {
|
|
349
|
+
if (record.run !== undefined) {
|
|
350
|
+
problems.push('api case 不得含 run (cli 专属, 用 steps 声明调用)');
|
|
351
|
+
}
|
|
352
|
+
validateEnv(record.env, problems);
|
|
353
|
+
validateSteps(record.steps, problems);
|
|
354
|
+
validateApiExpect(record.expect, problems);
|
|
355
|
+
} else {
|
|
356
|
+
if (record.steps !== undefined) {
|
|
357
|
+
problems.push('cli case 不得含 steps (api 专属)');
|
|
358
|
+
}
|
|
359
|
+
if (record.env !== undefined) {
|
|
360
|
+
problems.push('cli case 不得含顶层 env (请用 run.env)');
|
|
361
|
+
}
|
|
362
|
+
validateRun(record.run, problems);
|
|
363
|
+
validateExpect(record.expect, problems);
|
|
364
|
+
}
|
|
365
|
+
return problems;
|
|
366
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// bun / node 均可直跑 TS, 目标取保守基线
|
|
4
|
+
"target": "ES2022",
|
|
5
|
+
"lib": ["ES2022"],
|
|
6
|
+
"module": "preserve",
|
|
7
|
+
"moduleResolution": "bundler",
|
|
8
|
+
// 开发态解析: monorepo 内对 API 包的引用直指单源 src (零构建), 发布态由 API 包
|
|
9
|
+
// package.json 的 exports 指向 dist; tsconfig paths 优先级高于 node_modules 解析
|
|
10
|
+
// (bun 运行时 / tsc / bun build 三处已实测, 2026-09-29), 消费方项目无本配置不受影响
|
|
11
|
+
"paths": {
|
|
12
|
+
"{{SCOPE}}/{{NAME}}": [
|
|
13
|
+
"./packages/{{NAME}}/src/index.ts"
|
|
14
|
+
],
|
|
15
|
+
"{{SCOPE}}/{{NAME}}/testing": [
|
|
16
|
+
"./packages/{{NAME}}/src/fixtures.ts"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
"strict": true,
|
|
21
|
+
"noUncheckedIndexedAccess": true,
|
|
22
|
+
"noImplicitOverride": true,
|
|
23
|
+
"noFallthroughCasesInSwitch": true,
|
|
24
|
+
|
|
25
|
+
"noEmit": true,
|
|
26
|
+
"allowImportingTsExtensions": true,
|
|
27
|
+
"verbatimModuleSyntax": true,
|
|
28
|
+
"erasableSyntaxOnly": true,
|
|
29
|
+
"isolatedModules": true,
|
|
30
|
+
"esModuleInterop": true,
|
|
31
|
+
"skipLibCheck": true,
|
|
32
|
+
"forceConsistentCasingInFileNames": true,
|
|
33
|
+
|
|
34
|
+
"types": ["bun"]
|
|
35
|
+
},
|
|
36
|
+
// 变异生成器的产物 (scripts/transcription/mutants/gen-*/packages/*/src/*.ts) 由 make-mutants.ts
|
|
37
|
+
// 生成, 是派生件而非源码; 不排除则从根跑 tsc 会把它们收进编译范围并变红 (实测命中)
|
|
38
|
+
// 生成器包 (packages/create-clis) 的两个模板空间同理不进本仓检查面: assets/ 是按清单产出的
|
|
39
|
+
// 构建产物 (目录结构是新项目根, 含占位符路径与跨包引用), template-skeletons/ 是镜像新项目布局的
|
|
40
|
+
// 骨架; 二者只在新项目语境里成立 (同款排除见 .gitignore / .prettierignore / .oxlintrc.json)
|
|
41
|
+
"exclude": [
|
|
42
|
+
"scripts/transcription/mutants",
|
|
43
|
+
"packages/create-clis/assets",
|
|
44
|
+
"packages/create-clis/scripts/template-skeletons"
|
|
45
|
+
]
|
|
46
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
// 用 .jsonc 而非 .json: 缓存键的输入面需要就地注释说明口径 (turbo 官方支持的注释载体, 见
|
|
3
|
+
// https://turborepo.dev/docs/reference/configuration 「Use turbo.jsonc to add comments」)。
|
|
4
|
+
"$schema": "https://turbo.build/schema.json",
|
|
5
|
+
"tasks": {
|
|
6
|
+
"build": {
|
|
7
|
+
"dependsOn": ["^build"],
|
|
8
|
+
"outputs": ["dist/**", "assets/**"],
|
|
9
|
+
// 缓存键输入面: 生成器包 (create-clis) 的构建会从仓库根读骨架源来产出模板资产, 而 turbo
|
|
10
|
+
// 默认只把「包目录内」的文件算进缓存键, 根级文件的改动不进键; 曾实测出双向事故: 改根级
|
|
11
|
+
// 骨架源命中缓存不重算 (陈旧资产被当最新), 以及根构建把缓存里的旧资产还原回磁盘、覆盖掉
|
|
12
|
+
// 刚修好的版本。故显式补根级输入面, 范围取「宁大勿漏」。
|
|
13
|
+
// 口径: $TURBO_DEFAULT$ 保住包目录默认面 (含 .gitignore 语义; 显式写 inputs 会丢掉默认面,
|
|
14
|
+
// 官方文档明示); 其余条目是模板构建会读的根级源, 与 .gitignore 无关的保守超集。
|
|
15
|
+
// 注意: 显式 glob 不再享 .gitignore 过滤, 所以对 packages/ 这类会落构建产物的目录必须显式
|
|
16
|
+
// 排除 (dist / .turbo / node_modules / assets), 否则产物进缓存键, 每次构建自我失效、缓存恒
|
|
17
|
+
// 不命中, 或根级源变更后凭空多一轮重算。assets 只排除生成器包自己那份 (那是本任务的构建
|
|
18
|
+
// 产物); 不写成通用的 `packages/**/assets/**`, 防将来某包把真源放 assets 被误排除在外。
|
|
19
|
+
// 同步义务: 骨架清单的唯一权威是 packages/create-clis/scripts/template-manifest.ts; 新增
|
|
20
|
+
// 根级骨架源时先登记那份清单, 再照本条补一条 glob, 两处不互为来源。
|
|
21
|
+
"inputs": [
|
|
22
|
+
"$TURBO_DEFAULT$",
|
|
23
|
+
"$TURBO_ROOT$/.editorconfig",
|
|
24
|
+
"$TURBO_ROOT$/.gitattributes",
|
|
25
|
+
"$TURBO_ROOT$/.gitignore",
|
|
26
|
+
"$TURBO_ROOT$/.gitignorerc.json",
|
|
27
|
+
"$TURBO_ROOT$/.mailmap",
|
|
28
|
+
"$TURBO_ROOT$/.npmrc",
|
|
29
|
+
"$TURBO_ROOT$/.nvmrc",
|
|
30
|
+
"$TURBO_ROOT$/.oxlintrc.json",
|
|
31
|
+
"$TURBO_ROOT$/.prettierignore",
|
|
32
|
+
"$TURBO_ROOT$/.prettierrc",
|
|
33
|
+
"$TURBO_ROOT$/.releaserc.json",
|
|
34
|
+
"$TURBO_ROOT$/.github/**",
|
|
35
|
+
"$TURBO_ROOT$/.vscode/**",
|
|
36
|
+
"$TURBO_ROOT$/AGENTS.md",
|
|
37
|
+
"$TURBO_ROOT$/CODE_OF_CONDUCT.md",
|
|
38
|
+
"$TURBO_ROOT$/CONTRIBUTING.md",
|
|
39
|
+
"$TURBO_ROOT$/CONTRIBUTING.zh-CN.md",
|
|
40
|
+
"$TURBO_ROOT$/LICENSE",
|
|
41
|
+
"$TURBO_ROOT$/README.md",
|
|
42
|
+
"$TURBO_ROOT$/README.zh-CN.md",
|
|
43
|
+
"$TURBO_ROOT$/SECURITY.md",
|
|
44
|
+
"$TURBO_ROOT$/bunfig.toml",
|
|
45
|
+
"$TURBO_ROOT$/docs/**",
|
|
46
|
+
"$TURBO_ROOT$/lefthook.yml",
|
|
47
|
+
"$TURBO_ROOT$/package.json",
|
|
48
|
+
"$TURBO_ROOT$/packages/**",
|
|
49
|
+
"!$TURBO_ROOT$/packages/**/dist/**",
|
|
50
|
+
"!$TURBO_ROOT$/packages/**/.turbo/**",
|
|
51
|
+
"!$TURBO_ROOT$/packages/**/node_modules/**",
|
|
52
|
+
"!$TURBO_ROOT$/packages/create-clis/assets/**",
|
|
53
|
+
"$TURBO_ROOT$/scripts/**",
|
|
54
|
+
"$TURBO_ROOT$/tsconfig.json",
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
"typecheck": {},
|
|
58
|
+
"test": {},
|
|
59
|
+
},
|
|
60
|
+
}
|
package/bin/create-clis
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# create-clis 启动器: 挑选运行时 (Bun 优先, 其次 Node) 后交给 npm 分发入口 (bin/create-clis.mjs)。
|
|
3
|
+
# 经 ~/.local/bin/create-clis 软链调用; readlink 解出仓库内路径 (BSD / GNU 皆可)。
|
|
4
|
+
#
|
|
5
|
+
# 为什么不像既有 CLI 包那样直接 exec 真实入口: 生成器只认产物 (dist/create-clis.js, 无源码回退),
|
|
6
|
+
# 而产物必须先与 dist/manifest.json 的摘要对账才许执行; 该自证逻辑只在 bin/create-clis.mjs 一处
|
|
7
|
+
# 实现, 三个入口全部经它, 免得 sh / cmd 两份 shell 各自复刻判定 (复刻即分叉)。
|
|
8
|
+
#
|
|
9
|
+
# 运行时解析防劫持 (安全审计项 runtime-resolution:bare-name-cwd-precedence-windows):
|
|
10
|
+
# 本入口的 command -v 与 exec 都按 shell 的 PATH 查找; shell 层无法过滤 PATH 中的空 / 相对
|
|
11
|
+
# 条目 (两者在 POSIX 下均意为当前目录), 该边界属已知前提: 本入口只负责把控制权交给
|
|
12
|
+
# bin/create-clis.mjs, 真正解析「跑产物的那个运行时」在那一侧完成 (按 PATH 解析绝对路径并跳过
|
|
13
|
+
# 这两类条目), 防御落在那一侧。对照实测与本条的证据面见
|
|
14
|
+
# packages/sweep-node-modules-cli/src/launcher.runtime-resolution.test.ts (同款逻辑的钉住用例);
|
|
15
|
+
# win32 侧的对应处理见 bin/create-clis.cmd 与 bin/create-clis.mjs 的文件头。
|
|
16
|
+
|
|
17
|
+
# readlink 为空 = 未经软链直跑, 此时 $0 即自身路径
|
|
18
|
+
target=$(readlink "$0" 2>/dev/null)
|
|
19
|
+
case "$target" in
|
|
20
|
+
"") target=$0 ;;
|
|
21
|
+
/*) ;;
|
|
22
|
+
*) target="$(dirname "$0")/$target" ;;
|
|
23
|
+
esac
|
|
24
|
+
root=$(cd "$(dirname "$target")/.." && pwd)
|
|
25
|
+
|
|
26
|
+
if command -v bun >/dev/null 2>&1; then
|
|
27
|
+
exec bun "$root/bin/create-clis.mjs" "$@"
|
|
28
|
+
fi
|
|
29
|
+
|
|
30
|
+
if command -v node >/dev/null 2>&1; then
|
|
31
|
+
exec node "$root/bin/create-clis.mjs" "$@"
|
|
32
|
+
fi
|
|
33
|
+
|
|
34
|
+
echo "create-clis: 未找到 bun 或 node, 请至少安装其一" >&2
|
|
35
|
+
exit 1
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
rem create-clis 启动器 (Windows): 挑选运行时 (Bun 优先, 其次 Node) 后交给 npm 分发入口
|
|
3
|
+
rem (bin/create-clis.mjs, 内含产物自证)。与 sh 启动器 (bin/create-clis) 同逻辑; 未经 Windows
|
|
4
|
+
rem 真机验证 (证据缺口)。
|
|
5
|
+
rem 分支结构全程只用单行 if 判定 (不用标签与括号块), 与 sh 启动器一一对应。
|
|
6
|
+
rem
|
|
7
|
+
rem 运行时解析防劫持 (安全审计项 runtime-resolution:bare-name-cwd-precedence-windows):
|
|
8
|
+
rem 裸名执行与 where 的默认搜索都含当前目录 (官方文档: by default, where searches the current
|
|
9
|
+
rem directory and the paths that are specified in the PATH environment variable; path 命令页:
|
|
10
|
+
rem the current directory is always searched before the directories specified in the command path),
|
|
11
|
+
rem 而本生成器的调用现场在用户自己的目录里: 目录内放一个同名 bun.exe / bun.cmd 即可顶替真实
|
|
12
|
+
rem 运行时。故改用 for 的 PATH 展开修饰符 (官方 for 文档: Searches the directories listed in the
|
|
13
|
+
rem PATH environment variable and expands 变量 to the fully qualified name of the first directory
|
|
14
|
+
rem found): 只搜 PATH, 不搜当前目录, 也不派生任何子进程; 解析出的绝对路径交给末行执行, 带路径
|
|
15
|
+
rem 的命令不再触发搜索序。候选扩展名取 .com / .exe: 扩展名相对序 (.com 先于 .exe) 与 libuv 一致;
|
|
16
|
+
rem 搜索粒度则不同: 本实现扩展名优先 (.com 扫完全部 PATH 目录再试 .exe), npm 启动器
|
|
17
|
+
rem (bin/create-clis.mjs, 走 Node 的 libuv 搜索) 目录优先 (逐目录内先 .com 再 .exe); 仅当多个
|
|
18
|
+
rem PATH 目录分别存在不同扩展名的 bun / node 时, 三入口可能选中不同二进制 (与既有 CLI 包同款
|
|
19
|
+
rem 登记, 见 packages/sweep-node-modules/docs/adrs/0007-platform-portability.md)。
|
|
20
|
+
setlocal
|
|
21
|
+
set "ROOT=%~dp0.."
|
|
22
|
+
set "ENTRY=%ROOT%\bin\create-clis.mjs"
|
|
23
|
+
set "RUNNER="
|
|
24
|
+
|
|
25
|
+
for %%I in (bun.com bun.exe) do if not defined RUNNER set "RUNNER=%%~$PATH:I"
|
|
26
|
+
if not defined RUNNER for %%I in (node.com node.exe) do if not defined RUNNER set "RUNNER=%%~$PATH:I"
|
|
27
|
+
|
|
28
|
+
if not defined RUNNER echo create-clis: 未找到 bun 或 node, 请至少安装其一 1>&2
|
|
29
|
+
if not defined RUNNER exit /b 1
|
|
30
|
+
|
|
31
|
+
"%RUNNER%" "%ENTRY%" %*
|
|
32
|
+
exit /b %errorlevel%
|