UNPKG

schema2typebox

Version:

Creates typebox code from JSON schemas

71 lines (64 loc) 2.73 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HELP_TEXT = exports.DEFAULT_OUTPUT_FILE_NAME = exports.DEFAULT_INPUT_FILE_NAME = exports.createOutputPath = exports.createInputPath = exports.runCli = void 0; const minimist_1 = __importDefault(require("minimist")); const node_fs_1 = require("node:fs"); const package_json_1 = __importDefault(require("../package.json")); const programmatic_usage_1 = require("./programmatic-usage"); const runCli = async () => { const args = (0, minimist_1.default)(process.argv.slice(2), { alias: { input: "i", output: "o", help: "h", }, default: { input: exports.DEFAULT_INPUT_FILE_NAME, output: exports.DEFAULT_OUTPUT_FILE_NAME, }, }); if (args.help) { return process.stdout.write(exports.HELP_TEXT); } const typeboxCode = await (0, programmatic_usage_1.schema2typebox)({ input: (0, node_fs_1.readFileSync)((0, exports.createInputPath)(args.input), "utf-8"), }); if (args["output-stdout"]) { return process.stdout.write(typeboxCode); } return (0, node_fs_1.writeFileSync)((0, exports.createOutputPath)(args.output), typeboxCode, "utf-8"); }; exports.runCli = runCli; const createInputPath = (inputFileName) => { return process.cwd() + `/${inputFileName}`; }; exports.createInputPath = createInputPath; const createOutputPath = (outputFileName) => { return process.cwd() + `/${outputFileName}`; }; exports.createOutputPath = createOutputPath; exports.DEFAULT_INPUT_FILE_NAME = "schema.json"; exports.DEFAULT_OUTPUT_FILE_NAME = "generated-typebox.ts"; exports.HELP_TEXT = ` schema2typebox generates TypeBox code from JSON schemas. The generated output is formatted based on the prettier config inside your repo (or the default one, if you don't have one). Version: ${package_json_1.default.version} Usage: schema2typebox [ARGUMENTS] Arguments: -h, --help Displays this menu. -i, --input Specifies the relative path to the file containing the JSON schema that will be used to generated typebox code. Defaults to "${exports.DEFAULT_INPUT_FILE_NAME}". -o, --output Specifies the relative path to generated file that will contain the typebox code. Defaults to "${exports.DEFAULT_OUTPUT_FILE_NAME}". --output-stdout Does not generate an output file and prints the generated code to stdout instead. Has precedence over -o/--output. `; //# sourceMappingURL=cli.js.map