forked from ferdikoomen/openapi-typescript-codegen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·56 lines (51 loc) · 2.18 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
'use strict';
const path = require('path');
const { program } = require('commander');
const pkg = require('../package.json');
const params = program
.name('openapi')
.usage('[options]')
.version(pkg.version)
.requiredOption('-i, --input <value>', 'OpenAPI specification, can be a path, url or string content (required)')
.requiredOption('-o, --output <value>', 'Output directory (required)')
.option('-c, --client <value>', 'HTTP client to generate [fetch, xhr, node, axios, angular]', 'fetch')
.option('--name <value>', 'Custom client class name')
.option('--useOptions', 'Use options instead of arguments')
.option('--useUnionTypes', 'Use union types instead of enums')
.option('--exportCore <value>', 'Write core files to disk', true)
.option('--exportServices <value>', 'Write services to disk', true)
.option('--exportModels <value>', 'Write models to disk', true)
.option('--exportSchemas <value>', 'Write schemas to disk', false)
.option('--indent <value>', 'Indentation options [4, 2, tabs]', '4')
.option('--postfixServices <value>', 'Service name postfix', 'Service')
.option('--postfixModels <value>', 'Model name postfix')
.option('--request <value>', 'Path to custom request file')
.parse(process.argv)
.opts();
const OpenAPI = require(path.resolve(__dirname, '../dist/index.js'));
if (OpenAPI) {
OpenAPI.generate({
input: params.input,
output: params.output,
httpClient: params.client,
clientName: params.name,
useOptions: params.useOptions,
useUnionTypes: params.useUnionTypes,
exportCore: JSON.parse(params.exportCore) === true,
exportServices: JSON.parse(params.exportServices) === true,
exportModels: JSON.parse(params.exportModels) === true,
exportSchemas: JSON.parse(params.exportSchemas) === true,
indent: params.indent,
postfixServices: params.postfixServices,
postfixModels: params.postfixModels,
request: params.request,
})
.then(() => {
process.exit(0);
})
.catch(error => {
console.error(error);
process.exit(1);
});
}