UNPKG

wrekenfile-converter

Version:

Convert OpenAPI and Postman specs to Wrekenfile format with mini-chunking for vector DB storage

55 lines (54 loc) 2.53 kB
#!/usr/bin/env node "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = __importDefault(require("fs")); const postman_to_wrekenfile_1 = require("../postman-to-wrekenfile"); function printUsage() { console.log('Usage: npx ts-node src/cli-postman-to-wrekenfile.ts <postman_collection.json> <output_wrekenfile.yaml> [postman_environment.json]'); process.exit(1); } function main() { return __awaiter(this, void 0, void 0, function* () { const args = process.argv.slice(2); if (args.length < 2) { printUsage(); } const [inputFile, outputFile, envFile] = args; if (!fs_1.default.existsSync(inputFile)) { console.error(`❌ Input file not found: ${inputFile}`); process.exit(1); } let variables = {}; if (envFile) { if (!fs_1.default.existsSync(envFile)) { console.error(`❌ Environment file not found: ${envFile}`); process.exit(1); } variables = (0, postman_to_wrekenfile_1.loadEnvironmentFile)(envFile); } try { const postmanContent = fs_1.default.readFileSync(inputFile, 'utf8'); const postmanCollection = JSON.parse(postmanContent); const wrekenfileYaml = (0, postman_to_wrekenfile_1.generateWrekenfile)(postmanCollection, variables); fs_1.default.writeFileSync(outputFile, wrekenfileYaml); console.log(`✅ Wrekenfile generated: ${outputFile}`); } catch (error) { console.error(`❌ Error generating Wrekenfile: ${error.message}`); process.exit(1); } }); } main();