/** * `plugins list` — print every installed plugin row across all tenants * (or filtered to one). */ import { defineCommand } from "citty"; import consola from "consola"; export const pluginsListCommand = defineCommand({ meta: { name: "list", description: "List installed plugins.", }, args: { tenantId: { type: "string", description: "Filter to a single tenant.", }, enabled: { type: "string", description: "Filter: 'true' for enabled only, 'false' for disabled only.", }, }, async run({ args }) { const { getDbClient } = await import("@toolctrl/db/client.server"); const prisma = getDbClient(); const where: Record = {}; if (typeof args.tenantId === "string" && args.tenantId.length > 0) { where.tenantId = args.tenantId; } if (args.enabled === "true") where.enabled = true; if (args.enabled === "false") where.enabled = false; const rows = await prisma.plugin.findMany({ where: where as never, orderBy: [{ tenantId: "asc" }, { pluginId: "asc" }], select: { id: true, tenantId: true, pluginId: true, version: true, enabled: true, installedAt: true, }, }); if (rows.length === 0) { consola.info("No installed plugins matched the filter."); return; } for (const row of rows) { const state = row.enabled ? "ON " : "OFF"; consola.log(`${state} ${row.tenantId.padEnd(28)} ${row.pluginId.padEnd(36)} v${row.version}`); } consola.success(`${rows.length} plugin row(s) listed.`); }, });