react-query-lightbase-codegen 1.1.1 → 1.1.2

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.
@@ -1,22 +0,0 @@
1
- export const generateImports = ({ schemaName, apiDirectory, queryClientDir, schemaImports, }) => {
2
- const importTypes = schemaImports.join(',');
3
- return `
4
- import {
5
- useQuery,
6
- useMutation,
7
- UseQueryOptions,
8
- UseMutationOptions,
9
- QueryKey,
10
- SetDataOptions,
11
- QueryFilters
12
- } from '@tanstack/react-query';
13
-
14
- import { AxiosError } from 'axios';
15
- import { api } from '${apiDirectory}';
16
- import { queryClient } from '${queryClientDir}';
17
-
18
- import {${importTypes}} from './${schemaName}'
19
-
20
- type Updater<TInput, TOutput> = TOutput | ((input: TInput) => TOutput);
21
- `;
22
- };
@@ -1,39 +0,0 @@
1
- import chalk from 'chalk';
2
- import { readFileSync, writeFileSync, readdir, mkdirSync } from 'fs';
3
- import { join, parse } from 'path';
4
- import { convertSwaggerFile } from './convertSwaggerFile.js';
5
- import { generateImports, generateQueryHooks } from './generateHooks.js';
6
- import { generateSchemas } from './generateSchemas.js';
7
- export function importSpecs({ sourceDirectory, exportDirectory, apiDirectory, queryClientDir, headerFilters, }) {
8
- readdir(sourceDirectory, function (err, filenames) {
9
- if (err) {
10
- console.log(err);
11
- throw err;
12
- }
13
- filenames.map(async (filename) => {
14
- try {
15
- const data = readFileSync(join(process.cwd(), sourceDirectory + '/' + filename), 'utf-8');
16
- const { ext } = parse(sourceDirectory + '/' + filename);
17
- const format = ['.yaml', '.yml'].includes(ext.toLowerCase()) ? 'yaml' : 'json';
18
- const name = filename.split('.')[0];
19
- let spec = await convertSwaggerFile(data, format);
20
- const operationIds = [];
21
- mkdirSync(join(process.cwd(), `${exportDirectory}/${name}`), { recursive: true });
22
- const { implementation, schemaImports } = generateQueryHooks({ spec, operationIds, headerFilters });
23
- const schemaName = `useQueries${filename.split('.')[0]}.schema`;
24
- const imports = generateImports({ apiDirectory, queryClientDir, schemaName, schemaImports });
25
- const hooksName = `useQueries${filename.split('.')[0]}`;
26
- writeFileSync(join(process.cwd(), `${exportDirectory}/${name}/${hooksName}.tsx`), imports + implementation);
27
- const schemas = generateSchemas({ spec });
28
- writeFileSync(join(process.cwd(), `${exportDirectory}/${name}/${schemaName}.tsx`), schemas);
29
- console.log(chalk.green(`🎉 [${filename}] Your OpenAPI spec has been converted into react query hooks`));
30
- }
31
- catch (error) {
32
- if (error.code === 'EISDIR') {
33
- return;
34
- }
35
- console.log(chalk.red(`[${filename}]:`), chalk.red(error));
36
- }
37
- });
38
- });
39
- }