UNPKG

@interopio/desktop-cli

Version:

io.Connect Desktop Seed Repository CLI Tools

171 lines 6.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateCommand = void 0; const commander_1 = require("commander"); const utils_1 = require("../utils"); const license_validator_1 = require("../services/license-validator"); const component_manager_1 = require("../services/component-manager"); const modification_manager_1 = require("../services/modification-manager"); exports.validateCommand = new commander_1.Command('validate') .description('Validate the entire setup and configuration') .action(async () => { try { utils_1.Logger.info('Starting comprehensive validation...'); let hasErrors = false; // Validate license utils_1.Logger.info('Validating license...'); const licenseValidator = new license_validator_1.LicenseValidator(); const licenseValid = await licenseValidator.validate(); if (licenseValid) { utils_1.Logger.success('License validation passed'); } else { utils_1.Logger.error('License validation failed'); hasErrors = true; } // Validate package.json structure utils_1.Logger.info('Validating package.json...'); const packageValid = await validatePackageJson(); if (packageValid) { utils_1.Logger.success('package.json validation passed'); } else { utils_1.Logger.error('package.json validation failed'); hasErrors = true; } // Validate directory structure utils_1.Logger.info('Validating directory structure...'); const structureValid = await validateDirectoryStructure(); if (structureValid) { utils_1.Logger.success('Directory structure validation passed'); } else { utils_1.Logger.error('Directory structure validation failed'); hasErrors = true; } // Validate components utils_1.Logger.info('Validating components...'); const componentsValid = await validateComponents(); if (componentsValid) { utils_1.Logger.success('Component validation passed'); } else { utils_1.Logger.error('Component validation failed'); hasErrors = true; } // Validate modifications utils_1.Logger.info('Validating modifications...'); const modificationManager = new modification_manager_1.ModificationManager(); const modificationsValid = await modificationManager.validate(); if (modificationsValid) { utils_1.Logger.success('Modifications validation passed'); } else { utils_1.Logger.error('Modifications validation failed'); hasErrors = true; } // Summary if (hasErrors) { utils_1.Logger.error('Validation completed with errors'); process.exit(1); } else { utils_1.Logger.success('All validations passed successfully!'); } } catch (error) { utils_1.Logger.error(`Validation failed: ${error instanceof Error ? error.message : String(error)}`); process.exit(1); } }); async function validatePackageJson() { try { const packageJson = await utils_1.ConfigManager.getPackageJson(); let isValid = true; // Check required fields if (!packageJson.name) { utils_1.Logger.error('package.json: name field is required'); isValid = false; } if (!packageJson.version) { utils_1.Logger.error('package.json: version field is required'); isValid = false; } if (!packageJson.iocdComponents) { utils_1.Logger.error('package.json: iocdComponents section is required'); isValid = false; } else { // Validate iocdComponents structure const components = packageJson.iocdComponents; if (typeof components !== 'object') { utils_1.Logger.error('package.json: iocdComponents must be an object'); isValid = false; } else { for (const [name, version] of Object.entries(components)) { if (typeof version !== 'string') { utils_1.Logger.error(`package.json: Component ${name} version must be a string`); isValid = false; } } } } return isValid; } catch (error) { utils_1.Logger.error(`package.json validation error: ${error instanceof Error ? error.message : String(error)}`); return false; } } async function validateDirectoryStructure() { const requiredDirs = [ { path: utils_1.PathUtils.getComponentsDir(), name: 'components', required: false }, { path: utils_1.PathUtils.getModificationsDir(), name: 'modifications', required: false }, { path: utils_1.PathUtils.getDistDir(), name: 'dist', required: false }, { path: 'docs', name: 'docs', required: false }, { path: '.vscode', name: '.vscode', required: false } ]; let isValid = true; for (const dir of requiredDirs) { const exists = await utils_1.FileUtils.exists(dir.path); if (dir.required && !exists) { utils_1.Logger.error(`Required directory missing: ${dir.name}`); isValid = false; } else if (exists) { utils_1.Logger.debug(`Directory found: ${dir.name}`); } else { utils_1.Logger.debug(`Optional directory not found: ${dir.name}`); } } return isValid; } async function validateComponents() { try { const componentManager = new component_manager_1.ComponentManager(); const components = await componentManager.list(); let isValid = true; for (const component of components) { if (!component.installed) { utils_1.Logger.warning(`Component not installed: ${component.name}@${component.version}`); // This is a warning, not an error } else { // Validate component structure const componentJsonPath = `${component.path}/component.json`; if (!(await utils_1.FileUtils.exists(componentJsonPath))) { utils_1.Logger.error(`Component metadata missing: ${component.name}/component.json`); isValid = false; } } } return isValid; } catch (error) { utils_1.Logger.error(`Component validation error: ${error instanceof Error ? error.message : String(error)}`); return false; } } //# sourceMappingURL=validate.js.map