json-light
Version:
Allow to extend yaml or json files configuration
39 lines • 1.68 kB
JavaScript
;
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../index");
const helper_1 = require("../helper");
module.exports = (args) => __awaiter(void 0, void 0, void 0, function* () {
const input = args.input || args.i;
const type = args.type || args.t;
const output = args.output || args.o;
if (!input) {
console.error('input is required!');
return;
}
let data = index_1.JsonLight.json(input);
if (data === null) {
const str = yield helper_1.jsonLightHelp.fs.read(input);
if (str === null) {
throw new Error(`File ${input} not found`);
}
data = JSON.parse(str);
}
const decompressed = index_1.JsonLight.decompress(data, { type });
const result = JSON.stringify(decompressed);
if (output) {
yield helper_1.jsonLightHelp.fs.write(output, result);
}
else {
console.log(result);
}
});
//# sourceMappingURL=decompress.js.map