feat: scanChanges 扩展返回 DocumentStatus、planCompleted、buildUnlocked
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
import { readdir, stat, readFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import type { ChangeStatus } from "../types.ts";
|
||||
import type { ChangeStatus, DocumentStatus, RuneConfig } from "../types.ts";
|
||||
import { getChangesDir, getArchiveDir } from "./config.ts";
|
||||
import { parseTasks } from "./task-parser.ts";
|
||||
|
||||
export async function scanChanges(
|
||||
projectRoot: string,
|
||||
config?: RuneConfig,
|
||||
): Promise<ChangeStatus[]> {
|
||||
const changesDir = getChangesDir(projectRoot);
|
||||
const results: ChangeStatus[] = [];
|
||||
const planDocs = config?.stages.plan?.documents;
|
||||
|
||||
try {
|
||||
const entries = await readdir(changesDir);
|
||||
@@ -17,11 +19,34 @@ export async function scanChanges(
|
||||
const entryStat = await stat(entryPath);
|
||||
if (!entryStat.isDirectory()) continue;
|
||||
|
||||
const docs = await readdir(entryPath);
|
||||
const documents = docs.filter((d) => d.endsWith(".md"));
|
||||
const files = await readdir(entryPath);
|
||||
const mdFiles = new Set(files.filter((f) => f.endsWith(".md")));
|
||||
|
||||
let documents: DocumentStatus[];
|
||||
|
||||
if (planDocs) {
|
||||
documents = planDocs.map((docConfig) => {
|
||||
const fileName = `${docConfig.name}.md`;
|
||||
const completed = mdFiles.has(fileName);
|
||||
const deps = docConfig.depend ?? [];
|
||||
const dependMet =
|
||||
deps.length === 0 ||
|
||||
deps.every((dep) => mdFiles.has(`${dep}.md`));
|
||||
return { name: docConfig.name, completed, dependMet };
|
||||
});
|
||||
} else {
|
||||
documents = Array.from(mdFiles).map((fileName) => ({
|
||||
name: fileName.replace(/\.md$/, ""),
|
||||
completed: true,
|
||||
dependMet: true,
|
||||
}));
|
||||
}
|
||||
|
||||
const planCompleted = planDocs ? documents.every((d) => d.completed) : false;
|
||||
const buildUnlocked = planCompleted;
|
||||
|
||||
let taskProgress: { completed: number; total: number } | null = null;
|
||||
const taskFile = docs.find((d) => d === "task.md");
|
||||
const taskFile = files.find((d) => d === "task.md");
|
||||
if (taskFile) {
|
||||
const content = await readFile(join(entryPath, taskFile), "utf-8");
|
||||
const tasks = parseTasks(content);
|
||||
@@ -31,7 +56,13 @@ export async function scanChanges(
|
||||
};
|
||||
}
|
||||
|
||||
results.push({ name: entry, documents, taskProgress });
|
||||
results.push({
|
||||
name: entry,
|
||||
documents,
|
||||
planCompleted,
|
||||
buildUnlocked,
|
||||
taskProgress,
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user