UNPKG

@microfox/cli

Version:

Universal CLI tool for creating modern TypeScript packages with npm availability checking

129 lines (128 loc) 8.19 kB
#!/usr/bin/env node "use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/commands/status.ts var status_exports = {}; __export(status_exports, { logsCommand: () => logsCommand, metricsCommand: () => metricsCommand, statusCommand: () => statusCommand }); module.exports = __toCommonJS(status_exports); var import_chalk = __toESM(require("chalk")); var import_axios = __toESM(require("axios")); var import_inquirer = __toESM(require("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 import_inquirer.default.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 import_axios.default.get(`${API_BASE_URL}${runId}`); return response.data; } catch (error) { if (import_axios.default.isAxiosError(error) && ((_a = error.response) == null ? void 0 : _a.status) === 404) { console.error(import_chalk.default.red(`\u274C Error: Deployment with Run ID "${runId}" not found.`)); } else { console.error(import_chalk.default.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(import_chalk.default.cyan.bold("\u{1F680} Deployment Status")); console.log(import_chalk.default.gray("----------------------------------------")); console.log(`${import_chalk.default.bold("Run ID:")} ${deployment.sha}`); console.log(`${import_chalk.default.bold("Status:")} ${import_chalk.default.green(deployment.status)}`); console.log(`${import_chalk.default.bold("Description:")} ${deployment.statusDescription}`); console.log(`${import_chalk.default.bold("Stage:")} ${deployment.stage}`); console.log(`${import_chalk.default.bold("Start Time:")} ${deployment.startTime ? new Date(deployment.startTime).toLocaleString() : "N/A"}`); console.log(`${import_chalk.default.bold("End Time:")} ${deployment.endTime ? new Date(deployment.endTime).toLocaleString() : "N/A"}`); console.log(`${import_chalk.default.bold("Base URL:")} ${deployment.baseUrl ? import_chalk.default.underline.blue(deployment.baseUrl) : "N/A"}`); console.log(import_chalk.default.gray("----------------------------------------")); } async function logsCommand(runId) { const finalRunId = await getRunId(runId); const data = await getDeploymentData(finalRunId); const logs = data.data.deploymentLogs; console.log(import_chalk.default.cyan.bold("\u{1F4DC} Deployment Logs")); console.log(import_chalk.default.gray("----------------------------------------")); console.log(logs); console.log(import_chalk.default.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(import_chalk.default.cyan.bold("\u{1F4CA} Deployment Metrics")); console.log(import_chalk.default.gray("----------------------------------------")); console.log(import_chalk.default.bold.underline("System")); console.log(` Platform: ${metrics.system.platform}`); console.log(` Architecture: ${metrics.system.arch}`); console.log(` Node Version: ${metrics.system.nodeVersion}`); console.log(import_chalk.default.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(import_chalk.default.bold.underline("\nResources")); console.log(import_chalk.default.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(import_chalk.default.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(import_chalk.default.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(import_chalk.default.gray("----------------------------------------")); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { logsCommand, metricsCommand, statusCommand }); //# sourceMappingURL=status.js.map