gatelight 0.0.0-stage → 0.17.9
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/.antigravity-plugin/plugin.json +9 -0
- package/.claude-plugin/plugin.json +11 -0
- package/.codex-plugin/plugin.json +18 -0
- package/.mcp.json +8 -0
- package/bin/modwall +8 -0
- package/bin/node.sh +14 -0
- package/bin/testcraft +8 -0
- package/bin/testpace +8 -0
- package/entry/command +44 -0
- package/hooks/antigravity.sh +24 -0
- package/hooks/codex.json +50 -0
- package/hooks/codex.sh +7 -0
- package/hooks/hooks.json +43 -0
- package/hooks/testpace.ts +25 -0
- package/hooks.json +16 -0
- package/mcp_config.json +8 -0
- package/package.json +21 -4
- package/setup.mjs +99 -0
- package/skills/merge/SKILL.md +42 -0
- package/skills/modular/SKILL.md +75 -0
- package/skills/setup/SKILL.md +101 -0
- package/skills/setup-modwall/SKILL.md +112 -0
- package/skills/setup-testcraft/SKILL.md +23 -0
- package/skills/setup-testcraft/checklist/dev-login.md +20 -0
- package/skills/write-tests/SKILL.md +153 -0
- package/src/base/agent.ts +100 -0
- package/src/base/baseline.ts +54 -0
- package/src/base/commandline.ts +40 -0
- package/src/base/commands.ts +94 -0
- package/src/base/confirm.ts +161 -0
- package/src/base/contract.ts +94 -0
- package/src/base/coverage.ts +46 -0
- package/src/base/entry.ts +90 -0
- package/src/base/excerpt.ts +46 -0
- package/src/base/execute.ts +70 -0
- package/src/base/exit.ts +6 -0
- package/src/base/format.ts +27 -0
- package/src/base/full.ts +160 -0
- package/src/base/gate.ts +251 -0
- package/src/base/git.ts +361 -0
- package/src/base/glob.ts +38 -0
- package/src/base/hook.ts +297 -0
- package/src/base/hookformat.ts +257 -0
- package/src/base/judging.ts +27 -0
- package/src/base/layermap.ts +69 -0
- package/src/base/module.ts +88 -0
- package/src/base/process-group.ts +101 -0
- package/src/base/records.ts +66 -0
- package/src/base/repo.ts +155 -0
- package/src/base/sessions.ts +55 -0
- package/src/base/shell.ts +176 -0
- package/src/base/stop.ts +100 -0
- package/src/base/store.ts +348 -0
- package/src/base/version.ts +24 -0
- package/src/cli.ts +186 -0
- package/src/craft/change.ts +24 -0
- package/src/craft/checklist.ts +157 -0
- package/src/craft/commands.ts +111 -0
- package/src/craft/config.ts +15 -0
- package/src/craft/full.ts +30 -0
- package/src/craft/index.ts +12 -0
- package/src/craft/session.ts +21 -0
- package/src/mcp.ts +79 -0
- package/src/modules.ts +10 -0
- package/src/modwall.ts +8 -0
- package/src/pace/commands.ts +281 -0
- package/src/pace/config.ts +103 -0
- package/src/pace/consent.ts +81 -0
- package/src/pace/focused.ts +208 -0
- package/src/pace/full.ts +38 -0
- package/src/pace/index.ts +16 -0
- package/src/pace/record.ts +84 -0
- package/src/pace/report.ts +335 -0
- package/src/pace/results.ts +243 -0
- package/src/pace/run/node-test-reporter.mjs +34 -0
- package/src/pace/run/node-test.ts +26 -0
- package/src/pace/run/playwright-reporter.mjs +48 -0
- package/src/pace/run/playwright.ts +34 -0
- package/src/pace/run/runner.ts +157 -0
- package/src/pace/run/targets.ts +130 -0
- package/src/pace/run/vitest-launcher.mjs +101 -0
- package/src/pace/run/vitest.ts +22 -0
- package/src/pace/session.ts +35 -0
- package/src/pace/testlist.ts +91 -0
- package/src/pace/tests.ts +22 -0
- package/src/pace/verify.ts +95 -0
- package/src/testcraft.ts +9 -0
- package/src/wall/check.ts +258 -0
- package/src/wall/commands.ts +279 -0
- package/src/wall/config.ts +394 -0
- package/src/wall/database.ts +136 -0
- package/src/wall/dbcheck.ts +389 -0
- package/src/wall/dbrules.ts +213 -0
- package/src/wall/edit.ts +64 -0
- package/src/wall/files.ts +35 -0
- package/src/wall/full.ts +30 -0
- package/src/wall/index.ts +15 -0
- package/src/wall/init.ts +149 -0
- package/src/wall/layermap.ts +124 -0
- package/src/wall/layout.ts +231 -0
- package/src/wall/loosen.ts +157 -0
- package/src/wall/miniprogram.ts +80 -0
- package/src/wall/project.ts +88 -0
- package/src/wall/rules.ts +400 -0
- package/src/wall/session.ts +198 -0
- package/src/wall/sql.ts +510 -0
- package/src/wall/store.ts +39 -0
- package/README.md +0 -3
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// 接入核对:由程序实际跑几次项目的 files 命令,看它守不守约定,不靠 agent 说"检查过了"。
|
|
2
|
+
// 这几次运行不记进 runs.jsonl(不是开发中的测试,不该算进报告),但和别的测试一样占住工作区。
|
|
3
|
+
|
|
4
|
+
import { failureCause, type Repo, runClaimed } from '../base/repo.ts'
|
|
5
|
+
import type { RunningMarker } from '../base/store.ts'
|
|
6
|
+
|
|
7
|
+
/** 核对时交给 files 的不存在的路径。 */
|
|
8
|
+
export const MISSING = 'testpace-verify-no-such-file.test.js'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 测试声明的开头:test(、it(、describe( 和它们的 .only、.skip、.each 这类写法(不含 beforeEach、use 这些钩子和配置,
|
|
12
|
+
* 按行跑时那一行没有测试),Python 的 def test_,Go 的 func Test。
|
|
13
|
+
*/
|
|
14
|
+
const TEST_DECLARATION = /^(\s*)(?:(?:test|it|describe)(?:\.(?:only|skip|todo|fixme|fail|slow|each|concurrent|sequential|serial|parallel|describe))*\s*\(|def test_|func Test)/
|
|
15
|
+
|
|
16
|
+
/** 文件里第一个测试声明所在的行和列(都从 1 起);找不到返回 undefined。 */
|
|
17
|
+
export function firstTest(text: string): { line: number; column: number } | undefined {
|
|
18
|
+
const lines = text.split('\n')
|
|
19
|
+
for (const [index, line] of lines.entries()) {
|
|
20
|
+
const match = TEST_DECLARATION.exec(line)
|
|
21
|
+
if (match) return { line: index + 1, column: match[1]!.length + 1 }
|
|
22
|
+
}
|
|
23
|
+
return undefined
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type VerifyResult =
|
|
27
|
+
| { kind: 'done'; failed: number; skipped: number }
|
|
28
|
+
| { kind: 'busy'; marker: RunningMarker }
|
|
29
|
+
| { kind: 'interrupted' }
|
|
30
|
+
|
|
31
|
+
class Stopped {
|
|
32
|
+
readonly result: VerifyResult
|
|
33
|
+
constructor(result: VerifyResult) {
|
|
34
|
+
this.result = result
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 核对 files 命令:不存在的文件要失败;给了测试文件(相对仓库根目录,text 是文件内容)时,逐个核对它能通过、
|
|
40
|
+
* 混进不存在的路径要失败、文件:行号 和 文件:行号:列号 能用;给了几个时,再核对它们一起交给 files 能通过
|
|
41
|
+
* (focused 会把不同种类的测试一起交过去)。每项结果交给 say。
|
|
42
|
+
*/
|
|
43
|
+
export async function verifyFiles(
|
|
44
|
+
repo: Repo,
|
|
45
|
+
command: string,
|
|
46
|
+
tree: string,
|
|
47
|
+
tests: { path: string; text: string }[],
|
|
48
|
+
say: (line: string) => void,
|
|
49
|
+
): Promise<VerifyResult> {
|
|
50
|
+
let failed = 0
|
|
51
|
+
let skipped = 0
|
|
52
|
+
const probe = async (title: string, args: string[], shouldPass: boolean): Promise<boolean> => {
|
|
53
|
+
const run = await runClaimed(repo, 'files', command, args, tree)
|
|
54
|
+
if ('busy' in run) throw new Stopped({ kind: 'busy', marker: run.busy })
|
|
55
|
+
if (run.execution.interrupted) throw new Stopped({ kind: 'interrupted' })
|
|
56
|
+
const passed = run.execution.exitCode === 0
|
|
57
|
+
const ok = passed === shouldPass
|
|
58
|
+
if (!ok) failed += 1
|
|
59
|
+
say(ok ? `通过 ${title}` : `没通过 ${title}:实际${passed ? '通过了' : `失败了(${failureCause(run.execution)})`},日志 ${run.log}`)
|
|
60
|
+
return ok
|
|
61
|
+
}
|
|
62
|
+
const skip = (text: string): void => {
|
|
63
|
+
skipped += 1
|
|
64
|
+
say(`没查 ${text}`)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
await probe(`files 给了不存在的文件要失败(${MISSING})`, [MISSING], false)
|
|
69
|
+
if (tests.length === 0) {
|
|
70
|
+
skip('其余几项要测试文件:testpace verify <测试文件>...,每种测试(交给不同工具或配置跑的)各挑一个跑得快、不依赖外部服务的')
|
|
71
|
+
return { kind: 'done', failed, skipped }
|
|
72
|
+
}
|
|
73
|
+
const passing: string[] = []
|
|
74
|
+
for (const test of tests) {
|
|
75
|
+
if (!(await probe(`files 跑 ${test.path} 要通过`, [test.path], true))) {
|
|
76
|
+
skip(`${test.path} 的其余几项要这个文件先能通过:先看日志,或换一个能通过的测试文件`)
|
|
77
|
+
continue
|
|
78
|
+
}
|
|
79
|
+
passing.push(test.path)
|
|
80
|
+
await probe(`${test.path} 里混进一个不存在的路径要失败`, [test.path, MISSING], false)
|
|
81
|
+
const at = firstTest(test.text)
|
|
82
|
+
if (!at) {
|
|
83
|
+
skip(`${test.path} 的 文件:行号:没找到测试声明(test(、it(、describe(、def test_、func Test),换一个测试文件`)
|
|
84
|
+
} else {
|
|
85
|
+
await probe(`文件:行号 要能用(${test.path}:${at.line})`, [`${test.path}:${at.line}`], true)
|
|
86
|
+
await probe(`文件:行号:列号 要能用(${test.path}:${at.line}:${at.column})`, [`${test.path}:${at.line}:${at.column}`], true)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (passing.length > 1) await probe(`几个文件一起交给 files 要通过(${passing.join(' ')})`, passing, true)
|
|
90
|
+
return { kind: 'done', failed, skipped }
|
|
91
|
+
} catch (error) {
|
|
92
|
+
if (error instanceof Stopped) return error.result
|
|
93
|
+
throw error
|
|
94
|
+
}
|
|
95
|
+
}
|
package/src/testcraft.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// testcraft 命令行入口:checklist、status(实现在 craft/commands.ts)。
|
|
2
|
+
// 这个文件的路径不能变:bin/testcraft 和整组里"测试写法"的那一段按它找。
|
|
3
|
+
|
|
4
|
+
import './modules.ts'
|
|
5
|
+
import { runCommandLine } from './base/commandline.ts'
|
|
6
|
+
import { main } from './craft/commands.ts'
|
|
7
|
+
|
|
8
|
+
// 没有在 agent 的沙箱里跑不了的子命令:只读项目里的文件和 git,不写记录、不用 LayerMap
|
|
9
|
+
process.exitCode = await runCommandLine({ name: 'testcraft', run: main }, process.argv.slice(2))
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
// 检查整个项目:配置、R1–R5、R6 里迁移文件和模块代码切身份那部分、放宽项是否经用户同意;R4 和入口新增导出只提示;LayerMap 没看全的地方照列。
|
|
2
|
+
// modwall check 和 modwall status 共用。没有 LayerMap 时只剩按路径判断的 R5、读迁移文件的 R6 和配置保护,检查不通过。
|
|
3
|
+
// 放宽项用户同意过没有问底座(base/confirm.ts):这里只交条目,不弹窗、不存同意记录。
|
|
4
|
+
|
|
5
|
+
import { readFileSync, writeFileSync } from 'node:fs'
|
|
6
|
+
import { join } from 'node:path'
|
|
7
|
+
import { askUser } from '../base/confirm.ts'
|
|
8
|
+
import { EXIT } from '../base/exit.ts'
|
|
9
|
+
import type { Repo } from '../base/repo.ts'
|
|
10
|
+
import { CONFIG_PATH } from './config.ts'
|
|
11
|
+
import { unreadSql } from './database.ts'
|
|
12
|
+
import { codeRoleSwitches, migrationViolations } from './dbrules.ts'
|
|
13
|
+
import { type ChangeFacts, type ProjectImports, readChanges, readImports } from './layermap.ts'
|
|
14
|
+
import { miniprogramRefs } from './miniprogram.ts'
|
|
15
|
+
import type { Layout } from './layout.ts'
|
|
16
|
+
import { looseningItems } from './loosen.ts'
|
|
17
|
+
import { layoutOf, type Project } from './project.ts'
|
|
18
|
+
import {
|
|
19
|
+
BLOCKING_RULES,
|
|
20
|
+
behaviorHints,
|
|
21
|
+
entryExports,
|
|
22
|
+
type Hint,
|
|
23
|
+
importViolations,
|
|
24
|
+
RULE_NAMES,
|
|
25
|
+
uncheckedItems,
|
|
26
|
+
unownedFiles,
|
|
27
|
+
type Violation,
|
|
28
|
+
withAssets,
|
|
29
|
+
} from './rules.ts'
|
|
30
|
+
import { branchKey, type Store } from './store.ts'
|
|
31
|
+
|
|
32
|
+
export interface Report {
|
|
33
|
+
/** 配置有错:别的都不查。 */
|
|
34
|
+
configProblems: string[]
|
|
35
|
+
/** 配置有错里有路径重叠。 */
|
|
36
|
+
overlapping: boolean
|
|
37
|
+
/** layermap imports 用不了:R1、R2、R3 没查(R4 和入口清单也就没查);R5、R6 照常查了。 */
|
|
38
|
+
layermapProblem?: string
|
|
39
|
+
/** 只有 layermap check 没跑成:R1–R3 照常查了,R4 和入口新增导出这次没查。 */
|
|
40
|
+
changesProblem?: string
|
|
41
|
+
violations: Violation[]
|
|
42
|
+
loosening: Loosening
|
|
43
|
+
/** 有还没同意的放宽项时:说给 agent 的话(怎么调确认工具,编号和弹窗文字)。 */
|
|
44
|
+
ask?: string[]
|
|
45
|
+
/** 配置删掉了(放宽项里有这一项):规则不再查。 */
|
|
46
|
+
removed: boolean
|
|
47
|
+
behavior: Hint[]
|
|
48
|
+
entryExports: Hint[]
|
|
49
|
+
unchecked: string[]
|
|
50
|
+
layout?: Layout
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type Loosening = Array<{ item: string; confirmed: boolean }>
|
|
54
|
+
|
|
55
|
+
/** 配置能不能用:有错(problems)、删掉了(removed)、能用(给出划分)。check 和确认工具共用。 */
|
|
56
|
+
export type Prepared = { problems: string[]; overlapping: boolean } | { removed: true } | { layout: Layout }
|
|
57
|
+
|
|
58
|
+
export function prepare(project: Project): Prepared {
|
|
59
|
+
const { now, before } = project
|
|
60
|
+
if (now.problems.length) return { problems: now.problems, overlapping: false }
|
|
61
|
+
if (!now.config) {
|
|
62
|
+
if (before.config) return { removed: true }
|
|
63
|
+
const problem = now.hasDir
|
|
64
|
+
? `有 .modwall/ 目录但没有 ${CONFIG_PATH}:用 modwall init 按现有目录生成配置草稿`
|
|
65
|
+
: `工作区里删掉了 .modwall/,分叉点上的 ${CONFIG_PATH} 又不在或校验不过:没有能用的配置,没法判断这次放宽了什么。要继续用 modwall 就恢复配置;要退出,先在默认分支上把配置改好,再删掉 .modwall/`
|
|
66
|
+
return { problems: [problem], overlapping: false }
|
|
67
|
+
}
|
|
68
|
+
const layout = layoutOf(project, now.config)
|
|
69
|
+
return layout.problems.length ? { problems: layout.problems, overlapping: layout.overlapping } : { layout }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** 弹窗开头说这是什么的半句。 */
|
|
73
|
+
export const LOOSEN_HEADING = '这次改动里放宽模块边界规则的地方'
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 和分叉点上的配置比,放宽了哪些、各自用户同意过没有。配置要能用(或删掉了)才有意义。
|
|
77
|
+
* 有没同意的,底座把它们按编号存好,ask 是让 agent 去调确认工具的话。
|
|
78
|
+
*/
|
|
79
|
+
export function looseningOf(project: Project, repo: Repo): { loosening: Loosening; ask?: string[] } {
|
|
80
|
+
const items = looseningItems(project.before.config, project.now)
|
|
81
|
+
const asked = askUser(repo, 'wall', LOOSEN_HEADING, items)
|
|
82
|
+
return {
|
|
83
|
+
loosening: items.map(item => ({ item: item.text, confirmed: asked.confirmed.includes(item) })),
|
|
84
|
+
...(asked.ask ? { ask: asked.ask.lines } : {}),
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function analyze(project: Project, repo: Repo): Report {
|
|
89
|
+
const report: Report = { configProblems: [], overlapping: false, violations: [], loosening: [], removed: false, behavior: [], entryExports: [], unchecked: [] }
|
|
90
|
+
const prepared = prepare(project)
|
|
91
|
+
if ('problems' in prepared) {
|
|
92
|
+
report.configProblems = prepared.problems
|
|
93
|
+
report.overlapping = prepared.overlapping
|
|
94
|
+
return report
|
|
95
|
+
}
|
|
96
|
+
const loosened = looseningOf(project, repo)
|
|
97
|
+
report.loosening = loosened.loosening
|
|
98
|
+
if (loosened.ask) report.ask = loosened.ask
|
|
99
|
+
if ('removed' in prepared) {
|
|
100
|
+
report.removed = true
|
|
101
|
+
return report
|
|
102
|
+
}
|
|
103
|
+
const { layout } = prepared
|
|
104
|
+
report.layout = layout
|
|
105
|
+
const read = (path: string): string => readFileSync(join(project.root, path), 'utf8')
|
|
106
|
+
const database = migrationViolations(layout.databases, read)
|
|
107
|
+
// 小程序的 .json、.wxml、.wxss 里的引用 LayerMap 不读,modwall 自己读,和 import 一起判
|
|
108
|
+
const miniprogram = miniprogramRefs(project.files, read)
|
|
109
|
+
const switches = codeRoleSwitches(layout.databases, project.files, path => layout.owner(path), read)
|
|
110
|
+
report.violations = [...unownedFiles(layout, project.files), ...database.violations, ...switches]
|
|
111
|
+
|
|
112
|
+
let facts: ProjectImports | undefined
|
|
113
|
+
const imports = readImports(project.root)
|
|
114
|
+
if (imports.ok) {
|
|
115
|
+
const assets = withAssets(imports.value, project.files)
|
|
116
|
+
facts = { imports: [...assets.imports, ...miniprogram.imports], unresolved: assets.unresolved }
|
|
117
|
+
// 数据库里模块之间的引用和代码的 import 一起算环
|
|
118
|
+
report.violations = [...importViolations(layout, facts, database.edges), ...report.violations]
|
|
119
|
+
} else {
|
|
120
|
+
report.layermapProblem = imports.problem
|
|
121
|
+
}
|
|
122
|
+
let changes: ChangeFacts | undefined
|
|
123
|
+
if (project.base && imports.ok) {
|
|
124
|
+
const read = readChanges(project.root, project.base.commit)
|
|
125
|
+
if (read.ok) {
|
|
126
|
+
changes = read.value
|
|
127
|
+
report.behavior = behaviorHints(layout, changes)
|
|
128
|
+
report.entryExports = entryExports(layout, changes)
|
|
129
|
+
} else {
|
|
130
|
+
report.changesProblem = read.problem
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
report.unchecked = [
|
|
134
|
+
...uncheckedItems(layout, facts, changes),
|
|
135
|
+
...miniprogram.unresolved.map(text => `${text}:小程序的引用没对上项目里的文件`),
|
|
136
|
+
...unreadSql(layout.databases, project.files, path => layout.owner(path)).map(path => `${path}:不在迁移目录里,R6 只查它有没有切身份(应用自己的查询文件可以不管;是迁移的话放进迁移目录)`),
|
|
137
|
+
]
|
|
138
|
+
return report
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** R1–R3、R5、R6 都查了:配置能用、layermap imports 跑成了。只有这样的检查,越界列表才完整。 */
|
|
142
|
+
function complete(report: Report): boolean {
|
|
143
|
+
return report.configProblems.length === 0 && !report.removed && report.layermapProblem === undefined
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function exitCode(report: Report): number {
|
|
147
|
+
if (report.configProblems.length || report.layermapProblem || report.changesProblem) return EXIT.usage
|
|
148
|
+
if (report.violations.length || report.loosening.some(item => !item.confirmed)) return EXIT.fail
|
|
149
|
+
return EXIT.ok
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const LIMIT = 50
|
|
153
|
+
|
|
154
|
+
function list<T>(items: T[], line: (item: T) => string[]): string[] {
|
|
155
|
+
const lines = items.slice(0, LIMIT).flatMap(line)
|
|
156
|
+
if (items.length > LIMIT) lines.push(` ……还有 ${items.length - LIMIT} 条`)
|
|
157
|
+
return lines
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** 越界按规则分组;一组的改法都一样时只写一次。modwall db check 也用。 */
|
|
161
|
+
export function violationLines(violations: Violation[]): string[] {
|
|
162
|
+
const lines: string[] = []
|
|
163
|
+
for (const rule of BLOCKING_RULES) {
|
|
164
|
+
const group = violations.filter(violation => violation.rule === rule)
|
|
165
|
+
if (group.length === 0) continue
|
|
166
|
+
const same = group.every(violation => violation.fix === group[0]?.fix)
|
|
167
|
+
lines.push(`${rule} ${RULE_NAMES[rule]}(${group.length} 处)`)
|
|
168
|
+
lines.push(
|
|
169
|
+
...list(group, violation => [
|
|
170
|
+
` ✗ ${violation.where[0]}`,
|
|
171
|
+
...violation.where.slice(1).map(text => ` ${text}`),
|
|
172
|
+
...(same ? [] : [` 改法:${violation.fix}`]),
|
|
173
|
+
]),
|
|
174
|
+
)
|
|
175
|
+
if (same) lines.push(` 改法:${group[0]?.fix}`)
|
|
176
|
+
}
|
|
177
|
+
return lines
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** 放宽项要用户同意:怎么调确认工具由底座说(report.ask),这里只加上这是什么、不同意时怎么办。 */
|
|
181
|
+
function confirmLines(report: Report, count: number): string[] {
|
|
182
|
+
return [`放宽规则 ${count} 项(和分叉点上的配置比),要用户同意。用户不同意的,改回去,按越界的改法改代码。`, ...(report.ask ?? [])]
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function formatReport(report: Report): string {
|
|
186
|
+
const code = exitCode(report)
|
|
187
|
+
const lines: string[] = []
|
|
188
|
+
if (report.configProblems.length) {
|
|
189
|
+
lines.push(`modwall check:配置有问题(${CONFIG_PATH}),先改好再检查:`, ...report.configProblems.map(text => ` ✗ ${text}`))
|
|
190
|
+
if (report.overlapping) lines.push('各项的路径不能重叠:一个代码文件只能属于模块、共享层、装配层、映射、outside 里的一项。')
|
|
191
|
+
return lines.join('\n')
|
|
192
|
+
}
|
|
193
|
+
const unconfirmed = report.loosening.filter(item => !item.confirmed).map(item => item.item)
|
|
194
|
+
if (report.removed) {
|
|
195
|
+
lines.push(unconfirmed.length ? 'modwall check:没通过。' : 'modwall check:通过。配置删掉了,用户同意过:这份改动退出 modwall,不再检查。')
|
|
196
|
+
if (unconfirmed.length) lines.push('', ...confirmLines(report, unconfirmed.length))
|
|
197
|
+
return lines.join('\n')
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (code === EXIT.ok) lines.push('modwall check:通过。项目里没有越界。')
|
|
201
|
+
else if (report.layermapProblem) lines.push('modwall check:没通过,LayerMap 用不了,R1、R2、R3、R4 和入口新增导出都没查(R5、R6 照常查了):', ` ${report.layermapProblem}`)
|
|
202
|
+
else if (report.changesProblem) {
|
|
203
|
+
lines.push('modwall check:没通过,这次改动增删的关系没读到,R4 和入口新增导出没查(R1、R2、R3、R5、R6 照常查了,结果在下面):', ` ${report.changesProblem}`)
|
|
204
|
+
} else lines.push('modwall check:没通过。')
|
|
205
|
+
|
|
206
|
+
if (report.violations.length) {
|
|
207
|
+
lines.push('', `越界 ${report.violations.length} 处(按项目当前的全部代码算,要改到清零):`, ...violationLines(report.violations))
|
|
208
|
+
}
|
|
209
|
+
if (unconfirmed.length) lines.push('', ...confirmLines(report, unconfirmed.length))
|
|
210
|
+
else if (report.loosening.length) lines.push('', `放宽规则 ${report.loosening.length} 项,用户都同意过。`)
|
|
211
|
+
|
|
212
|
+
const hints: string[] = []
|
|
213
|
+
if (report.behavior.length) {
|
|
214
|
+
hints.push(`R4 ${RULE_NAMES.R4}(${report.behavior.length} 处,先只提示)`)
|
|
215
|
+
hints.push(...list(report.behavior, hint => [` · ${hint.where}`, ` 建议:${hint.fix}`]))
|
|
216
|
+
}
|
|
217
|
+
if (report.entryExports.length) {
|
|
218
|
+
hints.push('这次给模块的入口新增了导出(不算违规,留作试点数据;不要为了过 R1 把内部的东西全从入口导出):')
|
|
219
|
+
hints.push(...list(report.entryExports, hint => [` · ${hint.where}`]))
|
|
220
|
+
}
|
|
221
|
+
if (report.unchecked.length) {
|
|
222
|
+
hints.push('没检查到(LayerMap 标明没看全的地方,不拦):')
|
|
223
|
+
hints.push(...list(report.unchecked, text => [` · ${text}`]))
|
|
224
|
+
}
|
|
225
|
+
if (hints.length) lines.push('', '提示:', ...hints)
|
|
226
|
+
return lines.join('\n')
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* 记一份检查日志:哪条规则、哪个位置,上一次(同一分支)的越界这次改正了哪些。
|
|
231
|
+
* 两次都查全了才比:没查全的那次越界列表不完整,不算改正,也不作为下一次比较的基准。
|
|
232
|
+
*/
|
|
233
|
+
export function logCheck(store: Store, project: Project, report: Report): void {
|
|
234
|
+
const violations = report.violations.map(violation => violation.key)
|
|
235
|
+
const whole = complete(report)
|
|
236
|
+
const key = branchKey(project.branch)
|
|
237
|
+
const before = whole ? (store.last.get(key)?.violations ?? []) : []
|
|
238
|
+
if (whole) store.last.put(key, { violations, at: Date.now() })
|
|
239
|
+
const entry = {
|
|
240
|
+
kind: 'check',
|
|
241
|
+
at: Date.now(),
|
|
242
|
+
branch: project.branch,
|
|
243
|
+
base: project.base?.commit,
|
|
244
|
+
result: ['pass', 'fail', 'error'][exitCode(report)],
|
|
245
|
+
complete: whole,
|
|
246
|
+
violations,
|
|
247
|
+
fixed: before.filter(key => !violations.includes(key)),
|
|
248
|
+
configProblems: report.configProblems.length,
|
|
249
|
+
layermapProblem: report.layermapProblem,
|
|
250
|
+
changesProblem: report.changesProblem,
|
|
251
|
+
loosening: report.loosening.length,
|
|
252
|
+
unconfirmed: report.loosening.filter(item => !item.confirmed).length,
|
|
253
|
+
behaviorHints: report.behavior.map(hint => hint.where),
|
|
254
|
+
entryExports: report.entryExports.length,
|
|
255
|
+
unchecked: report.unchecked.length,
|
|
256
|
+
}
|
|
257
|
+
writeFileSync(store.logPath('modwall-check'), `${JSON.stringify(entry, null, 1)}\n`)
|
|
258
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
// modwall 的命令:init、check、db check、status。命令入口(src/modwall.ts)分发到这里。
|
|
2
|
+
// 找仓库、存记录、让用户确认、调 LayerMap 都用底座的;合并前的检查(check)是整组里的一段(见 full.ts),不用另外登记。
|
|
3
|
+
|
|
4
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import { CONTRACT_FILE, loadContract } from '../base/contract.ts'
|
|
7
|
+
import { EXIT } from '../base/exit.ts'
|
|
8
|
+
import { filesNow } from '../base/git.ts'
|
|
9
|
+
import { matchesAny } from '../base/glob.ts'
|
|
10
|
+
import { LAYERMAP_COMMAND, LAYERMAP_MINIMUM, layermapVersion } from '../base/layermap.ts'
|
|
11
|
+
import { openRepo, type Repo } from '../base/repo.ts'
|
|
12
|
+
import { analyze, exitCode, formatReport, logCheck, prepare, type Report, violationLines } from './check.ts'
|
|
13
|
+
import { CONFIG_PATH, MODWALL_DIR, schemeOf } from './config.ts'
|
|
14
|
+
import { catalogViolations, readCatalog } from './dbcheck.ts'
|
|
15
|
+
import { draftConfig } from './init.ts'
|
|
16
|
+
import type { Module } from './layout.ts'
|
|
17
|
+
import { configText } from './loosen.ts'
|
|
18
|
+
import { contentKey, currentKey, layoutOf, openProject, type Project } from './project.ts'
|
|
19
|
+
import { BLOCKING_RULES, unownedFiles } from './rules.ts'
|
|
20
|
+
import { openStore, type Store } from './store.ts'
|
|
21
|
+
|
|
22
|
+
const USAGE = `用法:
|
|
23
|
+
modwall init 按现有目录生成配置草稿(${CONFIG_PATH})
|
|
24
|
+
modwall check 检查整个项目:R1–R5、R6 里迁移文件那部分、放宽项是否经用户同意;通过时记一条通过记录。
|
|
25
|
+
接入了的仓库,testpace full 里自动跑它
|
|
26
|
+
modwall db check --psql "<执行 SQL 的命令>" [--app <应用名>]
|
|
27
|
+
查库里的现状(R6 里库的那部分),迁移跑完之后执行;SQL 从标准输入交给这条命令,比如
|
|
28
|
+
--psql "psql \$DATABASE_URL"、--psql "napbox exec postgres --temp \$ENV -- psql";
|
|
29
|
+
几个应用都写了 database 时用 --app 指定查哪个应用的库
|
|
30
|
+
modwall status 越界、例外和确认情况,LayerMap 和 testpace 有没有接上`
|
|
31
|
+
|
|
32
|
+
/** 退出码用底座的:0 通过;1 没通过;2 用法、配置或环境问题。 */
|
|
33
|
+
|
|
34
|
+
function repoHere(): Repo | undefined {
|
|
35
|
+
const repo = openRepo(process.cwd())
|
|
36
|
+
if (!repo) console.error('modwall 要在 git 仓库里运行。')
|
|
37
|
+
return repo
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function init(): number {
|
|
41
|
+
const dir = repoHere()?.root
|
|
42
|
+
if (!dir) return EXIT.usage
|
|
43
|
+
if (existsSync(join(dir, CONFIG_PATH))) {
|
|
44
|
+
console.error(`已经有 ${CONFIG_PATH} 了,不覆盖。要重来就先删掉它。`)
|
|
45
|
+
return EXIT.usage
|
|
46
|
+
}
|
|
47
|
+
const config = draftConfig(dir, filesNow(dir))
|
|
48
|
+
mkdirSync(join(dir, MODWALL_DIR), { recursive: true })
|
|
49
|
+
const text = `${JSON.stringify(JSON.parse(configText(config)), null, 2)}\n`
|
|
50
|
+
writeFileSync(join(dir, CONFIG_PATH), text)
|
|
51
|
+
const lines = [`已生成配置草稿 ${CONFIG_PATH}(按常见的目录名认的,要核对):`, ...text.trimEnd().split('\n').map(line => ` ${line}`)]
|
|
52
|
+
const reopened = openProject(dir)
|
|
53
|
+
const project = 'project' in reopened ? reopened.project : undefined
|
|
54
|
+
if (project?.now.config) {
|
|
55
|
+
const layout = layoutOf(project, project.now.config)
|
|
56
|
+
if (schemeOf(config).apps.every(app => app.roots.length === 0)) lines.push('', '没认出模块根目录:把 roots 填成放模块的目录(它下面每个子目录是一个模块)。')
|
|
57
|
+
if (layout.problems.length) lines.push('', '配置有问题:', ...layout.problems.map(text => ` ✗ ${text}`))
|
|
58
|
+
const unowned = unownedFiles(layout, project.files)
|
|
59
|
+
if (unowned.length) {
|
|
60
|
+
lines.push('', `还有 ${unowned.length} 个代码文件没有归属(R5),把它们搬进模块、共享层或装配层,或者调整配置:`)
|
|
61
|
+
lines.push(...unowned.slice(0, 20).map(violation => ` · ${violation.where[0]}`))
|
|
62
|
+
if (unowned.length > 20) lines.push(` ……还有 ${unowned.length - 20} 个`)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
lines.push('', '从现在起,没有归属的代码文件不能新建也不能修改。核对好之后跑 modwall check,把列出的越界改到清零;首次接入时整份配置要用户在弹窗里确认一次。')
|
|
66
|
+
console.log(lines.join('\n'))
|
|
67
|
+
return EXIT.ok
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function open(): { project: Project; store: Store; repo: Repo } | number {
|
|
71
|
+
const repo = repoHere()
|
|
72
|
+
if (!repo) return EXIT.usage
|
|
73
|
+
const opened = openProject(repo.root)
|
|
74
|
+
if ('notJoined' in opened) {
|
|
75
|
+
console.log('这个仓库没有接入 modwall(没有 .modwall/ 目录),不检查。')
|
|
76
|
+
return EXIT.ok
|
|
77
|
+
}
|
|
78
|
+
return { project: opened.project, store: openStore(repo), repo }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function check(): number {
|
|
82
|
+
const opened = open()
|
|
83
|
+
if (typeof opened === 'number') return opened
|
|
84
|
+
const { project, store, repo } = opened
|
|
85
|
+
if (!project.base) {
|
|
86
|
+
console.error(`没法检查:${project.baseProblem}(放宽项要和分叉点上的配置比)`)
|
|
87
|
+
return EXIT.usage
|
|
88
|
+
}
|
|
89
|
+
// 按开始检查时的内容记通过记录
|
|
90
|
+
const key = contentKey(project)
|
|
91
|
+
const report = analyze(project, repo)
|
|
92
|
+
console.log(formatReport(report))
|
|
93
|
+
logCheck(store, project, report)
|
|
94
|
+
const code = exitCode(report)
|
|
95
|
+
if (code !== EXIT.ok) return code
|
|
96
|
+
// 结论是按开始时的内容得出的:检查的过程中内容改过,这次不记、不算
|
|
97
|
+
if (!store.passes.saveChecked(key, () => currentKey(project.root) ?? '', { at: Date.now() })) {
|
|
98
|
+
console.log('\n检查过程中内容改过(检查是按开始时的样子做的),这次的结论不算:代码不再改动时重跑 modwall check。')
|
|
99
|
+
return EXIT.fail
|
|
100
|
+
}
|
|
101
|
+
return EXIT.ok
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** modwall db check --psql "<命令>" [--app <应用名>]:不通过时退出码 1,没查成是 2。 */
|
|
105
|
+
function dbCheck(args: string[]): number {
|
|
106
|
+
let psql: string | undefined
|
|
107
|
+
let appName: string | undefined
|
|
108
|
+
for (let i = 0; i < args.length; i++) {
|
|
109
|
+
const arg = args[i]
|
|
110
|
+
if ((arg === '--psql' || arg === '--app') && args[i + 1] !== undefined) {
|
|
111
|
+
if (arg === '--psql') psql = args[++i]
|
|
112
|
+
else appName = args[++i]
|
|
113
|
+
} else {
|
|
114
|
+
console.error(`不认识的参数:${arg}\n${USAGE}`)
|
|
115
|
+
return EXIT.usage
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (!psql?.trim()) {
|
|
119
|
+
console.error(`modwall db check 要用 --psql 告诉它用什么命令执行 SQL(比如 --psql "psql \$DATABASE_URL")。\n${USAGE}`)
|
|
120
|
+
return EXIT.usage
|
|
121
|
+
}
|
|
122
|
+
const opened = open()
|
|
123
|
+
if (typeof opened === 'number') return opened
|
|
124
|
+
const { project } = opened
|
|
125
|
+
const prepared = prepare(project)
|
|
126
|
+
if ('problems' in prepared) {
|
|
127
|
+
console.error(`modwall db check:配置有问题(${CONFIG_PATH}),先改好再检查:\n${prepared.problems.map(text => ` ✗ ${text}`).join('\n')}`)
|
|
128
|
+
return EXIT.usage
|
|
129
|
+
}
|
|
130
|
+
if ('removed' in prepared) {
|
|
131
|
+
console.error(`modwall db check:工作区里没有 ${CONFIG_PATH},不知道模块怎么分。`)
|
|
132
|
+
return EXIT.usage
|
|
133
|
+
}
|
|
134
|
+
const { databases } = prepared.layout
|
|
135
|
+
if (databases.length === 0) {
|
|
136
|
+
console.error(`modwall db check:${CONFIG_PATH} 里没有写 database(用 Postgres 的应用写 "database": { "migrations": …, "shared": … })。`)
|
|
137
|
+
return EXIT.usage
|
|
138
|
+
}
|
|
139
|
+
const named = databases.map(database => database.app.name)
|
|
140
|
+
const database = appName === undefined ? (databases.length === 1 ? databases[0] : undefined) : databases.find(item => item.app.name === appName)
|
|
141
|
+
if (!database) {
|
|
142
|
+
console.error(
|
|
143
|
+
appName === undefined
|
|
144
|
+
? `modwall db check:${named.join('、')} 几个应用都写了 database,用 --app 指定查哪个应用的库。`
|
|
145
|
+
: `modwall db check:没有写了 database 的应用叫 ${appName}(写了的有:${named.filter(Boolean).join('、') || '单应用的写法,不用 --app'})。`,
|
|
146
|
+
)
|
|
147
|
+
return EXIT.usage
|
|
148
|
+
}
|
|
149
|
+
const catalog = readCatalog(project.root, psql)
|
|
150
|
+
if (!catalog.ok) {
|
|
151
|
+
console.error(`modwall db check:没查成,${catalog.problem}`)
|
|
152
|
+
return EXIT.usage
|
|
153
|
+
}
|
|
154
|
+
const violations = catalogViolations(database, catalog.value)
|
|
155
|
+
const which = database.app.name === undefined ? '' : `(${database.app.name} 应用的库)`
|
|
156
|
+
if (violations.length === 0) {
|
|
157
|
+
console.log(`modwall db check:通过${which}。库里没有越界。`)
|
|
158
|
+
return EXIT.ok
|
|
159
|
+
}
|
|
160
|
+
console.log([`modwall db check:没通过${which}。`, '', `库里越界 ${violations.length} 处(改迁移或跑迁移的工具,不要直接改库):`, ...violationLines(violations)].join('\n'))
|
|
161
|
+
return EXIT.fail
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function status(): number {
|
|
165
|
+
const opened = open()
|
|
166
|
+
if (typeof opened === 'number') return opened
|
|
167
|
+
const { project, store, repo } = opened
|
|
168
|
+
const lines: string[] = []
|
|
169
|
+
lines.push(project.base ? `和 ${project.base.branch} 的分叉点 ${project.base.commit.slice(0, 8)} 比(当前分支 ${project.branch})。` : `没算分叉点:${project.baseProblem}`)
|
|
170
|
+
const report = analyze(project, repo)
|
|
171
|
+
const config = project.now.config
|
|
172
|
+
if (report.configProblems.length) lines.push('配置有问题:', ...report.configProblems.map(text => ` ✗ ${text}`))
|
|
173
|
+
else if (config && report.layout) {
|
|
174
|
+
const { modules, scheme } = report.layout
|
|
175
|
+
const line = (module: Module, indent: string): string => `${indent}${module.id}(${module.dir})入口:${module.entries.length ? module.entries.join('、') : '还没有'}`
|
|
176
|
+
if (!scheme.grouped) {
|
|
177
|
+
lines.push(`模块(${modules.length} 个):`)
|
|
178
|
+
for (const module of modules) lines.push(line(module, ' '))
|
|
179
|
+
} else {
|
|
180
|
+
lines.push(`模块(${modules.length} 个,按应用分):`)
|
|
181
|
+
for (const app of scheme.apps) {
|
|
182
|
+
const own = modules.filter(module => module.app === app.name)
|
|
183
|
+
lines.push(` ${app.name} 应用(${own.length} 个):`, ...(own.length ? own.map(module => line(module, ' ')) : [' 还没有模块']))
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
lines.push(scheme.allow.length ? `例外(allow,${scheme.allow.length} 条):` : '例外(allow):没有')
|
|
187
|
+
for (const entry of scheme.allow) lines.push(` ${entry.rule} ${entry.from} → ${entry.to}:${entry.reason}`)
|
|
188
|
+
}
|
|
189
|
+
lines.push(...looseningStatus(report))
|
|
190
|
+
if (!report.configProblems.length && !report.removed) {
|
|
191
|
+
const counts = BLOCKING_RULES.map(rule => `${rule} ${report.violations.filter(violation => violation.rule === rule).length}`)
|
|
192
|
+
if (report.layermapProblem) lines.push(`越界:只查了 R5、R6(${counts.slice(-2).join('、')}),LayerMap 用不了,R1–R4 没查`)
|
|
193
|
+
else if (report.changesProblem) lines.push(`越界:${counts.join('、')};R4 和入口新增导出没查(这次改动增删的关系没读到)`)
|
|
194
|
+
else lines.push(`越界:${counts.join('、')};R4 提示 ${report.behavior.length}(详情跑 modwall check)`)
|
|
195
|
+
}
|
|
196
|
+
lines.push(`通过记录:${store.passes.get(contentKey(project)) ? '当前内容 modwall check 通过过' : '当前内容还没有通过记录(modwall check)'}`)
|
|
197
|
+
const version = layermapVersion()
|
|
198
|
+
lines.push(
|
|
199
|
+
version
|
|
200
|
+
? `LayerMap:${version}${report.layermapProblem ? `,用不了:${report.layermapProblem}` : report.changesProblem ? `,layermap check 没跑成:${report.changesProblem}` : ',能用'}(最低 ${LAYERMAP_MINIMUM})`
|
|
201
|
+
: `LayerMap:没找到 layermap 命令,要装 LayerMap 插件(${LAYERMAP_MINIMUM} 以上);${LAYERMAP_COMMAND}`,
|
|
202
|
+
)
|
|
203
|
+
lines.push(...testpaceStatus(project, report.layout !== undefined && report.layout.databases.length > 0))
|
|
204
|
+
console.log(lines.join('\n'))
|
|
205
|
+
return EXIT.ok
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function looseningStatus(report: Report): string[] {
|
|
209
|
+
if (report.loosening.length === 0) return ['放宽项:没有(和分叉点上的配置比)']
|
|
210
|
+
return ['放宽项(和分叉点上的配置比):', ...report.loosening.map(item => ` ${item.confirmed ? '✓ 用户同意过' : '· 还没同意'}:${item.item}`)]
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 合并前谁来拦:接入了 testpace(有 testpace.json)的仓库,modwall check 是整组里的一段。
|
|
215
|
+
* 写了 database 的,库里的现状要项目自己在整组里跑 modwall db check,这里只能看 testpace.json 的 full 里写没写。
|
|
216
|
+
*/
|
|
217
|
+
function testpaceStatus(project: Project, hasDatabase: boolean): string[] {
|
|
218
|
+
const contract = loadContract(project.root)
|
|
219
|
+
if (!contract) {
|
|
220
|
+
return [
|
|
221
|
+
`testpace:这个仓库没接入(没有 ${CONTRACT_FILE}):会话说明、停止门、合并门都不管它,只能自己记得跑 modwall check。`,
|
|
222
|
+
...(hasDatabase ? ['数据库:库里的现状要在迁移跑完后用 modwall db check 查;没接入 testpace,要项目自己安排在测试里跑。'] : []),
|
|
223
|
+
]
|
|
224
|
+
}
|
|
225
|
+
const lines = ['testpace:接入了。modwall check 是整组(testpace full)里的一段,没通过就不留整组通过记录,合并门照常拦。']
|
|
226
|
+
if (contract.raw === undefined) lines.push(` ${CONTRACT_FILE} 读不了,没核对 ignore`)
|
|
227
|
+
else if (matchesAny(CONFIG_PATH, contract.ignore)) {
|
|
228
|
+
lines.push(` ✗ ${CONTRACT_FILE} 的 ignore 盖住了 ${CONFIG_PATH}:改配置不会重跑整组,放宽规则就绕过了合并门。从 ignore 里去掉它。`)
|
|
229
|
+
}
|
|
230
|
+
if (hasDatabase) {
|
|
231
|
+
const full = contract.raw?.full
|
|
232
|
+
if (contract.raw === undefined) lines.push(`数据库:${CONTRACT_FILE} 读不了,没核对整组里有没有跑 modwall db check。`)
|
|
233
|
+
else if (typeof full === 'string' && full.includes('modwall db check')) lines.push('数据库:testpace 的 full 里跑了 modwall db check。')
|
|
234
|
+
else lines.push(`数据库:${CONTRACT_FILE} 的 full 里没看到 modwall db check。确认整组里迁移跑完后执行了它(写在 full 调用的脚本里的这里看不到);没接上的话,库里的现状没人查。`)
|
|
235
|
+
}
|
|
236
|
+
return lines
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* 在 agent 的沙箱里跑不了的子命令和它要做的事(见 base/commandline.ts)。
|
|
241
|
+
* check、status 要 LayerMap 的地图:它存在项目外面,沙箱里更新不了,R1–R4 查不成,check 会给出假的"没通过"。
|
|
242
|
+
* db check 跑的是项目给的命令,要连数据库。init 只读写项目里的文件,不在里面。
|
|
243
|
+
*/
|
|
244
|
+
export function outside(argv: string[]): string | undefined {
|
|
245
|
+
switch (argv[0]) {
|
|
246
|
+
case 'check':
|
|
247
|
+
return '让 LayerMap 更新它的地图(存在项目外面)、写 .git/testpace/ 的记录'
|
|
248
|
+
case 'status':
|
|
249
|
+
return '让 LayerMap 更新它的地图(存在项目外面)'
|
|
250
|
+
case 'db':
|
|
251
|
+
return argv[1] === 'check' ? '跑 --psql 给的命令连数据库' : undefined
|
|
252
|
+
default:
|
|
253
|
+
return undefined
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function main(argv: string[]): number {
|
|
258
|
+
switch (argv[0]) {
|
|
259
|
+
case 'init':
|
|
260
|
+
return init()
|
|
261
|
+
case 'check':
|
|
262
|
+
return check()
|
|
263
|
+
case 'db':
|
|
264
|
+
if (argv[1] === 'check') return dbCheck(argv.slice(2))
|
|
265
|
+
console.error(`不认识的命令:db ${argv[1] ?? ''}\n${USAGE}`)
|
|
266
|
+
return EXIT.usage
|
|
267
|
+
case 'status':
|
|
268
|
+
return status()
|
|
269
|
+
case undefined:
|
|
270
|
+
case '-h':
|
|
271
|
+
case '--help':
|
|
272
|
+
case 'help':
|
|
273
|
+
console.log(USAGE)
|
|
274
|
+
return argv[0] === undefined ? EXIT.usage : EXIT.ok
|
|
275
|
+
default:
|
|
276
|
+
console.error(`不认识的命令:${argv[0]}\n${USAGE}`)
|
|
277
|
+
return EXIT.usage
|
|
278
|
+
}
|
|
279
|
+
}
|