UNPKG

@kontent-ai/model-generator

Version:

This utility generates strongly-typed models for Delivery JS SDK, Migration toolkit or just general scripting to improve the experience when referencing Kontent.ai related objects.

54 lines 2.13 kB
import chalk from "chalk"; import { getManagementKontentFetcher } from "../../fetch/management-kontent-fetcher.js"; import { getFileManager } from "../../files/file-manager.js"; import { getSyncGenerator } from "./sync.generator.js"; export async function generateSyncModelsAsync(config) { console.log(chalk.green("Model generator started \n")); console.log(`Generating '${chalk.yellow("sync-sdk")}' models\n`); const { syncFiles, environmentInfo } = await getFilesAsync(config); const fileManager = getFileManager({ disableComments: config.disableComments ?? false, ...config, environmentInfo, }); const setFiles = await fileManager.getSetFilesAsync([syncFiles]); if (config.createFiles) { fileManager.createFiles(setFiles); } console.log(chalk.green("\nCompleted")); return setFiles; } async function getFilesAsync(config) { const kontentFetcher = getManagementKontentFetcher({ environmentId: config.environmentId, managementApiKey: config.managementApiKey, baseUrl: config.managementBaseUrl, }); const environmentInfo = await kontentFetcher.getEnvironmentInfoAsync(); const [languages, taxonomies, types, snippets, collections, workflows] = await Promise.all([ kontentFetcher.getLanguagesAsync(), kontentFetcher.getTaxonomiesAsync(), kontentFetcher.getTypesAsync(), kontentFetcher.getSnippetsAsync(), kontentFetcher.getCollectionsAsync(), kontentFetcher.getWorkflowsAsync(), ]); const syncGenerator = getSyncGenerator({ moduleFileExtension: config.moduleFileExtension, disableComments: config.disableComments ?? false, environmentData: { environment: environmentInfo, taxonomies: taxonomies, languages: languages, workflows: workflows, types: types, snippets: snippets, collections: collections, }, }); return { syncFiles: syncGenerator.getSyncFiles(), environmentInfo, }; } //# sourceMappingURL=sync-func.js.map