react-query-lightbase-codegen 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.codegen = void 0;
4
+ const react_query_codegen_js_1 = require("./react-query-codegen.js");
5
+ Object.defineProperty(exports, "codegen", { enumerable: true, get: function () { return react_query_codegen_js_1.codegen; } });
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const chalk_1 = __importDefault(require("chalk"));
7
+ const commander_1 = __importDefault(require("commander"));
8
+ const fs_1 = require("fs");
9
+ const path_1 = require("path");
10
+ const import_open_api_1 = __importDefault(require("./scripts/import-open-api"));
11
+ const log = console.log; // tslint:disable-line:no-console
12
+ commander_1.default.option('-o, --output [value]', 'output file destination');
13
+ commander_1.default.option('-f, --file [value]', 'input file (yaml or json openapi specs)');
14
+ commander_1.default.parse(process.argv);
15
+ const createSuccessMessage = (backend) => chalk_1.default.green(`${backend ? `[${backend}] ` : ''}🎉 Your OpenAPI spec has been converted into react query hooks`);
16
+ const successWithoutOutputMessage = chalk_1.default.yellow('Success! No output path specified; printed to standard output.');
17
+ const importSpecs = async (options) => {
18
+ if (!options.file) {
19
+ throw new Error("You need to provide an input specification with `--file`, '--url', or `--github`");
20
+ }
21
+ const data = fs_1.readFileSync(path_1.join(process.cwd(), options.file), 'utf-8');
22
+ const { ext } = path_1.parse(options.file);
23
+ const format = ['.yaml', '.yml'].includes(ext.toLowerCase()) ? 'yaml' : 'json';
24
+ return import_open_api_1.default({
25
+ data,
26
+ format,
27
+ });
28
+ };
29
+ // Use flags as configuration
30
+ importSpecs(commander_1.default)
31
+ .then((data) => {
32
+ if (commander_1.default.output) {
33
+ fs_1.writeFileSync(path_1.join(process.cwd(), commander_1.default.output), data);
34
+ log(createSuccessMessage());
35
+ }
36
+ else {
37
+ log(data);
38
+ log(successWithoutOutputMessage);
39
+ }
40
+ })
41
+ .catch((err) => {
42
+ log(chalk_1.default.red(err));
43
+ process.exit(1);
44
+ });
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.codegen = void 0;
7
+ const commander_1 = __importDefault(require("commander"));
8
+ const fs_1 = require("fs");
9
+ const path_1 = require("path");
10
+ const { version } = JSON.parse(fs_1.readFileSync(path_1.join(__dirname, '../../package.json'), 'utf-8'));
11
+ const codegen = () => {
12
+ commander_1.default
13
+ .version(version)
14
+ .command('import [open-api-file]', 'generate react-query hooks from OpenAPI specs')
15
+ .parse(process.argv);
16
+ };
17
+ exports.codegen = codegen;