mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
perf(browser): precompute browser help
This commit is contained in:
31
openclaw.mjs
31
openclaw.mjs
@@ -128,13 +128,18 @@ const buildMissingEntryErrorMessage = async () => {
|
||||
const isBareRootHelpInvocation = (argv) =>
|
||||
argv.length === 3 && (argv[2] === "--help" || argv[2] === "-h");
|
||||
|
||||
const loadPrecomputedRootHelpText = () => {
|
||||
const isBrowserHelpInvocation = (argv) =>
|
||||
argv.length === 4 && argv[2] === "browser" && (argv[3] === "--help" || argv[3] === "-h");
|
||||
|
||||
const isHelpFastPathDisabled = () =>
|
||||
process.env.OPENCLAW_DISABLE_CLI_STARTUP_HELP_FAST_PATH === "1";
|
||||
|
||||
const loadPrecomputedHelpText = (key) => {
|
||||
try {
|
||||
const raw = readFileSync(new URL("./dist/cli-startup-metadata.json", import.meta.url), "utf8");
|
||||
const parsed = JSON.parse(raw);
|
||||
return typeof parsed?.rootHelpText === "string" && parsed.rootHelpText.length > 0
|
||||
? parsed.rootHelpText
|
||||
: null;
|
||||
const value = parsed?.[key];
|
||||
return typeof value === "string" && value.length > 0 ? value : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
@@ -144,7 +149,7 @@ const tryOutputBareRootHelp = async () => {
|
||||
if (!isBareRootHelpInvocation(process.argv)) {
|
||||
return false;
|
||||
}
|
||||
const precomputed = loadPrecomputedRootHelpText();
|
||||
const precomputed = loadPrecomputedHelpText("rootHelpText");
|
||||
if (precomputed) {
|
||||
process.stdout.write(precomputed);
|
||||
return true;
|
||||
@@ -166,7 +171,21 @@ const tryOutputBareRootHelp = async () => {
|
||||
return false;
|
||||
};
|
||||
|
||||
if (await tryOutputBareRootHelp()) {
|
||||
const tryOutputBrowserHelp = () => {
|
||||
if (!isBrowserHelpInvocation(process.argv)) {
|
||||
return false;
|
||||
}
|
||||
const precomputed = loadPrecomputedHelpText("browserHelpText");
|
||||
if (!precomputed) {
|
||||
return false;
|
||||
}
|
||||
process.stdout.write(precomputed);
|
||||
return true;
|
||||
};
|
||||
|
||||
if (!isHelpFastPathDisabled() && (await tryOutputBareRootHelp())) {
|
||||
// OK
|
||||
} else if (!isHelpFastPathDisabled() && tryOutputBrowserHelp()) {
|
||||
// OK
|
||||
} else {
|
||||
await installProcessWarningFilter();
|
||||
|
||||
Reference in New Issue
Block a user