react-query-lightbase-codegen 0.0.5 → 0.0.6
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.
|
@@ -598,7 +598,7 @@ exports.generateRestfulComponent = generateRestfulComponent;
|
|
|
598
598
|
/**
|
|
599
599
|
* Main entry of the generator. Generate react-query component from openAPI.
|
|
600
600
|
*/
|
|
601
|
-
const importOpenApi = async ({ data, format }) => {
|
|
601
|
+
const importOpenApi = async ({ data, format, apiDir, }) => {
|
|
602
602
|
const operationIds = [];
|
|
603
603
|
let specs = await importSpecs(data, format);
|
|
604
604
|
exports.resolveDiscriminator(specs);
|
|
@@ -606,7 +606,7 @@ const importOpenApi = async ({ data, format }) => {
|
|
|
606
606
|
import { useQuery, useMutation, UseQueryOptions, UseMutationOptions, QueryKey } from 'react-query';
|
|
607
607
|
import queryString from 'query-string';
|
|
608
608
|
import {AxiosError} from 'axios';
|
|
609
|
-
import { api } from
|
|
609
|
+
import { api } from ${apiDir};
|
|
610
610
|
`;
|
|
611
611
|
output += '\n\n// SCEHMAS\n';
|
|
612
612
|
output += exports.generateSchemasDefinition(specs.components && specs.components.schemas);
|
|
@@ -10,19 +10,19 @@ const path_1 = require("path");
|
|
|
10
10
|
const import_open_api_1 = require("./import-open-api");
|
|
11
11
|
const log = console.log; // tslint:disable-line:no-console
|
|
12
12
|
const createSuccessMessage = (backend) => chalk_1.default.green(`🎉 ${backend ? `[${backend}] ` : ''} Your OpenAPI spec has been converted into react query hooks`);
|
|
13
|
-
function importSpecs(
|
|
14
|
-
fs_1.readdir(
|
|
13
|
+
function importSpecs({ sourceDirectory, exportDirectory, apiDirectory, }) {
|
|
14
|
+
fs_1.readdir(sourceDirectory, function (err, filenames) {
|
|
15
15
|
if (err) {
|
|
16
16
|
throw err;
|
|
17
17
|
}
|
|
18
18
|
filenames.map(async (filename) => {
|
|
19
|
-
const data = fs_1.readFileSync(path_1.join(process.cwd(),
|
|
20
|
-
const { ext } = path_1.parse(
|
|
19
|
+
const data = fs_1.readFileSync(path_1.join(process.cwd(), sourceDirectory + '/' + filename), 'utf-8');
|
|
20
|
+
const { ext } = path_1.parse(sourceDirectory + '/' + filename);
|
|
21
21
|
const format = ['.yaml', '.yml'].includes(ext.toLowerCase()) ? 'yaml' : 'json';
|
|
22
22
|
try {
|
|
23
23
|
const name = `useQueries${filename.split('.')[0]}.tsx`;
|
|
24
|
-
const fileExports = await import_open_api_1.importOpenApi({ data, format });
|
|
25
|
-
fs_1.writeFileSync(path_1.join(process.cwd(), `${
|
|
24
|
+
const fileExports = await import_open_api_1.importOpenApi({ data, format, apiDir: apiDirectory });
|
|
25
|
+
fs_1.writeFileSync(path_1.join(process.cwd(), `${exportDirectory}/${name}`), fileExports);
|
|
26
26
|
log(createSuccessMessage(filename));
|
|
27
27
|
}
|
|
28
28
|
catch (error) {
|
|
@@ -577,7 +577,7 @@ export const generateRestfulComponent = (operation, verb, route, operationIds, p
|
|
|
577
577
|
/**
|
|
578
578
|
* Main entry of the generator. Generate react-query component from openAPI.
|
|
579
579
|
*/
|
|
580
|
-
export const importOpenApi = async ({ data, format }) => {
|
|
580
|
+
export const importOpenApi = async ({ data, format, apiDir, }) => {
|
|
581
581
|
const operationIds = [];
|
|
582
582
|
let specs = await importSpecs(data, format);
|
|
583
583
|
resolveDiscriminator(specs);
|
|
@@ -585,7 +585,7 @@ export const importOpenApi = async ({ data, format }) => {
|
|
|
585
585
|
import { useQuery, useMutation, UseQueryOptions, UseMutationOptions, QueryKey } from 'react-query';
|
|
586
586
|
import queryString from 'query-string';
|
|
587
587
|
import {AxiosError} from 'axios';
|
|
588
|
-
import { api } from
|
|
588
|
+
import { api } from ${apiDir};
|
|
589
589
|
`;
|
|
590
590
|
output += '\n\n// SCEHMAS\n';
|
|
591
591
|
output += generateSchemasDefinition(specs.components && specs.components.schemas);
|
|
@@ -4,19 +4,19 @@ import { join, parse } from 'path';
|
|
|
4
4
|
import { importOpenApi } from './import-open-api';
|
|
5
5
|
const log = console.log; // tslint:disable-line:no-console
|
|
6
6
|
const createSuccessMessage = (backend) => chalk.green(`🎉 ${backend ? `[${backend}] ` : ''} Your OpenAPI spec has been converted into react query hooks`);
|
|
7
|
-
export function importSpecs(
|
|
8
|
-
readdir(
|
|
7
|
+
export function importSpecs({ sourceDirectory, exportDirectory, apiDirectory, }) {
|
|
8
|
+
readdir(sourceDirectory, function (err, filenames) {
|
|
9
9
|
if (err) {
|
|
10
10
|
throw err;
|
|
11
11
|
}
|
|
12
12
|
filenames.map(async (filename) => {
|
|
13
|
-
const data = readFileSync(join(process.cwd(),
|
|
14
|
-
const { ext } = parse(
|
|
13
|
+
const data = readFileSync(join(process.cwd(), sourceDirectory + '/' + filename), 'utf-8');
|
|
14
|
+
const { ext } = parse(sourceDirectory + '/' + filename);
|
|
15
15
|
const format = ['.yaml', '.yml'].includes(ext.toLowerCase()) ? 'yaml' : 'json';
|
|
16
16
|
try {
|
|
17
17
|
const name = `useQueries${filename.split('.')[0]}.tsx`;
|
|
18
|
-
const fileExports = await importOpenApi({ data, format });
|
|
19
|
-
writeFileSync(join(process.cwd(), `${
|
|
18
|
+
const fileExports = await importOpenApi({ data, format, apiDir: apiDirectory });
|
|
19
|
+
writeFileSync(join(process.cwd(), `${exportDirectory}/${name}`), fileExports);
|
|
20
20
|
log(createSuccessMessage(filename));
|
|
21
21
|
}
|
|
22
22
|
catch (error) {
|