teableio_teable/scripts/generate-openapi-types.mjs
Pengap 4c27e38c14
feat: support postgres db (#177)
* feat: support postgres db

* fix: postgres install date time

* fix: unit test

* chore: yarn.lock

* feat: add Makefile script

* chore: merge conflicts

* test: integration tests

* chore(deps): update yarn to v4.0.0-rc.42

---------

Co-authored-by: pengap <penganpingprivte@gmail.com>
2023-10-08 15:11:19 +08:00

30 lines
873 B
JavaScript

import openapiTS from 'openapi-typescript';
import path from 'path';
import fs from 'fs';
async function generateTypes() {
const localPath = path.resolve(process.cwd(), 'apps/nestjs-backend/dist/openapi.json');
const output = await openapiTS(localPath, {
commentHeader:
[
'/* eslint-disable sonarjs/no-duplicate-string */',
'/* eslint-disable @typescript-eslint/naming-convention */',
'/* eslint-disable prettier/prettier */',
].join('\n') + '\n',
});
const outputPath = path.resolve(process.cwd(), 'apps/nextjs-app/src/api/types.ts');
const outputDir = path.dirname(outputPath);
// mkdir if it doesn't exist
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
fs.writeFileSync(outputPath, output);
console.log('Types generated and saved successfully.');
}
generateTypes();