@microfox/cli
Version:
Universal CLI tool for creating modern TypeScript packages with npm availability checking
94 lines (92 loc) • 6.02 kB
JavaScript
// src/commands/status.ts
import chalk from "chalk";
import axios from "axios";
import inquirer from "inquirer";
var API_BASE_URL = "https://staging-cicd.microfox.app/api/deployment-status/agent/status/";
async function getRunId(runId) {
if (runId) {
return runId;
}
const { promptedRunId } = await inquirer.prompt([
{
type: "input",
name: "promptedRunId",
message: "Please enter the deployment Run ID:",
validate: (input) => !!input || "Run ID cannot be empty."
}
]);
return promptedRunId;
}
async function getDeploymentData(runId) {
var _a;
try {
const response = await axios.get(`${API_BASE_URL}${runId}`);
return response.data;
} catch (error) {
if (axios.isAxiosError(error) && ((_a = error.response) == null ? void 0 : _a.status) === 404) {
console.error(chalk.red(`\u274C Error: Deployment with Run ID "${runId}" not found.`));
} else {
console.error(chalk.red("\u274C An error occurred while fetching deployment status:"));
console.error(error);
}
process.exit(1);
}
}
async function statusCommand(runId) {
const finalRunId = await getRunId(runId);
const data = await getDeploymentData(finalRunId);
const deployment = data.data.deployment;
console.log(chalk.cyan.bold("\u{1F680} Deployment Status"));
console.log(chalk.gray("----------------------------------------"));
console.log(`${chalk.bold("Run ID:")} ${deployment.sha}`);
console.log(`${chalk.bold("Status:")} ${chalk.green(deployment.status)}`);
console.log(`${chalk.bold("Description:")} ${deployment.statusDescription}`);
console.log(`${chalk.bold("Stage:")} ${deployment.stage}`);
console.log(`${chalk.bold("Start Time:")} ${deployment.startTime ? new Date(deployment.startTime).toLocaleString() : "N/A"}`);
console.log(`${chalk.bold("End Time:")} ${deployment.endTime ? new Date(deployment.endTime).toLocaleString() : "N/A"}`);
console.log(`${chalk.bold("Base URL:")} ${deployment.baseUrl ? chalk.underline.blue(deployment.baseUrl) : "N/A"}`);
console.log(chalk.gray("----------------------------------------"));
}
async function logsCommand(runId) {
const finalRunId = await getRunId(runId);
const data = await getDeploymentData(finalRunId);
const logs = data.data.deploymentLogs;
console.log(chalk.cyan.bold("\u{1F4DC} Deployment Logs"));
console.log(chalk.gray("----------------------------------------"));
console.log(logs);
console.log(chalk.gray("----------------------------------------"));
}
async function metricsCommand(runId) {
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D;
const finalRunId = await getRunId(runId);
const data = await getDeploymentData(finalRunId);
const metrics = data.data.deployment.metrics;
console.log(chalk.cyan.bold("\u{1F4CA} Deployment Metrics"));
console.log(chalk.gray("----------------------------------------"));
console.log(chalk.bold.underline("System"));
console.log(` Platform: ${metrics.system.platform}`);
console.log(` Architecture: ${metrics.system.arch}`);
console.log(` Node Version: ${metrics.system.nodeVersion}`);
console.log(chalk.bold.underline("\nTiming (ms)"));
for (const [step, duration] of Object.entries(((_a = metrics == null ? void 0 : metrics.timing) == null ? void 0 : _a.stepDurations) || {})) {
console.log(` ${step}:`.padEnd(15) + `${duration ? `${duration}ms` : "N/A"}`);
}
console.log(` Total Duration:`.padEnd(15) + `${((_b = metrics == null ? void 0 : metrics.timing) == null ? void 0 : _b.totalDuration) ? `${metrics.timing.totalDuration}ms` : "N/A"}`);
console.log(chalk.bold.underline("\nResources"));
console.log(chalk.bold(" CPU:"));
console.log(` Peak: ${((_d = (_c = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _c.cpu) == null ? void 0 : _d.peak) ? `${(_f = (_e = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _e.cpu) == null ? void 0 : _f.peak}${(_h = (_g = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _g.cpu) == null ? void 0 : _h.usageUnits}` : "N/A"}`);
console.log(` Average: ${((_j = (_i = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _i.cpu) == null ? void 0 : _j.average) ? `${(_l = (_k = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _k.cpu) == null ? void 0 : _l.average}${(_n = (_m = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _m.cpu) == null ? void 0 : _n.usageUnits}` : "N/A"}`);
console.log(chalk.bold(" Memory:"));
console.log(` Peak: ${((_p = (_o = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _o.memory) == null ? void 0 : _p.peak) ? `${(_r = (_q = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _q.memory) == null ? void 0 : _r.peak.toFixed(2)}${(_t = (_s = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _s.memory) == null ? void 0 : _t.usageUnits}` : "N/A"}`);
console.log(` Average: ${((_v = (_u = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _u.memory) == null ? void 0 : _v.average) ? `${(_x = (_w = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _w.memory) == null ? void 0 : _x.average.toFixed(2)}${(_z = (_y = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _y.memory) == null ? void 0 : _z.usageUnits}` : "N/A"}`);
console.log(chalk.bold(" Disk:"));
console.log(` Final Size: ${((_B = (_A = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _A.diskSize) == null ? void 0 : _B.final) ? `${(((_D = (_C = metrics == null ? void 0 : metrics.resources) == null ? void 0 : _C.diskSize) == null ? void 0 : _D.final) / (1024 * 1024)).toFixed(2)} MB` : "N/A"}`);
console.log(chalk.gray("----------------------------------------"));
}
export {
statusCommand,
logsCommand,
metricsCommand
};
//# sourceMappingURL=chunk-MSVUZOBM.mjs.map