mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 18:50:42 +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 { theme } from "../terminal/theme.js";
|
||||||
import { commitPluginInstallRecordsWithConfig } from "./plugins-install-record-commit.js";
|
import { commitPluginInstallRecordsWithConfig } from "./plugins-install-record-commit.js";
|
||||||
import { refreshPluginRegistryAfterConfigMutation } from "./plugins-registry-refresh.js";
|
import { refreshPluginRegistryAfterConfigMutation } from "./plugins-registry-refresh.js";
|
||||||
|
import { logPluginUpdateOutcomes } from "./plugins-update-outcomes.js";
|
||||||
import {
|
import {
|
||||||
resolveHookPackUpdateSelection,
|
resolveHookPackUpdateSelection,
|
||||||
resolvePluginUpdateSelection,
|
resolvePluginUpdateSelection,
|
||||||
@@ -92,29 +93,10 @@ export async function runPluginUpdateCommand(params: {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const outcome of pluginResult.outcomes) {
|
const outcomeSummary = logPluginUpdateOutcomes({
|
||||||
if (outcome.status === "error") {
|
outcomes: [...pluginResult.outcomes, ...hookResult.outcomes],
|
||||||
defaultRuntime.log(theme.error(outcome.message));
|
log: (message) => defaultRuntime.log(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);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!params.opts.dryRun && (pluginResult.changed || hookResult.changed)) {
|
if (!params.opts.dryRun && (pluginResult.changed || hookResult.changed)) {
|
||||||
const nextPluginInstallRecords = pluginResult.config.plugins?.installs ?? {};
|
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.");
|
defaultRuntime.log("Restart the gateway to load plugins and hooks.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (outcomeSummary.hasErrors) {
|
||||||
pluginResult.outcomes.some((outcome) => outcome.status === "error") ||
|
|
||||||
hookResult.outcomes.some((outcome) => outcome.status === "error")
|
|
||||||
) {
|
|
||||||
defaultRuntime.exit(1);
|
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