UNPKG

@canboat/canboatjs

Version:

Native javascript version of canboat

140 lines (139 loc) 4.76 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 fromPgn_1 = require("../fromPgn"); const minimist_1 = __importDefault(require("minimist")); const readline_1 = __importDefault(require("readline")); const utils_1 = require("./utils"); const utilities_1 = require("../utilities"); const fs_1 = __importDefault(require("fs")); const util_1 = __importDefault(require("util")); const argv = (0, minimist_1.default)(process.argv.slice(2), { alias: { h: 'help' }, string: ['pgn', 'manufacturer', 'src', 'file', 'dst', 'filter', 'id'], boolean: [ 'n', 'r', 'camel', 'camel-compat', 'show-non-matches', //'show-create-pgns', 'pretty', 'show-warnings', 'coalesced', 'js', 'js-colors', 'no-enums', 'include-raw-data', 'include-byte-mapping' ] }); (0, utils_1.printVersion)(argv); if (argv['help']) { console.error(`Usage: ${process.argv[1]} [options] Options: -c don't check for invalid values -n output null values -r parse $MXPGN as little endian --no-enums don't output enum values --include-raw-data include raw data in output --include-byte-mapping include byte mapping in output --file <path> read from the given file --pretty output pretty json --js output in JavaScript format --js-colors output in JavaScript format with colors --camel output field names in camelCase --camel-compat output field names in camelCase and regular --show-non-matches show pgn data without any matches --show-warnings show warning messages --coalesced force coalesced format --fast force fast format --pgn <number> filter for the given pgn number --id <camelCaseId> filter for the given pgn id --src <number> filter for the given source address --dst <number> filter for the given destination address --manufacturer <str> filter for pgns from the given manufacturer --filter <js> filter for the given JavaScript expression -h, --help output usage information`); process.exit(1); } let format = undefined; if (argv['coalesced']) { format = 1; } else if (argv['fast']) { format = 0; } const filter = (0, utilities_1.setupFilters)(argv); const parser = new fromPgn_1.Parser({ returnNulls: argv['n'] === true, littleEndianMXPGN: argv['r'] === true, checkForInvalidFields: argv['c'] !== true, useCamel: argv['camel'], useCamelCompat: argv['camel-compat'], returnNonMatches: argv['show-non-matches'], includeInputData: true, createPGNObjects: true, format, resolveEnums: argv['enums'] === undefined || argv['enums'] === true, includeRawData: argv['include-raw-data'], includeByteMapping: argv['include-byte-mapping'] }); parser.on('error', (pgn, error) => { console.error(`Error parsing ${pgn.pgn} ${error}`); console.error(error.stack); }); parser.on('warning', (pgn, error) => { if (argv['show-warnings']) { console.error(`Warning parsing ${pgn.pgn} ${error}`); } }); let rl; const file = argv['file']; if (file) { const fileStream = fs_1.default.createReadStream(file); rl = readline_1.default.createInterface({ input: fileStream, crlfDelay: Infinity // This option ensures that '\r\n' is treated as a single line break }); } else { rl = readline_1.default.createInterface({ input: process.stdin, output: process.stdout, terminal: false }); } rl.on('line', (line) => { if (argv['log-input']) { console.log(line); } if (line.length === 0) { return; } let pgn; if (line.length > 13 && line.charAt(13) === ';') { if (line.charAt(14) === 'A') { pgn = parser.parseString(line.substring(16)); } } else { pgn = parser.parseString(line.trim()); } if (pgn && (0, utilities_1.filterPGN)(pgn, filter)) { if (argv['js'] || argv['js-colors']) { console.log(util_1.default.inspect(pgn, { depth: null, colors: argv['js-colors'], breakLength: 1 })); } else { console.log(JSON.stringify(pgn, null, argv['pretty'] ? 2 : 0)); } } }); //# sourceMappingURL=analyzerjs.js.map