refactor: install optional channels for directory

This commit is contained in:
Peter Steinberger
2026-03-19 07:22:30 +00:00
parent 06845a1974
commit ba1bb8505f
2 changed files with 132 additions and 7 deletions

View File

@@ -1,7 +1,8 @@
import type { Command } from "commander";
import { resolveChannelDefaultAccountId } from "../channels/plugins/helpers.js";
import { getChannelPlugin } from "../channels/plugins/index.js";
import { loadConfig } from "../config/config.js";
import { resolveInstallableChannelPlugin } from "../commands/channel-setup/channel-plugin-resolution.js";
import { loadConfig, writeConfigFile } from "../config/config.js";
import { danger } from "../globals.js";
import { resolveMessageChannelSelection } from "../infra/outbound/channel-selection.js";
import { defaultRuntime } from "../runtime.js";
@@ -96,13 +97,32 @@ export function registerDirectoryCli(program: Command) {
.option("--json", "Output JSON", false);
const resolve = async (opts: { channel?: string; account?: string }) => {
const cfg = loadConfig();
const selection = await resolveMessageChannelSelection({
cfg,
channel: opts.channel ?? null,
});
let cfg = loadConfig();
const explicitChannel = opts.channel?.trim();
const resolvedExplicit = explicitChannel
? await resolveInstallableChannelPlugin({
cfg,
runtime: defaultRuntime,
rawChannel: explicitChannel,
allowInstall: true,
supports: (plugin) => Boolean(plugin.directory),
})
: null;
if (resolvedExplicit?.configChanged) {
cfg = resolvedExplicit.cfg;
await writeConfigFile(cfg);
}
const selection = explicitChannel
? {
channel: resolvedExplicit?.channelId,
}
: await resolveMessageChannelSelection({
cfg,
channel: opts.channel ?? null,
});
const channelId = selection.channel;
const plugin = getChannelPlugin(channelId);
const plugin =
resolvedExplicit?.plugin ?? (channelId ? getChannelPlugin(channelId) : undefined);
if (!plugin) {
throw new Error(`Unsupported channel: ${String(channelId)}`);
}