mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 04:17:27 +00:00
refactor(cli): dedupe plugin install config wiring
This commit is contained in:
@@ -127,6 +127,29 @@ function applySlotSelectionForPlugin(
|
|||||||
return { config: result.config, warnings: result.warnings };
|
return { config: result.config, warnings: result.warnings };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createPluginInstallLogger(): { info: (msg: string) => void; warn: (msg: string) => void } {
|
||||||
|
return {
|
||||||
|
info: (msg) => defaultRuntime.log(msg),
|
||||||
|
warn: (msg) => defaultRuntime.log(theme.warn(msg)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function enablePluginInConfig(config: OpenClawConfig, pluginId: string): OpenClawConfig {
|
||||||
|
return {
|
||||||
|
...config,
|
||||||
|
plugins: {
|
||||||
|
...config.plugins,
|
||||||
|
entries: {
|
||||||
|
...config.plugins?.entries,
|
||||||
|
[pluginId]: {
|
||||||
|
...(config.plugins?.entries?.[pluginId] as object | undefined),
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function logSlotWarnings(warnings: string[]) {
|
function logSlotWarnings(warnings: string[]) {
|
||||||
if (warnings.length === 0) {
|
if (warnings.length === 0) {
|
||||||
return;
|
return;
|
||||||
@@ -531,23 +554,19 @@ export function registerPluginsCli(program: Command) {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let next: OpenClawConfig = {
|
let next: OpenClawConfig = enablePluginInConfig(
|
||||||
...cfg,
|
{
|
||||||
plugins: {
|
...cfg,
|
||||||
...cfg.plugins,
|
plugins: {
|
||||||
load: {
|
...cfg.plugins,
|
||||||
...cfg.plugins?.load,
|
load: {
|
||||||
paths: merged,
|
...cfg.plugins?.load,
|
||||||
},
|
paths: merged,
|
||||||
entries: {
|
|
||||||
...cfg.plugins?.entries,
|
|
||||||
[probe.pluginId]: {
|
|
||||||
...(cfg.plugins?.entries?.[probe.pluginId] as object | undefined),
|
|
||||||
enabled: true,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
probe.pluginId,
|
||||||
|
);
|
||||||
next = recordPluginInstall(next, {
|
next = recordPluginInstall(next, {
|
||||||
pluginId: probe.pluginId,
|
pluginId: probe.pluginId,
|
||||||
source: "path",
|
source: "path",
|
||||||
@@ -566,29 +585,14 @@ export function registerPluginsCli(program: Command) {
|
|||||||
|
|
||||||
const result = await installPluginFromPath({
|
const result = await installPluginFromPath({
|
||||||
path: resolved,
|
path: resolved,
|
||||||
logger: {
|
logger: createPluginInstallLogger(),
|
||||||
info: (msg) => defaultRuntime.log(msg),
|
|
||||||
warn: (msg) => defaultRuntime.log(theme.warn(msg)),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
defaultRuntime.error(result.error);
|
defaultRuntime.error(result.error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let next: OpenClawConfig = {
|
let next = enablePluginInConfig(cfg, result.pluginId);
|
||||||
...cfg,
|
|
||||||
plugins: {
|
|
||||||
...cfg.plugins,
|
|
||||||
entries: {
|
|
||||||
...cfg.plugins?.entries,
|
|
||||||
[result.pluginId]: {
|
|
||||||
...(cfg.plugins?.entries?.[result.pluginId] as object | undefined),
|
|
||||||
enabled: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const source: "archive" | "path" = resolveArchiveKind(resolved) ? "archive" : "path";
|
const source: "archive" | "path" = resolveArchiveKind(resolved) ? "archive" : "path";
|
||||||
next = recordPluginInstall(next, {
|
next = recordPluginInstall(next, {
|
||||||
pluginId: result.pluginId,
|
pluginId: result.pluginId,
|
||||||
@@ -630,29 +634,14 @@ export function registerPluginsCli(program: Command) {
|
|||||||
|
|
||||||
const result = await installPluginFromNpmSpec({
|
const result = await installPluginFromNpmSpec({
|
||||||
spec: raw,
|
spec: raw,
|
||||||
logger: {
|
logger: createPluginInstallLogger(),
|
||||||
info: (msg) => defaultRuntime.log(msg),
|
|
||||||
warn: (msg) => defaultRuntime.log(theme.warn(msg)),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
defaultRuntime.error(result.error);
|
defaultRuntime.error(result.error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
let next: OpenClawConfig = {
|
let next = enablePluginInConfig(cfg, result.pluginId);
|
||||||
...cfg,
|
|
||||||
plugins: {
|
|
||||||
...cfg.plugins,
|
|
||||||
entries: {
|
|
||||||
...cfg.plugins?.entries,
|
|
||||||
[result.pluginId]: {
|
|
||||||
...(cfg.plugins?.entries?.[result.pluginId] as object | undefined),
|
|
||||||
enabled: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
next = recordPluginInstall(next, {
|
next = recordPluginInstall(next, {
|
||||||
pluginId: result.pluginId,
|
pluginId: result.pluginId,
|
||||||
source: "npm",
|
source: "npm",
|
||||||
|
|||||||
Reference in New Issue
Block a user