react-query-lightbase-codegen 0.0.21 → 0.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.
- package/lib/bin/react-query-codegen-import.js +39 -0
- package/lib/bin/react-query-codegen.js +8 -0
- package/lib/cjs/import-open-api.js +149 -130
- package/lib/esm/import-open-api.js +149 -130
- package/lib/scripts/import-open-api.js +605 -0
- package/lib/types.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import program from 'commander';
|
|
3
|
+
import { readFileSync, writeFileSync } from 'fs';
|
|
4
|
+
import { join, parse } from 'path';
|
|
5
|
+
import importOpenApi from '../scripts/import-open-api';
|
|
6
|
+
const log = console.log; // tslint:disable-line:no-console
|
|
7
|
+
program.option('-o, --output [value]', 'output file destination');
|
|
8
|
+
program.option('-f, --file [value]', 'input file (yaml or json openapi specs)');
|
|
9
|
+
program.parse(process.argv);
|
|
10
|
+
const createSuccessMessage = (backend) => chalk.green(`${backend ? `[${backend}] ` : ''}🎉 Your OpenAPI spec has been converted into react query hooks`);
|
|
11
|
+
const successWithoutOutputMessage = chalk.yellow('Success! No output path specified; printed to standard output.');
|
|
12
|
+
const importSpecs = async (options) => {
|
|
13
|
+
if (!options.file) {
|
|
14
|
+
throw new Error("You need to provide an input specification with `--file`, '--url', or `--github`");
|
|
15
|
+
}
|
|
16
|
+
const data = readFileSync(join(process.cwd(), options.file), 'utf-8');
|
|
17
|
+
const { ext } = parse(options.file);
|
|
18
|
+
const format = ['.yaml', '.yml'].includes(ext.toLowerCase()) ? 'yaml' : 'json';
|
|
19
|
+
return importOpenApi({
|
|
20
|
+
data,
|
|
21
|
+
format,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
// Use flags as configuration
|
|
25
|
+
importSpecs(program)
|
|
26
|
+
.then((data) => {
|
|
27
|
+
if (program.output) {
|
|
28
|
+
writeFileSync(join(process.cwd(), program.output), data);
|
|
29
|
+
log(createSuccessMessage());
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
log(data);
|
|
33
|
+
log(successWithoutOutputMessage);
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
.catch((err) => {
|
|
37
|
+
log(chalk.red(err));
|
|
38
|
+
process.exit(1);
|
|
39
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import program from 'commander';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
const { version } = JSON.parse(readFileSync(join(__dirname, '../../package.json'), 'utf-8'));
|
|
5
|
+
program
|
|
6
|
+
.version(version)
|
|
7
|
+
.command('import [open-api-file]', 'generate react-query hooks from OpenAPI specs')
|
|
8
|
+
.parse(process.argv);
|