UNPKG

@interopio/desktop-cli

Version:

io.Connect Desktop Seed Repository CLI Tools

111 lines 4.76 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.startCommand = void 0; const commander_1 = require("commander"); const utils_1 = require("../utils"); const child_process_1 = require("child_process"); const path_1 = __importDefault(require("path")); exports.startCommand = new commander_1.Command('start') .description('Start the io.Connect Desktop platform') .option('--dev', 'Start in development mode') .option('--debug', 'Start with debug logging') .option('--config <path>', 'Path to custom configuration file') .option('--port <number>', 'Port number for the platform', '9990') .action(async (options) => { try { utils_1.Logger.info('Starting io.Connect Desktop platform...'); // Check if components are installed const componentsDir = utils_1.PathUtils.getComponentsDir(); if (!(await utils_1.FileUtils.exists(componentsDir))) { utils_1.Logger.error('Components not found. Please run: npm run setup'); process.exit(1); } // Check for core iocd component const iocdDir = utils_1.PathUtils.getComponentDir('iocd'); if (!(await utils_1.FileUtils.exists(iocdDir))) { utils_1.Logger.error('Core iocd component not found. Please run: iocd setup'); process.exit(1); } // Check if this is a mock component installation const componentJsonPath = path_1.default.join(iocdDir, 'component.json'); if (await utils_1.FileUtils.exists(componentJsonPath)) { try { const componentInfo = await utils_1.FileUtils.readJson(componentJsonPath); if (componentInfo?.mock) { utils_1.Logger.warning('Detected mock iocd component - this is for development/testing only!'); utils_1.Logger.info('For production use, configure proper GitHub or HTTP storage.'); } } catch (error) { // Ignore JSON parsing errors, continue with startup } } // Build startup command const executableName = process.platform === 'win32' ? 'io-connect-desktop.exe' : 'io-connect-desktop'; const executable = path_1.default.join(iocdDir, executableName); let finalExecutable; if (await utils_1.FileUtils.exists(executable)) { finalExecutable = executable; utils_1.Logger.debug(`Using native executable: ${executable}`); } else { utils_1.Logger.error('iocd executable not found. Component may be corrupted.'); utils_1.Logger.debug(`Checked paths: ${executable}`); process.exit(1); } const args = []; if (options.dev) { args.push('--dev'); utils_1.Logger.info('Development mode enabled'); } if (options.debug) { args.push('--debug'); utils_1.Logger.info('Debug logging enabled'); } if (options.config) { args.push('--config', options.config); utils_1.Logger.info(`Using custom config: ${options.config}`); } if (options.port) { args.push('--port', String(options.port)); utils_1.Logger.info(`Using port: ${options.port}`); } // Start the platform let child; utils_1.Logger.info(`Executing: ${finalExecutable} ${args.join(' ')}`); child = (0, child_process_1.spawn)(finalExecutable, args, { stdio: 'inherit', cwd: process.cwd(), env: process.env }); // Handle process events child.on('error', (error) => { utils_1.Logger.error(`Failed to start platform: ${error.message}`); process.exit(1); }); child.on('exit', (code) => { if (code !== 0) { utils_1.Logger.error(`Platform exited with code ${code}`); process.exit(code || 1); } utils_1.Logger.info('Platform stopped'); }); // Handle graceful shutdown process.on('SIGINT', () => { utils_1.Logger.info('Stopping platform...'); child.kill('SIGINT'); }); process.on('SIGTERM', () => { utils_1.Logger.info('Stopping platform...'); child.kill('SIGTERM'); }); } catch (error) { utils_1.Logger.error(`Failed to start platform: ${error instanceof Error ? error.message : String(error)}`); process.exit(1); } }); //# sourceMappingURL=start.js.map