-
-
Notifications
You must be signed in to change notification settings - Fork 355
Expand file tree
/
Copy pathgenerate-schemas.js
More file actions
45 lines (38 loc) · 1.16 KB
/
generate-schemas.js
File metadata and controls
45 lines (38 loc) · 1.16 KB
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
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
import { exec } from 'node:child_process';
import process from 'node:process';
import { config } from 'dotenv-flow';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
config({
default_node_env: 'development',
path: resolve(__dirname, '../'),
});
const apiUrl = process.env.VITE_APP_API_URL || 'http://localhost:8080';
const definitions = {
public: {
schema: 'All%20Internal%20-%20for%20Tolgee%20Web%20application',
output: './src/service/apiSchema.generated.ts',
},
billing: {
schema: 'V2%20Billing',
output: '../../billing/frontend/billingApiSchema.generated.ts',
},
};
const definition = definitions[process.argv[2]];
if (!definition) {
throw new Error('Invalid definition');
}
const command = `openapi-typescript ${apiUrl}/v3/api-docs/${definition.schema} --output ${definition.output}`;
exec(command, (error, stdout, stderr) => {
if (error) {
console.log(`error: ${error.message}`);
return;
}
if (stderr) {
console.log(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
});