import 'json-schema-to-typescript' only in dev mode
This commit is contained in:
@@ -14,7 +14,8 @@ const nextConfig = {
|
||||
MONGO_PASS: envVar.get('MONGO_PASS').required(!isBuildStage).asString()
|
||||
},
|
||||
publicRuntimeConfig: {
|
||||
TENANT_TYPE: envVar.get('TENANT_TYPE').required(!isBuildStage).asString()
|
||||
TENANT_TYPE: envVar.get('TENANT_TYPE').required(!isBuildStage).asString(),
|
||||
NODE_ENV: envVar.get('NODE_ENV').asString()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1
src/next-types.d.ts
vendored
1
src/next-types.d.ts
vendored
@@ -8,6 +8,7 @@ declare module 'next/config' {
|
||||
|
||||
export interface PublicRuntimeConfig {
|
||||
TENANT_TYPE?: string
|
||||
NODE_ENV?: string
|
||||
}
|
||||
|
||||
const getConfig: () => {
|
||||
|
||||
@@ -2,20 +2,20 @@ import { Validator } from 'jsonschema'
|
||||
import { getDefaults, isObject, merge } from './defaults'
|
||||
import { TransformedValidatorResult, ValidatorOptions } from './types'
|
||||
import { transformInstance } from './transform'
|
||||
import { compile, JSONSchema } from 'json-schema-to-typescript'
|
||||
import type { JSONSchema } from 'json-schema-to-typescript'
|
||||
import * as fs from 'fs/promises'
|
||||
import { join } from 'path'
|
||||
import { NetworkError } from '../utils/errors'
|
||||
import getConfig from 'next/config'
|
||||
|
||||
const {
|
||||
publicRuntimeConfig: { TENANT_TYPE }
|
||||
publicRuntimeConfig: { TENANT_TYPE, NODE_ENV }
|
||||
} = getConfig()
|
||||
|
||||
const validatorStorage = new Validator()
|
||||
|
||||
export async function addSchema(schemas: JSONSchema[]) {
|
||||
if (TENANT_TYPE === 'local') {
|
||||
if (TENANT_TYPE === 'local' && NODE_ENV === 'development') {
|
||||
const fileName = join('./src/types/ApiSchemas.ts')
|
||||
const fileNameFrontend = join('./src/types/ApiSchemasFrontend.ts')
|
||||
const style = await fs.readFile('./.prettierrc.json', 'utf8').then(JSON.parse)
|
||||
@@ -25,6 +25,7 @@ export async function addSchema(schemas: JSONSchema[]) {
|
||||
if (!schema.id) throw new SyntaxError('Id of schema has to be defined!')
|
||||
validatorStorage.addSchema(schema)
|
||||
// compile schema to interface
|
||||
const { compile } = await import('json-schema-to-typescript')
|
||||
let entity = await compile(schema, schema.id, {
|
||||
style,
|
||||
bannerComment: data === '' ? undefined : '\n\n\n',
|
||||
|
||||
@@ -70,6 +70,4 @@ export function addSchemas() {
|
||||
])
|
||||
}
|
||||
|
||||
export const waitForInitSchemas = new Resolvable(() => {
|
||||
return addSchemas()
|
||||
})
|
||||
export const waitForInitSchemas = new Resolvable(addSchemas)
|
||||
|
||||
Reference in New Issue
Block a user