@7nohe/openapi-react-query-codegen
Advanced tools
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| "use strict"; | ||
| exports.__esModule = true; | ||
| exports.requestsOutputPath = exports.queriesOutputPath = exports.defaultOutputPath = void 0; | ||
| exports.defaultOutputPath = "openapi"; | ||
| exports.queriesOutputPath = "queries"; | ||
| exports.requestsOutputPath = "requests"; |
| { | ||
| "name": "@7nohe/openapi-react-query-codegen", | ||
| "version": "0.1.5", | ||
| "version": "0.2.0", | ||
| "description": "OpenAPI React Query Codegen", | ||
@@ -5,0 +5,0 @@ "bin": { |
+9
-4
@@ -12,10 +12,15 @@ #!/usr/bin/env node | ||
| program | ||
| .name('openapi-rq') | ||
| .name("openapi-rq") | ||
| .version(package_json_1["default"].version) | ||
| .description("Generate React Query code based on OpenAPI") | ||
| .requiredOption("-p, --path <path>", "Path to OpenAPI file") | ||
| .option("-o, --output-dir [directory]", "Directory to output the generated package", "openapi") | ||
| .requiredOption("-i, --input <value>", "OpenAPI specification, can be a path, url or string content (required)") | ||
| .option("-o, --output <value>", "Output directory", "openapi") | ||
| .option("-c, --client <value>", "HTTP client to generate [fetch, xhr, node, axios, angular]", "fetch") | ||
| .option("--exportSchemas <value>", "Write schemas to disk", false) | ||
| .option("--indent <value>", "Indentation options [4, 2, tabs]", "4") | ||
| .option("--postfix <value>", "Service name postfix", "Service") | ||
| .option("--request <value>", "Path to custom request file") | ||
| .parse(); | ||
| var options = program.opts(); | ||
| console.log("Generating React Query code using OpenApi file ".concat(options.path)); | ||
| console.log("Generating React Query code using OpenApi file ".concat(options.output)); | ||
| (0, generate_1.generate)(options); |
+18
-8
| "use strict"; | ||
| var __assign = (this && this.__assign) || function () { | ||
| __assign = Object.assign || function(t) { | ||
| for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
| s = arguments[i]; | ||
| for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
| t[p] = s[p]; | ||
| } | ||
| return t; | ||
| }; | ||
| return __assign.apply(this, arguments); | ||
| }; | ||
| var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -47,15 +58,14 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
| var createSource_1 = require("./createSource"); | ||
| var constants_1 = require("./constants"); | ||
| function generate(options) { | ||
| var _a; | ||
| return __awaiter(this, void 0, void 0, function () { | ||
| var openApiOutputPath, source; | ||
| return __generator(this, function (_a) { | ||
| switch (_a.label) { | ||
| return __generator(this, function (_b) { | ||
| switch (_b.label) { | ||
| case 0: | ||
| openApiOutputPath = path_1["default"].join(options.outputDir, "requests"); | ||
| return [4 /*yield*/, (0, openapi_typescript_codegen_1.generate)({ | ||
| input: options.path, | ||
| output: openApiOutputPath | ||
| })]; | ||
| openApiOutputPath = path_1["default"].join((_a = options.output) !== null && _a !== void 0 ? _a : constants_1.defaultOutputPath, constants_1.requestsOutputPath); | ||
| return [4 /*yield*/, (0, openapi_typescript_codegen_1.generate)(__assign(__assign({}, options), { httpClient: options.client, output: openApiOutputPath }))]; | ||
| case 1: | ||
| _a.sent(); | ||
| _b.sent(); | ||
| source = (0, createSource_1.createSource)(openApiOutputPath); | ||
@@ -62,0 +72,0 @@ (0, print_1.print)(source, options); |
@@ -9,12 +9,16 @@ "use strict"; | ||
| var path_1 = __importDefault(require("path")); | ||
| var constants_1 = require("./constants"); | ||
| function printGeneratedTS(result, options) { | ||
| var dir = path_1["default"].join(options.outputDir, "queries"); | ||
| var _a; | ||
| var dir = path_1["default"].join((_a = options.output) !== null && _a !== void 0 ? _a : constants_1.defaultOutputPath, constants_1.queriesOutputPath); | ||
| if (!fs_1["default"].existsSync(dir)) { | ||
| fs_1["default"].mkdirSync(dir, { recursive: true }); | ||
| } | ||
| fs_1["default"].writeFileSync(path_1["default"].join(dir, 'index.ts'), result); | ||
| fs_1["default"].writeFileSync(path_1["default"].join(dir, "index.ts"), result); | ||
| } | ||
| function print(result, options) { | ||
| if (!fs_1["default"].existsSync(options.outputDir)) { | ||
| fs_1["default"].mkdirSync(options.outputDir); | ||
| var _a; | ||
| var outputPath = (_a = options.output) !== null && _a !== void 0 ? _a : constants_1.defaultOutputPath; | ||
| if (!fs_1["default"].existsSync(outputPath)) { | ||
| fs_1["default"].mkdirSync(outputPath); | ||
| } | ||
@@ -21,0 +25,0 @@ printGeneratedTS(result, options); |
+1
-1
| { | ||
| "name": "@7nohe/openapi-react-query-codegen", | ||
| "version": "0.1.5", | ||
| "version": "0.2.0", | ||
| "description": "OpenAPI React Query Codegen", | ||
@@ -5,0 +5,0 @@ "bin": { |
+12
-7
@@ -21,11 +21,16 @@ # OpenAPI React Query Codegen | ||
| Usage: openapi-rq [options] | ||
| Usage: openapi-rq [options] | ||
| Generate React Query code based on OpenAPI | ||
| Generate React Query code based on OpenAPI | ||
| Options: | ||
| -V, --version output the version number | ||
| -p, --path <path> Path to OpenAPI file | ||
| -o, --output-dir [directory] Directory to output the generated package (default: "openapi") | ||
| -h, --help display help for command | ||
| Options: | ||
| -V, --version output the version number | ||
| -i, --input <value> OpenAPI specification, can be a path, url or string content (required) | ||
| -o, --output <value> Output directory (default: "openapi") | ||
| -c, --client <value> HTTP client to generate [fetch, xhr, node, axios, angular] (default: "fetch") | ||
| --exportSchemas <value> Write schemas to disk (default: false) | ||
| --indent <value> Indentation options [4, 2, tabs] (default: "4") | ||
| --postfix <value> Service name postfix (default: "Service") | ||
| --request <value> Path to custom request file | ||
| -h, --help display help for command | ||
| ``` | ||
@@ -32,0 +37,0 @@ |
35262
12.06%16
33.33%450
5.88%103
5.1%