import * as plugins from './plugins.js'; import * as paths from './paths.js'; import { tspmIpcClient } from './classes.ipcclient.js'; import { Logger, LogLevel } from './utils.errorhandler.js'; import type { IProcessConfig } from './classes.tspm.js'; export interface CliArguments { verbose?: boolean; watch?: boolean; memory?: string; cwd?: string; daemon?: boolean; test?: boolean; name?: string; autorestart?: boolean; watchPaths?: string[]; [key: string]: any; } // Helper function to parse memory strings (e.g., "512MB", "2GB") function parseMemoryString(memStr: string): number { const units = { KB: 1024, MB: 1024 * 1024, GB: 1024 * 1024 * 1024, }; const match = memStr.toUpperCase().match(/^(\d+(?:\.\d+)?)\s*(KB|MB|GB)?$/); if (!match) { throw new Error( `Invalid memory format: ${memStr}. Use format like "512MB" or "2GB"`, ); } const value = parseFloat(match[1]); const unit = (match[2] || 'MB') as keyof typeof units; return Math.floor(value * units[unit]); } // Helper function to format memory for display function formatMemory(bytes: number): string { if (bytes >= 1024 * 1024 * 1024) { return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`; } else if (bytes >= 1024 * 1024) { return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; } else if (bytes >= 1024) { return `${(bytes / 1024).toFixed(1)} KB`; } else { return `${bytes} B`; } } // Helper function for padding strings function pad(str: string, length: number): string { return str.length > length ? str.substring(0, length - 3) + '...' : str.padEnd(length); } export const run = async (): Promise => { const cliLogger = new Logger('CLI'); const tspmProjectinfo = new plugins.projectinfo.ProjectInfo(paths.packageDir); // Check if debug mode is enabled const debugMode = process.env.TSPM_DEBUG === 'true'; if (debugMode) { cliLogger.setLevel(LogLevel.DEBUG); cliLogger.debug('Debug mode enabled'); } const smartcliInstance = new plugins.smartcli.Smartcli(); smartcliInstance.addVersion(tspmProjectinfo.npm.version); // Default command - show help and list processes smartcliInstance.standardCommand().subscribe({ next: async (argvArg: CliArguments) => { console.log( `TSPM - TypeScript Process Manager v${tspmProjectinfo.npm.version}`, ); console.log('Usage: tspm [command] [options]'); console.log('\nCommands:'); console.log(' start