#!/usr/bin/env node import { Command } from 'commander'; import chalk from 'chalk'; import { initCommand } from './commands/init'; import { pullCommand } from './commands/pull'; import { pushCommand } from './commands/push'; import { statusCommand } from './commands/status'; import { updateCommand, updateApplyCommand, checkForUpdateBackground } from './commands/update'; const VERSION = '1.1.0'; const program = new Command(); program .name('kisync') .description('CLI tool for syncing local folders with KIS API Builder') .version(VERSION); program .command('init') .description('Initialize a new kisync project in the current directory') .action(async () => { try { await initCommand(); await checkForUpdateBackground(VERSION); } catch (err: any) { console.error(chalk.red(`Ошибка: ${err.message}`)); process.exit(1); } }); program .command('pull') .description('Download all endpoints from server to local files') .option('--force', 'Overwrite local changes without prompting') .action(async (opts) => { try { await pullCommand(opts.force); await checkForUpdateBackground(VERSION); } catch (err: any) { console.error(chalk.red(`Ошибка: ${err.message}`)); process.exit(1); } }); program .command('push') .description('Upload local changes to server') .option('--force', 'Force push, overwriting server changes') .action(async (opts) => { try { await pushCommand(opts.force); await checkForUpdateBackground(VERSION); } catch (err: any) { console.error(chalk.red(`Ошибка: ${err.message}`)); process.exit(1); } }); program .command('status') .description('Show sync status — what changed locally and on server') .action(async () => { try { await statusCommand(); await checkForUpdateBackground(VERSION); } catch (err: any) { console.error(chalk.red(`Ошибка: ${err.message}`)); process.exit(1); } }); program .command('update') .description('Проверить обновления и обновить kisync') .option('--apply', 'Скачать и установить обновление') .action(async (opts) => { try { if (opts.apply) { await updateApplyCommand(VERSION); } else { await updateCommand(VERSION); } } catch (err: any) { console.error(chalk.red(`Ошибка: ${err.message}`)); process.exit(1); } }); program.parse();