UNPKG

insomnia-importers

Version:

Various data importers for Insomnia

49 lines 1.88 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.go = void 0; const commander_1 = __importDefault(require("commander")); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const package_json_1 = require("../package.json"); const convert_1 = require("./convert"); const go = async () => { // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Configure the arguments parsing // // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // commander_1.default .version(package_json_1.version, '-v, --version') .usage('[options] <input>') .option('-o, --output <path>', 'output directory') .parse(process.argv); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Set up the directory to work on // // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // const inputPath = commander_1.default.args[0]; if (!inputPath) { console.log('Input path not specified'); process.exit(1); } // ~~~~~~~~~~~~~~~~~~~~~~ // // Convert the input file // // ~~~~~~~~~~~~~~~~~~~~~~ // const fullInputPath = path_1.default.resolve(inputPath); const fileContents = fs_1.default.readFileSync(fullInputPath, 'utf8'); const result = await (0, convert_1.convert)(fileContents); const exportContents = JSON.stringify(result.data, null, 2); // ~~~~~~~~~~~~~~~~ // // Write the output // // ~~~~~~~~~~~~~~~~ // const outputPath = commander_1.default.args[1]; if (outputPath) { const fullOutputPath = path_1.default.resolve(outputPath); fs_1.default.writeFileSync(fullOutputPath, exportContents); } else { console.log(exportContents); } }; exports.go = go; //# sourceMappingURL=cli.js.map