/** * Deployments command for CLI. * * Shows deployment history for an application. * * @module */ import { isErr } from "@mks2508/no-throw"; import chalk from "chalk"; import Table from "cli-table3"; import { getCoolifyService } from "../../coolify/index.js"; import { formatStatus } from "../../utils/format.js"; import { resolveUuid } from "../coolify-state.js"; import { resolveAppNameOrUuid } from "../name-resolver.js"; /** * Deployments command handler. * If no UUID is provided, reads from .coolify.json in the current directory. * * @param uuid - Application UUID (optional if .coolify.json exists) * @param options - Command options */ export async function deploymentsCommand( uuid: string | undefined, options: { full?: boolean; limit?: number } = {}, ) { let resolvedUuid = resolveUuid(uuid); if (!resolvedUuid && uuid) { resolvedUuid = await resolveAppNameOrUuid(uuid); } if (!resolvedUuid) { console.error( chalk.red("Error: No UUID/name provided and no .coolify.json found"), ); return; } uuid = resolvedUuid; const coolify = getCoolifyService(); const initResult = await coolify.init(); if (isErr(initResult)) { console.error(chalk.red(`Error: ${initResult.error.message}`)); return; } const result = await coolify.getApplicationDeploymentHistory(uuid); if (isErr(result)) { console.error(chalk.red(`Error: ${result.error.message}`)); return; } let deployments = result.value; // Show most recent first deployments = deployments.reverse(); if (options.limit) { deployments = deployments.slice(0, options.limit); } if (deployments.length === 0) { console.log(chalk.yellow("No deployments found")); return; } const table = new Table({ head: [ chalk.cyan("ID"), chalk.cyan("UUID"), chalk.cyan("Status"), chalk.cyan("Commit"), chalk.cyan("Created"), ], ...(options.full ? { colWidths: [8, 36, 20, 10, 20] } : {}), }); for (const dep of deployments) { table.push([ String(dep.id), dep.uuid || "-", formatStatus(dep.status), dep.commit?.slice(0, 7) || "-", new Date(dep.created_at).toLocaleString(), ]); } console.log(table.toString()); console.log(chalk.gray(`Total: ${deployments.length} deployment(s)`)); }