mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-12 21:53:00 -06:00
c70aee247e
* refactor(scripts): migrate JavaScript tools to TypeScript * fix(ci): keep changed-scope preflight zero-install * fix(ci): preserve zero-install script owners * fix(ci): complete script migration follow-through * fix(release): keep stable closeout zero-install * fix(scripts): preserve standalone execution boundaries * fix(scripts): repair standalone loader boundaries * fix(scripts): normalize gateway observation ids * fix(scripts): keep Docker packager standalone * test(scripts): preserve rebase cleanup helpers * test(sessions): use tracked temp directory
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
// Parses report CLI output arguments and writes optional artifacts.
|
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
import { parseFlagArgs, stringFlag } from "./arg-utils.mts";
|
|
|
|
type ReportCliArgs = { jsonPath: string | null; markdownPath: string | null; rootDir: string };
|
|
|
|
export function parseReportCliArgs(argv: string[]) {
|
|
const options: ReportCliArgs = {
|
|
rootDir: process.cwd(),
|
|
jsonPath: null,
|
|
markdownPath: null,
|
|
};
|
|
const flagEntries = [
|
|
["--root", "rootDir"],
|
|
["--json", "jsonPath"],
|
|
["--markdown", "markdownPath"],
|
|
] satisfies Array<[string, keyof ReportCliArgs]>;
|
|
const flagSpecs = flagEntries.map(([flag, key]) =>
|
|
stringFlag<ReportCliArgs>(flag, key, {
|
|
allowInline: false,
|
|
missingValueMessage: `Expected ${flag} <value>.`,
|
|
rejectShortOptions: true,
|
|
}),
|
|
);
|
|
return parseFlagArgs(argv, options, flagSpecs, {
|
|
duplicateOptionMessage: (flag: string) => `${flag} was provided more than once.`,
|
|
onUnhandledArg(arg: string) {
|
|
throw new Error(`Unsupported argument: ${arg}`);
|
|
},
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Writes an optional report artifact, creating its parent directory first.
|
|
*/
|
|
export async function writeReportArtifact(filePath: string | null, content: string) {
|
|
if (!filePath) {
|
|
return;
|
|
}
|
|
await mkdir(path.dirname(filePath), { recursive: true });
|
|
await writeFile(filePath, content, "utf8");
|
|
}
|