mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-06 06:41:08 +00:00
fix: unblock cli startup metadata
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { renderRootHelpText } from "../src/cli/program/root-help.ts";
|
||||
|
||||
function dedupe(values: string[]): string[] {
|
||||
const seen = new Set<string>();
|
||||
@@ -78,40 +79,10 @@ export function readBundledChannelCatalogIds(
|
||||
.map((entry) => entry.id);
|
||||
}
|
||||
|
||||
async function captureStdout(action: () => void | Promise<void>): Promise<string> {
|
||||
let output = "";
|
||||
const originalWrite = process.stdout.write.bind(process.stdout);
|
||||
const captureWrite: typeof process.stdout.write = ((chunk: string | Uint8Array) => {
|
||||
output += String(chunk);
|
||||
return true;
|
||||
}) as typeof process.stdout.write;
|
||||
process.stdout.write = captureWrite;
|
||||
try {
|
||||
await action();
|
||||
} finally {
|
||||
process.stdout.write = originalWrite;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
export async function renderBundledRootHelpText(
|
||||
distDirOverride: string = distDir,
|
||||
_distDirOverride: string = distDir,
|
||||
): Promise<string> {
|
||||
const bundleName = readdirSync(distDirOverride).find(
|
||||
(entry) => entry.startsWith("root-help-") && entry.endsWith(".js"),
|
||||
);
|
||||
if (!bundleName) {
|
||||
throw new Error("No root-help bundle found in dist; cannot write CLI startup metadata.");
|
||||
}
|
||||
const moduleUrl = pathToFileURL(path.join(distDirOverride, bundleName)).href;
|
||||
const mod = (await import(moduleUrl)) as { outputRootHelp?: () => void | Promise<void> };
|
||||
if (typeof mod.outputRootHelp !== "function") {
|
||||
throw new Error(`Bundle ${bundleName} does not export outputRootHelp.`);
|
||||
}
|
||||
|
||||
return captureStdout(async () => {
|
||||
await mod.outputRootHelp?.();
|
||||
});
|
||||
return await renderRootHelpText({ pluginDescriptors: [] });
|
||||
}
|
||||
|
||||
export async function writeCliStartupMetadata(options?: {
|
||||
|
||||
Reference in New Issue
Block a user