UNPKG

@argdown/cli

Version:

A command line interface for exporting Argdown files to html, dot or json.

68 lines 2.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handler = exports.builder = exports.desc = exports.command = void 0; const node_1 = require("@argdown/node"); const runArgdown_1 = require("./runArgdown"); exports.command = "json [inputGlob] [outputDir]"; exports.desc = "export Argdown input as JSON files"; exports.builder = { logParserErrors: { alias: "e", describe: "Log parser errors to console", type: "boolean", default: true }, spaces: { alias: "s", describe: "Spaces used for indentation", type: "number" }, removeMap: { describe: "Remove map data", type: "boolean" }, removeEmbeddedRelations: { describe: "Remove relations embedded in statement and relation objects", type: "boolean" } }; const handler = async (args) => { let config = await node_1.argdown.loadConfig(args.config); config.json = config.json || {}; if (args.spaces !== null) { config.json.spaces = args.spaces; } if (args.removeEmbeddedRelations) { config.json.removeEmbeddedRelations = true; } if (args.removeMap) { config.json.exportMap = false; } if (args.inputGlob) { config.inputPath = args.inputGlob; } config.saveAs = config.saveAs || {}; if (args.outputDir) { config.saveAs.outputDir = args.outputDir; } config.logLevel = args.verbose ? "verbose" : config.logLevel; config.logLevel = args.silent ? "silent" : config.logLevel; config.watch = args.watch || config.watch; config.process = ["load-file", "parse-input"]; config.logParserErrors = args.logParserErrors || config.logParserErrors; if (config.logParserErrors) { config.process.push("log-parser-errors"); } config.process.push("build-model"); config.process.push("colorize"); config.process.push("export-json"); if (!args.stdout || args.outputDir) { config.process.push("save-as-json"); } if (args.stdout) { config.process.push("stdout-json"); } await (0, runArgdown_1.runArgdown)(node_1.argdown, config, true, "JSON export canceled", "export", "to JSON"); }; exports.handler = handler; //# sourceMappingURL=JSONCommand.js.map