UNPKG

imm-noc

Version:

A tool for noc inquiry

42 lines (41 loc) 1.79 kB
#!/usr/local/bin/node 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()); }); }; const fs = require('fs'); const { ArgumentParser } = require('argparse'); const parser = new ArgumentParser({ description: 'Merge json objects' }); parser.add_argument('-j', '--json', { help: 'Json files', nargs: "+" }); parser.add_argument('-t', '--to', { help: 'Target json files' }); const args = parser.parse_args(); const target_file = args.to ? args.to : "nocs.json"; function mergeJSON(json_files) { var targetJSON = {}; // read json files for (var json_file of json_files) { let rawdata = fs.readFileSync(json_file); var json_data = JSON.parse(rawdata); targetJSON = Object.assign(Object.assign({}, targetJSON), json_data); } // write JSON string to a file const target_json = JSON.stringify(targetJSON); fs.writeFileSync('nocs.json', target_json, (err) => { if (err) { throw err; } console.log("JSON data is saved."); }); } (() => __awaiter(this, void 0, void 0, function* () { console.time("Searching time"); mergeJSON(args.json); console.timeEnd("Searching time"); }))();