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