UNPKG

junit2json

Version:
43 lines 1.74 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const node_fs_1 = __importDefault(require("node:fs")); const yargs_1 = __importDefault(require("yargs")); const helpers_1 = require("yargs/helpers"); const index_js_1 = require("./index.js"); const argv = (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)) .usage('Usage: $0 [path]') .command('$0 <path>', 'Convert JUnit XML format to JSON') .options({ p: { type: 'boolean', alias: 'pretty', describe: 'Output pretty JSON', default: false }, f: { type: 'string', alias: 'filter-tags', describe: 'Filter XML tag names' }, }) .alias('p', 'pretty') .alias('f', 'filter-tags') .coerce('f', (filter) => filter?.split(',')) .positional('path', { describe: 'JUnit XML path', type: 'string', demandOption: true, }) .example('$0 -p -f system-out,system-err junit.xml', 'Output pretty JSON with filter <system-out> and <system-err> tags.') .strict() .parseSync(); const main = async () => { const xmlString = node_fs_1.default.readFileSync(argv.path, 'utf8').toString(); const filterSet = new Set(argv.filterTags); const _replacer = (key, value) => { if (filterSet.has(key)) return undefined; return value; }; const indent = (argv.pretty) ? 2 : 0; const replacer = (argv.filterTags && argv.filterTags.length > 0) ? _replacer : undefined; const output = await (0, index_js_1.parse)(xmlString); console.log(JSON.stringify(output, replacer, indent)); }; main(); //# sourceMappingURL=cli.js.map