mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 06:20:43 +00:00
refactor: centralize plugin update outcome logging
This commit is contained in:
@@ -10,6 +10,7 @@ import { defaultRuntime } from "../runtime.js";
|
||||
import { theme } from "../terminal/theme.js";
|
||||
import { commitPluginInstallRecordsWithConfig } from "./plugins-install-record-commit.js";
|
||||
import { refreshPluginRegistryAfterConfigMutation } from "./plugins-registry-refresh.js";
|
||||
import { logPluginUpdateOutcomes } from "./plugins-update-outcomes.js";
|
||||
import {
|
||||
resolveHookPackUpdateSelection,
|
||||
resolvePluginUpdateSelection,
|
||||
@@ -92,29 +93,10 @@ export async function runPluginUpdateCommand(params: {
|
||||
},
|
||||
});
|
||||
|
||||
for (const outcome of pluginResult.outcomes) {
|
||||
if (outcome.status === "error") {
|
||||
defaultRuntime.log(theme.error(outcome.message));
|
||||
continue;
|
||||
}
|
||||
if (outcome.status === "skipped") {
|
||||
defaultRuntime.log(theme.warn(outcome.message));
|
||||
continue;
|
||||
}
|
||||
defaultRuntime.log(outcome.message);
|
||||
}
|
||||
|
||||
for (const outcome of hookResult.outcomes) {
|
||||
if (outcome.status === "error") {
|
||||
defaultRuntime.log(theme.error(outcome.message));
|
||||
continue;
|
||||
}
|
||||
if (outcome.status === "skipped") {
|
||||
defaultRuntime.log(theme.warn(outcome.message));
|
||||
continue;
|
||||
}
|
||||
defaultRuntime.log(outcome.message);
|
||||
}
|
||||
const outcomeSummary = logPluginUpdateOutcomes({
|
||||
outcomes: [...pluginResult.outcomes, ...hookResult.outcomes],
|
||||
log: (message) => defaultRuntime.log(message),
|
||||
});
|
||||
|
||||
if (!params.opts.dryRun && (pluginResult.changed || hookResult.changed)) {
|
||||
const nextPluginInstallRecords = pluginResult.config.plugins?.installs ?? {};
|
||||
@@ -147,10 +129,7 @@ export async function runPluginUpdateCommand(params: {
|
||||
defaultRuntime.log("Restart the gateway to load plugins and hooks.");
|
||||
}
|
||||
|
||||
if (
|
||||
pluginResult.outcomes.some((outcome) => outcome.status === "error") ||
|
||||
hookResult.outcomes.some((outcome) => outcome.status === "error")
|
||||
) {
|
||||
if (outcomeSummary.hasErrors) {
|
||||
defaultRuntime.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
26
src/cli/plugins-update-outcomes.ts
Normal file
26
src/cli/plugins-update-outcomes.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { theme } from "../terminal/theme.js";
|
||||
|
||||
export type PluginUpdateCliOutcome = {
|
||||
status: string;
|
||||
message: string;
|
||||
};
|
||||
|
||||
export function logPluginUpdateOutcomes(params: {
|
||||
outcomes: readonly PluginUpdateCliOutcome[];
|
||||
log: (message: string) => void;
|
||||
}): { hasErrors: boolean } {
|
||||
let hasErrors = false;
|
||||
for (const outcome of params.outcomes) {
|
||||
if (outcome.status === "error") {
|
||||
hasErrors = true;
|
||||
params.log(theme.error(outcome.message));
|
||||
continue;
|
||||
}
|
||||
if (outcome.status === "skipped") {
|
||||
params.log(theme.warn(outcome.message));
|
||||
continue;
|
||||
}
|
||||
params.log(outcome.message);
|
||||
}
|
||||
return { hasErrors };
|
||||
}
|
||||
Reference in New Issue
Block a user