@interopio/desktop-cli
Version:
io.Connect Desktop Seed Repository CLI Tools
205 lines • 9.06 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.componentCommand = void 0;
const commander_1 = require("commander");
const utils_1 = require("../utils");
const component_manager_1 = require("../services/component-manager");
const inquirer_1 = __importDefault(require("inquirer"));
const chalk_1 = __importDefault(require("chalk"));
exports.componentCommand = new commander_1.Command('component')
.description('Manage io.Connect Desktop components');
// Component install command
exports.componentCommand
.command('install')
.description('Install all components from package.json')
.action(async () => {
try {
const componentManager = new component_manager_1.ComponentManager();
await componentManager.installAll();
utils_1.Logger.success(`All components installed successfully for ${process.platform}-${process.arch}`);
}
catch (error) {
utils_1.Logger.error(`Component installation failed: ${error instanceof Error ? error.message : String(error)}`);
utils_1.Logger.info('💡 Tip: Configure proxy via environment variables if needed:');
utils_1.Logger.info(' HTTP_PROXY / HTTPS_PROXY, PROXY_HOST, PROXY_PORT, PROXY_USERNAME, PROXY_PASSWORD');
process.exit(1);
}
});
// Component add command
exports.componentCommand
.command('add <component>')
.description('Add a new component')
.action(async (component) => {
try {
// Parse component@version format
const [name, version] = component.includes('@')
? component.split('@')
: [component, 'latest'];
const componentManager = new component_manager_1.ComponentManager();
// If version is 'latest', get available versions
if (version === 'latest') {
const available = await componentManager.getAvailableComponents();
const componentMeta = available.find(c => c.name === name);
if (!componentMeta) {
utils_1.Logger.error(`Component '${name}' not found`);
process.exit(1);
}
await componentManager.add(name, componentMeta.version);
}
else {
await componentManager.add(name, version);
}
utils_1.Logger.success(`Component ${name}@${version} added successfully for ${process.platform}-${process.arch}`);
}
catch (error) {
utils_1.Logger.error(`Failed to add component: ${error instanceof Error ? error.message : String(error)}`);
process.exit(1);
}
});
// Component remove command
exports.componentCommand
.command('remove <component>')
.description('Remove a component')
.action(async (component) => {
try {
const componentManager = new component_manager_1.ComponentManager();
// Confirm removal
const { confirmed } = await inquirer_1.default.prompt([
{
type: 'confirm',
name: 'confirmed',
message: `Are you sure you want to remove component '${component}'?`,
default: false
}
]);
if (!confirmed) {
utils_1.Logger.info('Operation cancelled');
return;
}
await componentManager.remove(component);
utils_1.Logger.success(`Component ${component} removed successfully`);
}
catch (error) {
utils_1.Logger.error(`Failed to remove component: ${error instanceof Error ? error.message : String(error)}`);
process.exit(1);
}
});
// Component list command
exports.componentCommand
.command('list')
.description('List installed components')
.action(async () => {
try {
const componentManager = new component_manager_1.ComponentManager();
const components = await componentManager.list();
if (components.length === 0) {
utils_1.Logger.info('No components installed');
return;
}
console.log('\nInstalled Components:');
console.log('────────────────────────────────────────');
for (const component of components) {
const status = component.installed ? chalk_1.default.green('✓ installed') : chalk_1.default.red('✗ not installed');
const sizeInfo = component.size ? ` (${formatBytes(component.size)})` : '';
console.log(`${chalk_1.default.cyan(component.name)}@${component.version} - ${status}${sizeInfo}`);
if (component.path) {
console.log(` Path: ${chalk_1.default.gray(component.path)}`);
}
}
console.log('');
}
catch (error) {
utils_1.Logger.error(`Failed to list components: ${error instanceof Error ? error.message : String(error)}`);
process.exit(1);
}
});
// Component update command
exports.componentCommand
.command('update [component]')
.description('Update component(s)')
.option('--all', 'Update all components')
.action(async (component, options) => {
try {
const componentManager = new component_manager_1.ComponentManager();
if (options?.all || !component) {
utils_1.Logger.info(`Updating all components for ${process.platform}-${process.arch}...`);
await componentManager.update();
utils_1.Logger.success(`All components updated successfully for ${process.platform}-${process.arch}`);
}
else {
utils_1.Logger.info(`Updating component: ${component} for ${process.platform}-${process.arch}`);
await componentManager.update(component);
utils_1.Logger.success(`Component ${component} updated successfully for ${process.platform}-${process.arch}`);
}
}
catch (error) {
utils_1.Logger.error(`Failed to update component(s): ${error instanceof Error ? error.message : String(error)}`);
process.exit(1);
}
});
// Component all command
exports.componentCommand
.command('all')
.description('Show all available components')
.action(async () => {
try {
const componentManager = new component_manager_1.ComponentManager();
const available = await componentManager.getAvailableComponents();
console.log(`\nAvailable Components for ${process.platform}-${process.arch}:`);
console.log('────────────────────────────────────────');
for (const component of available) {
const licenseReq = component.licenseRequired ? chalk_1.default.yellow('(license required)') : '';
const platforms = component.platforms.join(', ');
console.log(`${chalk_1.default.cyan(component.name)}@${component.version} ${licenseReq}`);
console.log(` ${component.description}`);
console.log(` Platforms: ${chalk_1.default.gray(platforms)}`);
console.log(` Source: ${chalk_1.default.gray(component.source)}`);
console.log('');
}
}
catch (error) {
utils_1.Logger.error(`Failed to fetch available components: ${error instanceof Error ? error.message : String(error)}`);
process.exit(1);
}
});
// Component cache command
exports.componentCommand
.command('cache')
.description('Manage component cache')
.option('--clear', 'Clear the component cache')
.action(async (options) => {
try {
const componentManager = new component_manager_1.ComponentManager();
if (options?.clear) {
await componentManager.clearCache();
}
else {
console.log('\nComponent Cache Management:');
console.log('──────────────────────────');
console.log('Use --clear to clear the component cache');
console.log('Cache is used to speed up component downloads');
console.log('');
console.log('Environment variables:');
console.log(' IOCD_CACHE_ENABLED - Enable/disable cache (default: true)');
console.log(' IOCD_CACHE_DIR - Cache directory path');
console.log(' IOCD_CACHE_MAX_AGE - Max age in milliseconds (default: 24h)');
console.log(' IOCD_CACHE_MAX_SIZE - Max size in bytes (default: 1GB)');
}
}
catch (error) {
utils_1.Logger.error(`Cache operation failed: ${error instanceof Error ? error.message : String(error)}`);
process.exit(1);
}
});
function formatBytes(bytes) {
if (bytes === 0)
return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i];
}
//# sourceMappingURL=component.js.map