99 lines
2.6 KiB
JavaScript
99 lines
2.6 KiB
JavaScript
import fs from 'node:fs'
|
|
import path from 'node:path'
|
|
|
|
import {
|
|
domainSchemaObject,
|
|
skillSchemaObject,
|
|
skillConfigSchemaObject,
|
|
skillLocaleConfigObject
|
|
} from '@/schemas/skill-schemas'
|
|
import { toolManifestSchemaObject } from '@/schemas/tool-schemas'
|
|
import { toolkitSchemaObject } from '@/schemas/toolkit-schemas'
|
|
import {
|
|
globalEntitySchemaObject,
|
|
globalResolverSchemaObject,
|
|
globalAnswersSchemaObject
|
|
} from '@/schemas/global-data-schemas'
|
|
import {
|
|
amazonVoiceConfiguration,
|
|
googleCloudVoiceConfiguration,
|
|
watsonVoiceConfiguration
|
|
} from '@/schemas/voice-config-schemas'
|
|
import { configSchemaObject } from '@/schemas/core-schemas'
|
|
|
|
import { createSetupStatus } from '../setup/setup-status'
|
|
|
|
/**
|
|
* Generate JSON schemas
|
|
* @param {string} categoryName
|
|
* @param {Map<string, Object>} schemas
|
|
*/
|
|
export const generateSchemas = async (categoryName, schemas) => {
|
|
const categorySchemasPath = path.join(process.cwd(), 'schemas', categoryName)
|
|
|
|
await fs.promises.mkdir(categorySchemasPath, { recursive: true })
|
|
|
|
for (const [schemaName, schemaObject] of schemas.entries()) {
|
|
const schemaPath = path.join(categorySchemasPath, `${schemaName}.json`)
|
|
|
|
await fs.promises.writeFile(
|
|
schemaPath,
|
|
JSON.stringify(
|
|
{
|
|
$schema: 'https://json-schema.org/draft-07/schema',
|
|
...schemaObject
|
|
},
|
|
null,
|
|
2
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
export default async () => {
|
|
const status = createSetupStatus('Generating JSON schemas...').start()
|
|
|
|
await Promise.all([
|
|
generateSchemas(
|
|
'core-schemas',
|
|
new Map([['config', configSchemaObject]])
|
|
),
|
|
generateSchemas(
|
|
'global-data',
|
|
new Map([
|
|
['global-entity', globalEntitySchemaObject],
|
|
['global-resolver', globalResolverSchemaObject],
|
|
['global-answers', globalAnswersSchemaObject]
|
|
])
|
|
),
|
|
generateSchemas(
|
|
'skill-schemas',
|
|
new Map([
|
|
['domain', domainSchemaObject],
|
|
['skill', skillSchemaObject],
|
|
['skill-config', skillConfigSchemaObject],
|
|
['skill-locale-config', skillLocaleConfigObject]
|
|
])
|
|
),
|
|
generateSchemas(
|
|
'tool-schemas',
|
|
new Map([['tool', toolManifestSchemaObject]])
|
|
),
|
|
generateSchemas(
|
|
'toolkit-schemas',
|
|
new Map([['toolkit', toolkitSchemaObject]])
|
|
),
|
|
generateSchemas(
|
|
'voice-config-schemas',
|
|
new Map([
|
|
['amazon', amazonVoiceConfiguration],
|
|
['google-cloud', googleCloudVoiceConfiguration],
|
|
['watson-stt', watsonVoiceConfiguration],
|
|
['watson-tts', watsonVoiceConfiguration]
|
|
])
|
|
)
|
|
])
|
|
|
|
status.succeed('JSON schemas: ready')
|
|
}
|