86 lines
2.5 KiB
JavaScript
86 lines
2.5 KiB
JavaScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { execFileSync } from "node:child_process";
|
|
const root = path.resolve(import.meta.dirname, "..");
|
|
const git = (...args) =>
|
|
execFileSync("git", args, {
|
|
cwd: root,
|
|
encoding: "utf8",
|
|
stdio: ["ignore", "pipe", "pipe"],
|
|
}).trim();
|
|
const tasks = JSON.parse(
|
|
fs.readFileSync(path.join(root, "docs/tasks/tasks.json"), "utf8"),
|
|
);
|
|
const id = process.argv[2];
|
|
if (!id || !Object.hasOwn(tasks, id)) {
|
|
console.error(`用法: pnpm task:check <${Object.keys(tasks).join("|")}>`);
|
|
process.exit(1);
|
|
}
|
|
const task = tasks[id];
|
|
const fail = (message) => {
|
|
console.error(message);
|
|
process.exit(1);
|
|
};
|
|
try {
|
|
git("merge-base", "--is-ancestor", task.base, "HEAD");
|
|
} catch {
|
|
fail(
|
|
`HEAD不包含最低代码基线${task.base}。同步包含该任务卡的集成提交,禁止从旧main猜测实现。`,
|
|
);
|
|
}
|
|
for (const file of [
|
|
"AGENTS.md",
|
|
"docs/tasks/README.md",
|
|
`docs/tasks/${id}.md`,
|
|
...task.requires,
|
|
])
|
|
if (!fs.existsSync(path.join(root, file))) fail(`缺少前置文件:${file}`);
|
|
const supplied = process.argv.indexOf("--reference");
|
|
const candidates =
|
|
supplied >= 0
|
|
? [process.argv[supplied + 1]]
|
|
: ["../heroui", "../reference/heroui"];
|
|
const reference = candidates
|
|
.filter(Boolean)
|
|
.map((p) => path.resolve(root, p))
|
|
.find((p) => fs.existsSync(path.join(p, ".git")));
|
|
if (!reference)
|
|
fail(
|
|
"找不到只读HeroUI参考仓库;用 --reference /absolute/path 指定。不依赖旧聊天中的相邻目录。构建不得依赖该目录。",
|
|
);
|
|
for (const file of task.sources) {
|
|
try {
|
|
execFileSync("git", ["cat-file", "-e", `${task.upstream}:${file}`], {
|
|
cwd: reference,
|
|
stdio: "pipe",
|
|
});
|
|
} catch {
|
|
fail(`固定源缺失:${task.upstream}:${file},参考目录${reference}`);
|
|
}
|
|
}
|
|
console.log(
|
|
JSON.stringify(
|
|
{
|
|
task: id,
|
|
status: task.status,
|
|
root,
|
|
head: git("rev-parse", "HEAD"),
|
|
branch: git("branch", "--show-current"),
|
|
minimumBase: task.base,
|
|
reference,
|
|
sourceBaseline: task.upstream,
|
|
requires: task.requires,
|
|
checks: task.checks,
|
|
},
|
|
null,
|
|
2,
|
|
),
|
|
);
|
|
if (git("status", "--porcelain"))
|
|
console.log(
|
|
"注意:工作区有未提交内容。先确认归属并保留;本命令不会切分支、覆盖或清理文件。",
|
|
);
|
|
console.log(
|
|
"前置检查通过;不是功能验收。按任务卡执行并更新仓库内结果记录,勿依赖临时文件或旧会话。",
|
|
);
|