superjolt
Version:
AI-powered deployment platform with MCP support - Deploy JavaScript apps using natural language with Claude Desktop
130 lines • 6.69 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MachineListCommand = void 0;
const nest_commander_1 = require("nest-commander");
const common_1 = require("@nestjs/common");
const api_service_1 = require("../services/api.service");
const auth_service_1 = require("../services/auth.service");
const logger_service_1 = require("../services/logger.service");
const authenticated_command_1 = require("./authenticated.command");
const table_utils_1 = require("../utils/table.utils");
const chalk_1 = __importDefault(require("chalk"));
let MachineListCommand = class MachineListCommand extends authenticated_command_1.AuthenticatedCommand {
apiService;
authService;
logger;
constructor(apiService, authService, logger) {
super();
this.apiService = apiService;
this.authService = authService;
this.logger = logger;
}
async execute() {
try {
this.logger.log(chalk_1.default.dim('Fetching machines...\n'));
const [response, currentUser] = await Promise.all([
this.apiService.listMachines(),
this.apiService.getCurrentUser().catch(() => null),
]);
if (response.machines.length === 0) {
this.logger.log(chalk_1.default.yellow('No machines found.'));
this.logger.log(chalk_1.default.dim('\nCreate your first machine with:'));
this.logger.log(chalk_1.default.cyan(' superjolt machine:create'));
return;
}
const table = (0, table_utils_1.createResourceTable)(['ID', 'Name', 'Status', 'Specs', 'CPU', 'Memory', 'Disk', 'Created'], {
wordWrap: true,
colWidths: [23, 20, 12, 20, 15, 15, 15, 12],
});
response.machines.forEach((machine) => {
const isDefault = currentUser?.lastUsedMachineId === machine.id;
const id = isDefault
? chalk_1.default.blue(`→ ${machine.id}`)
: ` ${machine.id}`;
const name = machine.name;
const status = (0, table_utils_1.formatStatus)(machine.status || 'unknown');
const created = (0, table_utils_1.formatDate)(machine.createdAt);
const cpuCores = machine.cpuCores || 2;
const memoryTotal = machine.memoryTotal || 2147483648;
const diskTotal = machine.diskTotal || 53687091200;
const specs = `${cpuCores} vCPU\n${(0, table_utils_1.formatBytes)(memoryTotal)} RAM\n${(0, table_utils_1.formatBytes)(diskTotal)} Disk`;
const cpuUsage = machine.cpuUsage !== undefined
? `${machine.cpuUsage.toFixed(1)}%`
: '-';
let memoryDisplay = '-';
if (machine.memoryUsage !== undefined && machine.memoryTotal) {
const memPercent = ((machine.memoryUsage / machine.memoryTotal) *
100).toFixed(1);
memoryDisplay = `${(0, table_utils_1.formatBytes)(machine.memoryUsage)}\n${memPercent}%`;
}
let diskDisplay = '-';
if (machine.diskUsage !== undefined && machine.diskTotal) {
const diskPercent = ((machine.diskUsage / machine.diskTotal) *
100).toFixed(1);
diskDisplay = `${(0, table_utils_1.formatBytes)(machine.diskUsage)}\n${diskPercent}%`;
}
table.push([
id,
name,
status,
specs,
cpuUsage,
memoryDisplay,
diskDisplay,
created,
]);
});
this.logger.log(table.toString());
const runningCount = response.machines.filter((m) => m.status?.toLowerCase() === 'running').length;
const stoppedCount = response.machines.length - runningCount;
let summary = chalk_1.default.dim(`\nTotal: ${response.total} machine${response.total !== 1 ? 's' : ''}`);
if (runningCount > 0 || stoppedCount > 0) {
summary += chalk_1.default.dim(` (${runningCount} running, ${stoppedCount} stopped)`);
}
if (currentUser?.tenant) {
const { machineCount, maxMachines } = currentUser.tenant;
summary += chalk_1.default.dim(` | Usage: ${machineCount}/${maxMachines}`);
const percentUsed = (machineCount / maxMachines) * 100;
if (percentUsed >= 100) {
summary += chalk_1.default.red(' (limit reached!)');
}
else if (percentUsed >= 80) {
summary += chalk_1.default.yellow(` (${Math.round(percentUsed)}% used)`);
}
}
this.logger.log(summary);
if (currentUser?.lastUsedMachineId) {
this.logger.log(chalk_1.default.dim(`\nDefault machine: ${chalk_1.default.blue(currentUser.lastUsedMachineId)}`));
}
}
catch (error) {
this.logger.error(`\n${error.message}`);
process.exit(1);
}
}
};
exports.MachineListCommand = MachineListCommand;
exports.MachineListCommand = MachineListCommand = __decorate([
(0, common_1.Injectable)(),
(0, nest_commander_1.Command)({
name: 'machine:list',
aliases: ['machines'],
description: 'List all machines',
}),
__metadata("design:paramtypes", [api_service_1.ApiService,
auth_service_1.AuthService,
logger_service_1.LoggerService])
], MachineListCommand);
//# sourceMappingURL=machine-list.command.js.map