docs(release): seal and deliver task agreement 1.25 with retained production state
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import fs from 'node:fs';
|
||||
import { normalizeTasks } from './normalize.mjs';
|
||||
import { summarize } from './summary.mjs';
|
||||
import { renderText } from './render.mjs';
|
||||
|
||||
try {
|
||||
const args = process.argv.slice(2);
|
||||
if (args.length < 1 || args.length > 2 || !args[0] || args[0].startsWith('-') ||
|
||||
(args.length === 2 && args[1] !== '--json')) {
|
||||
throw new TypeError('用法:node src/cli.mjs <JSON文件> [--json]');
|
||||
}
|
||||
|
||||
const source = fs.readFileSync(args[0], 'utf8');
|
||||
const tasks = normalizeTasks(JSON.parse(source));
|
||||
const summary = summarize(tasks);
|
||||
const output = args[1] === '--json' ? JSON.stringify(summary) : renderText(summary);
|
||||
process.stdout.write(output + '\n');
|
||||
process.exitCode = 0;
|
||||
} catch (error) {
|
||||
process.stderr.write(`输入错误:${error.message}\n`);
|
||||
process.exitCode = 2;
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
const statuses = new Set(['todo', 'doing', 'done', 'blocked']);
|
||||
|
||||
export function normalizeTasks(input) {
|
||||
if (!Array.isArray(input)) throw new TypeError('任务必须是数组');
|
||||
if (input.length > 10000) throw new RangeError('任务数量不能超过10000项');
|
||||
|
||||
const ids = new Set();
|
||||
const tasks = [];
|
||||
for (const task of input) {
|
||||
if (task === null || typeof task !== 'object' || Array.isArray(task)) {
|
||||
throw new TypeError('每项任务必须是对象');
|
||||
}
|
||||
if (typeof task.id !== 'string' || typeof task.title !== 'string') {
|
||||
throw new TypeError('任务id和title必须是字符串');
|
||||
}
|
||||
const id = task.id.trim();
|
||||
const title = task.title.trim();
|
||||
if (!id || !title) throw new TypeError('任务id和title不能为空');
|
||||
if (ids.has(id)) throw new TypeError(`任务id重复:${id}`);
|
||||
|
||||
const { status, minutes } = task;
|
||||
if (!statuses.has(status)) {
|
||||
throw new TypeError('任务status必须是todo、doing、done或blocked');
|
||||
}
|
||||
if (!Number.isSafeInteger(minutes) || minutes < 0 || minutes > 1000000) {
|
||||
throw new RangeError('任务minutes必须是0到1000000之间的安全整数');
|
||||
}
|
||||
ids.add(id);
|
||||
tasks.push({ id, title, status, minutes });
|
||||
}
|
||||
return tasks;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
export function renderText(summary) {
|
||||
const { total, counts, completedPercent, remainingMinutes } = summary;
|
||||
return [
|
||||
`交付进度:${counts.done}/${total}(${completedPercent}%)`,
|
||||
`待办 ${counts.todo} · 进行中 ${counts.doing} · 已完成 ${counts.done} · 阻塞 ${counts.blocked}`,
|
||||
`剩余预计:${remainingMinutes} 分钟`,
|
||||
].join('\n');
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
export function summarize(tasks) {
|
||||
const counts = { todo: 0, doing: 0, done: 0, blocked: 0 };
|
||||
let remainingMinutes = 0;
|
||||
for (const task of tasks) {
|
||||
counts[task.status] += 1;
|
||||
if (task.status !== 'done') remainingMinutes += task.minutes;
|
||||
}
|
||||
|
||||
const total = tasks.length;
|
||||
return {
|
||||
total,
|
||||
counts,
|
||||
completedPercent: total === 0 ? 0 : Math.round(counts.done / total * 100),
|
||||
remainingMinutes,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user