refactor: centralize channel ui metadata
This commit is contained in:
@@ -106,6 +106,7 @@ import { loginWeb } from "../../web/login.js";
|
||||
import { startWebLoginWithQr, waitForWebLogin } from "../../web/login-qr.js";
|
||||
import { sendMessageWhatsApp, sendPollWhatsApp } from "../../web/outbound.js";
|
||||
import { registerMemoryCli } from "../../cli/memory-cli.js";
|
||||
import { formatNativeDependencyHint } from "./native-deps.js";
|
||||
|
||||
import type { PluginRuntime } from "./types.js";
|
||||
|
||||
@@ -134,6 +135,7 @@ export function createPluginRuntime(): PluginRuntime {
|
||||
system: {
|
||||
enqueueSystemEvent,
|
||||
runCommandWithTimeout,
|
||||
formatNativeDependencyHint,
|
||||
},
|
||||
media: {
|
||||
loadWebMedia,
|
||||
|
||||
28
src/plugins/runtime/native-deps.ts
Normal file
28
src/plugins/runtime/native-deps.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
export type NativeDependencyHintParams = {
|
||||
packageName: string;
|
||||
manager?: "pnpm" | "npm" | "yarn";
|
||||
rebuildCommand?: string;
|
||||
approveBuildsCommand?: string;
|
||||
downloadCommand?: string;
|
||||
};
|
||||
|
||||
export function formatNativeDependencyHint(params: NativeDependencyHintParams): string {
|
||||
const manager = params.manager ?? "pnpm";
|
||||
const rebuildCommand =
|
||||
params.rebuildCommand ??
|
||||
(manager === "npm"
|
||||
? `npm rebuild ${params.packageName}`
|
||||
: manager === "yarn"
|
||||
? `yarn rebuild ${params.packageName}`
|
||||
: `pnpm rebuild ${params.packageName}`);
|
||||
const approveBuildsCommand =
|
||||
params.approveBuildsCommand ??
|
||||
(manager === "pnpm" ? `pnpm approve-builds (select ${params.packageName})` : undefined);
|
||||
const steps = [approveBuildsCommand, rebuildCommand, params.downloadCommand].filter(
|
||||
(step): step is string => Boolean(step),
|
||||
);
|
||||
if (steps.length === 0) {
|
||||
return `Install ${params.packageName} and rebuild its native module.`;
|
||||
}
|
||||
return `Install ${params.packageName} and rebuild its native module (${steps.join("; ")}).`;
|
||||
}
|
||||
@@ -59,6 +59,7 @@ type RecordChannelActivity = typeof import("../../infra/channel-activity.js").re
|
||||
type GetChannelActivity = typeof import("../../infra/channel-activity.js").getChannelActivity;
|
||||
type EnqueueSystemEvent = typeof import("../../infra/system-events.js").enqueueSystemEvent;
|
||||
type RunCommandWithTimeout = typeof import("../../process/exec.js").runCommandWithTimeout;
|
||||
type FormatNativeDependencyHint = typeof import("./native-deps.js").formatNativeDependencyHint;
|
||||
type LoadWebMedia = typeof import("../../web/media.js").loadWebMedia;
|
||||
type DetectMime = typeof import("../../media/mime.js").detectMime;
|
||||
type MediaKindFromMime = typeof import("../../media/constants.js").mediaKindFromMime;
|
||||
@@ -146,6 +147,7 @@ export type PluginRuntime = {
|
||||
system: {
|
||||
enqueueSystemEvent: EnqueueSystemEvent;
|
||||
runCommandWithTimeout: RunCommandWithTimeout;
|
||||
formatNativeDependencyHint: FormatNativeDependencyHint;
|
||||
};
|
||||
media: {
|
||||
loadWebMedia: LoadWebMedia;
|
||||
|
||||
Reference in New Issue
Block a user