UNPKG

@interopio/desktop-cli

Version:

io.Connect Desktop Seed Repository CLI Tools

189 lines 7.1 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PathUtils = exports.ConfigManager = exports.FileUtils = exports.Logger = exports.debug = void 0; exports.validateVersion = validateVersion; const fs_extra_1 = __importDefault(require("fs-extra")); const path_1 = __importDefault(require("path")); const chalk_1 = __importDefault(require("chalk")); const debug_1 = __importDefault(require("debug")); // Create debug instances for different parts of the CLI exports.debug = { cli: (0, debug_1.default)('iocd:cli'), setup: (0, debug_1.default)('iocd:setup'), component: (0, debug_1.default)('iocd:component'), license: (0, debug_1.default)('iocd:license'), modifications: (0, debug_1.default)('iocd:modifications'), package: (0, debug_1.default)('iocd:package'), validate: (0, debug_1.default)('iocd:validate'), start: (0, debug_1.default)('iocd:start'), storage: (0, debug_1.default)('iocd:storage'), utils: (0, debug_1.default)('iocd:utils') }; class Logger { static info(message) { console.log(chalk_1.default.blue('ℹ'), message); } static success(message) { console.log(chalk_1.default.green('✓'), message); } static warning(message) { console.log(chalk_1.default.yellow('⚠'), message); } static error(message) { console.log(chalk_1.default.red('✗'), message); } static debug(message, namespace) { // Use specific debug namespace if provided, otherwise use generic utils const debugFn = namespace ? exports.debug[namespace] || exports.debug.utils : exports.debug.utils; debugFn(message); // Also show in console if DEBUG environment variable is set and matches if (process.env.DEBUG && this.shouldShowDebug(namespace || 'utils')) { console.log(chalk_1.default.gray('🔍'), message); } } static shouldShowDebug(namespace) { const debugEnv = process.env.DEBUG || ''; if (!debugEnv) return false; // Handle wildcard patterns like "iocd:*" const patterns = debugEnv.split(',').map(p => p.trim()); for (const pattern of patterns) { // Skip negative patterns (starting with -) if (pattern.startsWith('-')) continue; // Check for exact match or wildcard match if (pattern === `iocd:${namespace}` || pattern === 'iocd:*' || pattern === '*') { return true; } } return false; } } exports.Logger = Logger; class FileUtils { static async exists(filePath) { try { await fs_extra_1.default.access(filePath); return true; } catch { return false; } } static async ensureDir(dirPath) { await fs_extra_1.default.ensureDir(dirPath); } static async copyFile(src, dest) { Logger.debug(`Copying file: ${src} -> ${dest}`, 'utils'); await fs_extra_1.default.copy(src, dest); } static async removeFile(filePath) { if (await this.exists(filePath)) { Logger.debug(`Removing file: ${filePath}`, 'utils'); await fs_extra_1.default.remove(filePath); } } static async readJson(filePath) { try { return await fs_extra_1.default.readJson(filePath); } catch { return null; } } static async writeJson(filePath, data) { await fs_extra_1.default.writeJson(filePath, data, { spaces: 2 }); } static async writeFile(filePath, content) { await fs_extra_1.default.writeFile(filePath, content, 'utf8'); } } exports.FileUtils = FileUtils; class ConfigManager { static async getPackageJson() { const packageJson = await FileUtils.readJson(this.packageJsonPath); if (!packageJson) { throw new Error('package.json not found '); } return packageJson; } static async updatePackageJson(updates) { const packageJson = await this.getPackageJson(); const updated = { ...packageJson, ...updates }; await FileUtils.writeJson(this.packageJsonPath, updated); } static async getComponentConfig() { const packageJson = await this.getPackageJson(); return packageJson.iocdComponents || {}; } static async updateComponentConfig(components) { await this.updatePackageJson({ iocdComponents: components }); } static async getLicenseInfo() { return await FileUtils.readJson(this.licenseJsonPath); } static async hasValidLicense() { const license = await this.getLicenseInfo(); if (!license) return false; // Check expiration if (license.expiresAt) { const expirationDate = new Date(license.expiresAt); if (expirationDate < new Date()) { return false; } } return true; } } exports.ConfigManager = ConfigManager; ConfigManager.packageJsonPath = path_1.default.resolve('package.json'); ConfigManager.licenseJsonPath = path_1.default.resolve('license.json'); class PathUtils { static getComponentsDir() { return path_1.default.resolve('components'); } static getModificationsDir() { return path_1.default.resolve('modifications'); } static getDistDir() { return path_1.default.resolve('dist'); } static getScriptsDir() { return path_1.default.resolve('scripts'); } static getComponentDir(componentName) { return path_1.default.join(this.getComponentsDir(), componentName); } static getModificationDir(componentName) { return path_1.default.join(this.getModificationsDir(), componentName); } } exports.PathUtils = PathUtils; function validateVersion(version) { const semverRegex = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/; return semverRegex.test(version); } // Re-export component system types and classes __exportStar(require("../types/component"), exports); __exportStar(require("../components"), exports); //# sourceMappingURL=index.js.map