#!/usr/bin/env node import { Command } from 'commander' import { convertCollection } from './converter/collection.js' import { readFileSync } from 'node:fs' import { fileURLToPath } from 'node:url' import { dirname, join } from 'node:path' const __dirname = dirname(fileURLToPath(import.meta.url)) const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8')) as { version: string } const program = new Command() program .name('bru-converter') .description('Convert OpenCollection YAML collections to Bruno .bru format') .version(pkg.version) .argument('', 'Path to OpenCollection YAML directory (must contain opencollection.yml)') .argument('[output-dir]', 'Path to write .bru collection', './output') .option('-q, --quiet', 'Suppress summary output') .action(async (inputDir: string, outputDir: string, opts: { quiet?: boolean }) => { try { const result = await convertCollection(inputDir, outputDir) if (!opts.quiet) { console.log( `Converted ${result.requestsConverted} requests, ${result.environmentsConverted} environments, ${result.foldersConverted} folders` ) console.log(`Output: ${outputDir}`) if (result.warnings.length > 0) { console.log('Warnings:') for (const w of result.warnings) { console.log(` - ${w.file}: ${w.message}`) } } } process.exit(0) } catch (err) { const message = err instanceof Error ? err.message : String(err) console.error(`Error: ${message}`) process.exit(1) } }) program.parse()