From 9aee071fce44c38ed0ba11c32dca4bf34f66cf53 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 22 Jul 2024 14:08:37 +0200 Subject: [PATCH 001/183] Refactors CLI setup, uses chalk instead of colors, updates tsconfig/eslint, adds error handler and prepares migrate action --- .eslintrc.cjs | 16 - README.md | 2 +- eslint.config.js | 25 + lib/cli/cli.ts | 142 -- lib/common-helper.ts | 13 +- lib/core/core.models.ts | 22 + lib/core/core.utils.ts | 3 + lib/core/error.utils.ts | 62 + lib/core/index.ts | 3 + lib/file-helper.ts | 8 +- lib/generator.ts | 524 +++--- .../delivery-content-type.generator.ts | 18 +- .../delivery/delivery-taxonomy.generator.ts | 12 +- .../migration/migration-generator.ts | 13 + lib/generators/project/project.generator.ts | 28 +- lib/index.ts | 1 + lib/models.ts | 3 +- lib/node/cli/actions/delivery-action.ts | 37 + lib/node/cli/actions/migrate-action.ts | 1 + lib/node/cli/app.ts | 32 + lib/node/cli/args/args-fetcher.ts | 59 + lib/node/cli/args/args-setter.ts | 38 + lib/node/cli/cli.models.ts | 29 + lib/node/cli/commands.ts | 71 + lib/text-helper.ts | 21 +- package-lock.json | 1499 +++++++++++++++-- package.json | 29 +- sample/content-types/actor.ts | 2 +- sample/content-types/movie.ts | 2 +- sample/project/assetFolders.ts | 2 +- sample/project/collections.ts | 2 +- sample/project/contentTypeSnippets.ts | 2 +- sample/project/contentTypes.ts | 2 +- sample/project/languages.ts | 2 +- sample/project/roles.ts | 2 +- sample/project/taxonomies.ts | 2 +- sample/project/webhooks.ts | 2 +- sample/project/workflows.ts | 2 +- sample/taxonomies/movietype.ts | 2 +- sample/taxonomies/releasecategory.ts | 2 +- clean.ts => scripts/clean.ts | 4 +- scripts/file-version-script.ts | 10 +- scripts/generate-delivery-models.ts | 18 +- tsconfig.es2022.json | 21 +- tsconfig.json | 28 +- 45 files changed, 2131 insertions(+), 687 deletions(-) delete mode 100644 .eslintrc.cjs create mode 100644 eslint.config.js delete mode 100644 lib/cli/cli.ts create mode 100644 lib/core/core.models.ts create mode 100644 lib/core/core.utils.ts create mode 100644 lib/core/error.utils.ts create mode 100644 lib/core/index.ts create mode 100644 lib/generators/migration/migration-generator.ts create mode 100644 lib/node/cli/actions/delivery-action.ts create mode 100644 lib/node/cli/actions/migrate-action.ts create mode 100644 lib/node/cli/app.ts create mode 100644 lib/node/cli/args/args-fetcher.ts create mode 100644 lib/node/cli/args/args-setter.ts create mode 100644 lib/node/cli/cli.models.ts create mode 100644 lib/node/cli/commands.ts rename clean.ts => scripts/clean.ts (61%) diff --git a/.eslintrc.cjs b/.eslintrc.cjs deleted file mode 100644 index fe7f8ac..0000000 --- a/.eslintrc.cjs +++ /dev/null @@ -1,16 +0,0 @@ -/* eslint-env node */ -module.exports = { - extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], - parser: '@typescript-eslint/parser', - plugins: ['@typescript-eslint'], - parserOptions: { - tsconfigRootDir: __dirname, - project: ['./tsconfig.json'] - }, - rules: { - '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-unused-vars': 'off', - '@typescript-eslint/no-namespace': 'off' - }, - root: true -}; diff --git a/README.md b/README.md index 5a1a533..e9e9a66 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ await generateModelsAsync({ `pascalCase`, `snakeCase` - `taxonomyTypeResolver`- Name resolver for taxonomy type names. Available options are: `camelCase`, `pascalCase`, `snakeCase` -- `sdkType`- Type of sdk for which models are generated. Available options are: `delivery` +- `sdkType`- Type of sdk for which models are generated. Available options are: `delivery`, `migration` - `exportWebhooks` - Indicates if webhooks are exported - `exportWorkflows` - Indicates if workflows are exported - `exportAssetFolders` - Indicates if asset folders are exported diff --git a/eslint.config.js b/eslint.config.js new file mode 100644 index 0000000..21e7940 --- /dev/null +++ b/eslint.config.js @@ -0,0 +1,25 @@ +import eslint from '@eslint/js'; +import tseslint from 'typescript-eslint'; + +export default tseslint.config(eslint.configs.recommended, ...tseslint.configs.recommendedTypeChecked, { + languageOptions: { + parserOptions: { + project: true, + tsconfigRootDir: import.meta.dirname + } + }, + rules: { + '@typescript-eslint/no-namespace': 'off', + '@typescript-eslint/naming-convention': [ + 'warn', + { + selector: 'interface', + format: ['PascalCase'], + custom: { + regex: '^I[A-Z]', + match: false + } + } + ] + } +}); diff --git a/lib/cli/cli.ts b/lib/cli/cli.ts deleted file mode 100644 index bdb330d..0000000 --- a/lib/cli/cli.ts +++ /dev/null @@ -1,142 +0,0 @@ -#!/usr/bin/env node -import yargs from 'yargs'; -import { generateModelsAsync } from '../generator.js'; -import { ModuleResolution } from '../models.js'; - -const argv = yargs(process.argv.slice(2)) - .example( - 'kontent-generate --environmentId=xxx --apiKey=yyy', - 'Basic configuration to generate strongly typed models' - ) - .alias('p', 'environmentId') - .describe('p', 'environmentId') - .alias('i', 'environmentId') - .describe('i', 'environmentId') - .alias('k', 'apiKey') - .describe('k', 'Management API Key') - .alias('o', 'outputDir') - .describe('o', 'Directory where generated files will be created') - .alias('a', 'addTimestamp') - .describe('a', 'Indicates if timestamp should be generated') - .alias('e', 'addEnvironmentInfo') - .describe('e', 'Indicates if environment info stamp should be generated') - .alias('t', 'sdkType') - .describe('t', 'Type of sdk for which models are generated. Available options are: delivery') - .alias('m', 'moduleResolution') - .describe('m', 'Module resolution for imports. Available options are: node, nodeNext') - .option('exportLanguages', { - description: 'Indicates if languages are exported' - }) - .option('exportCollections', { - description: 'Indicates if collections are exported' - }) - .option('exportAssetFolders', { - description: 'Indicates if asset folders are exported' - }) - .option('exportWorkflows', { - description: 'Indicates if workflows are exported' - }) - .option('exportWebhooks', { - description: 'Indicates if webhooks are exported' - }) - .option('taxonomyTypeResolver', { - description: 'Name resolver for taxonomy type names. Available options are: camelCase, pascalCase, snakeCase' - }) - .option('contentTypeResolver', { - description: 'Name resolver for content type names. Available options are: camelCase, pascalCase, snakeCase' - }) - .option('contentTypeSnippetResolver', { - description: - 'Name resolver for content type snippet names. Available options are: camelCase, pascalCase, snakeCase' - }) - .option('taxonomyTypeFileResolver', { - description: 'Name resolver for taxonomy filenames. Available options are: camelCase, pascalCase, snakeCase' - }) - .option('contentTypeFileResolver', { - description: 'Name resolver for content type filenames. Available options are: camelCase, pascalCase, snakeCase' - }) - .option('contentTypeSnippetFileResolver', { - description: - 'Name resolver for content type snippet filenames. Available options are: camelCase, pascalCase, snakeCase' - }) - .option('exportRoles', { - description: 'Indicates if roles are exported. Only available for Enterprise subscription plans' - }) - .option('isEnterpriseSubscription', { - description: 'Indicates if enterprise subscription endpoint can be used to export data.' - }) - .option('sortTaxonomyTerms', { - description: 'Indicates if taxonomy terms are sorted alphabetically.' - }) - .option('managementApiUrl', { - description: 'Sets the url of Management API.' - }) - .help('h') - .alias('h', 'help').argv; - -const run = async () => { - const resolvedArgs = (await argv) as any; - - // user config - const environmentId = resolvedArgs.environmentId; - const apiKey = resolvedArgs.apiKey; - const outputDir = resolvedArgs.outputDir; - const addTimestamp = resolvedArgs.addTimestamp; - const addEnvironmentInfo = resolvedArgs.addEnvironmentInfo; - const elementResolver = resolvedArgs.elementResolver; - const contentTypeFileResolver = resolvedArgs.contentTypeFileResolver; - const contentTypeSnippetFileResolver = resolvedArgs.contentTypeSnippetFileResolver; - const taxonomyTypeFileResolver = resolvedArgs.taxonomyTypeFileResolver; - const contentTypeResolver = resolvedArgs.contentTypeResolver; - const taxonomyTypeResolver = resolvedArgs.taxonomyTypeResolver; - const moduleResolution = resolvedArgs.moduleResolution; - const contentTypeSnippetResolver = resolvedArgs.contentTypeSnippetResolver; - const sdkType = resolvedArgs.sdkType; - const exportWebhooks = !resolvedArgs.exportWebhooks ? true : resolvedArgs.exportWebhooks === 'true'; - const sortTaxonomyTerms = !resolvedArgs.sortTaxonomyTerms ? true : resolvedArgs.sortTaxonomyTerms === 'true'; - const exportWorkflows = !resolvedArgs.exportWorkflows ? true : resolvedArgs.exportWorkflows === 'true'; - const exportAssetFolders = !resolvedArgs.exportAssetFolders ? true : resolvedArgs.exportAssetFolders === 'true'; - const exportCollections = !resolvedArgs.exportCollections ? true : resolvedArgs.exportCollections === 'true'; - const exportLanguages = !resolvedArgs.exportLanguages ? true : resolvedArgs.exportLanguages === 'true'; - const exportRoles = !resolvedArgs.exportRoles ? true : resolvedArgs.exportRoles === 'true'; - const isEnterpriseSubscription = !resolvedArgs.isEnterpriseSubscription - ? true - : resolvedArgs.isEnterpriseSubscription === 'true'; - - if (!environmentId) { - throw Error(`Please provide environment id using 'environmentId' argument`); - } - - await generateModelsAsync({ - environmentId: environmentId, - managementApiUrl: resolvedArgs.managementApiUrl, - apiKey: apiKey, - outputDir: outputDir, - isEnterpriseSubscription: isEnterpriseSubscription, - addTimestamp: addTimestamp === 'true' ? true : false, - addEnvironmentInfo: addEnvironmentInfo === 'true' ? true : false, - elementResolver: elementResolver, - contentTypeFileResolver: contentTypeFileResolver, - contentTypeResolver: contentTypeResolver, - taxonomyTypeFileResolver: taxonomyTypeFileResolver, - taxonomyTypeResolver: taxonomyTypeResolver, - contentTypeSnippetFileResolver: contentTypeSnippetFileResolver, - contentTypeSnippetResolver: contentTypeSnippetResolver, - formatOptions: undefined, - sdkType: sdkType ?? 'delivery', - sortConfig: { - sortTaxonomyTerms: sortTaxonomyTerms - }, - moduleResolution: moduleResolution?.toString() === 'node' ? 'node' : 'nodeNext', - exportProjectSettings: { - exportWebhooks: exportWebhooks ?? true, - exportWorkflows: exportWorkflows ?? true, - exportAssetFolders: exportAssetFolders ?? true, - exportCollections: exportCollections ?? true, - exportLanguages: exportLanguages ?? true, - exportRoles: exportRoles ?? true - } - }); -}; - -run(); diff --git a/lib/common-helper.ts b/lib/common-helper.ts index 560baee..ad1af01 100644 --- a/lib/common-helper.ts +++ b/lib/common-helper.ts @@ -24,19 +24,17 @@ export class CommonHelper { } getElementCodename(element: ContentTypeElements.ContentTypeElementModel): string | undefined { - const codename = (element)['codename']; - - return codename ?? undefined; + return element.codename; } isElementRequired(element: ContentTypeElements.ContentTypeElementModel): boolean { - const isRequired = (element)['is_required']; + const isRequired = (<{ is_required?: boolean }>element)['is_required']; return isRequired === true; } getElementGuidelines(element: ContentTypeElements.ContentTypeElementModel): string | null { - const guidelines = (element)['guidelines']; + const guidelines = (<{ guidelines?: string }>element)['guidelines']; if (!guidelines) { return null; @@ -67,8 +65,7 @@ export class CommonHelper { taxonomies: TaxonomyModels.Taxonomy[] ): string | null { if (element.type === 'taxonomy') { - const taxonomyElement = element as ContentTypeElements.ITaxonomyElement; - const taxonomyGroupId = taxonomyElement?.taxonomy_group?.id; + const taxonomyGroupId = element.taxonomy_group?.id; if (!taxonomyGroupId) { return element.type; @@ -82,7 +79,7 @@ export class CommonHelper { return taxonomy.name; } - return (element)['name']; + return (<{ name?: string }>element).name ?? null; } getBarrelExportCode(data: { filenames: string[]; moduleResolution: ModuleResolution }): string { diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts new file mode 100644 index 0000000..380ee75 --- /dev/null +++ b/lib/core/core.models.ts @@ -0,0 +1,22 @@ +export type CliAction = 'delivery' | 'migration'; + +export interface ErrorData { + readonly message: string; + readonly requestData?: string; + readonly requestUrl?: string; + readonly isUnknownError: boolean; + readonly error: unknown; +} + +export interface OriginalManagementError { + readonly response?: { + readonly status?: number; + readonly config?: { + readonly url?: string; + readonly data?: string; + }; + readonly data?: { + readonly error_code?: number; + }; + }; +} diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts new file mode 100644 index 0000000..ec8d183 --- /dev/null +++ b/lib/core/core.utils.ts @@ -0,0 +1,3 @@ +export function exitProgram(data: { readonly message: string }): never { + throw Error(data.message); +} diff --git a/lib/core/error.utils.ts b/lib/core/error.utils.ts new file mode 100644 index 0000000..b13d126 --- /dev/null +++ b/lib/core/error.utils.ts @@ -0,0 +1,62 @@ +import { SharedModels } from '@kontent-ai/management-sdk'; +import chalk from 'chalk'; +import { ErrorData, OriginalManagementError } from './core.models.js'; + +export function extractErrorData(error: unknown): ErrorData { + let isUnknownError: boolean = true; + let message: string = `Unknown error`; + let requestUrl: string | undefined = undefined; + let requestData: string | undefined = undefined; + + if (error instanceof SharedModels.ContentManagementBaseKontentError) { + isUnknownError = false; + const originalError = error.originalError as OriginalManagementError | undefined; + + requestUrl = originalError?.response?.config?.url; + requestData = originalError?.response?.config?.data; + + message = `${error.message}: ${error.validationErrors.map((m) => m.message).join(', ')}`; + } else if (error instanceof Error) { + message = error.message; + } + + const errorData: ErrorData = { + message: message, + requestData: requestData, + requestUrl: requestUrl, + error: error, + isUnknownError: isUnknownError + }; + + return errorData; +} + +export function is404Error(error: unknown): boolean { + if (error instanceof SharedModels.ContentManagementBaseKontentError) { + const originalError = error.originalError as OriginalManagementError | undefined; + + if (originalError?.response?.status === 404) { + return true; + } + } + + return false; +} + +export function handleError(error: unknown): void { + const errorData = extractErrorData(error); + + if (errorData.isUnknownError) { + console.error(error); + } + + if (errorData.requestData) { + console.log(`${chalk.red('Request data')}: ${errorData.requestData}`); + } + + if (errorData.requestUrl) { + console.log(`${chalk.red('Request url')}: ${errorData.requestUrl}`); + } + + console.error(`${chalk.red('Error:')} ${errorData.message}`); +} diff --git a/lib/core/index.ts b/lib/core/index.ts new file mode 100644 index 0000000..f9d96f3 --- /dev/null +++ b/lib/core/index.ts @@ -0,0 +1,3 @@ +export * from './core.utils.js'; +export * from './error.utils.js'; +export * from './core.models.js'; diff --git a/lib/file-helper.ts b/lib/file-helper.ts index 67332df..8a5ff30 100644 --- a/lib/file-helper.ts +++ b/lib/file-helper.ts @@ -1,4 +1,4 @@ -import Colors from 'colors'; +import chalk from 'chalk'; import { Options } from 'prettier'; import { formatHelper } from './format-helper.js'; import * as fs from 'fs'; @@ -10,14 +10,14 @@ export class FileHelper { const contentToStore = await formatHelper.formatCodeAsync(text, formatOptions); fs.writeFileSync('./' + finalFilename, contentToStore); - console.log(`Created '${Colors.yellow(finalFilename)}'`); + console.log(`Created '${chalk.yellow(finalFilename)}'`); } catch (error) { - console.log(`Failed to format file '${Colors.red(filename)}'. Skipping prettier for this file.`); + console.log(`Failed to format file '${chalk.red(filename)}'. Skipping prettier for this file.`); const contentToStore = text; fs.writeFileSync('./' + finalFilename, contentToStore); - console.log(`Created '${Colors.yellow(finalFilename)}'`); + console.log(`Created '${chalk.yellow(finalFilename)}'`); } } diff --git a/lib/generator.ts b/lib/generator.ts index 2cf71fc..08c8aee 100644 --- a/lib/generator.ts +++ b/lib/generator.ts @@ -1,4 +1,4 @@ -import Colors from 'colors'; +import chalk from 'chalk'; import { IGenerateModelsConfig, ModuleResolution } from './models.js'; import { deliveryContentTypeGenerator } from './generators/delivery/delivery-content-type.generator.js'; import { projectGenerator } from './generators/index.js'; @@ -11,13 +11,31 @@ import { WebhookModels, WorkflowModels } from '@kontent-ai/management-sdk'; -import { deliveryTaxonomylGenerator as deliveryTaxonomyGenerator } from './generators/delivery/delivery-taxonomy.generator.js'; +import { deliveryTaxonomyGenerator } from './generators/delivery/delivery-taxonomy.generator.js'; import { commonHelper } from './common-helper.js'; import { parse } from 'path'; import { fileHelper } from './file-helper.js'; export async function generateModelsAsync(config: IGenerateModelsConfig): Promise { - console.log(Colors.green(`Model generator started \n`)); + console.log(chalk.green(`Model generator started \n`)); + + try { + if (config.sdkType === 'delivery') { + await generateDeliveryModelsAsync(config); + } else if (config.sdkType === 'migration') { + await generateMigrationModelsAsync(); + } else { + throw Error(`Unsupported 'sdkType'. Supported values are: 'delivery', 'migration'`); + } + console.log(chalk.green(`\nCompleted`)); + } catch (error) { + console.log(chalk.red(`Failed with error:`)); + throw error; + } +} + +async function generateDeliveryModelsAsync(config: IGenerateModelsConfig): Promise { + console.log(`Generating '${chalk.yellow('delivery')}' models\n`); const outputDir: string = config.outputDir ? `${config.outputDir}/`.replaceAll('//', '/') : `./`; @@ -31,287 +49,267 @@ export async function generateModelsAsync(config: IGenerateModelsConfig): Promis const taxonomiesFolderPath: string = `${outputDir}${taxonomiesFolderName}`; const projectFolderPath: string = `${outputDir}${projectFolderName}`; - try { - if (config.sdkType === 'delivery') { - console.log(`Generating '${Colors.yellow('delivery')}' models\n`); - - // prepare directories - fileHelper.createDir(contentTypesFolderPath); - fileHelper.createDir(contentTypeSnippetsFolderPath); - fileHelper.createDir(taxonomiesFolderPath); - fileHelper.createDir(projectFolderPath); - - const managementClient = createManagementClient({ - environmentId: config.environmentId, - apiKey: config.apiKey, - baseUrl: config.managementApiUrl - }); + // prepare directories + fileHelper.createDir(contentTypesFolderPath); + fileHelper.createDir(contentTypeSnippetsFolderPath); + fileHelper.createDir(taxonomiesFolderPath); + fileHelper.createDir(projectFolderPath); - const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; + const managementClient = createManagementClient({ + environmentId: config.environmentId, + apiKey: config.apiKey, + baseUrl: config.managementApiUrl + }); - const projectInformation = (await managementClient.environmentInformation().toPromise()).data; - console.log(`Project '${Colors.yellow(projectInformation.project.name)}'`); - console.log(`Environment '${Colors.yellow(projectInformation.project.environment)}'\n`); - console.log(`Module resolution '${Colors.yellow(moduleResolution)}'\n`); + const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; - const types = commonHelper.sortAlphabetically( - (await managementClient.listContentTypes().toAllPromise()).data.items, - (item) => item.name - ); - const snippets = commonHelper.sortAlphabetically( - (await managementClient.listContentTypeSnippets().toAllPromise()).data.items, - (item) => item.name - ); - const taxonomies = commonHelper.sortAlphabetically( - (await managementClient.listTaxonomies().toAllPromise()).data.items, - (item) => item.name - ); + const projectInformation = (await managementClient.environmentInformation().toPromise()).data; + console.log(`Project '${chalk.yellow(projectInformation.project.name)}'`); + console.log(`Environment '${chalk.yellow(projectInformation.project.environment)}'\n`); + console.log(`Module resolution '${chalk.yellow(moduleResolution)}'\n`); - console.log(`Found '${Colors.yellow(types.length.toString())}' types`); - console.log(`Found '${Colors.yellow(snippets.length.toString())}' content type snippets`); - console.log(`Found '${Colors.yellow(taxonomies.length.toString())}' taxonomies`); + const types = commonHelper.sortAlphabetically( + (await managementClient.listContentTypes().toAllPromise()).data.items, + (item) => item.name + ); + const snippets = commonHelper.sortAlphabetically( + (await managementClient.listContentTypeSnippets().toAllPromise()).data.items, + (item) => item.name + ); + const taxonomies = commonHelper.sortAlphabetically( + (await managementClient.listTaxonomies().toAllPromise()).data.items, + (item) => item.name + ); - const workflows: WorkflowModels.Workflow[] = []; - const roles: RoleModels.Role[] = []; - const assetFolders: AssetFolderModels.AssetFolder[] = []; - const collections: CollectionModels.Collection[] = []; - const webhooks: WebhookModels.Webhook[] = []; - const languages: LanguageModels.LanguageModel[] = []; + console.log(`Found '${chalk.yellow(types.length.toString())}' types`); + console.log(`Found '${chalk.yellow(snippets.length.toString())}' content type snippets`); + console.log(`Found '${chalk.yellow(taxonomies.length.toString())}' taxonomies`); - const exportAllProjectSettings = config.exportProjectSettings ? false : true; + const workflows: WorkflowModels.Workflow[] = []; + const roles: RoleModels.Role[] = []; + const assetFolders: AssetFolderModels.AssetFolder[] = []; + const collections: CollectionModels.Collection[] = []; + const webhooks: WebhookModels.Webhook[] = []; + const languages: LanguageModels.LanguageModel[] = []; - if (config.exportProjectSettings?.exportWorkflows || exportAllProjectSettings) { - workflows.push( - ...commonHelper.sortAlphabetically( - (await managementClient.listWorkflows().toPromise()).data, - (item) => item.name - ) - ); - console.log(`Found '${Colors.yellow(workflows.length.toString())}' workflows`); - } else { - console.log(`Skipping '${Colors.red('workflows')}' export`); - } + const exportAllProjectSettings = config.exportProjectSettings ? false : true; - if (config.isEnterpriseSubscription) { - if (config.exportProjectSettings?.exportRoles || exportAllProjectSettings) { - roles.push( - ...commonHelper.sortAlphabetically( - (await managementClient.listRoles().toPromise()).data.roles, - (item) => item.name - ) - ); - console.log(`Found '${Colors.yellow(roles.length.toString())}' roles`); - } else { - console.log(`Skipping '${Colors.red('roles')}' export`); - } - } else { - console.log(`Skipping '${Colors.red('roles')}' export because enterprise subscription is disabled`); - } + if (config.exportProjectSettings?.exportWorkflows || exportAllProjectSettings) { + workflows.push( + ...commonHelper.sortAlphabetically( + (await managementClient.listWorkflows().toPromise()).data, + (item) => item.name + ) + ); + console.log(`Found '${chalk.yellow(workflows.length.toString())}' workflows`); + } else { + console.log(`Skipping '${chalk.red('workflows')}' export`); + } - if (config.exportProjectSettings?.exportAssetFolders || exportAllProjectSettings) { - assetFolders.push( - ...commonHelper.sortAlphabetically( - (await managementClient.listAssetFolders().toPromise()).data.items, - (item) => item.name - ) - ); - console.log( - `Found '${Colors.yellow(projectGenerator.getAssetFoldersCount(assetFolders).toString())}' asset folders` - ); - } else { - console.log(`Skipping '${Colors.red('asset folders')}' export`); - } + if (config.isEnterpriseSubscription) { + if (config.exportProjectSettings?.exportRoles || exportAllProjectSettings) { + roles.push( + ...commonHelper.sortAlphabetically( + (await managementClient.listRoles().toPromise()).data.roles, + (item) => item.name + ) + ); + console.log(`Found '${chalk.yellow(roles.length.toString())}' roles`); + } else { + console.log(`Skipping '${chalk.red('roles')}' export`); + } + } else { + console.log(`Skipping '${chalk.red('roles')}' export because enterprise subscription is disabled`); + } - if (config.exportProjectSettings?.exportCollections || exportAllProjectSettings) { - collections.push( - ...commonHelper.sortAlphabetically( - (await managementClient.listCollections().toPromise()).data.collections, - (item) => item.name - ) - ); - console.log(`Found '${Colors.yellow(collections.length.toString())}' collections`); - } else { - console.log(`Skipping '${Colors.red('collections')}' export`); - } + if (config.exportProjectSettings?.exportAssetFolders || exportAllProjectSettings) { + assetFolders.push( + ...commonHelper.sortAlphabetically( + (await managementClient.listAssetFolders().toPromise()).data.items, + (item) => item.name + ) + ); + console.log( + `Found '${chalk.yellow(projectGenerator.getAssetFoldersCount(assetFolders).toString())}' asset folders` + ); + } else { + console.log(`Skipping '${chalk.red('asset folders')}' export`); + } - if (config.exportProjectSettings?.exportWebhooks || exportAllProjectSettings) { - webhooks.push( - ...commonHelper.sortAlphabetically( - (await managementClient.listWebhooks().toPromise()).data.webhooks, - (item) => item.name - ) - ); - console.log(`Found '${Colors.yellow(webhooks.length.toString())}' webhooks`); - } else { - console.log(`Skipping '${Colors.red('webhooks')}' export`); - } + if (config.exportProjectSettings?.exportCollections || exportAllProjectSettings) { + collections.push( + ...commonHelper.sortAlphabetically( + (await managementClient.listCollections().toPromise()).data.collections, + (item) => item.name + ) + ); + console.log(`Found '${chalk.yellow(collections.length.toString())}' collections`); + } else { + console.log(`Skipping '${chalk.red('collections')}' export`); + } - if (config.exportProjectSettings?.exportLanguages || exportAllProjectSettings) { - languages.push( - ...commonHelper.sortAlphabetically( - (await managementClient.listLanguages().toAllPromise()).data.items, - (item) => item.name - ) - ); - console.log(`Found '${Colors.yellow(languages.length.toString())}' languages`); - } else { - console.log(`Skipping '${Colors.red('languages')}' export`); - } + if (config.exportProjectSettings?.exportWebhooks || exportAllProjectSettings) { + webhooks.push( + ...commonHelper.sortAlphabetically( + (await managementClient.listWebhooks().toPromise()).data.webhooks, + (item) => item.name + ) + ); + console.log(`Found '${chalk.yellow(webhooks.length.toString())}' webhooks`); + } else { + console.log(`Skipping '${chalk.red('webhooks')}' export`); + } - console.log(''); + if (config.exportProjectSettings?.exportLanguages || exportAllProjectSettings) { + languages.push( + ...commonHelper.sortAlphabetically( + (await managementClient.listLanguages().toAllPromise()).data.items, + (item) => item.name + ) + ); + console.log(`Found '${chalk.yellow(languages.length.toString())}' languages`); + } else { + console.log(`Skipping '${chalk.red('languages')}' export`); + } - // create content type models - const deliveryModels = await deliveryContentTypeGenerator.generateModelsAsync({ - outputDir: outputDir, - types: types, - typeFolderName: contentTypesFolderName, - taxonomyFolderName: taxonomiesFolderName, - typeSnippetsFolderName: contentTypeSnippetsFolderName, - taxonomies: taxonomies, - snippets: snippets, - addTimestamp: config.addTimestamp, - addEnvironmentInfo: config.addEnvironmentInfo, - elementResolver: config.elementResolver, - contentTypeFileNameResolver: config.contentTypeFileResolver, - contentTypeResolver: config.contentTypeResolver, - taxonomyFileResolver: config.taxonomyTypeFileResolver, - taxonomyResolver: config.taxonomyTypeResolver, - contentTypeSnippetFileNameResolver: config.contentTypeSnippetFileResolver, - contentTypeSnippetResolver: config.contentTypeSnippetResolver, - moduleResolution: moduleResolution - }); + console.log(''); - // create taxonomy types - const taxonomyFiles = await deliveryTaxonomyGenerator.generateTaxonomyTypesAsync({ - taxonomies: taxonomies, - outputDir: outputDir, - taxonomyFolderName: taxonomiesFolderName, - addTimestamp: config.addTimestamp, - fileResolver: config.taxonomyTypeFileResolver, - taxonomyResolver: config.taxonomyTypeResolver - }); + // create content type models + const deliveryModels = deliveryContentTypeGenerator.generateModels({ + outputDir: outputDir, + types: types, + typeFolderName: contentTypesFolderName, + taxonomyFolderName: taxonomiesFolderName, + typeSnippetsFolderName: contentTypeSnippetsFolderName, + taxonomies: taxonomies, + snippets: snippets, + addTimestamp: config.addTimestamp, + addEnvironmentInfo: config.addEnvironmentInfo, + elementResolver: config.elementResolver, + contentTypeFileNameResolver: config.contentTypeFileResolver, + contentTypeResolver: config.contentTypeResolver, + taxonomyFileResolver: config.taxonomyTypeFileResolver, + taxonomyResolver: config.taxonomyTypeResolver, + contentTypeSnippetFileNameResolver: config.contentTypeSnippetFileResolver, + contentTypeSnippetResolver: config.contentTypeSnippetResolver, + moduleResolution: moduleResolution + }); - // create project structure - const projectFiles = await projectGenerator.generateProjectModel({ - outputDir: outputDir, - environmentInfo: projectInformation.project, - addTimestamp: config.addTimestamp, - formatOptions: config.formatOptions, - addEnvironmentInfo: config.addEnvironmentInfo, - languages: languages, - taxonomies: taxonomies, - types: types, - workflows: workflows, - assetFolders: assetFolders, - collections: collections, - roles: roles, - snippets: snippets, - webhooks: webhooks, - projectFolderName: projectFolderName, - sortConfig: config.sortConfig ?? { - sortTaxonomyTerms: true - } - }); + // create taxonomy types + const taxonomyFiles = deliveryTaxonomyGenerator.generateTaxonomyTypes({ + taxonomies: taxonomies, + outputDir: outputDir, + taxonomyFolderName: taxonomiesFolderName, + addTimestamp: config.addTimestamp, + fileResolver: config.taxonomyTypeFileResolver, + taxonomyResolver: config.taxonomyTypeResolver + }); - // create barrel export - const barrelExportFilename: string = 'index.ts'; + // create project structure + const projectFiles = projectGenerator.generateProjectModel({ + outputDir: outputDir, + environmentInfo: projectInformation.project, + addTimestamp: config.addTimestamp, + formatOptions: config.formatOptions, + addEnvironmentInfo: config.addEnvironmentInfo, + languages: languages, + taxonomies: taxonomies, + types: types, + workflows: workflows, + assetFolders: assetFolders, + collections: collections, + roles: roles, + snippets: snippets, + webhooks: webhooks, + projectFolderName: projectFolderName, + sortConfig: config.sortConfig ?? { + sortTaxonomyTerms: true + } + }); - // content types - for (const file of deliveryModels.contentTypeFiles) { - await fileHelper.createFileOnFsAsync(file.text, file.filename, config.formatOptions); - } - const contentTypeBarrelCode = commonHelper.getBarrelExportCode({ - moduleResolution: moduleResolution, - filenames: [ - ...deliveryModels.contentTypeFiles.map((m) => { - const path = parse(m.filename); - return `./${path.name}`; - }) - ] - }); - const contentTypeBarrelExportPath: string = `${contentTypesFolderPath}${barrelExportFilename}`; - await fileHelper.createFileOnFsAsync( - contentTypeBarrelCode, - contentTypeBarrelExportPath, - config.formatOptions - ); + // create barrel export + const barrelExportFilename: string = 'index.ts'; - // content type snippets - for (const file of deliveryModels.snippetFiles) { - await fileHelper.createFileOnFsAsync(file.text, file.filename, config.formatOptions); - } - const contentTypeSnippetsBarrelCode = commonHelper.getBarrelExportCode({ - moduleResolution: moduleResolution, - filenames: [ - ...deliveryModels.snippetFiles.map((m) => { - const path = parse(m.filename); - return `./${path.name}`; - }) - ] - }); - const contentTypeSnippetsBarrelExportPath: string = `${contentTypeSnippetsFolderPath}${barrelExportFilename}`; - await fileHelper.createFileOnFsAsync( - contentTypeSnippetsBarrelCode, - contentTypeSnippetsBarrelExportPath, - config.formatOptions - ); + // content types + for (const file of deliveryModels.contentTypeFiles) { + await fileHelper.createFileOnFsAsync(file.text, file.filename, config.formatOptions); + } + const contentTypeBarrelCode = commonHelper.getBarrelExportCode({ + moduleResolution: moduleResolution, + filenames: [ + ...deliveryModels.contentTypeFiles.map((m) => { + const path = parse(m.filename); + return `./${path.name}`; + }) + ] + }); + const contentTypeBarrelExportPath: string = `${contentTypesFolderPath}${barrelExportFilename}`; + await fileHelper.createFileOnFsAsync(contentTypeBarrelCode, contentTypeBarrelExportPath, config.formatOptions); - // taxonomies - for (const file of taxonomyFiles) { - await fileHelper.createFileOnFsAsync(file.text, file.filename, config.formatOptions); - } - const taxonomiesBarrelCode = commonHelper.getBarrelExportCode({ - moduleResolution: moduleResolution, - filenames: [ - ...taxonomyFiles.map((m) => { - const path = parse(m.filename); - return `./${path.name}`; - }) - ] - }); - const taxonomiesBarrelExportPath: string = `${taxonomiesFolderPath}${barrelExportFilename}`; - await fileHelper.createFileOnFsAsync( - taxonomiesBarrelCode, - taxonomiesBarrelExportPath, - config.formatOptions - ); + // content type snippets + for (const file of deliveryModels.snippetFiles) { + await fileHelper.createFileOnFsAsync(file.text, file.filename, config.formatOptions); + } + const contentTypeSnippetsBarrelCode = commonHelper.getBarrelExportCode({ + moduleResolution: moduleResolution, + filenames: [ + ...deliveryModels.snippetFiles.map((m) => { + const path = parse(m.filename); + return `./${path.name}`; + }) + ] + }); + const contentTypeSnippetsBarrelExportPath: string = `${contentTypeSnippetsFolderPath}${barrelExportFilename}`; + await fileHelper.createFileOnFsAsync( + contentTypeSnippetsBarrelCode, + contentTypeSnippetsBarrelExportPath, + config.formatOptions + ); - // project barrel - for (const file of projectFiles) { - await fileHelper.createFileOnFsAsync(file.text, file.filename, config.formatOptions); - } - const projectBarrelCode = commonHelper.getBarrelExportCode({ - moduleResolution: moduleResolution, - filenames: [ - ...projectFiles.map((m) => { - const path = parse(m.filename); - return `./${path.name}`; - }) - ] - }); - const projectBarrelExportPath: string = `${projectFolderPath}${barrelExportFilename}`; - await fileHelper.createFileOnFsAsync(projectBarrelCode, projectBarrelExportPath, config.formatOptions); + // taxonomies + for (const file of taxonomyFiles) { + await fileHelper.createFileOnFsAsync(file.text, file.filename, config.formatOptions); + } + const taxonomiesBarrelCode = commonHelper.getBarrelExportCode({ + moduleResolution: moduleResolution, + filenames: [ + ...taxonomyFiles.map((m) => { + const path = parse(m.filename); + return `./${path.name}`; + }) + ] + }); + const taxonomiesBarrelExportPath: string = `${taxonomiesFolderPath}${barrelExportFilename}`; + await fileHelper.createFileOnFsAsync(taxonomiesBarrelCode, taxonomiesBarrelExportPath, config.formatOptions); - // main barrel - const mainBarrelCode = commonHelper.getBarrelExportCode({ - moduleResolution: moduleResolution, - filenames: [ - `./${projectFolderName}index`, - `./${contentTypesFolderName}index`, - `./${contentTypeSnippetsFolderName}index`, - `./${taxonomiesFolderName}index` - ] - }); - const mainBarrelExportPath: string = `${outputDir}${barrelExportFilename}`; - await fileHelper.createFileOnFsAsync(mainBarrelCode, mainBarrelExportPath, config.formatOptions); - } else if (config.sdkType === 'management') { - console.log('Not available yet'); - } else { - throw Error(`Unsupported 'sdkType'. Supported values are: delivery, management`); - } - console.log(Colors.green(`\nCompleted`)); - } catch (error) { - console.log(Colors.red(`Failed with error:`)); - throw error; + // project barrel + for (const file of projectFiles) { + await fileHelper.createFileOnFsAsync(file.text, file.filename, config.formatOptions); } + const projectBarrelCode = commonHelper.getBarrelExportCode({ + moduleResolution: moduleResolution, + filenames: [ + ...projectFiles.map((m) => { + const path = parse(m.filename); + return `./${path.name}`; + }) + ] + }); + const projectBarrelExportPath: string = `${projectFolderPath}${barrelExportFilename}`; + await fileHelper.createFileOnFsAsync(projectBarrelCode, projectBarrelExportPath, config.formatOptions); + + // main barrel + const mainBarrelCode = commonHelper.getBarrelExportCode({ + moduleResolution: moduleResolution, + filenames: [ + `./${projectFolderName}index`, + `./${contentTypesFolderName}index`, + `./${contentTypeSnippetsFolderName}index`, + `./${taxonomiesFolderName}index` + ] + }); + const mainBarrelExportPath: string = `${outputDir}${barrelExportFilename}`; + await fileHelper.createFileOnFsAsync(mainBarrelCode, mainBarrelExportPath, config.formatOptions); } + +async function generateMigrationModelsAsync(): Promise {} diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 02390b8..ac8f1c7 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -1,4 +1,4 @@ -import Colors from 'colors'; +import chalk from 'chalk'; import { commonHelper, IGeneratedFile } from '../../common-helper.js'; import { ContentTypeResolver, @@ -58,7 +58,7 @@ interface IExtractImportsResult { export class DeliveryContentTypeGenerator { private readonly deliveryNpmPackageName: string = '@kontent-ai/delivery-sdk'; - async generateModelsAsync(data: { + generateModels(data: { outputDir: string; typeFolderName: string; typeSnippetsFolderName: string; @@ -76,7 +76,7 @@ export class DeliveryContentTypeGenerator { taxonomyFileResolver?: TaxonomyTypeFileNameResolver; taxonomyResolver?: TaxonomyTypeResolver; moduleResolution: ModuleResolution; - }): Promise<{ contentTypeFiles: IGeneratedFile[]; snippetFiles: IGeneratedFile[] }> { + }): { contentTypeFiles: IGeneratedFile[]; snippetFiles: IGeneratedFile[] } { const typeFiles: IGeneratedFile[] = []; const snippetFiles: IGeneratedFile[] = []; @@ -85,7 +85,7 @@ export class DeliveryContentTypeGenerator { if (data.elementResolver) { addNewLineAfterResolvers = true; console.log( - `Using '${Colors.yellow( + `Using '${chalk.yellow( data.elementResolver instanceof Function ? 'custom' : data.elementResolver )}' name resolver for content type elements` ); @@ -94,7 +94,7 @@ export class DeliveryContentTypeGenerator { if (data.contentTypeFileNameResolver) { addNewLineAfterResolvers = true; console.log( - `Using '${Colors.yellow( + `Using '${chalk.yellow( data.contentTypeFileNameResolver instanceof Function ? 'custom' : data.contentTypeFileNameResolver )}' name resolver for content type filenames` ); @@ -103,7 +103,7 @@ export class DeliveryContentTypeGenerator { if (data.contentTypeSnippetFileNameResolver) { addNewLineAfterResolvers = true; console.log( - `Using '${Colors.yellow( + `Using '${chalk.yellow( data.contentTypeSnippetFileNameResolver instanceof Function ? 'custom' : data.contentTypeSnippetFileNameResolver @@ -114,7 +114,7 @@ export class DeliveryContentTypeGenerator { if (data.contentTypeResolver) { addNewLineAfterResolvers = true; console.log( - `Using '${Colors.yellow( + `Using '${chalk.yellow( data.contentTypeResolver instanceof Function ? 'custom' : data.contentTypeResolver )}' name resolver for content types` ); @@ -123,7 +123,7 @@ export class DeliveryContentTypeGenerator { if (data.contentTypeSnippetResolver) { addNewLineAfterResolvers = true; console.log( - `Using '${Colors.yellow( + `Using '${chalk.yellow( data.contentTypeSnippetResolver instanceof Function ? 'custom' : data.contentTypeSnippetResolver )}' name resolver for content type snippets` ); @@ -725,7 +725,7 @@ export type ${typeName} = IContentItem<{ }): IExtendedContentTypeElement[] { const extendedElements: IExtendedContentTypeElement[] = []; - const elements = data.contentType ? data.contentType.elements : data.contentTypeSnippet?.elements ?? []; + const elements = data.contentType ? data.contentType.elements : (data.contentTypeSnippet?.elements ?? []); for (const element of elements) { extendedElements.push( diff --git a/lib/generators/delivery/delivery-taxonomy.generator.ts b/lib/generators/delivery/delivery-taxonomy.generator.ts index 017d6a9..e3ed6c3 100644 --- a/lib/generators/delivery/delivery-taxonomy.generator.ts +++ b/lib/generators/delivery/delivery-taxonomy.generator.ts @@ -1,5 +1,5 @@ import { TaxonomyTypeFileNameResolver, TaxonomyTypeResolver } from '../../models.js'; -import Colors from 'colors'; +import chalk from 'chalk'; import { commonHelper, IGeneratedFile } from '../../common-helper.js'; import { TaxonomyModels } from '@kontent-ai/management-sdk'; import { @@ -10,19 +10,19 @@ import { } from './delivery-mappers.js'; export class DeliveryTaxonomyGenerator { - async generateTaxonomyTypesAsync(config: { + generateTaxonomyTypes(config: { outputDir: string; taxonomies: TaxonomyModels.Taxonomy[]; taxonomyFolderName: string; addTimestamp: boolean; fileResolver?: TaxonomyTypeFileNameResolver; taxonomyResolver?: TaxonomyTypeResolver; - }): Promise { + }): IGeneratedFile[] { const files: IGeneratedFile[] = []; if (config.taxonomyResolver) { console.log( - `Using '${Colors.yellow( + `Using '${chalk.yellow( config.taxonomyResolver instanceof Function ? 'custom' : config.taxonomyResolver )}' name resolver for taxonomy type` ); @@ -30,7 +30,7 @@ export class DeliveryTaxonomyGenerator { if (config.fileResolver) { console.log( - `Using '${Colors.yellow( + `Using '${chalk.yellow( config.fileResolver instanceof Function ? 'custom' : config.fileResolver )}' name resolver for taxonomy filename` ); @@ -141,4 +141,4 @@ export type ${config.taxonomyNameMap(config.taxonomy)} = ${this.getTaxonomyTerms } } -export const deliveryTaxonomylGenerator = new DeliveryTaxonomyGenerator(); +export const deliveryTaxonomyGenerator = new DeliveryTaxonomyGenerator(); diff --git a/lib/generators/migration/migration-generator.ts b/lib/generators/migration/migration-generator.ts new file mode 100644 index 0000000..eb24c6c --- /dev/null +++ b/lib/generators/migration/migration-generator.ts @@ -0,0 +1,13 @@ +export interface MigrationGeneratorConfig { + environmentId: string; + apiKey: string; +} + +export function migrationGenerator(config: MigrationGeneratorConfig) { + console.log(config); + return { + generateModels(): string { + return 'todo'; + } + }; +} diff --git a/lib/generators/project/project.generator.ts b/lib/generators/project/project.generator.ts index 991b35e..6aabd8a 100644 --- a/lib/generators/project/project.generator.ts +++ b/lib/generators/project/project.generator.ts @@ -168,8 +168,8 @@ export class ProjectGenerator { element: ContentTypeElements.ContentTypeElementModel, taxonomies: TaxonomyModels.Taxonomy[] ): string | undefined { - if ((element as any)['name']) { - return (element as any)['name']; + if ((element as { name?: string })['name']) { + return (element as { name: string })['name']; } if (element.type === 'taxonomy') { @@ -722,19 +722,17 @@ export class ProjectGenerator { }); } - const code: string = ` - { - ${steps.map((step) => { - return ` - ${step.codename}: { - name: '${commonHelper.escapeNameValue(step.name)}', - codename: '${step.codename}', - id: '${step.id}' - } - `; - })} - } - `; + const code = `{${steps.reduce((code, step) => { + return ( + code + + ` + ${step.codename}: { + name: '${commonHelper.escapeNameValue(step.name)}', + codename: '${step.codename}', + id: '${step.id}' + },` + ); + }, ``)}}`; return code; } diff --git a/lib/index.ts b/lib/index.ts index 1369907..dd37f13 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -3,5 +3,6 @@ export * from './text-helper.js'; export * from './name-helper.js'; export * from './models.js'; export * from './generator.js'; +export * from './core/index.js'; export * from './generators/index.js'; diff --git a/lib/models.ts b/lib/models.ts index e31855f..c017e16 100644 --- a/lib/models.ts +++ b/lib/models.ts @@ -2,10 +2,9 @@ import { PropertyNameResolver } from '@kontent-ai/delivery-sdk'; import { ContentTypeModels, ContentTypeSnippetModels, TaxonomyModels } from '@kontent-ai/management-sdk'; import { Options } from 'prettier'; - export type ModuleResolution = 'nodeNext' | 'node'; export type DefaultResolverType = 'camelCase' | 'pascalCase' | 'snakeCase'; -export type SdkType = 'delivery' | 'management'; +export type SdkType = 'delivery' | 'migration'; export type ElementResolver = DefaultResolverType | PropertyNameResolver; export type ContentTypeFileNameResolver = diff --git a/lib/node/cli/actions/delivery-action.ts b/lib/node/cli/actions/delivery-action.ts new file mode 100644 index 0000000..b3f5121 --- /dev/null +++ b/lib/node/cli/actions/delivery-action.ts @@ -0,0 +1,37 @@ +import { ModuleResolution } from '../../../models.js'; +import { generateModelsAsync } from '../../../generator.js'; +import { CliArgumentsFetcher } from '../cli.models.js'; + +export async function deliveryActionAsync(cliFetcher: CliArgumentsFetcher): Promise { + await generateModelsAsync({ + environmentId: cliFetcher.getRequiredArgumentValue('environmentId'), + managementApiUrl: cliFetcher.getRequiredArgumentValue('managementApiUrl'), + apiKey: cliFetcher.getRequiredArgumentValue('apiKey'), + outputDir: cliFetcher.getRequiredArgumentValue('outputDir'), + isEnterpriseSubscription: cliFetcher.getBooleanArgumentValue('isEnterpriseSubscription', false), + addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), + addEnvironmentInfo: cliFetcher.getBooleanArgumentValue('addEnvironmentInfo', false), + elementResolver: undefined, + contentTypeFileResolver: undefined, + contentTypeResolver: undefined, + taxonomyTypeFileResolver: undefined, + taxonomyTypeResolver: undefined, + contentTypeSnippetFileResolver: undefined, + contentTypeSnippetResolver: undefined, + formatOptions: undefined, + sdkType: 'delivery', + sortConfig: { + sortTaxonomyTerms: cliFetcher.getBooleanArgumentValue('sortTaxonomyTerms', true) + }, + moduleResolution: + cliFetcher.getRequiredArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext', + exportProjectSettings: { + exportWebhooks: true, + exportWorkflows: true, + exportAssetFolders: true, + exportCollections: true, + exportLanguages: true, + exportRoles: true + } + }); +} diff --git a/lib/node/cli/actions/migrate-action.ts b/lib/node/cli/actions/migrate-action.ts new file mode 100644 index 0000000..de2066a --- /dev/null +++ b/lib/node/cli/actions/migrate-action.ts @@ -0,0 +1 @@ +export async function migrateActionAsync(): Promise {} diff --git a/lib/node/cli/app.ts b/lib/node/cli/app.ts new file mode 100644 index 0000000..53ed668 --- /dev/null +++ b/lib/node/cli/app.ts @@ -0,0 +1,32 @@ +#!/usr/bin/env node +import chalk from 'chalk'; + +import { handleError, exitProgram } from '../../core/index.js'; +import { deliveryActionAsync } from './actions/delivery-action.js'; +import { migrateActionAsync } from './actions/migrate-action.js'; +import { argumentsFetcherAsync } from './args/args-fetcher.js'; +import { cliArgs } from './commands.js'; + +// This enabled --help with all commands, options & samples +cliArgs.registerCommands(); + +const run = async () => { + const argsFetcher = await argumentsFetcherAsync(); + const action = argsFetcher.getCliAction(); + + if (action === 'delivery') { + return await deliveryActionAsync(argsFetcher); + } + + if (action === 'migration') { + return await migrateActionAsync(); + } + + exitProgram({ + message: `Invalid action '${chalk.red(action)}'` + }); +}; + +run().catch((err) => { + handleError(err); +}); diff --git a/lib/node/cli/args/args-fetcher.ts b/lib/node/cli/args/args-fetcher.ts new file mode 100644 index 0000000..ad7c404 --- /dev/null +++ b/lib/node/cli/args/args-fetcher.ts @@ -0,0 +1,59 @@ +import yargs from 'yargs'; +import { hideBin } from 'yargs/helpers'; +import chalk from 'chalk'; +import { CliArgumentsFetcher } from '../cli.models.js'; +import { CliAction } from '../../../core/core.models.js'; +import { exitProgram } from '../../../core/index.js'; + +type ArgvResult = { + [x: string]: unknown; + _: (string | number)[]; + $0: string; +}; + +export async function argumentsFetcherAsync(): Promise { + const argv = yargs(hideBin(process.argv)); + const resolvedArgv: ArgvResult = await argv.argv; + + const getOptionalArgumentValue = (argName: string) => { + return resolvedArgv[argName]?.toString(); + }; + + return { + getCliAction(): CliAction { + const command = resolvedArgv._?.[0]?.toString()?.toLowerCase(); + + if (command === 'delivery') { + return 'delivery'; + } + if (command === 'migration') { + return 'migration'; + } + + throw Error(`Unsupported command '${chalk.yellow(command)}'`); + }, + getOptionalArgumentValue(argName: string): string | undefined { + return resolvedArgv[argName]?.toString(); + }, + getRequiredArgumentValue(argName: string): string { + const value = getOptionalArgumentValue(argName); + + if (!value) { + exitProgram({ + message: `Missing '${chalk.yellow(argName)}' argument value` + }); + } + + return value; + }, + getBooleanArgumentValue(argName: string, defaultValue: boolean): boolean { + const value = getOptionalArgumentValue(argName); + + if (!value) { + return defaultValue; + } + + return value.toLowerCase() === 'true'.toLowerCase(); + } + }; +} diff --git a/lib/node/cli/args/args-setter.ts b/lib/node/cli/args/args-setter.ts new file mode 100644 index 0000000..f1b8a28 --- /dev/null +++ b/lib/node/cli/args/args-setter.ts @@ -0,0 +1,38 @@ +import yargs from 'yargs'; +import { hideBin } from 'yargs/helpers'; +import { CliArgumentsSetter, Command, CommandOption } from '../cli.models.js'; + +export function argumentsSetter(): CliArgumentsSetter { + const argv = yargs(hideBin(process.argv)); + + return { + withCommand(command: Command): CliArgumentsSetter { + argv.command(command.name, command.description, (yargs) => { + command.examples.forEach((example) => yargs.example(command.name, example)); + command.options.forEach((option) => { + yargs.positional(option.name, { + alias: option.alias, + describe: option.description, + type: option.type, + demandOption: option.isRequired + }); + }); + }); + + return this; + }, + withOption(option: CommandOption): CliArgumentsSetter { + argv.option(option.name, { + alias: option.alias, + description: option.description, + type: option.type, + demandOption: option.isRequired + }); + + return this; + }, + registerCommands(): void { + argv.parseSync(); + } + }; +} diff --git a/lib/node/cli/cli.models.ts b/lib/node/cli/cli.models.ts new file mode 100644 index 0000000..b9aca0a --- /dev/null +++ b/lib/node/cli/cli.models.ts @@ -0,0 +1,29 @@ +import { CliAction } from '../../core/index.js'; + +export interface Command { + readonly name: string; + readonly description: string; + readonly options: readonly CommandOption[]; + readonly examples: string[]; +} + +export interface CommandOption { + readonly name: string; + readonly isRequired: boolean; + readonly alias?: string; + readonly description?: string; + readonly type?: 'boolean' | 'number' | 'string'; +} + +export type CliArgumentsSetter = { + withCommand(command: Command): CliArgumentsSetter; + withOption(option: CommandOption): CliArgumentsSetter; + registerCommands(): void; +}; + +export type CliArgumentsFetcher = { + getCliAction(): CliAction; + getOptionalArgumentValue(argName: string): string | undefined; + getRequiredArgumentValue(argName: string): string; + getBooleanArgumentValue(argName: string, defaultValue: boolean): boolean; +}; diff --git a/lib/node/cli/commands.ts b/lib/node/cli/commands.ts new file mode 100644 index 0000000..aac8969 --- /dev/null +++ b/lib/node/cli/commands.ts @@ -0,0 +1,71 @@ +import { argumentsSetter } from './args/args-setter.js'; + +export const cliArgs = argumentsSetter() + .withCommand({ + name: 'delivery', + description: + 'Generates Delivery & project models based on the content types and content items in your Kontent.ai project', + examples: [`kontent-generate delivery --environmentId=x --apiKey=x`], + options: [ + { + name: `environmentId`, + description: `Id of the environment`, + type: 'string', + isRequired: true + }, + { + name: `apiKey`, + description: `Management API key`, + type: 'string', + isRequired: true + }, + { + name: `outputDir`, + description: `Directory where generated files will be created`, + type: 'string', + isRequired: false + }, + { + name: `addTimestamp`, + description: `Indicates if timestamp should be generated`, + type: 'string', + isRequired: false + }, + { + name: `addEnvironmentInfo`, + description: `Indicates if environment info stamp should be generated`, + type: 'string', + isRequired: false + }, + { + name: `moduleResolution`, + description: `Module resolution for imports. Available options are: node, nodeNext`, + type: 'string', + isRequired: false + }, + { + name: `isEnterpriseSubscription`, + description: `Indicates if enterprise subscription endpoint can be used to export data`, + type: 'string', + isRequired: false + }, + { + name: `sortTaxonomyTerms`, + description: `Indicates if taxonomy terms are sorted alphabetically`, + type: 'string', + isRequired: false + }, + { + name: `managementApiUrl`, + description: `Sets the url of Management API`, + type: 'string', + isRequired: false + } + ] + }) + .withOption({ + alias: `h`, + name: `help`, + description: `Show help`, + isRequired: false + }); diff --git a/lib/text-helper.ts b/lib/text-helper.ts index b095045..bbf693f 100644 --- a/lib/text-helper.ts +++ b/lib/text-helper.ts @@ -7,19 +7,16 @@ import { DefaultResolverType } from './models.js'; export class TextHelper { resolveTextWithDefaultResolver(text: string, resolverType: DefaultResolverType): string { - if (resolverType === 'camelCase') { - return this.toCamelCase(text); + switch (resolverType) { + case 'camelCase': + return this.toCamelCase(text); + case 'pascalCase': + return this.toPascalCase(text); + case 'snakeCase': + return this.toSnakeCase(text); + default: + throw Error(`Invalid name resolver. Available options are: camelCase, pascalCase, snakeCase`); } - - if (resolverType === 'pascalCase') { - return this.toPascalCase(text); - } - - if (resolverType === 'snakeCase') { - return this.toSnakeCase(text); - } - - throw Error(`Invalid name resolver '${resolverType}'. Available options are: camelCase, pascalCase, snakeCase`); } toPascalCase(text: string): string { diff --git a/package-lock.json b/package-lock.json index e455629..da9aafc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,16 +11,17 @@ "dependencies": { "@kontent-ai/delivery-sdk": "14.10.0", "@kontent-ai/management-sdk": "6.5.0", - "colors": "1.4.0", + "@kontent-ai/migration-toolkit": "1.3.0", + "chalk": "5.0.0", "prettier": "3.3.3", "yargs": "17.7.2" }, "bin": { - "kontent-generate": "dist/es2022/lib/cli/cli.js" + "kontent-generate": "dist/es2022/lib/code/app.js" }, "devDependencies": { + "@types/eslint__js": "8.42.3", "@types/node": "20.14.11", - "@types/prettier": "3.0.0", "@types/yargs": "17.0.32", "@typescript-eslint/eslint-plugin": "7.16.1", "@typescript-eslint/parser": "7.16.1", @@ -28,7 +29,8 @@ "eslint": "8.57.0", "standard-version": "9.5.0", "tsx": "4.16.2", - "typescript": "5.5.3" + "typescript": "5.5.3", + "typescript-eslint": "7.16.1" }, "engines": { "node": ">= 20" @@ -654,6 +656,38 @@ "node": ">=6.9.0" } }, + "node_modules/@kontent-ai-consulting/tools-analytics": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/@kontent-ai-consulting/tools-analytics/-/tools-analytics-0.0.6.tgz", + "integrity": "sha512-G9sT9udNVYbXiFOhaHPRU/WOgaa4k78lvOMlpIXkJ8WcsPGh3cW+USsAVA7rmBMlUOTVQ/WlHsD/MtTIkbBYsA==", + "dependencies": { + "@kontent-ai/core-sdk": "10.3.1" + }, + "engines": { + "node": ">=16.0.0" + } + }, + "node_modules/@kontent-ai-consulting/tools-analytics/node_modules/@kontent-ai/core-sdk": { + "version": "10.3.1", + "resolved": "https://registry.npmjs.org/@kontent-ai/core-sdk/-/core-sdk-10.3.1.tgz", + "integrity": "sha512-t51FgHqJhIM1PnEIMGb5773W1waBFUpPgILQ03cUVEbO14nnhbTTpH5Wk1RJb5FV5KO9ONvSorU4uZjmTsxuNA==", + "dependencies": { + "axios": "1.6.2" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@kontent-ai-consulting/tools-analytics/node_modules/axios": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", + "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", + "dependencies": { + "follow-redirects": "^1.15.0", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/@kontent-ai/core-sdk": { "version": "10.6.0", "resolved": "https://registry.npmjs.org/@kontent-ai/core-sdk/-/core-sdk-10.6.0.tgz", @@ -690,6 +724,58 @@ "node": ">= 16" } }, + "node_modules/@kontent-ai/migration-toolkit": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/migration-toolkit/-/migration-toolkit-1.3.0.tgz", + "integrity": "sha512-afaYzOtW6OeTv/Z0xUeVGDTV0WcizC3lag7UdQYVMlZ0nhnZssi59dcdwmjXW8H5iCcfhhETWdbm/weQeIEGKg==", + "dependencies": { + "@kontent-ai-consulting/tools-analytics": "0.0.6", + "@kontent-ai/management-sdk": "6.5.0", + "browser-or-node": "3.0.0", + "bytes": "3.1.2", + "chalk": "5.3.0", + "deep-equal": "2.2.3", + "dotenv": "16.4.5", + "jszip": "3.10.1", + "mime": "4.0.4", + "ora": "8.0.1", + "p-limit": "6.1.0", + "prompts": "2.4.2", + "yargs": "17.7.2", + "zod": "3.23.8" + }, + "bin": { + "kontent-ai-migration-toolkit": "dist/es2022/node/cli/app.js" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/@kontent-ai/migration-toolkit/node_modules/chalk": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", + "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/@kontent-ai/migration-toolkit/node_modules/mime": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/mime/-/mime-4.0.4.tgz", + "integrity": "sha512-v8yqInVjhXyqP6+Kw4fV3ZzeMRqEW6FotRsKXjRS5VMTNIuXsdRoAvklpoRgSqXm6o9VNH4/C0mgedko9DdLsQ==", + "funding": [ + "https://github.com/sponsors/broofa" + ], + "bin": { + "mime": "bin/cli.js" + }, + "engines": { + "node": ">=16" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -725,6 +811,37 @@ "node": ">= 8" } }, + "node_modules/@types/eslint": { + "version": "8.56.10", + "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.56.10.tgz", + "integrity": "sha512-Shavhk87gCtY2fhXDctcfS3e6FdxWkCx1iUZ9eEUbh7rTqlZT0/IzOkCOVt0fCjcFuZ9FPYfuezTBImfHCDBGQ==", + "dev": true, + "dependencies": { + "@types/estree": "*", + "@types/json-schema": "*" + } + }, + "node_modules/@types/eslint__js": { + "version": "8.42.3", + "resolved": "https://registry.npmjs.org/@types/eslint__js/-/eslint__js-8.42.3.tgz", + "integrity": "sha512-alfG737uhmPdnvkrLdZLcEKJ/B8s9Y4hrZ+YAdzUeoArBlSUERA2E87ROfOaS4jd/C45fzOoZzidLc1IPwLqOw==", + "dev": true, + "dependencies": { + "@types/eslint": "*" + } + }, + "node_modules/@types/estree": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", + "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", + "dev": true + }, + "node_modules/@types/json-schema": { + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", + "dev": true + }, "node_modules/@types/minimist": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.5.tgz", @@ -746,16 +863,6 @@ "integrity": "sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==", "dev": true }, - "node_modules/@types/prettier": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-3.0.0.tgz", - "integrity": "sha512-mFMBfMOz8QxhYVbuINtswBp9VL2b4Y0QqYHwqLz3YbgtfAcat2Dl6Y1o4e22S/OVE6Ebl9m7wWiMT2lSbAs1wA==", - "deprecated": "This is a stub types definition. prettier provides its own type definitions, so you do not need this installed.", - "dev": true, - "dependencies": { - "prettier": "*" - } - }, "node_modules/@types/yargs": { "version": "17.0.32", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.32.tgz", @@ -963,9 +1070,9 @@ "dev": true }, "node_modules/acorn": { - "version": "8.12.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.0.tgz", - "integrity": "sha512-RTvkC4w+KNXrM39/lWCUaG0IbRkWdCv7W/IOW9oU6SawyxulvkQy5HQPVTKxEjczcUvapcrw3cFx/60VN/NRNw==", + "version": "8.12.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", + "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -1033,6 +1140,21 @@ "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", "dev": true }, + "node_modules/array-buffer-byte-length": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/array-buffer-byte-length/-/array-buffer-byte-length-1.0.1.tgz", + "integrity": "sha512-ahC5W1xgou+KTXix4sAO8Ki12Q+jf4i0+tmk3sC+zgcynshkHxzpXdImBehiUYKKKDwvfFiJl1tZt6ewscS1Mg==", + "dependencies": { + "call-bind": "^1.0.5", + "is-array-buffer": "^3.0.4" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/array-ify": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/array-ify/-/array-ify-1.0.0.tgz", @@ -1062,6 +1184,20 @@ "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, + "node_modules/available-typed-arrays": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", + "integrity": "sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==", + "dependencies": { + "possible-typed-array-names": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/axios": { "version": "1.7.2", "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", @@ -1099,12 +1235,43 @@ "node": ">=8" } }, + "node_modules/browser-or-node": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/browser-or-node/-/browser-or-node-3.0.0.tgz", + "integrity": "sha512-iczIdVJzGEYhP5DqQxYM9Hh7Ztpqqi+CXZpSmX8ALFs9ecXkQIeqRyM6TfxEfMVpwhl3dSuDvxdzzo9sUOIVBQ==" + }, "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", "dev": true }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", + "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "set-function-length": "^1.2.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -1141,19 +1308,39 @@ } }, "node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.0.0.tgz", + "integrity": "sha512-/duVOqst+luxCQRKEo4bNxinsOQtMP80ZYm7mMqzuh5PociNL0PvmHFvREJ9ueYL2TxlHjBcmLCdmocx9Vg+IQ==", + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/cli-cursor": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-4.0.0.tgz", + "integrity": "sha512-VGtlMu3x/4DOtIUwEkRezxUZ2lBacNJCHash0N0WeZDBS+7Ux1dm3XWAgWYxLJFMMdOeXMHXorshEFhbMSGelg==", "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" + "restore-cursor": "^4.0.0" }, "engines": { - "node": ">=10" + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" }, "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/cli-spinners": { + "version": "2.9.2", + "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.2.tgz", + "integrity": "sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==", + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/cliui": { @@ -1169,6 +1356,24 @@ "node": ">=12" } }, + "node_modules/cliui/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, + "node_modules/cliui/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", @@ -1185,14 +1390,6 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, - "node_modules/colors": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", - "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==", - "engines": { - "node": ">=0.1.90" - } - }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -1235,6 +1432,20 @@ "typedarray": "^0.0.6" } }, + "node_modules/concat-stream/node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dev": true, + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/conventional-changelog": { "version": "3.1.25", "resolved": "https://registry.npmjs.org/conventional-changelog/-/conventional-changelog-3.1.25.tgz", @@ -1499,8 +1710,7 @@ "node_modules/core-util-is": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", - "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", - "dev": true + "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" }, "node_modules/cross-spawn": { "version": "7.0.3", @@ -1585,12 +1795,75 @@ "node": ">=0.10.0" } }, + "node_modules/deep-equal": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-2.2.3.tgz", + "integrity": "sha512-ZIwpnevOurS8bpT4192sqAowWM76JDKSHYzMLty3BZGSswgq6pBaH3DhCSW5xVAZICZyKdOBPjwww5wfgT/6PA==", + "dependencies": { + "array-buffer-byte-length": "^1.0.0", + "call-bind": "^1.0.5", + "es-get-iterator": "^1.1.3", + "get-intrinsic": "^1.2.2", + "is-arguments": "^1.1.1", + "is-array-buffer": "^3.0.2", + "is-date-object": "^1.0.5", + "is-regex": "^1.1.4", + "is-shared-array-buffer": "^1.0.2", + "isarray": "^2.0.5", + "object-is": "^1.1.5", + "object-keys": "^1.1.1", + "object.assign": "^4.1.4", + "regexp.prototype.flags": "^1.5.1", + "side-channel": "^1.0.4", + "which-boxed-primitive": "^1.0.2", + "which-collection": "^1.0.1", + "which-typed-array": "^1.1.13" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", "dev": true }, + "node_modules/define-data-property": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", + "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "gopd": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/define-properties": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz", + "integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==", + "dependencies": { + "define-data-property": "^1.0.1", + "has-property-descriptors": "^1.0.0", + "object-keys": "^1.1.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -1657,7 +1930,6 @@ "version": "16.4.5", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", - "dev": true, "engines": { "node": ">=12" }, @@ -1786,9 +2058,9 @@ } }, "node_modules/emoji-regex": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.3.0.tgz", + "integrity": "sha512-QpLs9D9v9kArv4lfDEgg1X/gN5XLnf/A6l9cs8SPZLRZR3ZkY9+kwIQTxm+fsSej5UMYGE8fdoaZVIBlqG0XTw==" }, "node_modules/error-ex": { "version": "1.3.2", @@ -1799,6 +2071,44 @@ "is-arrayish": "^0.2.1" } }, + "node_modules/es-define-property": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", + "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", + "dependencies": { + "get-intrinsic": "^1.2.4" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-get-iterator": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/es-get-iterator/-/es-get-iterator-1.1.3.tgz", + "integrity": "sha512-sPZmqHBe6JIiTfN5q2pEi//TwxmAFHwj/XEuYjTuse78i8KxaqMTTzxPoFKuzRpDpTJ+0NAbpfenkmH2rePtuw==", + "dependencies": { + "call-bind": "^1.0.2", + "get-intrinsic": "^1.1.3", + "has-symbols": "^1.0.3", + "is-arguments": "^1.1.1", + "is-map": "^2.0.2", + "is-set": "^2.0.2", + "is-string": "^1.0.7", + "isarray": "^2.0.5", + "stop-iteration-iterator": "^1.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/esbuild": { "version": "0.21.5", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.21.5.tgz", @@ -1950,6 +2260,22 @@ "concat-map": "0.0.1" } }, + "node_modules/eslint/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/eslint/node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -1980,9 +2306,9 @@ } }, "node_modules/esquery": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz", - "integrity": "sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.6.0.tgz", + "integrity": "sha512-ca9pw9fomFcKPvFLXhBKUK90ZvGibiGOvRJNbjljY7s7uq/5YO4BOzcYtJqExdx99rF6aAcnRxHmcUHcz6sQsg==", "dev": true, "dependencies": { "estraverse": "^5.1.0" @@ -2179,6 +2505,14 @@ } } }, + "node_modules/for-each": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", + "integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==", + "dependencies": { + "is-callable": "^1.1.3" + } + }, "node_modules/form-data": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", @@ -2216,7 +2550,14 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", - "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/functions-have-names": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz", + "integrity": "sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==", "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -2229,6 +2570,35 @@ "node": "6.* || 8.* || >= 10.*" } }, + "node_modules/get-east-asian-width": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/get-east-asian-width/-/get-east-asian-width-1.2.0.tgz", + "integrity": "sha512-2nk+7SIVb14QrgXFHcm84tD4bKQz0RxPuMT8Ag5KPOq7J5fEmAg0UbXdTOSHqNuHSU28k55qnceesxXRZGzKWA==", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/get-intrinsic": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", + "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3", + "hasown": "^2.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/get-pkg-repo": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/get-pkg-repo/-/get-pkg-repo-4.2.1.tgz", @@ -2258,34 +2628,24 @@ "wrap-ansi": "^7.0.0" } }, - "node_modules/get-pkg-repo/node_modules/readable-stream": { - "version": "2.3.8", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", - "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "node_modules/get-pkg-repo/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, + "node_modules/get-pkg-repo/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", "dev": true, "dependencies": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "node_modules/get-pkg-repo/node_modules/safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "dev": true - }, - "node_modules/get-pkg-repo/node_modules/string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, - "dependencies": { - "safe-buffer": "~5.1.0" + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" } }, "node_modules/get-pkg-repo/node_modules/through2": { @@ -2317,9 +2677,9 @@ } }, "node_modules/get-tsconfig": { - "version": "4.7.5", - "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.7.5.tgz", - "integrity": "sha512-ZCuZCnlqNzjb4QprAzXKdpp/gh6KTxSJuw3IBsPnV/7fV4NxC9ckB+vPTt8w7fJA0TaSD7c55BR47JD6MEDyDw==", + "version": "4.7.6", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.7.6.tgz", + "integrity": "sha512-ZAqrLlu18NbDdRaHq+AKXzAmqIUPswPWKUchfytdAjiRFnCe5ojG2bstg6mRiZabkKfCoL/e98pbBELIV/YCeA==", "dev": true, "dependencies": { "resolve-pkg-maps": "^1.0.0" @@ -2484,6 +2844,17 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/gopd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", + "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "dependencies": { + "get-intrinsic": "^1.1.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", @@ -2526,6 +2897,14 @@ "node": ">=6" } }, + "node_modules/has-bigints": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz", + "integrity": "sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -2535,11 +2914,57 @@ "node": ">=8" } }, + "node_modules/has-property-descriptors": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", + "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", + "dependencies": { + "es-define-property": "^1.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-proto": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", + "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-tostringtag": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "dependencies": { + "has-symbols": "^1.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/hasown": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", - "dev": true, "dependencies": { "function-bind": "^1.1.2" }, @@ -2568,6 +2993,11 @@ "node": ">= 4" } }, + "node_modules/immediate": { + "version": "3.0.6", + "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", + "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==" + }, "node_modules/import-fresh": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", @@ -2616,8 +3046,7 @@ "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, "node_modules/ini": { "version": "1.3.8", @@ -2625,16 +3054,96 @@ "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", "dev": true }, + "node_modules/internal-slot": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.7.tgz", + "integrity": "sha512-NGnrKwXzSms2qUUih/ILZ5JBqNTSa1+ZmP6flaIp6KmSElgE9qdndzS3cqjrDovwFdmwsGsLdeFgB6suw+1e9g==", + "dependencies": { + "es-errors": "^1.3.0", + "hasown": "^2.0.0", + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/is-arguments": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", + "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", + "dependencies": { + "call-bind": "^1.0.2", + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-array-buffer": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/is-array-buffer/-/is-array-buffer-3.0.4.tgz", + "integrity": "sha512-wcjaerHw0ydZwfhiKbXJWLDY8A7yV7KhjQOpb83hGgGfId/aQa4TOvwyzn2PuswW2gPCYEL/nEAiSVpdOj1lXw==", + "dependencies": { + "call-bind": "^1.0.2", + "get-intrinsic": "^1.2.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-arrayish": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", "integrity": "sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==", "dev": true }, + "node_modules/is-bigint": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-bigint/-/is-bigint-1.0.4.tgz", + "integrity": "sha512-zB9CruMamjym81i2JZ3UMn54PKGsQzsJeo6xvN3HJJ4CAsQNB6iRutp2To77OfCNuoxspsIhzaPoO1zyCEhFOg==", + "dependencies": { + "has-bigints": "^1.0.1" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-boolean-object": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.2.tgz", + "integrity": "sha512-gDYaKHJmnj4aWxyj6YHyXVpdQawtVLHU5cb+eztPGczf6cjuTdwve5ZIEfgXqH4e57An1D1AKf8CZ3kYrQRqYA==", + "dependencies": { + "call-bind": "^1.0.2", + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-callable": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", + "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-core-module": { - "version": "2.14.0", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.14.0.tgz", - "integrity": "sha512-a5dFJih5ZLYlRtDc0dZWP7RiKr6xIKzmn/oAYCDvdLThadVgyJwlaoQPmRtMSpz+rk0OGAgIu+TcM9HUF0fk1A==", + "version": "2.15.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.15.0.tgz", + "integrity": "sha512-Dd+Lb2/zvk9SKy1TGCt1wFJFo/MWBPMX5x7KcvLajWTGuomczdQX61PvY5yK6SVACwpoexWo81IfFyoKY2QnTA==", "dev": true, "dependencies": { "hasown": "^2.0.2" @@ -2646,6 +3155,20 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-date-object": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.5.tgz", + "integrity": "sha512-9YQaSxsAiSwcvS33MBk3wTCVnWK+HhF8VZR2jRxehM16QcVOdHqPn4VPHmRK4lSr38n9JriurInLcP90xsYNfQ==", + "dependencies": { + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -2675,6 +3198,28 @@ "node": ">=0.10.0" } }, + "node_modules/is-interactive": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-2.0.0.tgz", + "integrity": "sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-map": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/is-map/-/is-map-2.0.3.tgz", + "integrity": "sha512-1Qed0/Hr2m+YqxnM09CjA2d/i6YZNfF6R2oRAOj36eUdS6qIV/huPJNSEpKbupewFs+ZsJlxsjjPbc0/afW6Lw==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-number": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", @@ -2684,6 +3229,20 @@ "node": ">=0.12.0" } }, + "node_modules/is-number-object": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.0.7.tgz", + "integrity": "sha512-k1U0IRzLMo7ZlYIfzRu23Oh6MiIFasgpb9X76eqfFZAqwH44UI4KTBvBYIZ1dSL9ZzChTB9ShHfLkR4pdW5krQ==", + "dependencies": { + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-obj": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz", @@ -2711,6 +3270,74 @@ "node": ">=0.10.0" } }, + "node_modules/is-regex": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", + "integrity": "sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==", + "dependencies": { + "call-bind": "^1.0.2", + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-set": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/is-set/-/is-set-2.0.3.tgz", + "integrity": "sha512-iPAjerrse27/ygGLxw+EBR9agv9Y6uLeYVJMu+QNCoouJ1/1ri0mGrcWpfCqFZuzzx3WjtwxG098X+n4OuRkPg==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-shared-array-buffer": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/is-shared-array-buffer/-/is-shared-array-buffer-1.0.3.tgz", + "integrity": "sha512-nA2hv5XIhLR3uVzDDfCIknerhx8XUKnstuOERPNNIinXG7v9u+ohXF67vxm4TPTEPU6lm61ZkwP3c9PCB97rhg==", + "dependencies": { + "call-bind": "^1.0.7" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-string": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.7.tgz", + "integrity": "sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==", + "dependencies": { + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-symbol": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.4.tgz", + "integrity": "sha512-C/CPBqKWnvdcxqIARxyOh4v1UUEOCHpgDa0WYgpKDFMszcrPcffg5uhwSgPCLD2WWxmq6isisz87tzT01tuGhg==", + "dependencies": { + "has-symbols": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-text-path": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/is-text-path/-/is-text-path-1.0.1.tgz", @@ -2723,11 +3350,47 @@ "node": ">=0.10.0" } }, + "node_modules/is-unicode-supported": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-2.0.0.tgz", + "integrity": "sha512-FRdAyx5lusK1iHG0TWpVtk9+1i+GjrzRffhDg4ovQ7mcidMQ6mj+MhKPmvh7Xwyv5gIS06ns49CA7Sqg7lC22Q==", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-weakmap": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/is-weakmap/-/is-weakmap-2.0.2.tgz", + "integrity": "sha512-K5pXYOm9wqY1RgjpL3YTkF39tni1XajUIkawTLUo9EZEVUFga5gSQJF8nNS7ZwJQ02y+1YCNYcMh+HIf1ZqE+w==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-weakset": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/is-weakset/-/is-weakset-2.0.3.tgz", + "integrity": "sha512-LvIm3/KWzS9oRFHugab7d+M/GcBXuXX5xZkzPmN+NxihdQlZUQ4dWuSV1xR/sq6upL1TJEDrfBgRepHFdBtSNQ==", + "dependencies": { + "call-bind": "^1.0.7", + "get-intrinsic": "^1.2.4" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", - "dev": true + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", + "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==" }, "node_modules/isexe": { "version": "2.0.0", @@ -2814,6 +3477,17 @@ "node": "*" } }, + "node_modules/jszip": { + "version": "3.10.1", + "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz", + "integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==", + "dependencies": { + "lie": "~3.3.0", + "pako": "~1.0.2", + "readable-stream": "~2.3.6", + "setimmediate": "^1.0.5" + } + }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -2832,6 +3506,14 @@ "node": ">=0.10.0" } }, + "node_modules/kleur": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", + "integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==", + "engines": { + "node": ">=6" + } + }, "node_modules/levn": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", @@ -2845,6 +3527,14 @@ "node": ">= 0.8.0" } }, + "node_modules/lie": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", + "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==", + "dependencies": { + "immediate": "~3.0.5" + } + }, "node_modules/lines-and-columns": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", @@ -2908,6 +3598,43 @@ "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", "dev": true }, + "node_modules/log-symbols": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-6.0.0.tgz", + "integrity": "sha512-i24m8rpwhmPIS4zscNzK6MSEhk0DUWa/8iYQWxhffV8jkI4Phvs3F+quL5xvS0gdQR0FyTCMMH33Y78dDTzzIw==", + "dependencies": { + "chalk": "^5.3.0", + "is-unicode-supported": "^1.3.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/log-symbols/node_modules/chalk": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", + "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/log-symbols/node_modules/is-unicode-supported": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-1.3.0.tgz", + "integrity": "sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", @@ -3168,6 +3895,14 @@ "node": ">= 0.6" } }, + "node_modules/mimic-fn": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", + "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", + "engines": { + "node": ">=6" + } + }, "node_modules/min-indent": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz", @@ -3257,6 +3992,57 @@ "node": ">=10" } }, + "node_modules/object-inspect": { + "version": "1.13.2", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", + "integrity": "sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/object-is": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.6.tgz", + "integrity": "sha512-F8cZ+KfGlSGi09lJT7/Nd6KJZ9ygtvYC0/UYYLI9nmQKLMnydpB9yvbv9K1uSkEu7FU9vYPmVwLg328tX+ot3Q==", + "dependencies": { + "call-bind": "^1.0.7", + "define-properties": "^1.2.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/object-keys": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", + "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/object.assign": { + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.5.tgz", + "integrity": "sha512-byy+U7gp+FVwmyzKPYhW2h5l3crpmGsxl7X2s8y43IgxvG4g3QZ6CffDtsNQy1WsmZpQbO+ybo0AlW7TY6DcBQ==", + "dependencies": { + "call-bind": "^1.0.5", + "define-properties": "^1.2.1", + "has-symbols": "^1.0.3", + "object-keys": "^1.1.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -3266,6 +4052,20 @@ "wrappy": "1" } }, + "node_modules/onetime": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", + "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", + "dependencies": { + "mimic-fn": "^2.1.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/optionator": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", @@ -3283,16 +4083,73 @@ "node": ">= 0.8.0" } }, + "node_modules/ora": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/ora/-/ora-8.0.1.tgz", + "integrity": "sha512-ANIvzobt1rls2BDny5fWZ3ZVKyD6nscLvfFRpQgfWsythlcsVUC9kL0zq6j2Z5z9wwp1kd7wpsD/T9qNPVLCaQ==", + "dependencies": { + "chalk": "^5.3.0", + "cli-cursor": "^4.0.0", + "cli-spinners": "^2.9.2", + "is-interactive": "^2.0.0", + "is-unicode-supported": "^2.0.0", + "log-symbols": "^6.0.0", + "stdin-discarder": "^0.2.1", + "string-width": "^7.0.0", + "strip-ansi": "^7.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/ora/node_modules/ansi-regex": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/ora/node_modules/chalk": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", + "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/ora/node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, "node_modules/p-limit": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", - "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", - "dev": true, + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-6.1.0.tgz", + "integrity": "sha512-H0jc0q1vOzlEk0TqAKXKZxdl7kX3OFUzCnNVUnq5Pc3DGo0kpeaMuPqxQn235HibwBEb0/pm9dgKTjXy66fBkg==", "dependencies": { - "yocto-queue": "^0.1.0" + "yocto-queue": "^1.1.1" }, "engines": { - "node": ">=10" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -3313,6 +4170,33 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/p-locate/node_modules/p-limit": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "dev": true, + "dependencies": { + "yocto-queue": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-locate/node_modules/yocto-queue": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", + "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/p-try": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", @@ -3322,6 +4206,11 @@ "node": ">=6" } }, + "node_modules/pako": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", + "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==" + }, "node_modules/parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", @@ -3416,6 +4305,14 @@ "node": ">=0.10.0" } }, + "node_modules/possible-typed-array-names": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz", + "integrity": "sha512-d7Uw+eZoloe0EHDIYoe+bQ5WXnGMOpmiZFTuMWCwpjzzkL2nTjcKiAk4hh8TjnGye2TwWOk3UXucZ+3rbmBa8Q==", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -3442,8 +4339,19 @@ "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", - "dev": true + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" + }, + "node_modules/prompts": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", + "integrity": "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==", + "dependencies": { + "kleur": "^3.0.3", + "sisteransi": "^1.0.5" + }, + "engines": { + "node": ">= 6" + } }, "node_modules/proxy-from-env": { "version": "1.1.0", @@ -3646,19 +4554,24 @@ "semver": "bin/semver" } }, - "node_modules/readable-stream": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", - "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "dev": true, - "dependencies": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - }, - "engines": { - "node": ">= 6" - } + "node_modules/readable-stream": { + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", + "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "dependencies": { + "core-util-is": "~1.0.0", + "inherits": "~2.0.3", + "isarray": "~1.0.0", + "process-nextick-args": "~2.0.0", + "safe-buffer": "~5.1.1", + "string_decoder": "~1.1.1", + "util-deprecate": "~1.0.1" + } + }, + "node_modules/readable-stream/node_modules/isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" }, "node_modules/redent": { "version": "3.0.0", @@ -3673,6 +4586,23 @@ "node": ">=8" } }, + "node_modules/regexp.prototype.flags": { + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz", + "integrity": "sha512-NcDiDkTLuPR+++OCKB0nWafEmhg/Da8aUPLPMQbK+bxKKCm1/S5he+AqYa4PlMCVBalb4/yxIRub6qkEx5yJbw==", + "dependencies": { + "call-bind": "^1.0.6", + "define-properties": "^1.2.1", + "es-errors": "^1.3.0", + "set-function-name": "^2.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -3721,6 +4651,21 @@ "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" } }, + "node_modules/restore-cursor": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-4.0.0.tgz", + "integrity": "sha512-I9fPXU9geO9bHOt9pHHOhOkYerIMsmVaWB0rA2AI9ERh/+x/i7MV5HKBNrg+ljO5eoPVgCcnFuRjJ9uH6I/3eg==", + "dependencies": { + "onetime": "^5.1.0", + "signal-exit": "^3.0.2" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/reusify": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", @@ -3771,29 +4716,14 @@ } }, "node_modules/safe-buffer": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ] + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, "node_modules/semver": { - "version": "7.6.2", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.2.tgz", - "integrity": "sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==", + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", "dev": true, "bin": { "semver": "bin/semver.js" @@ -3802,6 +4732,41 @@ "node": ">=10" } }, + "node_modules/set-function-length": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", + "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", + "dependencies": { + "define-data-property": "^1.1.4", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/set-function-name": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/set-function-name/-/set-function-name-2.0.2.tgz", + "integrity": "sha512-7PGFlmtwsEADb0WYyvCMa1t+yke6daIG4Wirafur5kcf+MhUnPms1UeR0CKQdTZD81yESwMHbtn+TR+dMviakQ==", + "dependencies": { + "define-data-property": "^1.1.4", + "es-errors": "^1.3.0", + "functions-have-names": "^1.2.3", + "has-property-descriptors": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/setimmediate": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", + "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==" + }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", @@ -3823,6 +4788,33 @@ "node": ">=8" } }, + "node_modules/side-channel": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", + "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==", + "dependencies": { + "call-bind": "^1.0.7", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.4", + "object-inspect": "^1.13.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/signal-exit": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" + }, + "node_modules/sisteransi": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", + "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==" + }, "node_modules/slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -3894,6 +4886,20 @@ "readable-stream": "^3.0.0" } }, + "node_modules/split2/node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dev": true, + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/standard-version": { "version": "9.5.0", "resolved": "https://registry.npmjs.org/standard-version/-/standard-version-9.5.0.tgz", @@ -3974,6 +4980,12 @@ "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==", "dev": true }, + "node_modules/standard-version/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "dev": true + }, "node_modules/standard-version/node_modules/escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", @@ -3992,6 +5004,20 @@ "node": ">=4" } }, + "node_modules/standard-version/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/standard-version/node_modules/supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", @@ -4022,26 +5048,75 @@ "node": ">=10" } }, + "node_modules/stdin-discarder": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/stdin-discarder/-/stdin-discarder-0.2.2.tgz", + "integrity": "sha512-UhDfHmA92YAlNnCfhmq0VeNL5bDbiZGg7sZ2IvPsXubGkiNa9EC+tUTsjBRsYUAz87btI6/1wf4XoVvQ3uRnmQ==", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/stop-iteration-iterator": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/stop-iteration-iterator/-/stop-iteration-iterator-1.0.0.tgz", + "integrity": "sha512-iCGQj+0l0HOdZ2AEeBADlsRC+vsnDsZsbdSiH1yNSjcfKM7fdpCMfqAL/dwF5BLiw/XhRft/Wax6zQbhq2BcjQ==", + "dependencies": { + "internal-slot": "^1.0.4" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/string_decoder": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", - "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", - "dev": true, + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", "dependencies": { - "safe-buffer": "~5.2.0" + "safe-buffer": "~5.1.0" } }, "node_modules/string-width": { - "version": "4.2.3", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", - "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", + "integrity": "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==", "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" + "emoji-regex": "^10.3.0", + "get-east-asian-width": "^1.0.0", + "strip-ansi": "^7.1.0" }, "engines": { - "node": ">=8" + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/string-width/node_modules/ansi-regex": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/string-width/node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, "node_modules/stringify-package": { @@ -4149,6 +5224,20 @@ "readable-stream": "3" } }, + "node_modules/through2/node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dev": true, + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -4244,10 +5333,36 @@ "node": ">=14.17" } }, + "node_modules/typescript-eslint": { + "version": "7.16.1", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-7.16.1.tgz", + "integrity": "sha512-889oE5qELj65q/tGeOSvlreNKhimitFwZqQ0o7PcWC7/lgRkAMknznsCsV8J8mZGTP/Z+cIbX8accf2DE33hrA==", + "dev": true, + "dependencies": { + "@typescript-eslint/eslint-plugin": "7.16.1", + "@typescript-eslint/parser": "7.16.1", + "@typescript-eslint/utils": "7.16.1" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.56.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, "node_modules/uglify-js": { - "version": "3.18.0", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.18.0.tgz", - "integrity": "sha512-SyVVbcNBCk0dzr9XL/R/ySrmYf0s372K6/hFklzgcp2lBFyXtw4I7BOdDjlLhE1aVqaI/SHWXWmYdlZxuyF38A==", + "version": "3.19.0", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.19.0.tgz", + "integrity": "sha512-wNKHUY2hYYkf6oSFfhwwiHo4WCHzHmzcXsqXYTN9ja3iApYIFbb2U6ics9hBcYLHcYGQoAlwnZlTrf3oF+BL/Q==", "dev": true, "optional": true, "bin": { @@ -4284,8 +5399,7 @@ "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", - "dev": true + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" }, "node_modules/uuid": { "version": "10.0.0", @@ -4324,6 +5438,56 @@ "node": ">= 8" } }, + "node_modules/which-boxed-primitive": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz", + "integrity": "sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==", + "dependencies": { + "is-bigint": "^1.0.1", + "is-boolean-object": "^1.1.0", + "is-number-object": "^1.0.4", + "is-string": "^1.0.5", + "is-symbol": "^1.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/which-collection": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/which-collection/-/which-collection-1.0.2.tgz", + "integrity": "sha512-K4jVyjnBdgvc86Y6BkaLZEN933SwYOuBFkdmBu9ZfkcAbdVbpITnDmjvZ/aQjRXQrv5EPkTnD1s39GiiqbngCw==", + "dependencies": { + "is-map": "^2.0.3", + "is-set": "^2.0.3", + "is-weakmap": "^2.0.2", + "is-weakset": "^2.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/which-typed-array": { + "version": "1.1.15", + "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.15.tgz", + "integrity": "sha512-oV0jmFtUky6CXfkqehVvBP/LSWJ2sy4vWMioiENyJLePrBO/yKyV9OyJySfAKosh+RYkIl5zJCNZ8/4JncrpdA==", + "dependencies": { + "available-typed-arrays": "^1.0.7", + "call-bind": "^1.0.7", + "for-each": "^0.3.3", + "gopd": "^1.0.1", + "has-tostringtag": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/word-wrap": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", @@ -4355,6 +5519,24 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/wrap-ansi/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, + "node_modules/wrap-ansi/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", @@ -4410,6 +5592,24 @@ "node": ">=10" } }, + "node_modules/yargs/node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, + "node_modules/yargs/node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/yargs/node_modules/yargs-parser": { "version": "21.1.1", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", @@ -4419,16 +5619,23 @@ } }, "node_modules/yocto-queue": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", - "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", - "dev": true, + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.1.1.tgz", + "integrity": "sha512-b4JR1PFR10y1mKjhHY9LaGo6tmrgjit7hxVIeAmyMw3jegXR4dhYqLaQF5zMXZxY7tLpMyJeLjr1C4rLmkVe8g==", "engines": { - "node": ">=10" + "node": ">=12.20" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/zod": { + "version": "3.23.8", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", + "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } } } diff --git a/package.json b/package.json index 5692119..caa509b 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "7.3.0", "description": "This utility generates strongly-typed models based on Content Types in a Kontent.ai project. These models can be used with SDKs", "bin": { - "kontent-generate": "./dist/es2022/lib/cli/cli.js" + "kontent-generate": "./dist/es2022/lib/code/app.js" }, "repository": { "type": "git", @@ -27,38 +27,41 @@ "types": "./dist/es2022/lib/index.d.ts", "type": "module", "scripts": { - "release": "npm run lint:check && standard-version && npm run update:version", - "release:major": "npm run lint:check && standard-version --release-as major && npm run update:version", - "release:major:beta": "npm run lint:check && standard-version --prerelease --release-as major && npm run update:version", + "release": "standard-version && npm run update:version", + "release:major": "standard-version --release-as major && npm run update:version", + "release:major:beta": "standard-version --prerelease --release-as major && npm run update:version", "release:beta": "standard-version --prerelease", "prerelease:standard": "standard-version --prerelease", "prerelease:major": "standard-version --prerelease --release-as major", - "prepublishOnly": "npm run lint:check && npm run build && npm run push:tags", + "prepublishOnly": "npm run build && npm run push:tags", "publish:beta": "npm publish --tag=next", "build:es2022": "tsc --p tsconfig.es2022.json", - "build": "npm run clean && npm run build:es2022", + "build": "npm run lint && npm run clean && npm run build:es2022", "test:all": "npm run build && npm run test:delivery-models", - "test:delivery-models": "tsx scripts/generate-delivery-models", - "test:help": "npm run build && cd sample && node ../dist/es2022/lib/cli/cli -h", - "lint:check": "npx eslint lib", - "clean": "tsx clean.ts", + "test:delivery": "tsx scripts/generate-delivery-models", + "test:help:command": "tsx lib/node/cli/app delivery --help", + "lint": "npx eslint lib", + "lint:fix": "npx eslint lib --fix", + "clean": "tsx scripts/clean.ts", "push:tags": "git push --tags", "update:version": "tsx ./scripts/update-version.ts" }, "dependencies": { "yargs": "17.7.2", "prettier": "3.3.3", - "colors": "1.4.0", + "chalk": "5.0.0", "@kontent-ai/delivery-sdk": "14.10.0", - "@kontent-ai/management-sdk": "6.5.0" + "@kontent-ai/management-sdk": "6.5.0", + "@kontent-ai/migration-toolkit": "1.3.0" }, "devDependencies": { "@types/yargs": "17.0.32", "standard-version": "9.5.0", "typescript": "5.5.3", "@types/node": "20.14.11", - "@types/prettier": "3.0.0", + "@types/eslint__js": "8.42.3", "@typescript-eslint/eslint-plugin": "7.16.1", + "typescript-eslint": "7.16.1", "@typescript-eslint/parser": "7.16.1", "eslint": "8.57.0", "tsx": "4.16.2", diff --git a/sample/content-types/actor.ts b/sample/content-types/actor.ts index cc9a3b7..bf70ade 100644 --- a/sample/content-types/actor.ts +++ b/sample/content-types/actor.ts @@ -1,6 +1,6 @@ import { type IContentItem, type Elements } from '@kontent-ai/delivery-sdk'; /** - * Generated by '@kontent-ai/model-generator@7.2.0' + * Generated by '@kontent-ai/model-generator@7.3.0' * * Actor * Id: 58099989-319f-495f-aa36-cb3710854e36 diff --git a/sample/content-types/movie.ts b/sample/content-types/movie.ts index 965996e..c207dbb 100644 --- a/sample/content-types/movie.ts +++ b/sample/content-types/movie.ts @@ -3,7 +3,7 @@ import { type Actor } from './actor.js'; import { type ReleaseCategory } from '../taxonomies/releasecategory.js'; /** - * Generated by '@kontent-ai/model-generator@7.2.0' + * Generated by '@kontent-ai/model-generator@7.3.0' * * Movie * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c diff --git a/sample/project/assetFolders.ts b/sample/project/assetFolders.ts index 39e128f..b0f2148 100644 --- a/sample/project/assetFolders.ts +++ b/sample/project/assetFolders.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.2.0' + * Generated by '@kontent-ai/model-generator@7.3.0' * * Project name: Movie Database * Environment: Production diff --git a/sample/project/collections.ts b/sample/project/collections.ts index f65ac10..25c73ae 100644 --- a/sample/project/collections.ts +++ b/sample/project/collections.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.2.0' + * Generated by '@kontent-ai/model-generator@7.3.0' * * Project name: Movie Database * Environment: Production diff --git a/sample/project/contentTypeSnippets.ts b/sample/project/contentTypeSnippets.ts index ecac6d1..ff834c5 100644 --- a/sample/project/contentTypeSnippets.ts +++ b/sample/project/contentTypeSnippets.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.2.0' + * Generated by '@kontent-ai/model-generator@7.3.0' * * Project name: Movie Database * Environment: Production diff --git a/sample/project/contentTypes.ts b/sample/project/contentTypes.ts index f0a96f6..6cd8dba 100644 --- a/sample/project/contentTypes.ts +++ b/sample/project/contentTypes.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.2.0' + * Generated by '@kontent-ai/model-generator@7.3.0' * * Project name: Movie Database * Environment: Production diff --git a/sample/project/languages.ts b/sample/project/languages.ts index dc2bfb5..4ffb90c 100644 --- a/sample/project/languages.ts +++ b/sample/project/languages.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.2.0' + * Generated by '@kontent-ai/model-generator@7.3.0' * * Project name: Movie Database * Environment: Production diff --git a/sample/project/roles.ts b/sample/project/roles.ts index 2c99a6e..e8b2c51 100644 --- a/sample/project/roles.ts +++ b/sample/project/roles.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.2.0' + * Generated by '@kontent-ai/model-generator@7.3.0' * * Project name: Movie Database * Environment: Production diff --git a/sample/project/taxonomies.ts b/sample/project/taxonomies.ts index 2e99e3d..33b55ec 100644 --- a/sample/project/taxonomies.ts +++ b/sample/project/taxonomies.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.2.0' + * Generated by '@kontent-ai/model-generator@7.3.0' * * Project name: Movie Database * Environment: Production diff --git a/sample/project/webhooks.ts b/sample/project/webhooks.ts index 01b5489..8a669bc 100644 --- a/sample/project/webhooks.ts +++ b/sample/project/webhooks.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.2.0' + * Generated by '@kontent-ai/model-generator@7.3.0' * * Project name: Movie Database * Environment: Production diff --git a/sample/project/workflows.ts b/sample/project/workflows.ts index 86f0483..b76e47e 100644 --- a/sample/project/workflows.ts +++ b/sample/project/workflows.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.2.0' + * Generated by '@kontent-ai/model-generator@7.3.0' * * Project name: Movie Database * Environment: Production diff --git a/sample/taxonomies/movietype.ts b/sample/taxonomies/movietype.ts index 0ca5beb..6d0aa26 100644 --- a/sample/taxonomies/movietype.ts +++ b/sample/taxonomies/movietype.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.2.0' + * Generated by '@kontent-ai/model-generator@7.3.0' * * MovieType * Id: 365a17e6-1929-27ab-9f67-a9273c846717 diff --git a/sample/taxonomies/releasecategory.ts b/sample/taxonomies/releasecategory.ts index bf1e256..52b0860 100644 --- a/sample/taxonomies/releasecategory.ts +++ b/sample/taxonomies/releasecategory.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.2.0' + * Generated by '@kontent-ai/model-generator@7.3.0' * * ReleaseCategory * Id: 09b6a348-0f86-7a68-4af3-7cab9a5c60b7 diff --git a/clean.ts b/scripts/clean.ts similarity index 61% rename from clean.ts rename to scripts/clean.ts index fa8e185..b7bd4b7 100644 --- a/clean.ts +++ b/scripts/clean.ts @@ -1,10 +1,10 @@ import fs from 'fs'; -import Colors from 'colors'; +import chalk from 'chalk'; const paths = ['dist']; for (const path of paths) { if (fs.existsSync(path)) { fs.rmSync(path, { recursive: true }); - console.log(`Path '${Colors.yellow(path)}' has been deleted`); + console.log(`Path '${chalk.yellow(path)}' has been deleted`); } } diff --git a/scripts/file-version-script.ts b/scripts/file-version-script.ts index 6fa9253..db66247 100644 --- a/scripts/file-version-script.ts +++ b/scripts/file-version-script.ts @@ -1,9 +1,9 @@ import fs from 'fs'; -import Colors from 'colors'; +import chalk from 'chalk'; import PackageJson from '../package.json' assert { type: 'json' }; export const createVersionFile = (date: Date, versionPath: string, propertyName: string) => { - console.log(Colors.cyan(`\nCreating version file at '${versionPath}' with prop '${propertyName}'`)); + console.log(chalk.cyan(`\nCreating version file at '${versionPath}' with prop '${propertyName}'`)); createFile(date, versionPath, propertyName); }; @@ -20,10 +20,10 @@ export const ${propName} = { fs.writeFile(filePath, src, { flag: 'w' }, (err) => { if (err) { - return console.log(Colors.red(err.message)); + return console.log(chalk.red(err.message)); } - console.log(Colors.green(`Updating version ${Colors.yellow(PackageJson.version)}`)); - console.log(`${Colors.green('Writing version to ')}${Colors.yellow(filePath)}\n`); + console.log(chalk.green(`Updating version ${chalk.yellow(PackageJson.version)}`)); + console.log(`${chalk.green('Writing version to ')}${chalk.yellow(filePath)}\n`); }); } diff --git a/scripts/generate-delivery-models.ts b/scripts/generate-delivery-models.ts index 824781f..dc3cf7b 100644 --- a/scripts/generate-delivery-models.ts +++ b/scripts/generate-delivery-models.ts @@ -1,7 +1,7 @@ import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; -import { ModuleResolution, generateModelsAsync } from '../lib/index.js'; -import Colors from 'colors'; +import { ModuleResolution, generateModelsAsync, handleError } from '../lib/index.js'; +import chalk from 'chalk'; const outputDir: string = './sample'; @@ -12,13 +12,13 @@ const run = async () => { }); // delete existing models - console.log(`Deleting existing folder '${Colors.yellow(outputDir)}'`); + console.log(`Deleting existing folder '${chalk.yellow(outputDir)}'`); rmSync(outputDir, { recursive: true, force: true }); - console.log(`Folder '${Colors.yellow(outputDir)}' deleted successfully`); + console.log(`Folder '${chalk.yellow(outputDir)}' deleted successfully`); const environmentVar = 'ENVIRONMENT_ID'; const moduleResolutionVar = 'MODULE_RESOLUTION'; @@ -29,14 +29,14 @@ const run = async () => { const moduleResolution = process.env[moduleResolutionVar]; if (!moduleResolutionVar) { - throw Error(`Missing '${Colors.red(moduleResolutionVar)}' env variable`); + throw Error(`Missing '${chalk.red(moduleResolutionVar)}' env variable`); } if (!environmentId) { - throw Error(`Missing '${Colors.red(environmentVar)}' env variable`); + throw Error(`Missing '${chalk.red(environmentVar)}' env variable`); } if (!apiKey) { - throw Error(`Missing '${Colors.red(apiKeyVar)}' env variable`); + throw Error(`Missing '${chalk.red(apiKeyVar)}' env variable`); } await generateModelsAsync({ @@ -54,4 +54,6 @@ const run = async () => { }); }; -run(); +run().catch((err) => { + handleError(err); +}); diff --git a/tsconfig.es2022.json b/tsconfig.es2022.json index f96ee40..6d5b1db 100644 --- a/tsconfig.es2022.json +++ b/tsconfig.es2022.json @@ -1,13 +1,10 @@ { - "extends": "./tsconfig.json", - "compilerOptions": { - "importHelpers": true, - "target": "es2022", - "outDir": "dist/es2022", - "moduleResolution": "NodeNext", - "module": "NodeNext" - }, - "include": [ - "lib/**/*" - ] -} \ No newline at end of file + "extends": "./tsconfig.json", + "compilerOptions": { + "importHelpers": true, + "target": "es2022", + "outDir": "dist/es2022", + "moduleResolution": "NodeNext", + "module": "NodeNext" + } +} diff --git a/tsconfig.json b/tsconfig.json index 53a7378..b9abb4f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,24 +1,32 @@ { + "compileOnSave": true, "compilerOptions": { - "module": "commonjs", - "target": "ESNext", + "baseUrl": ".", "outDir": "dist", - "rootDir": ".", "sourceMap": true, "declaration": true, + "moduleResolution": "NodeNext", + "module": "NodeNext", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "target": "es2022", "strict": true, - "skipLibCheck": true, - "esModuleInterop": true, + "strictNullChecks": true, + "strictPropertyInitialization": true, "resolveJsonModule": true, + "noImplicitReturns": true, + "allowUnreachableCode": false, + "skipLibCheck": true, "alwaysStrict": true, + "forceConsistentCasingInFileNames": true, "noUnusedParameters": false, "noUnusedLocals": true, "strictFunctionTypes": true, "noImplicitAny": true, - "strictNullChecks": true, - "strictPropertyInitialization": true, - "allowSyntheticDefaultImports": true, - "forceConsistentCasingInFileNames": true + "typeRoots": ["./node_modules/@types"], + "lib": ["esnext"] }, - "include": ["**/*.ts"] + "include": ["lib/**/*", "sample/**/*", "scripts/**/*", "eslint.config.js"], + "exclude": ["node_modules"] } From 3f04f57bc1244cd0f994b81a547d9a41fe024ade Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 22 Jul 2024 15:57:58 +0200 Subject: [PATCH 002/183] Prepares test scripts & utils, renames `sdkType` to `modelType`, removes `exportProjectSettings` config option --- README.md | 8 +- lib/generator.ts | 262 +++++++++--------- .../migration/migration-generator.ts | 23 +- lib/models.ts | 30 +- lib/node/cli/actions/delivery-action.ts | 16 +- package.json | 3 +- .../content-type-snippets/index.ts | 0 sample/{ => delivery}/content-types/actor.ts | 0 sample/{ => delivery}/content-types/index.ts | 0 sample/{ => delivery}/content-types/movie.ts | 0 sample/{ => delivery}/index.ts | 0 sample/{ => delivery}/project/assetFolders.ts | 0 sample/{ => delivery}/project/collections.ts | 0 .../project/contentTypeSnippets.ts | 0 sample/{ => delivery}/project/contentTypes.ts | 0 sample/{ => delivery}/project/index.ts | 0 sample/{ => delivery}/project/languages.ts | 0 sample/{ => delivery}/project/roles.ts | 0 sample/{ => delivery}/project/taxonomies.ts | 0 sample/{ => delivery}/project/webhooks.ts | 0 sample/{ => delivery}/project/workflows.ts | 0 sample/{ => delivery}/taxonomies/index.ts | 0 sample/{ => delivery}/taxonomies/movietype.ts | 0 .../taxonomies/releasecategory.ts | 0 .../delivery-models.ts} | 30 +- scripts/tests/migration-models.ts | 40 +++ scripts/utils/test.utils.ts | 22 ++ 27 files changed, 245 insertions(+), 189 deletions(-) rename sample/{ => delivery}/content-type-snippets/index.ts (100%) rename sample/{ => delivery}/content-types/actor.ts (100%) rename sample/{ => delivery}/content-types/index.ts (100%) rename sample/{ => delivery}/content-types/movie.ts (100%) rename sample/{ => delivery}/index.ts (100%) rename sample/{ => delivery}/project/assetFolders.ts (100%) rename sample/{ => delivery}/project/collections.ts (100%) rename sample/{ => delivery}/project/contentTypeSnippets.ts (100%) rename sample/{ => delivery}/project/contentTypes.ts (100%) rename sample/{ => delivery}/project/index.ts (100%) rename sample/{ => delivery}/project/languages.ts (100%) rename sample/{ => delivery}/project/roles.ts (100%) rename sample/{ => delivery}/project/taxonomies.ts (100%) rename sample/{ => delivery}/project/webhooks.ts (100%) rename sample/{ => delivery}/project/workflows.ts (100%) rename sample/{ => delivery}/taxonomies/index.ts (100%) rename sample/{ => delivery}/taxonomies/movietype.ts (100%) rename sample/{ => delivery}/taxonomies/releasecategory.ts (100%) rename scripts/{generate-delivery-models.ts => tests/delivery-models.ts} (54%) create mode 100644 scripts/tests/migration-models.ts create mode 100644 scripts/utils/test.utils.ts diff --git a/README.md b/README.md index e9e9a66..798ec58 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,9 @@ Apart from generating models via CLI, you may also generate models in code which configuration options (such as using custom name resolver). ```typescript -import { generateModelsAsync } from '@kontent-ai/model-generator'; +import { generateDeliveryModelsAsync } from '@kontent-ai/model-generator'; -await generateModelsAsync({ +await generateDeliveryModelsAsync({ sdkType: 'delivery', environmentId: 'da5abe9f-fdad-4168-97cd-b3464be2ccb9', isEnterpriseSubscription: true, @@ -53,7 +53,7 @@ You may customize the way filenames are stored on file system using the `content `taxonomyTypeFileResolver` configuration option: ```typescript -await generateModelsAsync({ +await generateDeliveryModelsAsync({ sdkType: 'delivery', environmentId: 'da5abe9f-fdad-4168-97cd-b3464be2ccb9', isEnterpriseSubscription: true, @@ -73,7 +73,7 @@ You may customize name of content types using the `contentTypeResolver` configur `taxonomyTypeResolver` option: ```typescript -await generateModelsAsync({ +await generateDeliveryModelsAsync({ sdkType: 'delivery', environmentId: 'da5abe9f-fdad-4168-97cd-b3464be2ccb9', isEnterpriseSubscription: true, diff --git a/lib/generator.ts b/lib/generator.ts index 08c8aee..a7feb07 100644 --- a/lib/generator.ts +++ b/lib/generator.ts @@ -1,13 +1,18 @@ import chalk from 'chalk'; -import { IGenerateModelsConfig, ModuleResolution } from './models.js'; +import { GenerateMigrationModelsConfig, IGenerateDeliveryModelsConfig, ModuleResolution } from './models.js'; import { deliveryContentTypeGenerator } from './generators/delivery/delivery-content-type.generator.js'; import { projectGenerator } from './generators/index.js'; import { AssetFolderModels, CollectionModels, + ContentTypeModels, + ContentTypeSnippetModels, createManagementClient, + EnvironmentModels, LanguageModels, + ManagementClient, RoleModels, + TaxonomyModels, WebhookModels, WorkflowModels } from '@kontent-ai/management-sdk'; @@ -15,26 +20,10 @@ import { deliveryTaxonomyGenerator } from './generators/delivery/delivery-taxono import { commonHelper } from './common-helper.js'; import { parse } from 'path'; import { fileHelper } from './file-helper.js'; +import { migrationGenerator } from './generators/migration/migration-generator.js'; -export async function generateModelsAsync(config: IGenerateModelsConfig): Promise { +export async function generateDeliveryModelsAsync(config: IGenerateDeliveryModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); - - try { - if (config.sdkType === 'delivery') { - await generateDeliveryModelsAsync(config); - } else if (config.sdkType === 'migration') { - await generateMigrationModelsAsync(); - } else { - throw Error(`Unsupported 'sdkType'. Supported values are: 'delivery', 'migration'`); - } - console.log(chalk.green(`\nCompleted`)); - } catch (error) { - console.log(chalk.red(`Failed with error:`)); - throw error; - } -} - -async function generateDeliveryModelsAsync(config: IGenerateModelsConfig): Promise { console.log(`Generating '${chalk.yellow('delivery')}' models\n`); const outputDir: string = config.outputDir ? `${config.outputDir}/`.replaceAll('//', '/') : `./`; @@ -55,122 +44,25 @@ async function generateDeliveryModelsAsync(config: IGenerateModelsConfig): Promi fileHelper.createDir(taxonomiesFolderPath); fileHelper.createDir(projectFolderPath); - const managementClient = createManagementClient({ + const client = createManagementClient({ environmentId: config.environmentId, apiKey: config.apiKey, baseUrl: config.managementApiUrl }); const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; + const projectInformation = await getEnvironmentInfoAsync(client); - const projectInformation = (await managementClient.environmentInformation().toPromise()).data; - console.log(`Project '${chalk.yellow(projectInformation.project.name)}'`); - console.log(`Environment '${chalk.yellow(projectInformation.project.environment)}'\n`); - console.log(`Module resolution '${chalk.yellow(moduleResolution)}'\n`); - - const types = commonHelper.sortAlphabetically( - (await managementClient.listContentTypes().toAllPromise()).data.items, - (item) => item.name - ); - const snippets = commonHelper.sortAlphabetically( - (await managementClient.listContentTypeSnippets().toAllPromise()).data.items, - (item) => item.name - ); - const taxonomies = commonHelper.sortAlphabetically( - (await managementClient.listTaxonomies().toAllPromise()).data.items, - (item) => item.name - ); - - console.log(`Found '${chalk.yellow(types.length.toString())}' types`); - console.log(`Found '${chalk.yellow(snippets.length.toString())}' content type snippets`); - console.log(`Found '${chalk.yellow(taxonomies.length.toString())}' taxonomies`); - - const workflows: WorkflowModels.Workflow[] = []; - const roles: RoleModels.Role[] = []; - const assetFolders: AssetFolderModels.AssetFolder[] = []; - const collections: CollectionModels.Collection[] = []; - const webhooks: WebhookModels.Webhook[] = []; - const languages: LanguageModels.LanguageModel[] = []; - - const exportAllProjectSettings = config.exportProjectSettings ? false : true; - - if (config.exportProjectSettings?.exportWorkflows || exportAllProjectSettings) { - workflows.push( - ...commonHelper.sortAlphabetically( - (await managementClient.listWorkflows().toPromise()).data, - (item) => item.name - ) - ); - console.log(`Found '${chalk.yellow(workflows.length.toString())}' workflows`); - } else { - console.log(`Skipping '${chalk.red('workflows')}' export`); - } + const types = await getTypesAsync(client); + const snippets = await getSnippetsAsync(client); + const taxonomies = await getTaxonomiesAsync(client); - if (config.isEnterpriseSubscription) { - if (config.exportProjectSettings?.exportRoles || exportAllProjectSettings) { - roles.push( - ...commonHelper.sortAlphabetically( - (await managementClient.listRoles().toPromise()).data.roles, - (item) => item.name - ) - ); - console.log(`Found '${chalk.yellow(roles.length.toString())}' roles`); - } else { - console.log(`Skipping '${chalk.red('roles')}' export`); - } - } else { - console.log(`Skipping '${chalk.red('roles')}' export because enterprise subscription is disabled`); - } - - if (config.exportProjectSettings?.exportAssetFolders || exportAllProjectSettings) { - assetFolders.push( - ...commonHelper.sortAlphabetically( - (await managementClient.listAssetFolders().toPromise()).data.items, - (item) => item.name - ) - ); - console.log( - `Found '${chalk.yellow(projectGenerator.getAssetFoldersCount(assetFolders).toString())}' asset folders` - ); - } else { - console.log(`Skipping '${chalk.red('asset folders')}' export`); - } - - if (config.exportProjectSettings?.exportCollections || exportAllProjectSettings) { - collections.push( - ...commonHelper.sortAlphabetically( - (await managementClient.listCollections().toPromise()).data.collections, - (item) => item.name - ) - ); - console.log(`Found '${chalk.yellow(collections.length.toString())}' collections`); - } else { - console.log(`Skipping '${chalk.red('collections')}' export`); - } - - if (config.exportProjectSettings?.exportWebhooks || exportAllProjectSettings) { - webhooks.push( - ...commonHelper.sortAlphabetically( - (await managementClient.listWebhooks().toPromise()).data.webhooks, - (item) => item.name - ) - ); - console.log(`Found '${chalk.yellow(webhooks.length.toString())}' webhooks`); - } else { - console.log(`Skipping '${chalk.red('webhooks')}' export`); - } - - if (config.exportProjectSettings?.exportLanguages || exportAllProjectSettings) { - languages.push( - ...commonHelper.sortAlphabetically( - (await managementClient.listLanguages().toAllPromise()).data.items, - (item) => item.name - ) - ); - console.log(`Found '${chalk.yellow(languages.length.toString())}' languages`); - } else { - console.log(`Skipping '${chalk.red('languages')}' export`); - } + const workflows: WorkflowModels.Workflow[] = await getWorkflowsAsync(client); + const roles: RoleModels.Role[] = config.isEnterpriseSubscription ? await getRolesAsync(client) : []; + const assetFolders: AssetFolderModels.AssetFolder[] = await getAssetFoldersAsync(client); + const collections: CollectionModels.Collection[] = await getCollectionsAsync(client); + const webhooks: WebhookModels.Webhook[] = await getWebhooksAsync(client); + const languages: LanguageModels.LanguageModel[] = await getLanguagesAsync(client); console.log(''); @@ -208,7 +100,7 @@ async function generateDeliveryModelsAsync(config: IGenerateModelsConfig): Promi // create project structure const projectFiles = projectGenerator.generateProjectModel({ outputDir: outputDir, - environmentInfo: projectInformation.project, + environmentInfo: projectInformation, addTimestamp: config.addTimestamp, formatOptions: config.formatOptions, addEnvironmentInfo: config.addEnvironmentInfo, @@ -310,6 +202,118 @@ async function generateDeliveryModelsAsync(config: IGenerateModelsConfig): Promi }); const mainBarrelExportPath: string = `${outputDir}${barrelExportFilename}`; await fileHelper.createFileOnFsAsync(mainBarrelCode, mainBarrelExportPath, config.formatOptions); + + console.log(chalk.green(`\nCompleted`)); +} + +export async function generateMigrationModelsAsync(config: GenerateMigrationModelsConfig): Promise { + const client = createManagementClient({ + environmentId: config.environmentId, + apiKey: config.apiKey, + baseUrl: config.managementApiUrl + }); + + const projectInformation = await getEnvironmentInfoAsync(client); + console.log(`Project '${chalk.yellow(projectInformation.name)}'`); + console.log(`Environment '${chalk.yellow(projectInformation.environment)}'\n`); + + const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; + console.log(`Module resolution '${chalk.yellow(moduleResolution)}'\n`); + + migrationGenerator({ + addTimestamp: config.addTimestamp, + addEnvironmentInfo: config.addEnvironmentInfo, + languages: await getLanguagesAsync(client), + workflows: await getWorkflowsAsync(client), + types: await getTypesAsync(client), + snippets: await getSnippetsAsync(client), + collections: await getCollectionsAsync(client) + }).generate(); +} + +async function getEnvironmentInfoAsync( + client: ManagementClient +): Promise { + const projectInformation = (await client.environmentInformation().toPromise()).data; + console.log(`Project '${chalk.yellow(projectInformation.project.name)}'`); + console.log(`Environment '${chalk.yellow(projectInformation.project.environment)}'\n`); + return projectInformation.project; +} + +async function getWorkflowsAsync(client: ManagementClient): Promise { + const items = commonHelper.sortAlphabetically((await client.listWorkflows().toPromise()).data, (item) => item.name); + console.log(`Found '${chalk.yellow(items.length.toString())}' workflows`); + return items; +} + +async function getRolesAsync(client: ManagementClient): Promise { + const items = commonHelper.sortAlphabetically( + (await client.listRoles().toPromise()).data.roles, + (item) => item.name + ); + console.log(`Found '${chalk.yellow(items.length.toString())}' roles`); + return items; +} + +async function getAssetFoldersAsync(client: ManagementClient): Promise { + const items = commonHelper.sortAlphabetically( + (await client.listAssetFolders().toPromise()).data.items, + (item) => item.name + ); + console.log(`Found '${chalk.yellow(items.length.toString())}' asset folders`); + return items; +} + +async function getCollectionsAsync(client: ManagementClient): Promise { + const items = commonHelper.sortAlphabetically( + (await client.listCollections().toPromise()).data.collections, + (item) => item.name + ); + console.log(`Found '${chalk.yellow(items.length.toString())}' collections`); + return items; } -async function generateMigrationModelsAsync(): Promise {} +async function getWebhooksAsync(client: ManagementClient): Promise { + const items = commonHelper.sortAlphabetically( + (await client.listWebhooks().toPromise()).data.webhooks, + (item) => item.name + ); + console.log(`Found '${chalk.yellow(items.length.toString())}' webhooks`); + return items; +} + +async function getLanguagesAsync(client: ManagementClient): Promise { + const items = commonHelper.sortAlphabetically( + (await client.listLanguages().toAllPromise()).data.items, + (item) => item.name + ); + console.log(`Found '${chalk.yellow(items.length.toString())}' languages`); + return items; +} + +async function getTypesAsync(client: ManagementClient): Promise { + const items = commonHelper.sortAlphabetically( + (await client.listContentTypes().toAllPromise()).data.items, + (item) => item.name + ); + console.log(`Found '${chalk.yellow(items.length.toString())}' types`); + return items; +} + +async function getSnippetsAsync(client: ManagementClient): Promise { + const items = commonHelper.sortAlphabetically( + (await client.listContentTypeSnippets().toAllPromise()).data.items, + (item) => item.name + ); + console.log(`Found '${chalk.yellow(items.length.toString())}' snippets`); + return items; +} + +async function getTaxonomiesAsync(client: ManagementClient): Promise { + const items = commonHelper.sortAlphabetically( + (await client.listTaxonomies().toAllPromise()).data.items, + (item) => item.name + ); + console.log(`Found '${chalk.yellow(items.length.toString())}' taxonomies`); + return items; +} diff --git a/lib/generators/migration/migration-generator.ts b/lib/generators/migration/migration-generator.ts index eb24c6c..b21454f 100644 --- a/lib/generators/migration/migration-generator.ts +++ b/lib/generators/migration/migration-generator.ts @@ -1,13 +1,28 @@ +import { + CollectionModels, + ContentTypeModels, + ContentTypeSnippetModels, + LanguageModels, + WorkflowModels +} from '@kontent-ai/management-sdk'; +import { IGeneratedFile } from '../../common-helper.js'; + export interface MigrationGeneratorConfig { - environmentId: string; - apiKey: string; + addTimestamp: boolean; + addEnvironmentInfo: boolean; + + types: ContentTypeModels.ContentType[]; + workflows: WorkflowModels.Workflow[]; + languages: LanguageModels.LanguageModel[]; + collections: CollectionModels.Collection[]; + snippets: ContentTypeSnippetModels.ContentTypeSnippet[]; } export function migrationGenerator(config: MigrationGeneratorConfig) { console.log(config); return { - generateModels(): string { - return 'todo'; + generate(): IGeneratedFile[] { + return []; } }; } diff --git a/lib/models.ts b/lib/models.ts index c017e16..e447c83 100644 --- a/lib/models.ts +++ b/lib/models.ts @@ -4,7 +4,7 @@ import { Options } from 'prettier'; export type ModuleResolution = 'nodeNext' | 'node'; export type DefaultResolverType = 'camelCase' | 'pascalCase' | 'snakeCase'; -export type SdkType = 'delivery' | 'migration'; +export type ModelType = 'delivery' | 'migration'; export type ElementResolver = DefaultResolverType | PropertyNameResolver; export type ContentTypeFileNameResolver = @@ -21,30 +21,16 @@ export type ContentTypeSnippetResolver = | ((contentTypeSnippet: ContentTypeSnippetModels.ContentTypeSnippet) => string); export type TaxonomyTypeResolver = DefaultResolverType | ((taxonomy: TaxonomyModels.Taxonomy) => string); -export interface IExportProjectSettings { - exportWebhooks: boolean; - exportWorkflows: boolean; - exportRoles: boolean; - exportAssetFolders: boolean; - exportCollections: boolean; - exportLanguages: boolean; -} - -export interface IGenerateModelsConfig { +export interface IGenerateDeliveryModelsConfig { environmentId: string; addTimestamp: boolean; addEnvironmentInfo: boolean; isEnterpriseSubscription: boolean; - sdkType: SdkType; + modelType: ModelType; apiKey: string; moduleResolution?: ModuleResolution; managementApiUrl?: string; - /** - * Determines what content structure objects are exported. - * If not set, all objects are exported - */ - exportProjectSettings?: IExportProjectSettings; outputDir?: string; sortConfig?: ISortConfig; contentTypeFileResolver?: ContentTypeFileNameResolver; @@ -60,3 +46,13 @@ export interface IGenerateModelsConfig { export interface ISortConfig { sortTaxonomyTerms: boolean; } + +export interface GenerateMigrationModelsConfig { + addEnvironmentInfo: boolean; + environmentId: string; + addTimestamp: boolean; + apiKey: string; + moduleResolution: ModuleResolution; + outputDir: string; + managementApiUrl?: string; +} diff --git a/lib/node/cli/actions/delivery-action.ts b/lib/node/cli/actions/delivery-action.ts index b3f5121..91942d5 100644 --- a/lib/node/cli/actions/delivery-action.ts +++ b/lib/node/cli/actions/delivery-action.ts @@ -1,9 +1,9 @@ import { ModuleResolution } from '../../../models.js'; -import { generateModelsAsync } from '../../../generator.js'; +import { generateDeliveryModelsAsync } from '../../../generator.js'; import { CliArgumentsFetcher } from '../cli.models.js'; export async function deliveryActionAsync(cliFetcher: CliArgumentsFetcher): Promise { - await generateModelsAsync({ + await generateDeliveryModelsAsync({ environmentId: cliFetcher.getRequiredArgumentValue('environmentId'), managementApiUrl: cliFetcher.getRequiredArgumentValue('managementApiUrl'), apiKey: cliFetcher.getRequiredArgumentValue('apiKey'), @@ -19,19 +19,11 @@ export async function deliveryActionAsync(cliFetcher: CliArgumentsFetcher): Prom contentTypeSnippetFileResolver: undefined, contentTypeSnippetResolver: undefined, formatOptions: undefined, - sdkType: 'delivery', + modelType: 'delivery', sortConfig: { sortTaxonomyTerms: cliFetcher.getBooleanArgumentValue('sortTaxonomyTerms', true) }, moduleResolution: - cliFetcher.getRequiredArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext', - exportProjectSettings: { - exportWebhooks: true, - exportWorkflows: true, - exportAssetFolders: true, - exportCollections: true, - exportLanguages: true, - exportRoles: true - } + cliFetcher.getRequiredArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' }); } diff --git a/package.json b/package.json index caa509b..6fc2dda 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "build:es2022": "tsc --p tsconfig.es2022.json", "build": "npm run lint && npm run clean && npm run build:es2022", "test:all": "npm run build && npm run test:delivery-models", - "test:delivery": "tsx scripts/generate-delivery-models", + "test:delivery": "tsx scripts/tests/delivery-models", + "test:migration": "tsx scripts/tests/migration-models", "test:help:command": "tsx lib/node/cli/app delivery --help", "lint": "npx eslint lib", "lint:fix": "npx eslint lib --fix", diff --git a/sample/content-type-snippets/index.ts b/sample/delivery/content-type-snippets/index.ts similarity index 100% rename from sample/content-type-snippets/index.ts rename to sample/delivery/content-type-snippets/index.ts diff --git a/sample/content-types/actor.ts b/sample/delivery/content-types/actor.ts similarity index 100% rename from sample/content-types/actor.ts rename to sample/delivery/content-types/actor.ts diff --git a/sample/content-types/index.ts b/sample/delivery/content-types/index.ts similarity index 100% rename from sample/content-types/index.ts rename to sample/delivery/content-types/index.ts diff --git a/sample/content-types/movie.ts b/sample/delivery/content-types/movie.ts similarity index 100% rename from sample/content-types/movie.ts rename to sample/delivery/content-types/movie.ts diff --git a/sample/index.ts b/sample/delivery/index.ts similarity index 100% rename from sample/index.ts rename to sample/delivery/index.ts diff --git a/sample/project/assetFolders.ts b/sample/delivery/project/assetFolders.ts similarity index 100% rename from sample/project/assetFolders.ts rename to sample/delivery/project/assetFolders.ts diff --git a/sample/project/collections.ts b/sample/delivery/project/collections.ts similarity index 100% rename from sample/project/collections.ts rename to sample/delivery/project/collections.ts diff --git a/sample/project/contentTypeSnippets.ts b/sample/delivery/project/contentTypeSnippets.ts similarity index 100% rename from sample/project/contentTypeSnippets.ts rename to sample/delivery/project/contentTypeSnippets.ts diff --git a/sample/project/contentTypes.ts b/sample/delivery/project/contentTypes.ts similarity index 100% rename from sample/project/contentTypes.ts rename to sample/delivery/project/contentTypes.ts diff --git a/sample/project/index.ts b/sample/delivery/project/index.ts similarity index 100% rename from sample/project/index.ts rename to sample/delivery/project/index.ts diff --git a/sample/project/languages.ts b/sample/delivery/project/languages.ts similarity index 100% rename from sample/project/languages.ts rename to sample/delivery/project/languages.ts diff --git a/sample/project/roles.ts b/sample/delivery/project/roles.ts similarity index 100% rename from sample/project/roles.ts rename to sample/delivery/project/roles.ts diff --git a/sample/project/taxonomies.ts b/sample/delivery/project/taxonomies.ts similarity index 100% rename from sample/project/taxonomies.ts rename to sample/delivery/project/taxonomies.ts diff --git a/sample/project/webhooks.ts b/sample/delivery/project/webhooks.ts similarity index 100% rename from sample/project/webhooks.ts rename to sample/delivery/project/webhooks.ts diff --git a/sample/project/workflows.ts b/sample/delivery/project/workflows.ts similarity index 100% rename from sample/project/workflows.ts rename to sample/delivery/project/workflows.ts diff --git a/sample/taxonomies/index.ts b/sample/delivery/taxonomies/index.ts similarity index 100% rename from sample/taxonomies/index.ts rename to sample/delivery/taxonomies/index.ts diff --git a/sample/taxonomies/movietype.ts b/sample/delivery/taxonomies/movietype.ts similarity index 100% rename from sample/taxonomies/movietype.ts rename to sample/delivery/taxonomies/movietype.ts diff --git a/sample/taxonomies/releasecategory.ts b/sample/delivery/taxonomies/releasecategory.ts similarity index 100% rename from sample/taxonomies/releasecategory.ts rename to sample/delivery/taxonomies/releasecategory.ts diff --git a/scripts/generate-delivery-models.ts b/scripts/tests/delivery-models.ts similarity index 54% rename from scripts/generate-delivery-models.ts rename to scripts/tests/delivery-models.ts index dc3cf7b..442978b 100644 --- a/scripts/generate-delivery-models.ts +++ b/scripts/tests/delivery-models.ts @@ -1,9 +1,10 @@ import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; -import { ModuleResolution, generateModelsAsync, handleError } from '../lib/index.js'; +import { ModuleResolution, generateDeliveryModelsAsync, handleError } from '../../lib/index.js'; import chalk from 'chalk'; +import { getEnvironmentRequiredValue } from 'scripts/utils/test.utils.js'; -const outputDir: string = './sample'; +const outputDir: string = './sample/delivery'; const run = async () => { // needed to load .env environment to current process when run via package.json script @@ -20,31 +21,16 @@ const run = async () => { console.log(`Folder '${chalk.yellow(outputDir)}' deleted successfully`); - const environmentVar = 'ENVIRONMENT_ID'; - const moduleResolutionVar = 'MODULE_RESOLUTION'; - const apiKeyVar = 'API_KEY'; + const environmentId = getEnvironmentRequiredValue('ENVIRONMENT_ID'); + const apiKey = getEnvironmentRequiredValue('API_KEY'); + const moduleResolution = getEnvironmentRequiredValue('MODULE_RESOLUTION'); - const environmentId = process.env[environmentVar]; - const apiKey = process.env[apiKeyVar]; - const moduleResolution = process.env[moduleResolutionVar]; - - if (!moduleResolutionVar) { - throw Error(`Missing '${chalk.red(moduleResolutionVar)}' env variable`); - } - - if (!environmentId) { - throw Error(`Missing '${chalk.red(environmentVar)}' env variable`); - } - if (!apiKey) { - throw Error(`Missing '${chalk.red(apiKeyVar)}' env variable`); - } - - await generateModelsAsync({ + await generateDeliveryModelsAsync({ addTimestamp: false, environmentId: environmentId, apiKey: apiKey, moduleResolution: moduleResolution?.toLowerCase() === 'node' ? 'node' : 'nodeNext', - sdkType: 'delivery', + modelType: 'delivery', isEnterpriseSubscription: true, addEnvironmentInfo: true, outputDir: outputDir, diff --git a/scripts/tests/migration-models.ts b/scripts/tests/migration-models.ts new file mode 100644 index 0000000..0ad98af --- /dev/null +++ b/scripts/tests/migration-models.ts @@ -0,0 +1,40 @@ +import * as dotenv from 'dotenv'; +import { rmSync } from 'fs'; +import { ModuleResolution, generateMigrationModelsAsync, handleError } from '../../lib/index.js'; +import chalk from 'chalk'; +import { getEnvironmentRequiredValue } from 'scripts/utils/test.utils.js'; + +const outputDir: string = './sample/migration'; + +const run = async () => { + // needed to load .env environment to current process when run via package.json script + dotenv.config({ + path: './.env' + }); + + // delete existing models + console.log(`Deleting existing folder '${chalk.yellow(outputDir)}'`); + rmSync(outputDir, { + recursive: true, + force: true + }); + + console.log(`Folder '${chalk.yellow(outputDir)}' deleted successfully`); + + const environmentId = getEnvironmentRequiredValue('ENVIRONMENT_ID'); + const apiKey = getEnvironmentRequiredValue('API_KEY'); + const moduleResolution = getEnvironmentRequiredValue('MODULE_RESOLUTION'); + + await generateMigrationModelsAsync({ + addTimestamp: false, + environmentId: environmentId, + apiKey: apiKey, + moduleResolution: moduleResolution?.toLowerCase() === 'node' ? 'node' : 'nodeNext', + addEnvironmentInfo: true, + outputDir: outputDir + }); +}; + +run().catch((err) => { + handleError(err); +}); diff --git a/scripts/utils/test.utils.ts b/scripts/utils/test.utils.ts new file mode 100644 index 0000000..7173677 --- /dev/null +++ b/scripts/utils/test.utils.ts @@ -0,0 +1,22 @@ +import chalk from 'chalk'; + +export function getEnvironmentRequiredValue(variableName: string): string { + const value = getEnvironmentOptionalValue(variableName); + + if (!value) { + throw new Error(`Missing environment variable '${chalk.red(variableName)}'`); + } + + return value; +} + +export function getEnvironmentOptionalValue(variableName: string): string | undefined { + // get value from environment variables first + const value = process.env[variableName]; + + if (!value) { + return undefined; + } + + return value; +} From 00e8226ede766123b0f7f35646d05f2546d8b190 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 24 Jul 2024 12:23:09 +0200 Subject: [PATCH 003/183] Adds support for generating base migration types --- lib/common-helper.ts | 6 ++ lib/core/core.utils.ts | 4 + lib/generator.ts | 73 +++++++++++++++---- .../migration/migration-generator.ts | 66 +++++++++++++++-- lib/models.ts | 2 +- lib/node/cli/actions/delivery-action.ts | 1 - sample/migration/index.ts | 2 + sample/migration/items/index.ts | 1 + sample/migration/migration-types.ts | 6 ++ scripts/tests/delivery-models.ts | 1 - 10 files changed, 137 insertions(+), 25 deletions(-) create mode 100644 sample/migration/index.ts create mode 100644 sample/migration/items/index.ts create mode 100644 sample/migration/migration-types.ts diff --git a/lib/common-helper.ts b/lib/common-helper.ts index ad1af01..af3adda 100644 --- a/lib/common-helper.ts +++ b/lib/common-helper.ts @@ -8,6 +8,12 @@ export interface IGeneratedFile { text: string; } +export interface GeneratedFile { + filename: string; + filepath: string; + text: string; +} + export class CommonHelper { sortAlphabetically(arrayToSort: T[], propertySelector: (item: T) => string): T[] { return arrayToSort.sort((a, b) => diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index ec8d183..9743204 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -1,3 +1,7 @@ export function exitProgram(data: { readonly message: string }): never { throw Error(data.message); } + +export function uniqueFilter(value: string, index: number, self: string[]) { + return self.indexOf(value) === index; +} diff --git a/lib/generator.ts b/lib/generator.ts index a7feb07..640943a 100644 --- a/lib/generator.ts +++ b/lib/generator.ts @@ -57,12 +57,12 @@ export async function generateDeliveryModelsAsync(config: IGenerateDeliveryModel const snippets = await getSnippetsAsync(client); const taxonomies = await getTaxonomiesAsync(client); - const workflows: WorkflowModels.Workflow[] = await getWorkflowsAsync(client); - const roles: RoleModels.Role[] = config.isEnterpriseSubscription ? await getRolesAsync(client) : []; - const assetFolders: AssetFolderModels.AssetFolder[] = await getAssetFoldersAsync(client); - const collections: CollectionModels.Collection[] = await getCollectionsAsync(client); - const webhooks: WebhookModels.Webhook[] = await getWebhooksAsync(client); - const languages: LanguageModels.LanguageModel[] = await getLanguagesAsync(client); + const workflows = await getWorkflowsAsync(client); + const roles = config.isEnterpriseSubscription ? await getRolesAsync(client) : []; + const assetFolders = await getAssetFoldersAsync(client); + const collections = await getCollectionsAsync(client); + const webhooks = await getWebhooksAsync(client); + const languages = await getLanguagesAsync(client); console.log(''); @@ -213,22 +213,67 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode baseUrl: config.managementApiUrl }); + const outputDir: string = config.outputDir ? `${config.outputDir}/`.replaceAll('//', '/') : `./`; + const barrelExportFilename: string = 'index.ts'; + const migrationItemsFolderName: string = `items/`; + const migrationItemsFolderPath: string = `${outputDir}${migrationItemsFolderName}`; + const projectInformation = await getEnvironmentInfoAsync(client); console.log(`Project '${chalk.yellow(projectInformation.name)}'`); console.log(`Environment '${chalk.yellow(projectInformation.environment)}'\n`); const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; console.log(`Module resolution '${chalk.yellow(moduleResolution)}'\n`); - - migrationGenerator({ + const migrationGeneratorObj = migrationGenerator({ + outputDir: outputDir, addTimestamp: config.addTimestamp, addEnvironmentInfo: config.addEnvironmentInfo, - languages: await getLanguagesAsync(client), - workflows: await getWorkflowsAsync(client), - types: await getTypesAsync(client), - snippets: await getSnippetsAsync(client), - collections: await getCollectionsAsync(client) - }).generate(); + environmentData: { + languages: await getLanguagesAsync(client), + workflows: await getWorkflowsAsync(client), + types: await getTypesAsync(client), + snippets: await getSnippetsAsync(client), + collections: await getCollectionsAsync(client) + } + }); + + // prepare directories + fileHelper.createDir(migrationItemsFolderPath); + + const migrationTypeFile = migrationGeneratorObj.getMigrationTypesFile(`migration-types.ts`); + const migrationItemFiles = migrationGeneratorObj.getmigrationItemFiles(); + const allFiles = [migrationTypeFile, ...migrationItemFiles]; + + // create all files on FS + for (const file of allFiles) { + await fileHelper.createFileOnFsAsync(file.text, file.filepath, config.formatOptions); + } + + // migration items barrel + await fileHelper.createFileOnFsAsync( + commonHelper.getBarrelExportCode({ + moduleResolution: moduleResolution, + filenames: [ + ...migrationItemFiles.map((m) => { + return `./${parse(m.filepath).name}`; + }) + ] + }), + `${migrationItemsFolderPath}${barrelExportFilename}`, + config.formatOptions + ); + + // main barrel + await fileHelper.createFileOnFsAsync( + commonHelper.getBarrelExportCode({ + moduleResolution: moduleResolution, + filenames: [`./${migrationItemsFolderName}index`, `./${migrationTypeFile.filename}`] + }), + `${outputDir}${barrelExportFilename}`, + config.formatOptions + ); + + console.log(chalk.green(`\nCompleted`)); } async function getEnvironmentInfoAsync( diff --git a/lib/generators/migration/migration-generator.ts b/lib/generators/migration/migration-generator.ts index b21454f..24ebee4 100644 --- a/lib/generators/migration/migration-generator.ts +++ b/lib/generators/migration/migration-generator.ts @@ -5,24 +5,74 @@ import { LanguageModels, WorkflowModels } from '@kontent-ai/management-sdk'; -import { IGeneratedFile } from '../../common-helper.js'; +import { GeneratedFile } from '../../common-helper.js'; +import { uniqueFilter } from '../../core/index.js'; export interface MigrationGeneratorConfig { addTimestamp: boolean; addEnvironmentInfo: boolean; + outputDir: string; - types: ContentTypeModels.ContentType[]; - workflows: WorkflowModels.Workflow[]; - languages: LanguageModels.LanguageModel[]; - collections: CollectionModels.Collection[]; - snippets: ContentTypeSnippetModels.ContentTypeSnippet[]; + environmentData: { + types: ContentTypeModels.ContentType[]; + workflows: WorkflowModels.Workflow[]; + languages: LanguageModels.LanguageModel[]; + collections: CollectionModels.Collection[]; + snippets: ContentTypeSnippetModels.ContentTypeSnippet[]; + }; } export function migrationGenerator(config: MigrationGeneratorConfig) { - console.log(config); return { - generate(): IGeneratedFile[] { + getMigrationTypesFile(filename: string): GeneratedFile { + return { + filepath: config.outputDir + filename, + filename: filename, + text: ` + ${getLanguageCodenamesType(config.environmentData.languages)} + ${getContentTypeCodenamesType(config.environmentData.types)} + ${getContentTypeCodenameType()} + ${getCollectionCodenamesType(config.environmentData.collections)} + ${getWorkflowCodenamesType(config.environmentData.workflows)} + ${getWorkflowStepCodenamesType(config.environmentData.workflows)} + ` + }; + }, + getmigrationItemFiles(): GeneratedFile[] { return []; } }; } + +function getLanguageCodenamesType(languages: LanguageModels.LanguageModel[]): string { + return `export type LanguageCodenames = ${languages.map((language) => `'${language.codename}'`).join(' | ')};`; +} + +function getContentTypeCodenameType(): string { + return `export type ContentTypeCodename = Codename;`; +} + +function getContentTypeCodenamesType(types: ContentTypeModels.ContentType[]): string { + return `export type ContentTypeCodenames = ${types.map((type) => `'${type.codename}'`).join(' | ')};`; +} + +function getWorkflowCodenamesType(workflows: WorkflowModels.Workflow[]): string { + return `export type WorkflowCodenames = ${workflows.map((workflow) => `'${workflow.codename}'`).join(' | ')};`; +} + +function getCollectionCodenamesType(collections: CollectionModels.Collection[]): string { + return `export type CollectionCodenames = ${collections.map((collection) => `'${collection.codename}'`).join(' | ')};`; +} + +function getWorkflowStepCodenamesType(workflows: WorkflowModels.Workflow[]): string { + return `export type WorkflowStepCodenames = ${workflows + .flatMap((workflow) => [ + ...workflow.steps, + workflow.publishedStep, + workflow.archivedStep, + workflow.scheduledStep + ]) + .map((workflowStep) => `'${workflowStep.codename}'`) + .filter(uniqueFilter) + .join(' | ')};`; +} diff --git a/lib/models.ts b/lib/models.ts index e447c83..0e8ef9c 100644 --- a/lib/models.ts +++ b/lib/models.ts @@ -26,7 +26,6 @@ export interface IGenerateDeliveryModelsConfig { addTimestamp: boolean; addEnvironmentInfo: boolean; isEnterpriseSubscription: boolean; - modelType: ModelType; apiKey: string; moduleResolution?: ModuleResolution; managementApiUrl?: string; @@ -55,4 +54,5 @@ export interface GenerateMigrationModelsConfig { moduleResolution: ModuleResolution; outputDir: string; managementApiUrl?: string; + formatOptions?: Options; } diff --git a/lib/node/cli/actions/delivery-action.ts b/lib/node/cli/actions/delivery-action.ts index 91942d5..811b378 100644 --- a/lib/node/cli/actions/delivery-action.ts +++ b/lib/node/cli/actions/delivery-action.ts @@ -19,7 +19,6 @@ export async function deliveryActionAsync(cliFetcher: CliArgumentsFetcher): Prom contentTypeSnippetFileResolver: undefined, contentTypeSnippetResolver: undefined, formatOptions: undefined, - modelType: 'delivery', sortConfig: { sortTaxonomyTerms: cliFetcher.getBooleanArgumentValue('sortTaxonomyTerms', true) }, diff --git a/sample/migration/index.ts b/sample/migration/index.ts new file mode 100644 index 0000000..3347667 --- /dev/null +++ b/sample/migration/index.ts @@ -0,0 +1,2 @@ +export * from './items/index.js'; +export * from './migration-types.js'; diff --git a/sample/migration/items/index.ts b/sample/migration/items/index.ts new file mode 100644 index 0000000..cb0ff5c --- /dev/null +++ b/sample/migration/items/index.ts @@ -0,0 +1 @@ +export {}; diff --git a/sample/migration/migration-types.ts b/sample/migration/migration-types.ts new file mode 100644 index 0000000..6a15aad --- /dev/null +++ b/sample/migration/migration-types.ts @@ -0,0 +1,6 @@ +export type LanguageCodenames = 'cz' | 'en' | 'German'; +export type ContentTypeCodenames = 'actor' | 'movie'; +export type ContentTypeCodename = Codename; +export type CollectionCodenames = 'default'; +export type WorkflowCodenames = 'default'; +export type WorkflowStepCodenames = 'draft' | 'review' | 'ready_to_publish' | 'published' | 'archived' | 'scheduled'; diff --git a/scripts/tests/delivery-models.ts b/scripts/tests/delivery-models.ts index 442978b..4590c94 100644 --- a/scripts/tests/delivery-models.ts +++ b/scripts/tests/delivery-models.ts @@ -30,7 +30,6 @@ const run = async () => { environmentId: environmentId, apiKey: apiKey, moduleResolution: moduleResolution?.toLowerCase() === 'node' ? 'node' : 'nodeNext', - modelType: 'delivery', isEnterpriseSubscription: true, addEnvironmentInfo: true, outputDir: outputDir, From fd52b1ea94984389142c763db3550ddfaedd33d1 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 24 Jul 2024 14:26:26 +0200 Subject: [PATCH 004/183] prepares new fileProcessor closure with output dir support --- lib/common-helper.ts | 1 - lib/file-helper.ts | 67 +++++++++++++++++-- lib/generator.ts | 26 +++---- .../migration/migration-generator.ts | 13 ++-- sample/migration/items/actor.ts | 1 + sample/migration/items/index.ts | 3 +- sample/migration/items/movie.ts | 1 + 7 files changed, 84 insertions(+), 28 deletions(-) create mode 100644 sample/migration/items/actor.ts create mode 100644 sample/migration/items/movie.ts diff --git a/lib/common-helper.ts b/lib/common-helper.ts index af3adda..5901814 100644 --- a/lib/common-helper.ts +++ b/lib/common-helper.ts @@ -10,7 +10,6 @@ export interface IGeneratedFile { export interface GeneratedFile { filename: string; - filepath: string; text: string; } diff --git a/lib/file-helper.ts b/lib/file-helper.ts index 8a5ff30..618c712 100644 --- a/lib/file-helper.ts +++ b/lib/file-helper.ts @@ -2,28 +2,81 @@ import chalk from 'chalk'; import { Options } from 'prettier'; import { formatHelper } from './format-helper.js'; import * as fs from 'fs'; +import { dirname } from 'path'; + +export function fileProcessor(outputDir: string) { + const createFileOnFsAsync = async ( + text: string, + filePath: string, + formatOptions: Options | undefined + ): Promise => { + const fullFilePath = `${outputDir.endsWith('/') ? outputDir : `${outputDir}/`}${filePath}`; + try { + const contentToStore = await formatHelper.formatCodeAsync(text, formatOptions); + + ensureDirectoryExistence(fullFilePath); + fs.writeFileSync('./' + fullFilePath, contentToStore, {}); + console.log(`Created '${chalk.yellow(fullFilePath)}'`); + } catch (error) { + console.log(`Failed to format file '${chalk.red(filePath)}'. Skipping prettier for this file.`); + + const contentToStore = text; + + fs.writeFileSync('./' + fullFilePath, contentToStore); + console.log(`Created '${chalk.yellow(fullFilePath)}'`); + } + }; + + const createDir = (dirPath: string): void => { + fs.mkdirSync(dirPath, { recursive: true }); + }; + + const ensureDirectoryExistence = (filePath: string): void => { + const resolvedDirname = dirname(filePath); + if (fs.existsSync(resolvedDirname)) { + return; + } + ensureDirectoryExistence(resolvedDirname); + fs.mkdirSync(resolvedDirname); + }; + + return { + createDir, + createFileOnFsAsync + }; +} export class FileHelper { - async createFileOnFsAsync(text: string, filename: string, formatOptions: Options | undefined): Promise { - const finalFilename = `${filename}`; + async createFileOnFsAsync(text: string, filePath: string, formatOptions: Options | undefined): Promise { + const fullFilePath = `${filePath}`; try { const contentToStore = await formatHelper.formatCodeAsync(text, formatOptions); - fs.writeFileSync('./' + finalFilename, contentToStore); - console.log(`Created '${chalk.yellow(finalFilename)}'`); + this.ensureDirectoryExistence(fullFilePath); + fs.writeFileSync('./' + fullFilePath, contentToStore, {}); + console.log(`Created '${chalk.yellow(fullFilePath)}'`); } catch (error) { - console.log(`Failed to format file '${chalk.red(filename)}'. Skipping prettier for this file.`); + console.log(`Failed to format file '${chalk.red(filePath)}'. Skipping prettier for this file.`); const contentToStore = text; - fs.writeFileSync('./' + finalFilename, contentToStore); - console.log(`Created '${chalk.yellow(finalFilename)}'`); + fs.writeFileSync('./' + fullFilePath, contentToStore); + console.log(`Created '${chalk.yellow(fullFilePath)}'`); } } createDir(dirPath: string): void { fs.mkdirSync(dirPath, { recursive: true }); } + + private ensureDirectoryExistence(filePath: string): void { + const resolvedDirname = dirname(filePath); + if (fs.existsSync(resolvedDirname)) { + return; + } + this.ensureDirectoryExistence(resolvedDirname); + fs.mkdirSync(resolvedDirname); + } } export const fileHelper = new FileHelper(); diff --git a/lib/generator.ts b/lib/generator.ts index 640943a..e3ca228 100644 --- a/lib/generator.ts +++ b/lib/generator.ts @@ -19,7 +19,7 @@ import { import { deliveryTaxonomyGenerator } from './generators/delivery/delivery-taxonomy.generator.js'; import { commonHelper } from './common-helper.js'; import { parse } from 'path'; -import { fileHelper } from './file-helper.js'; +import { fileHelper, fileProcessor } from './file-helper.js'; import { migrationGenerator } from './generators/migration/migration-generator.js'; export async function generateDeliveryModelsAsync(config: IGenerateDeliveryModelsConfig): Promise { @@ -214,9 +214,9 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode }); const outputDir: string = config.outputDir ? `${config.outputDir}/`.replaceAll('//', '/') : `./`; + const migrationFileProcessor = fileProcessor(outputDir); const barrelExportFilename: string = 'index.ts'; - const migrationItemsFolderName: string = `items/`; - const migrationItemsFolderPath: string = `${outputDir}${migrationItemsFolderName}`; + const migrationItemsFolderName: string = `items`; const projectInformation = await getEnvironmentInfoAsync(client); console.log(`Project '${chalk.yellow(projectInformation.name)}'`); @@ -225,7 +225,6 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; console.log(`Module resolution '${chalk.yellow(moduleResolution)}'\n`); const migrationGeneratorObj = migrationGenerator({ - outputDir: outputDir, addTimestamp: config.addTimestamp, addEnvironmentInfo: config.addEnvironmentInfo, environmentData: { @@ -237,39 +236,36 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode } }); - // prepare directories - fileHelper.createDir(migrationItemsFolderPath); - const migrationTypeFile = migrationGeneratorObj.getMigrationTypesFile(`migration-types.ts`); - const migrationItemFiles = migrationGeneratorObj.getmigrationItemFiles(); + const migrationItemFiles = migrationGeneratorObj.getMigrationItemFiles(migrationItemsFolderName); const allFiles = [migrationTypeFile, ...migrationItemFiles]; // create all files on FS for (const file of allFiles) { - await fileHelper.createFileOnFsAsync(file.text, file.filepath, config.formatOptions); + await migrationFileProcessor.createFileOnFsAsync(file.text, file.filename, config.formatOptions); } // migration items barrel - await fileHelper.createFileOnFsAsync( + await migrationFileProcessor.createFileOnFsAsync( commonHelper.getBarrelExportCode({ moduleResolution: moduleResolution, filenames: [ ...migrationItemFiles.map((m) => { - return `./${parse(m.filepath).name}`; + return `./${parse(m.filename).name}`; }) ] }), - `${migrationItemsFolderPath}${barrelExportFilename}`, + `${migrationItemsFolderName}/${barrelExportFilename}`, config.formatOptions ); // main barrel - await fileHelper.createFileOnFsAsync( + await migrationFileProcessor.createFileOnFsAsync( commonHelper.getBarrelExportCode({ moduleResolution: moduleResolution, - filenames: [`./${migrationItemsFolderName}index`, `./${migrationTypeFile.filename}`] + filenames: [`./${migrationItemsFolderName}/index`, `./${migrationTypeFile.filename}`] }), - `${outputDir}${barrelExportFilename}`, + `${barrelExportFilename}`, config.formatOptions ); diff --git a/lib/generators/migration/migration-generator.ts b/lib/generators/migration/migration-generator.ts index 24ebee4..caa164f 100644 --- a/lib/generators/migration/migration-generator.ts +++ b/lib/generators/migration/migration-generator.ts @@ -11,7 +11,6 @@ import { uniqueFilter } from '../../core/index.js'; export interface MigrationGeneratorConfig { addTimestamp: boolean; addEnvironmentInfo: boolean; - outputDir: string; environmentData: { types: ContentTypeModels.ContentType[]; @@ -23,10 +22,16 @@ export interface MigrationGeneratorConfig { } export function migrationGenerator(config: MigrationGeneratorConfig) { + const getMigrationItemType = (type: ContentTypeModels.ContentType, folderName: string): GeneratedFile => { + return { + filename: `${folderName}/${type.codename}.ts`, + text: 'todo' + }; + }; + return { getMigrationTypesFile(filename: string): GeneratedFile { return { - filepath: config.outputDir + filename, filename: filename, text: ` ${getLanguageCodenamesType(config.environmentData.languages)} @@ -38,8 +43,8 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { ` }; }, - getmigrationItemFiles(): GeneratedFile[] { - return []; + getMigrationItemFiles(folderName: string): GeneratedFile[] { + return config.environmentData.types.map((type) => getMigrationItemType(type, folderName)); } }; } diff --git a/sample/migration/items/actor.ts b/sample/migration/items/actor.ts new file mode 100644 index 0000000..3dae4fa --- /dev/null +++ b/sample/migration/items/actor.ts @@ -0,0 +1 @@ +todo; diff --git a/sample/migration/items/index.ts b/sample/migration/items/index.ts index cb0ff5c..79e8008 100644 --- a/sample/migration/items/index.ts +++ b/sample/migration/items/index.ts @@ -1 +1,2 @@ -export {}; +export * from './actor.js'; +export * from './movie.js'; diff --git a/sample/migration/items/movie.ts b/sample/migration/items/movie.ts new file mode 100644 index 0000000..3dae4fa --- /dev/null +++ b/sample/migration/items/movie.ts @@ -0,0 +1 @@ +todo; From 7a915afa827d7e7850dd9583fc83f27b04dc91f0 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 25 Jul 2024 09:57:21 +0200 Subject: [PATCH 005/183] Adds support for generating MigrationItem models --- lib/core/core.utils.ts | 4 + lib/file-helper.ts | 14 +- lib/generator.ts | 8 +- .../migration/migration-generator.ts | 138 ++++++++++++++++-- sample/migration/items/actor.ts | 14 +- sample/migration/items/movie.ts | 19 ++- sample/migration/migration-types.ts | 9 +- 7 files changed, 178 insertions(+), 28 deletions(-) diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 9743204..624fb5a 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -5,3 +5,7 @@ export function exitProgram(data: { readonly message: string }): never { export function uniqueFilter(value: string, index: number, self: string[]) { return self.indexOf(value) === index; } + +export function replaceTsExtensionWithJs(filePath: string): string { + return filePath.replace('.ts', '.js'); +} diff --git a/lib/file-helper.ts b/lib/file-helper.ts index 618c712..5022390 100644 --- a/lib/file-helper.ts +++ b/lib/file-helper.ts @@ -11,18 +11,14 @@ export function fileProcessor(outputDir: string) { formatOptions: Options | undefined ): Promise => { const fullFilePath = `${outputDir.endsWith('/') ? outputDir : `${outputDir}/`}${filePath}`; + let fileContent = text; try { - const contentToStore = await formatHelper.formatCodeAsync(text, formatOptions); - - ensureDirectoryExistence(fullFilePath); - fs.writeFileSync('./' + fullFilePath, contentToStore, {}); - console.log(`Created '${chalk.yellow(fullFilePath)}'`); + fileContent = await formatHelper.formatCodeAsync(fileContent, formatOptions); } catch (error) { console.log(`Failed to format file '${chalk.red(filePath)}'. Skipping prettier for this file.`); - - const contentToStore = text; - - fs.writeFileSync('./' + fullFilePath, contentToStore); + } finally { + ensureDirectoryExistence(fullFilePath); + fs.writeFileSync('./' + fullFilePath, fileContent, {}); console.log(`Created '${chalk.yellow(fullFilePath)}'`); } }; diff --git a/lib/generator.ts b/lib/generator.ts index e3ca228..77c3f82 100644 --- a/lib/generator.ts +++ b/lib/generator.ts @@ -217,6 +217,7 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode const migrationFileProcessor = fileProcessor(outputDir); const barrelExportFilename: string = 'index.ts'; const migrationItemsFolderName: string = `items`; + const migrationTypesFilename: string = `migration-types.ts`; const projectInformation = await getEnvironmentInfoAsync(client); console.log(`Project '${chalk.yellow(projectInformation.name)}'`); @@ -236,8 +237,11 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode } }); - const migrationTypeFile = migrationGeneratorObj.getMigrationTypesFile(`migration-types.ts`); - const migrationItemFiles = migrationGeneratorObj.getMigrationItemFiles(migrationItemsFolderName); + const migrationTypeFile = migrationGeneratorObj.getMigrationTypesFile(migrationTypesFilename); + const migrationItemFiles = migrationGeneratorObj.getMigrationItemFiles( + migrationTypesFilename, + migrationItemsFolderName + ); const allFiles = [migrationTypeFile, ...migrationItemFiles]; // create all files on FS diff --git a/lib/generators/migration/migration-generator.ts b/lib/generators/migration/migration-generator.ts index caa164f..a462cf5 100644 --- a/lib/generators/migration/migration-generator.ts +++ b/lib/generators/migration/migration-generator.ts @@ -1,12 +1,14 @@ import { CollectionModels, + ContentTypeElements, ContentTypeModels, ContentTypeSnippetModels, LanguageModels, WorkflowModels } from '@kontent-ai/management-sdk'; import { GeneratedFile } from '../../common-helper.js'; -import { uniqueFilter } from '../../core/index.js'; +import { replaceTsExtensionWithJs, uniqueFilter } from '../../core/index.js'; +import { textHelper } from '../../text-helper.js'; export interface MigrationGeneratorConfig { addTimestamp: boolean; @@ -21,11 +23,46 @@ export interface MigrationGeneratorConfig { }; } +const migrationTypeNames = { + languageCodenames: 'LanguageCodenames', + collectionCodenames: 'CollectionCodenames', + workflowCodenames: 'WorkflowCodenames', + workflowStepCodenames: 'WorkflowStepCodenames', + contentTypeCodenames: 'ContentTypeCodenames', + contentTypeCodename: 'ContentTypeCodename' +}; + +const migrationImportTypes = { + migrationItemSystem: 'MigrationItemSystem', + migrationElementModels: 'MigrationElementModels', + migrationItem: 'MigrationItem', + system: 'System', + codename: 'Codename' +}; + +const migrationToolkitNpmPackage = '@kontent-ai/migration-toolkit'; + export function migrationGenerator(config: MigrationGeneratorConfig) { - const getMigrationItemType = (type: ContentTypeModels.ContentType, folderName: string): GeneratedFile => { + const getMigrationItemType = ( + type: ContentTypeModels.ContentType, + migrationTypesFilename: string, + folderName: string + ): GeneratedFile => { return { filename: `${folderName}/${type.codename}.ts`, - text: 'todo' + text: ` + import {${migrationImportTypes.migrationItem}, ${migrationImportTypes.migrationElementModels}} from '${migrationToolkitNpmPackage}'; + import {${migrationImportTypes.system}, ${migrationTypeNames.workflowStepCodenames}} from '../${replaceTsExtensionWithJs(migrationTypesFilename)}'; + + export type ${textHelper.toPascalCase(type.name)}Item = ${migrationImportTypes.migrationItem}< + { + ${getFlattenedElements(type, config.environmentData.snippets) + .map((element) => `${element.codename}: ${getElementPropType(element)}`) + .join(',\n')}, + }, + ${migrationImportTypes.system}<'${type.codename}'>, + ${migrationTypeNames.workflowStepCodenames} + >;` }; }; @@ -34,43 +71,116 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { return { filename: filename, text: ` + import {${migrationImportTypes.migrationItemSystem}} from '${migrationToolkitNpmPackage}'; + ${getLanguageCodenamesType(config.environmentData.languages)} ${getContentTypeCodenamesType(config.environmentData.types)} - ${getContentTypeCodenameType()} ${getCollectionCodenamesType(config.environmentData.collections)} ${getWorkflowCodenamesType(config.environmentData.workflows)} ${getWorkflowStepCodenamesType(config.environmentData.workflows)} + ${getSystemType()} ` }; }, - getMigrationItemFiles(folderName: string): GeneratedFile[] { - return config.environmentData.types.map((type) => getMigrationItemType(type, folderName)); + getMigrationItemFiles(migrationTypesFilename: string, folderName: string): GeneratedFile[] { + return config.environmentData.types.map((type) => + getMigrationItemType(type, migrationTypesFilename, folderName) + ); } }; } -function getLanguageCodenamesType(languages: LanguageModels.LanguageModel[]): string { - return `export type LanguageCodenames = ${languages.map((language) => `'${language.codename}'`).join(' | ')};`; +function getFlattenedElements( + type: ContentTypeModels.ContentType, + snippets: ContentTypeSnippetModels.ContentTypeSnippet[] +): ContentTypeElements.ContentTypeElementModel[] { + return type.elements + .filter((element) => { + if (element.type === 'guidelines') { + return false; + } + return true; + }) + .flatMap((element) => { + if (element.type === 'snippet') { + const snippet = snippets.find((snippet) => snippet.id === element.snippet.id); + + if (!snippet) { + throw Error(`Could not find snippet with id '${element.snippet.id}'`); + } + + return snippet.elements; + } + + return element; + }); +} + +function getElementPropType(element: ContentTypeElements.ContentTypeElementModel): string { + if (element.type === 'text') { + return `${migrationImportTypes.migrationElementModels}.TextElement`; + } + if (element.type === 'asset') { + return `${migrationImportTypes.migrationElementModels}.AssetElement`; + } + if (element.type === 'custom') { + return `${migrationImportTypes.migrationElementModels}.CustomElement`; + } + if (element.type === 'date_time') { + return `${migrationImportTypes.migrationElementModels}.DateTimeElement`; + } + if (element.type === 'rich_text') { + return `${migrationImportTypes.migrationElementModels}.RichTextElement`; + } + if (element.type === 'number') { + return `${migrationImportTypes.migrationElementModels}.NumberElement`; + } + if (element.type === 'multiple_choice') { + return `${migrationImportTypes.migrationElementModels}.MultipleChoiceElement`; + } + if (element.type === 'subpages') { + return `${migrationImportTypes.migrationElementModels}.SubpagesElement`; + } + if (element.type === 'taxonomy') { + return `${migrationImportTypes.migrationElementModels}.TaxonomyElement`; + } + if (element.type === 'url_slug') { + return `${migrationImportTypes.migrationElementModels}.UrlSlugElement`; + } + if (element.type === 'modular_content') { + return `${migrationImportTypes.migrationElementModels}.LinkedItemsElement`; + } + + throw Error(`Element type '${element.type}' is not supported.`); } -function getContentTypeCodenameType(): string { - return `export type ContentTypeCodename = Codename;`; +function getSystemType(): string { + return `export type ${migrationImportTypes.system}<${migrationImportTypes.codename} extends ${migrationTypeNames.contentTypeCodenames}> = ${migrationImportTypes.migrationItemSystem}< + ${migrationImportTypes.codename}, + ${migrationTypeNames.languageCodenames}, + ${migrationTypeNames.collectionCodenames}, + ${migrationTypeNames.workflowCodenames} +>;`; +} + +function getLanguageCodenamesType(languages: LanguageModels.LanguageModel[]): string { + return `export type ${migrationTypeNames.languageCodenames} = ${languages.map((language) => `'${language.codename}'`).join(' | ')};`; } function getContentTypeCodenamesType(types: ContentTypeModels.ContentType[]): string { - return `export type ContentTypeCodenames = ${types.map((type) => `'${type.codename}'`).join(' | ')};`; + return `export type ${migrationTypeNames.contentTypeCodenames} = ${types.map((type) => `'${type.codename}'`).join(' | ')};`; } function getWorkflowCodenamesType(workflows: WorkflowModels.Workflow[]): string { - return `export type WorkflowCodenames = ${workflows.map((workflow) => `'${workflow.codename}'`).join(' | ')};`; + return `export type ${migrationTypeNames.workflowCodenames} = ${workflows.map((workflow) => `'${workflow.codename}'`).join(' | ')};`; } function getCollectionCodenamesType(collections: CollectionModels.Collection[]): string { - return `export type CollectionCodenames = ${collections.map((collection) => `'${collection.codename}'`).join(' | ')};`; + return `export type ${migrationTypeNames.collectionCodenames} = ${collections.map((collection) => `'${collection.codename}'`).join(' | ')};`; } function getWorkflowStepCodenamesType(workflows: WorkflowModels.Workflow[]): string { - return `export type WorkflowStepCodenames = ${workflows + return `export type ${migrationTypeNames.workflowStepCodenames} = ${workflows .flatMap((workflow) => [ ...workflow.steps, workflow.publishedStep, diff --git a/sample/migration/items/actor.ts b/sample/migration/items/actor.ts index 3dae4fa..bd9bb3c 100644 --- a/sample/migration/items/actor.ts +++ b/sample/migration/items/actor.ts @@ -1 +1,13 @@ -todo; +import { MigrationItem, MigrationElementModels } from '@kontent-ai/migration-toolkit'; +import { System, WorkflowStepCodenames } from '../migration-types.js'; + +export type ActorItem = MigrationItem< + { + url: MigrationElementModels.UrlSlugElement; + first_name: MigrationElementModels.TextElement; + last_name: MigrationElementModels.TextElement; + photo: MigrationElementModels.AssetElement; + }, + System<'actor'>, + WorkflowStepCodenames +>; diff --git a/sample/migration/items/movie.ts b/sample/migration/items/movie.ts index 3dae4fa..a0e21ef 100644 --- a/sample/migration/items/movie.ts +++ b/sample/migration/items/movie.ts @@ -1 +1,18 @@ -todo; +import { MigrationItem, MigrationElementModels } from '@kontent-ai/migration-toolkit'; +import { System, WorkflowStepCodenames } from '../migration-types.js'; + +export type MovieItem = MigrationItem< + { + title: MigrationElementModels.TextElement; + plot: MigrationElementModels.RichTextElement; + released: MigrationElementModels.DateTimeElement; + length: MigrationElementModels.NumberElement; + poster: MigrationElementModels.AssetElement; + category: MigrationElementModels.MultipleChoiceElement; + stars: MigrationElementModels.LinkedItemsElement; + seoname: MigrationElementModels.UrlSlugElement; + releasecategory: MigrationElementModels.TaxonomyElement; + }, + System<'movie'>, + WorkflowStepCodenames +>; diff --git a/sample/migration/migration-types.ts b/sample/migration/migration-types.ts index 6a15aad..9330d08 100644 --- a/sample/migration/migration-types.ts +++ b/sample/migration/migration-types.ts @@ -1,6 +1,13 @@ +import { MigrationItemSystem } from '@kontent-ai/migration-toolkit'; + export type LanguageCodenames = 'cz' | 'en' | 'German'; export type ContentTypeCodenames = 'actor' | 'movie'; -export type ContentTypeCodename = Codename; export type CollectionCodenames = 'default'; export type WorkflowCodenames = 'default'; export type WorkflowStepCodenames = 'draft' | 'review' | 'ready_to_publish' | 'published' | 'archived' | 'scheduled'; +export type System = MigrationItemSystem< + Codename, + LanguageCodenames, + CollectionCodenames, + WorkflowCodenames +>; From 480a9d1201271bedcde50fd7d0d31e1b349493c2 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 25 Jul 2024 11:11:16 +0200 Subject: [PATCH 006/183] Adds migration Item export type --- .../migration/migration-generator.ts | 53 ++++++++++--------- sample/migration/items/actor.ts | 11 ++-- sample/migration/items/movie.ts | 11 ++-- sample/migration/migration-types.ts | 6 ++- 4 files changed, 44 insertions(+), 37 deletions(-) diff --git a/lib/generators/migration/migration-generator.ts b/lib/generators/migration/migration-generator.ts index a462cf5..434ca82 100644 --- a/lib/generators/migration/migration-generator.ts +++ b/lib/generators/migration/migration-generator.ts @@ -29,14 +29,12 @@ const migrationTypeNames = { workflowCodenames: 'WorkflowCodenames', workflowStepCodenames: 'WorkflowStepCodenames', contentTypeCodenames: 'ContentTypeCodenames', - contentTypeCodename: 'ContentTypeCodename' -}; - -const migrationImportTypes = { migrationItemSystem: 'MigrationItemSystem', migrationElementModels: 'MigrationElementModels', migrationItem: 'MigrationItem', + migrationElements: 'MigrationElements', system: 'System', + item: 'Item', codename: 'Codename' }; @@ -51,17 +49,16 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { return { filename: `${folderName}/${type.codename}.ts`, text: ` - import {${migrationImportTypes.migrationItem}, ${migrationImportTypes.migrationElementModels}} from '${migrationToolkitNpmPackage}'; - import {${migrationImportTypes.system}, ${migrationTypeNames.workflowStepCodenames}} from '../${replaceTsExtensionWithJs(migrationTypesFilename)}'; + import {${migrationTypeNames.migrationElementModels}} from '${migrationToolkitNpmPackage}'; + import {${migrationTypeNames.item}} from '../${replaceTsExtensionWithJs(migrationTypesFilename)}'; - export type ${textHelper.toPascalCase(type.name)}Item = ${migrationImportTypes.migrationItem}< + export type ${textHelper.toPascalCase(type.name)}Item = ${migrationTypeNames.item}< + '${type.codename}', { ${getFlattenedElements(type, config.environmentData.snippets) .map((element) => `${element.codename}: ${getElementPropType(element)}`) .join(',\n')}, - }, - ${migrationImportTypes.system}<'${type.codename}'>, - ${migrationTypeNames.workflowStepCodenames} + } >;` }; }; @@ -71,7 +68,7 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { return { filename: filename, text: ` - import {${migrationImportTypes.migrationItemSystem}} from '${migrationToolkitNpmPackage}'; + import {${migrationTypeNames.migrationItemSystem}, ${migrationTypeNames.migrationItem}, ${migrationTypeNames.migrationElements}} from '${migrationToolkitNpmPackage}'; ${getLanguageCodenamesType(config.environmentData.languages)} ${getContentTypeCodenamesType(config.environmentData.types)} @@ -79,6 +76,7 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { ${getWorkflowCodenamesType(config.environmentData.workflows)} ${getWorkflowStepCodenamesType(config.environmentData.workflows)} ${getSystemType()} + ${getItemType()} ` }; }, @@ -118,45 +116,52 @@ function getFlattenedElements( function getElementPropType(element: ContentTypeElements.ContentTypeElementModel): string { if (element.type === 'text') { - return `${migrationImportTypes.migrationElementModels}.TextElement`; + return `${migrationTypeNames.migrationElementModels}.TextElement`; } if (element.type === 'asset') { - return `${migrationImportTypes.migrationElementModels}.AssetElement`; + return `${migrationTypeNames.migrationElementModels}.AssetElement`; } if (element.type === 'custom') { - return `${migrationImportTypes.migrationElementModels}.CustomElement`; + return `${migrationTypeNames.migrationElementModels}.CustomElement`; } if (element.type === 'date_time') { - return `${migrationImportTypes.migrationElementModels}.DateTimeElement`; + return `${migrationTypeNames.migrationElementModels}.DateTimeElement`; } if (element.type === 'rich_text') { - return `${migrationImportTypes.migrationElementModels}.RichTextElement`; + return `${migrationTypeNames.migrationElementModels}.RichTextElement`; } if (element.type === 'number') { - return `${migrationImportTypes.migrationElementModels}.NumberElement`; + return `${migrationTypeNames.migrationElementModels}.NumberElement`; } if (element.type === 'multiple_choice') { - return `${migrationImportTypes.migrationElementModels}.MultipleChoiceElement`; + return `${migrationTypeNames.migrationElementModels}.MultipleChoiceElement`; } if (element.type === 'subpages') { - return `${migrationImportTypes.migrationElementModels}.SubpagesElement`; + return `${migrationTypeNames.migrationElementModels}.SubpagesElement`; } if (element.type === 'taxonomy') { - return `${migrationImportTypes.migrationElementModels}.TaxonomyElement`; + return `${migrationTypeNames.migrationElementModels}.TaxonomyElement`; } if (element.type === 'url_slug') { - return `${migrationImportTypes.migrationElementModels}.UrlSlugElement`; + return `${migrationTypeNames.migrationElementModels}.UrlSlugElement`; } if (element.type === 'modular_content') { - return `${migrationImportTypes.migrationElementModels}.LinkedItemsElement`; + return `${migrationTypeNames.migrationElementModels}.LinkedItemsElement`; } throw Error(`Element type '${element.type}' is not supported.`); } +function getItemType(): string { + return `export type ${migrationTypeNames.item}< + ${migrationTypeNames.codename} extends ${migrationTypeNames.contentTypeCodenames}, + TElements extends ${migrationTypeNames.migrationElements} = ${migrationTypeNames.migrationElements}, + > = ${migrationTypeNames.migrationItem}, ${migrationTypeNames.workflowStepCodenames}>;`; +} + function getSystemType(): string { - return `export type ${migrationImportTypes.system}<${migrationImportTypes.codename} extends ${migrationTypeNames.contentTypeCodenames}> = ${migrationImportTypes.migrationItemSystem}< - ${migrationImportTypes.codename}, + return `export type ${migrationTypeNames.system}<${migrationTypeNames.codename} extends ${migrationTypeNames.contentTypeCodenames}> = ${migrationTypeNames.migrationItemSystem}< + ${migrationTypeNames.codename}, ${migrationTypeNames.languageCodenames}, ${migrationTypeNames.collectionCodenames}, ${migrationTypeNames.workflowCodenames} diff --git a/sample/migration/items/actor.ts b/sample/migration/items/actor.ts index bd9bb3c..d4c2978 100644 --- a/sample/migration/items/actor.ts +++ b/sample/migration/items/actor.ts @@ -1,13 +1,12 @@ -import { MigrationItem, MigrationElementModels } from '@kontent-ai/migration-toolkit'; -import { System, WorkflowStepCodenames } from '../migration-types.js'; +import { MigrationElementModels } from '@kontent-ai/migration-toolkit'; +import { Item } from '../migration-types.js'; -export type ActorItem = MigrationItem< +export type ActorItem = Item< + 'actor', { url: MigrationElementModels.UrlSlugElement; first_name: MigrationElementModels.TextElement; last_name: MigrationElementModels.TextElement; photo: MigrationElementModels.AssetElement; - }, - System<'actor'>, - WorkflowStepCodenames + } >; diff --git a/sample/migration/items/movie.ts b/sample/migration/items/movie.ts index a0e21ef..a71f67a 100644 --- a/sample/migration/items/movie.ts +++ b/sample/migration/items/movie.ts @@ -1,7 +1,8 @@ -import { MigrationItem, MigrationElementModels } from '@kontent-ai/migration-toolkit'; -import { System, WorkflowStepCodenames } from '../migration-types.js'; +import { MigrationElementModels } from '@kontent-ai/migration-toolkit'; +import { Item } from '../migration-types.js'; -export type MovieItem = MigrationItem< +export type MovieItem = Item< + 'movie', { title: MigrationElementModels.TextElement; plot: MigrationElementModels.RichTextElement; @@ -12,7 +13,5 @@ export type MovieItem = MigrationItem< stars: MigrationElementModels.LinkedItemsElement; seoname: MigrationElementModels.UrlSlugElement; releasecategory: MigrationElementModels.TaxonomyElement; - }, - System<'movie'>, - WorkflowStepCodenames + } >; diff --git a/sample/migration/migration-types.ts b/sample/migration/migration-types.ts index 9330d08..90b728b 100644 --- a/sample/migration/migration-types.ts +++ b/sample/migration/migration-types.ts @@ -1,4 +1,4 @@ -import { MigrationItemSystem } from '@kontent-ai/migration-toolkit'; +import { MigrationItemSystem, MigrationItem, MigrationElements } from '@kontent-ai/migration-toolkit'; export type LanguageCodenames = 'cz' | 'en' | 'German'; export type ContentTypeCodenames = 'actor' | 'movie'; @@ -11,3 +11,7 @@ export type System = MigrationItemSystem< CollectionCodenames, WorkflowCodenames >; +export type Item< + Codename extends ContentTypeCodenames, + TElements extends MigrationElements = MigrationElements +> = MigrationItem, WorkflowStepCodenames>; From 6b85ed2c0eadf79033087d59427c2a8fa2645d10 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 25 Jul 2024 12:49:27 +0200 Subject: [PATCH 007/183] Adds moduleResolution support to migration generator --- lib/common-helper.ts | 6 ++--- lib/core/core.models.ts | 3 +++ lib/core/core.utils.ts | 25 +++++++++++++++++++ lib/generator.ts | 19 +++++++------- .../delivery-content-type.generator.ts | 8 +++--- .../migration/migration-generator.ts | 22 +++++++++++++--- sample/migration/items/actor.ts | 4 +-- sample/migration/migration-types.ts | 2 +- 8 files changed, 66 insertions(+), 23 deletions(-) diff --git a/lib/common-helper.ts b/lib/common-helper.ts index 5901814..086caa9 100644 --- a/lib/common-helper.ts +++ b/lib/common-helper.ts @@ -49,7 +49,7 @@ export class CommonHelper { } getImportStatement(data: { - filePath: string; + filePathOrPackage: string; importValue: string; moduleResolution: ModuleResolution; isExternalLib: boolean; @@ -57,9 +57,9 @@ export class CommonHelper { let resolvedFilePath: string; if (data.moduleResolution === 'nodeNext' && !data.isExternalLib) { - resolvedFilePath = `${data.filePath}.js`; + resolvedFilePath = `${data.filePathOrPackage}.js`; } else { - resolvedFilePath = data.filePath; + resolvedFilePath = data.filePathOrPackage; } return `import { ${data.importValue} } from '${resolvedFilePath}';`; diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index 380ee75..2d843d1 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -1,4 +1,7 @@ export type CliAction = 'delivery' | 'migration'; +export type LibraryType = '@kontent-ai/migration-toolkit'; + +export type LiteralUnion = T | (string & NonNullable); export interface ErrorData { readonly message: string; diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 624fb5a..294832b 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -1,3 +1,6 @@ +import { ModuleResolution } from '../models.js'; +import { LibraryType, LiteralUnion } from './index.js'; + export function exitProgram(data: { readonly message: string }): never { throw Error(data.message); } @@ -9,3 +12,25 @@ export function uniqueFilter(value: string, index: number, self: string[]) { export function replaceTsExtensionWithJs(filePath: string): string { return filePath.replace('.ts', '.js'); } + +export function getFileNameWithoutExtension(filePath: string): string { + const lastDotIndex = filePath.lastIndexOf('.'); + if (lastDotIndex === -1) { + return filePath; + } + return filePath.substring(0, lastDotIndex); +} + +export function getImportStatement(data: { + filePathOrPackage: LiteralUnion; + importValue: string; + moduleResolution: ModuleResolution; +}): string { + const isExternalLib = !data.filePathOrPackage.endsWith('.js') && !data.filePathOrPackage.endsWith('.ts'); + const resolvedFilePath = + data.moduleResolution === 'nodeNext' && !isExternalLib + ? `${getFileNameWithoutExtension(data.filePathOrPackage)}.js` + : data.filePathOrPackage; + + return `import { ${data.importValue} } from '${resolvedFilePath}';`; +} diff --git a/lib/generator.ts b/lib/generator.ts index 77c3f82..f8a1f64 100644 --- a/lib/generator.ts +++ b/lib/generator.ts @@ -227,6 +227,7 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode console.log(`Module resolution '${chalk.yellow(moduleResolution)}'\n`); const migrationGeneratorObj = migrationGenerator({ addTimestamp: config.addTimestamp, + moduleResolution: config.moduleResolution, addEnvironmentInfo: config.addEnvironmentInfo, environmentData: { languages: await getLanguagesAsync(client), @@ -287,7 +288,7 @@ async function getEnvironmentInfoAsync( async function getWorkflowsAsync(client: ManagementClient): Promise { const items = commonHelper.sortAlphabetically((await client.listWorkflows().toPromise()).data, (item) => item.name); - console.log(`Found '${chalk.yellow(items.length.toString())}' workflows`); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' workflows`); return items; } @@ -296,7 +297,7 @@ async function getRolesAsync(client: ManagementClient): Promise item.name ); - console.log(`Found '${chalk.yellow(items.length.toString())}' roles`); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' roles`); return items; } @@ -305,7 +306,7 @@ async function getAssetFoldersAsync(client: ManagementClient): Promise item.name ); - console.log(`Found '${chalk.yellow(items.length.toString())}' asset folders`); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' asset folders`); return items; } @@ -314,7 +315,7 @@ async function getCollectionsAsync(client: ManagementClient): Promise item.name ); - console.log(`Found '${chalk.yellow(items.length.toString())}' collections`); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' collections`); return items; } @@ -323,7 +324,7 @@ async function getWebhooksAsync(client: ManagementClient): Promise item.name ); - console.log(`Found '${chalk.yellow(items.length.toString())}' webhooks`); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' webhooks`); return items; } @@ -332,7 +333,7 @@ async function getLanguagesAsync(client: ManagementClient): Promise item.name ); - console.log(`Found '${chalk.yellow(items.length.toString())}' languages`); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' languages`); return items; } @@ -341,7 +342,7 @@ async function getTypesAsync(client: ManagementClient): Promise item.name ); - console.log(`Found '${chalk.yellow(items.length.toString())}' types`); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' types`); return items; } @@ -350,7 +351,7 @@ async function getSnippetsAsync(client: ManagementClient): Promise item.name ); - console.log(`Found '${chalk.yellow(items.length.toString())}' snippets`); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' snippets`); return items; } @@ -359,6 +360,6 @@ async function getTaxonomiesAsync(client: ManagementClient): Promise item.name ); - console.log(`Found '${chalk.yellow(items.length.toString())}' taxonomies`); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' taxonomies`); return items; } diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index ac8f1c7..cf4da57 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -267,7 +267,7 @@ export class DeliveryContentTypeGenerator { imports.push( commonHelper.getImportStatement({ moduleResolution: data.moduleResolution, - filePath: fileName, + filePathOrPackage: fileName, importValue: `type ${taxonomyName}`, isExternalLib: false }) @@ -299,7 +299,7 @@ export class DeliveryContentTypeGenerator { imports.push( commonHelper.getImportStatement({ moduleResolution: data.moduleResolution, - filePath: filePath, + filePathOrPackage: filePath, importValue: `type ${typeName}`, isExternalLib: false }) @@ -317,7 +317,7 @@ export class DeliveryContentTypeGenerator { imports.push( commonHelper.getImportStatement({ moduleResolution: data.moduleResolution, - filePath: filePath, + filePathOrPackage: filePath, importValue: `type ${typeName}`, isExternalLib: false }) @@ -385,7 +385,7 @@ export class DeliveryContentTypeGenerator { let code = commonHelper.getImportStatement({ moduleResolution: data.moduleResolution, - filePath: this.deliveryNpmPackageName, + filePathOrPackage: this.deliveryNpmPackageName, importValue: `${topLevelImports.join(', ')}`, isExternalLib: true }); diff --git a/lib/generators/migration/migration-generator.ts b/lib/generators/migration/migration-generator.ts index 434ca82..da27bd4 100644 --- a/lib/generators/migration/migration-generator.ts +++ b/lib/generators/migration/migration-generator.ts @@ -7,12 +7,14 @@ import { WorkflowModels } from '@kontent-ai/management-sdk'; import { GeneratedFile } from '../../common-helper.js'; -import { replaceTsExtensionWithJs, uniqueFilter } from '../../core/index.js'; +import { getImportStatement, uniqueFilter } from '../../core/index.js'; import { textHelper } from '../../text-helper.js'; +import { ModuleResolution } from '../../models.js'; export interface MigrationGeneratorConfig { addTimestamp: boolean; addEnvironmentInfo: boolean; + moduleResolution: ModuleResolution; environmentData: { types: ContentTypeModels.ContentType[]; @@ -49,8 +51,16 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { return { filename: `${folderName}/${type.codename}.ts`, text: ` - import {${migrationTypeNames.migrationElementModels}} from '${migrationToolkitNpmPackage}'; - import {${migrationTypeNames.item}} from '../${replaceTsExtensionWithJs(migrationTypesFilename)}'; + ${getImportStatement({ + filePathOrPackage: migrationToolkitNpmPackage, + importValue: migrationTypeNames.migrationElementModels, + moduleResolution: config.moduleResolution + })} + ${getImportStatement({ + filePathOrPackage: `../${migrationTypesFilename}`, + importValue: migrationTypeNames.item, + moduleResolution: config.moduleResolution + })} export type ${textHelper.toPascalCase(type.name)}Item = ${migrationTypeNames.item}< '${type.codename}', @@ -68,7 +78,11 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { return { filename: filename, text: ` - import {${migrationTypeNames.migrationItemSystem}, ${migrationTypeNames.migrationItem}, ${migrationTypeNames.migrationElements}} from '${migrationToolkitNpmPackage}'; + ${getImportStatement({ + filePathOrPackage: migrationToolkitNpmPackage, + importValue: `${migrationTypeNames.migrationItemSystem}, ${migrationTypeNames.migrationItem}, ${migrationTypeNames.migrationElements}`, + moduleResolution: config.moduleResolution + })} ${getLanguageCodenamesType(config.environmentData.languages)} ${getContentTypeCodenamesType(config.environmentData.types)} diff --git a/sample/migration/items/actor.ts b/sample/migration/items/actor.ts index d4c2978..e2ff999 100644 --- a/sample/migration/items/actor.ts +++ b/sample/migration/items/actor.ts @@ -1,5 +1,5 @@ -import { MigrationElementModels } from '@kontent-ai/migration-toolkit'; -import { Item } from '../migration-types.js'; +import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; +import type { Item } from '../migration-types.js'; export type ActorItem = Item< 'actor', diff --git a/sample/migration/migration-types.ts b/sample/migration/migration-types.ts index 90b728b..114548c 100644 --- a/sample/migration/migration-types.ts +++ b/sample/migration/migration-types.ts @@ -1,4 +1,4 @@ -import { MigrationItemSystem, MigrationItem, MigrationElements } from '@kontent-ai/migration-toolkit'; +import type { MigrationItemSystem, MigrationItem, MigrationElements } from '@kontent-ai/migration-toolkit'; export type LanguageCodenames = 'cz' | 'en' | 'German'; export type ContentTypeCodenames = 'actor' | 'movie'; From 45f4e13b04e652b05896d51f1a2051a644ffbcd9 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 25 Jul 2024 12:56:32 +0200 Subject: [PATCH 008/183] imports only types --- lib/core/core.utils.ts | 2 +- sample/migration/items/movie.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 294832b..0bf5e4e 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -32,5 +32,5 @@ export function getImportStatement(data: { ? `${getFileNameWithoutExtension(data.filePathOrPackage)}.js` : data.filePathOrPackage; - return `import { ${data.importValue} } from '${resolvedFilePath}';`; + return `import type { ${data.importValue} } from '${resolvedFilePath}';`; } diff --git a/sample/migration/items/movie.ts b/sample/migration/items/movie.ts index a71f67a..9ce91d2 100644 --- a/sample/migration/items/movie.ts +++ b/sample/migration/items/movie.ts @@ -1,5 +1,5 @@ -import { MigrationElementModels } from '@kontent-ai/migration-toolkit'; -import { Item } from '../migration-types.js'; +import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; +import type { Item } from '../migration-types.js'; export type MovieItem = Item< 'movie', From 272a4b77ad4edc002d22cba8d2c8c6252d888aaa Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 25 Jul 2024 13:04:16 +0200 Subject: [PATCH 009/183] Adds migration related props readonly --- lib/common-helper.ts | 4 +- lib/core/core.models.ts | 4 ++ lib/generator.ts | 32 +++++++------- .../migration/migration-generator.ts | 42 +++++++++---------- lib/models.ts | 16 +++---- 5 files changed, 53 insertions(+), 45 deletions(-) diff --git a/lib/common-helper.ts b/lib/common-helper.ts index 086caa9..595e59a 100644 --- a/lib/common-helper.ts +++ b/lib/common-helper.ts @@ -9,8 +9,8 @@ export interface IGeneratedFile { } export interface GeneratedFile { - filename: string; - text: string; + readonly filename: string; + readonly text: string; } export class CommonHelper { diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index 2d843d1..9157e4f 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -1,6 +1,10 @@ +import { IManagementClient } from '@kontent-ai/management-sdk'; + export type CliAction = 'delivery' | 'migration'; export type LibraryType = '@kontent-ai/migration-toolkit'; +export type GeneratorManagementClient = Readonly>; + export type LiteralUnion = T | (string & NonNullable); export interface ErrorData { diff --git a/lib/generator.ts b/lib/generator.ts index f8a1f64..d5db066 100644 --- a/lib/generator.ts +++ b/lib/generator.ts @@ -7,20 +7,20 @@ import { CollectionModels, ContentTypeModels, ContentTypeSnippetModels, - createManagementClient, EnvironmentModels, LanguageModels, - ManagementClient, RoleModels, TaxonomyModels, WebhookModels, - WorkflowModels + WorkflowModels, + createManagementClient } from '@kontent-ai/management-sdk'; import { deliveryTaxonomyGenerator } from './generators/delivery/delivery-taxonomy.generator.js'; import { commonHelper } from './common-helper.js'; import { parse } from 'path'; import { fileHelper, fileProcessor } from './file-helper.js'; import { migrationGenerator } from './generators/migration/migration-generator.js'; +import { GeneratorManagementClient } from './core/index.js'; export async function generateDeliveryModelsAsync(config: IGenerateDeliveryModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); @@ -278,21 +278,21 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode } async function getEnvironmentInfoAsync( - client: ManagementClient -): Promise { + client: GeneratorManagementClient +): Promise> { const projectInformation = (await client.environmentInformation().toPromise()).data; console.log(`Project '${chalk.yellow(projectInformation.project.name)}'`); console.log(`Environment '${chalk.yellow(projectInformation.project.environment)}'\n`); return projectInformation.project; } -async function getWorkflowsAsync(client: ManagementClient): Promise { +async function getWorkflowsAsync(client: GeneratorManagementClient): Promise { const items = commonHelper.sortAlphabetically((await client.listWorkflows().toPromise()).data, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' workflows`); return items; } -async function getRolesAsync(client: ManagementClient): Promise { +async function getRolesAsync(client: GeneratorManagementClient): Promise { const items = commonHelper.sortAlphabetically( (await client.listRoles().toPromise()).data.roles, (item) => item.name @@ -301,7 +301,9 @@ async function getRolesAsync(client: ManagementClient): Promise { +async function getAssetFoldersAsync( + client: GeneratorManagementClient +): Promise { const items = commonHelper.sortAlphabetically( (await client.listAssetFolders().toPromise()).data.items, (item) => item.name @@ -310,7 +312,7 @@ async function getAssetFoldersAsync(client: ManagementClient): Promise { +async function getCollectionsAsync(client: GeneratorManagementClient): Promise { const items = commonHelper.sortAlphabetically( (await client.listCollections().toPromise()).data.collections, (item) => item.name @@ -319,7 +321,7 @@ async function getCollectionsAsync(client: ManagementClient): Promise { +async function getWebhooksAsync(client: GeneratorManagementClient): Promise { const items = commonHelper.sortAlphabetically( (await client.listWebhooks().toPromise()).data.webhooks, (item) => item.name @@ -328,7 +330,7 @@ async function getWebhooksAsync(client: ManagementClient): Promise { +async function getLanguagesAsync(client: GeneratorManagementClient): Promise { const items = commonHelper.sortAlphabetically( (await client.listLanguages().toAllPromise()).data.items, (item) => item.name @@ -337,7 +339,7 @@ async function getLanguagesAsync(client: ManagementClient): Promise { +async function getTypesAsync(client: GeneratorManagementClient): Promise { const items = commonHelper.sortAlphabetically( (await client.listContentTypes().toAllPromise()).data.items, (item) => item.name @@ -346,7 +348,9 @@ async function getTypesAsync(client: ManagementClient): Promise { +async function getSnippetsAsync( + client: GeneratorManagementClient +): Promise { const items = commonHelper.sortAlphabetically( (await client.listContentTypeSnippets().toAllPromise()).data.items, (item) => item.name @@ -355,7 +359,7 @@ async function getSnippetsAsync(client: ManagementClient): Promise { +async function getTaxonomiesAsync(client: GeneratorManagementClient): Promise { const items = commonHelper.sortAlphabetically( (await client.listTaxonomies().toAllPromise()).data.items, (item) => item.name diff --git a/lib/generators/migration/migration-generator.ts b/lib/generators/migration/migration-generator.ts index da27bd4..16277cd 100644 --- a/lib/generators/migration/migration-generator.ts +++ b/lib/generators/migration/migration-generator.ts @@ -12,16 +12,16 @@ import { textHelper } from '../../text-helper.js'; import { ModuleResolution } from '../../models.js'; export interface MigrationGeneratorConfig { - addTimestamp: boolean; - addEnvironmentInfo: boolean; - moduleResolution: ModuleResolution; - - environmentData: { - types: ContentTypeModels.ContentType[]; - workflows: WorkflowModels.Workflow[]; - languages: LanguageModels.LanguageModel[]; - collections: CollectionModels.Collection[]; - snippets: ContentTypeSnippetModels.ContentTypeSnippet[]; + readonly addTimestamp: boolean; + readonly addEnvironmentInfo: boolean; + readonly moduleResolution: ModuleResolution; + + readonly environmentData: { + readonly types: readonly ContentTypeModels.ContentType[]; + readonly workflows: readonly WorkflowModels.Workflow[]; + readonly languages: readonly LanguageModels.LanguageModel[]; + readonly collections: readonly CollectionModels.Collection[]; + readonly snippets: readonly ContentTypeSnippetModels.ContentTypeSnippet[]; }; } @@ -38,13 +38,13 @@ const migrationTypeNames = { system: 'System', item: 'Item', codename: 'Codename' -}; +} as const; const migrationToolkitNpmPackage = '@kontent-ai/migration-toolkit'; export function migrationGenerator(config: MigrationGeneratorConfig) { const getMigrationItemType = ( - type: ContentTypeModels.ContentType, + type: Readonly, migrationTypesFilename: string, folderName: string ): GeneratedFile => { @@ -103,9 +103,9 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { } function getFlattenedElements( - type: ContentTypeModels.ContentType, - snippets: ContentTypeSnippetModels.ContentTypeSnippet[] -): ContentTypeElements.ContentTypeElementModel[] { + type: Readonly, + snippets: readonly ContentTypeSnippetModels.ContentTypeSnippet[] +): readonly ContentTypeElements.ContentTypeElementModel[] { return type.elements .filter((element) => { if (element.type === 'guidelines') { @@ -128,7 +128,7 @@ function getFlattenedElements( }); } -function getElementPropType(element: ContentTypeElements.ContentTypeElementModel): string { +function getElementPropType(element: Readonly): string { if (element.type === 'text') { return `${migrationTypeNames.migrationElementModels}.TextElement`; } @@ -182,23 +182,23 @@ function getSystemType(): string { >;`; } -function getLanguageCodenamesType(languages: LanguageModels.LanguageModel[]): string { +function getLanguageCodenamesType(languages: readonly LanguageModels.LanguageModel[]): string { return `export type ${migrationTypeNames.languageCodenames} = ${languages.map((language) => `'${language.codename}'`).join(' | ')};`; } -function getContentTypeCodenamesType(types: ContentTypeModels.ContentType[]): string { +function getContentTypeCodenamesType(types: readonly ContentTypeModels.ContentType[]): string { return `export type ${migrationTypeNames.contentTypeCodenames} = ${types.map((type) => `'${type.codename}'`).join(' | ')};`; } -function getWorkflowCodenamesType(workflows: WorkflowModels.Workflow[]): string { +function getWorkflowCodenamesType(workflows: readonly WorkflowModels.Workflow[]): string { return `export type ${migrationTypeNames.workflowCodenames} = ${workflows.map((workflow) => `'${workflow.codename}'`).join(' | ')};`; } -function getCollectionCodenamesType(collections: CollectionModels.Collection[]): string { +function getCollectionCodenamesType(collections: readonly CollectionModels.Collection[]): string { return `export type ${migrationTypeNames.collectionCodenames} = ${collections.map((collection) => `'${collection.codename}'`).join(' | ')};`; } -function getWorkflowStepCodenamesType(workflows: WorkflowModels.Workflow[]): string { +function getWorkflowStepCodenamesType(workflows: readonly WorkflowModels.Workflow[]): string { return `export type ${migrationTypeNames.workflowStepCodenames} = ${workflows .flatMap((workflow) => [ ...workflow.steps, diff --git a/lib/models.ts b/lib/models.ts index 0e8ef9c..ebc6618 100644 --- a/lib/models.ts +++ b/lib/models.ts @@ -47,12 +47,12 @@ export interface ISortConfig { } export interface GenerateMigrationModelsConfig { - addEnvironmentInfo: boolean; - environmentId: string; - addTimestamp: boolean; - apiKey: string; - moduleResolution: ModuleResolution; - outputDir: string; - managementApiUrl?: string; - formatOptions?: Options; + readonly addEnvironmentInfo: boolean; + readonly environmentId: string; + readonly addTimestamp: boolean; + readonly apiKey: string; + readonly moduleResolution: ModuleResolution; + readonly outputDir: string; + readonly managementApiUrl?: string; + readonly formatOptions?: Options; } From 7471be23802fca6c4a9901908cce31d9b80529cb Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 15 Aug 2024 11:18:46 +0200 Subject: [PATCH 010/183] updates deps --- eslint.config.js => eslint.config.mjs | 0 package-lock.json | 940 ++++++++++++-------------- package.json | 24 +- tsconfig.json | 2 +- 4 files changed, 448 insertions(+), 518 deletions(-) rename eslint.config.js => eslint.config.mjs (100%) diff --git a/eslint.config.js b/eslint.config.mjs similarity index 100% rename from eslint.config.js rename to eslint.config.mjs diff --git a/package-lock.json b/package-lock.json index da9aafc..7d81d9c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,10 +9,10 @@ "version": "7.3.0", "license": "MIT", "dependencies": { - "@kontent-ai/delivery-sdk": "14.10.0", - "@kontent-ai/management-sdk": "6.5.0", - "@kontent-ai/migration-toolkit": "1.3.0", - "chalk": "5.0.0", + "@kontent-ai/delivery-sdk": "14.11.0", + "@kontent-ai/management-sdk": "7.2.0", + "@kontent-ai/migration-toolkit": "1.4.0", + "chalk": "5.3.0", "prettier": "3.3.3", "yargs": "17.7.2" }, @@ -21,16 +21,16 @@ }, "devDependencies": { "@types/eslint__js": "8.42.3", - "@types/node": "20.14.11", - "@types/yargs": "17.0.32", - "@typescript-eslint/eslint-plugin": "7.16.1", - "@typescript-eslint/parser": "7.16.1", + "@types/node": "22.3.0", + "@types/yargs": "17.0.33", + "@typescript-eslint/eslint-plugin": "8.1.0", + "@typescript-eslint/parser": "8.1.0", "dotenv-cli": "7.4.2", - "eslint": "8.57.0", + "eslint": "9.9.0", "standard-version": "9.5.0", - "tsx": "4.16.2", - "typescript": "5.5.3", - "typescript-eslint": "7.16.1" + "tsx": "4.17.0", + "typescript": "5.5.4", + "typescript-eslint": "8.1.0" }, "engines": { "node": ">= 20" @@ -145,9 +145,9 @@ } }, "node_modules/@esbuild/aix-ppc64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.21.5.tgz", - "integrity": "sha512-1SDgH6ZSPTlggy1yI6+Dbkiz8xzpHJEVAlF/AM1tHPLsf5STom9rwtjE4hKAF20FfXXNTFqEYXyJNWh1GiZedQ==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.23.0.tgz", + "integrity": "sha512-3sG8Zwa5fMcA9bgqB8AfWPQ+HFke6uD3h1s3RIwUNK8EG7a4buxvuFTs3j1IMs2NXAk9F30C/FF4vxRgQCcmoQ==", "cpu": [ "ppc64" ], @@ -157,13 +157,13 @@ "aix" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/android-arm": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.21.5.tgz", - "integrity": "sha512-vCPvzSjpPHEi1siZdlvAlsPxXl7WbOVUBBAowWug4rJHb68Ox8KualB+1ocNvT5fjv6wpkX6o/iEpbDrf68zcg==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.23.0.tgz", + "integrity": "sha512-+KuOHTKKyIKgEEqKbGTK8W7mPp+hKinbMBeEnNzjJGyFcWsfrXjSTNluJHCY1RqhxFurdD8uNXQDei7qDlR6+g==", "cpu": [ "arm" ], @@ -173,13 +173,13 @@ "android" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/android-arm64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.21.5.tgz", - "integrity": "sha512-c0uX9VAUBQ7dTDCjq+wdyGLowMdtR/GoC2U5IYk/7D1H1JYC0qseD7+11iMP2mRLN9RcCMRcjC4YMclCzGwS/A==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.23.0.tgz", + "integrity": "sha512-EuHFUYkAVfU4qBdyivULuu03FhJO4IJN9PGuABGrFy4vUuzk91P2d+npxHcFdpUnfYKy0PuV+n6bKIpHOB3prQ==", "cpu": [ "arm64" ], @@ -189,13 +189,13 @@ "android" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/android-x64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.21.5.tgz", - "integrity": "sha512-D7aPRUUNHRBwHxzxRvp856rjUHRFW1SdQATKXH2hqA0kAZb1hKmi02OpYRacl0TxIGz/ZmXWlbZgjwWYaCakTA==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.23.0.tgz", + "integrity": "sha512-WRrmKidLoKDl56LsbBMhzTTBxrsVwTKdNbKDalbEZr0tcsBgCLbEtoNthOW6PX942YiYq8HzEnb4yWQMLQuipQ==", "cpu": [ "x64" ], @@ -205,13 +205,13 @@ "android" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/darwin-arm64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.21.5.tgz", - "integrity": "sha512-DwqXqZyuk5AiWWf3UfLiRDJ5EDd49zg6O9wclZ7kUMv2WRFr4HKjXp/5t8JZ11QbQfUS6/cRCKGwYhtNAY88kQ==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.23.0.tgz", + "integrity": "sha512-YLntie/IdS31H54Ogdn+v50NuoWF5BDkEUFpiOChVa9UnKpftgwzZRrI4J132ETIi+D8n6xh9IviFV3eXdxfow==", "cpu": [ "arm64" ], @@ -221,13 +221,13 @@ "darwin" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/darwin-x64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.21.5.tgz", - "integrity": "sha512-se/JjF8NlmKVG4kNIuyWMV/22ZaerB+qaSi5MdrXtd6R08kvs2qCN4C09miupktDitvh8jRFflwGFBQcxZRjbw==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.23.0.tgz", + "integrity": "sha512-IMQ6eme4AfznElesHUPDZ+teuGwoRmVuuixu7sv92ZkdQcPbsNHzutd+rAfaBKo8YK3IrBEi9SLLKWJdEvJniQ==", "cpu": [ "x64" ], @@ -237,13 +237,13 @@ "darwin" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/freebsd-arm64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.21.5.tgz", - "integrity": "sha512-5JcRxxRDUJLX8JXp/wcBCy3pENnCgBR9bN6JsY4OmhfUtIHe3ZW0mawA7+RDAcMLrMIZaf03NlQiX9DGyB8h4g==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.23.0.tgz", + "integrity": "sha512-0muYWCng5vqaxobq6LB3YNtevDFSAZGlgtLoAc81PjUfiFz36n4KMpwhtAd4he8ToSI3TGyuhyx5xmiWNYZFyw==", "cpu": [ "arm64" ], @@ -253,13 +253,13 @@ "freebsd" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/freebsd-x64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.21.5.tgz", - "integrity": "sha512-J95kNBj1zkbMXtHVH29bBriQygMXqoVQOQYA+ISs0/2l3T9/kj42ow2mpqerRBxDJnmkUDCaQT/dfNXWX/ZZCQ==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.23.0.tgz", + "integrity": "sha512-XKDVu8IsD0/q3foBzsXGt/KjD/yTKBCIwOHE1XwiXmrRwrX6Hbnd5Eqn/WvDekddK21tfszBSrE/WMaZh+1buQ==", "cpu": [ "x64" ], @@ -269,13 +269,13 @@ "freebsd" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/linux-arm": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.21.5.tgz", - "integrity": "sha512-bPb5AHZtbeNGjCKVZ9UGqGwo8EUu4cLq68E95A53KlxAPRmUyYv2D6F0uUI65XisGOL1hBP5mTronbgo+0bFcA==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.23.0.tgz", + "integrity": "sha512-SEELSTEtOFu5LPykzA395Mc+54RMg1EUgXP+iw2SJ72+ooMwVsgfuwXo5Fn0wXNgWZsTVHwY2cg4Vi/bOD88qw==", "cpu": [ "arm" ], @@ -285,13 +285,13 @@ "linux" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/linux-arm64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.21.5.tgz", - "integrity": "sha512-ibKvmyYzKsBeX8d8I7MH/TMfWDXBF3db4qM6sy+7re0YXya+K1cem3on9XgdT2EQGMu4hQyZhan7TeQ8XkGp4Q==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.23.0.tgz", + "integrity": "sha512-j1t5iG8jE7BhonbsEg5d9qOYcVZv/Rv6tghaXM/Ug9xahM0nX/H2gfu6X6z11QRTMT6+aywOMA8TDkhPo8aCGw==", "cpu": [ "arm64" ], @@ -301,13 +301,13 @@ "linux" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/linux-ia32": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.21.5.tgz", - "integrity": "sha512-YvjXDqLRqPDl2dvRODYmmhz4rPeVKYvppfGYKSNGdyZkA01046pLWyRKKI3ax8fbJoK5QbxblURkwK/MWY18Tg==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.23.0.tgz", + "integrity": "sha512-P7O5Tkh2NbgIm2R6x1zGJJsnacDzTFcRWZyTTMgFdVit6E98LTxO+v8LCCLWRvPrjdzXHx9FEOA8oAZPyApWUA==", "cpu": [ "ia32" ], @@ -317,13 +317,13 @@ "linux" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/linux-loong64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.21.5.tgz", - "integrity": "sha512-uHf1BmMG8qEvzdrzAqg2SIG/02+4/DHB6a9Kbya0XDvwDEKCoC8ZRWI5JJvNdUjtciBGFQ5PuBlpEOXQj+JQSg==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.23.0.tgz", + "integrity": "sha512-InQwepswq6urikQiIC/kkx412fqUZudBO4SYKu0N+tGhXRWUqAx+Q+341tFV6QdBifpjYgUndV1hhMq3WeJi7A==", "cpu": [ "loong64" ], @@ -333,13 +333,13 @@ "linux" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/linux-mips64el": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.21.5.tgz", - "integrity": "sha512-IajOmO+KJK23bj52dFSNCMsz1QP1DqM6cwLUv3W1QwyxkyIWecfafnI555fvSGqEKwjMXVLokcV5ygHW5b3Jbg==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.23.0.tgz", + "integrity": "sha512-J9rflLtqdYrxHv2FqXE2i1ELgNjT+JFURt/uDMoPQLcjWQA5wDKgQA4t/dTqGa88ZVECKaD0TctwsUfHbVoi4w==", "cpu": [ "mips64el" ], @@ -349,13 +349,13 @@ "linux" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/linux-ppc64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.21.5.tgz", - "integrity": "sha512-1hHV/Z4OEfMwpLO8rp7CvlhBDnjsC3CttJXIhBi+5Aj5r+MBvy4egg7wCbe//hSsT+RvDAG7s81tAvpL2XAE4w==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.23.0.tgz", + "integrity": "sha512-cShCXtEOVc5GxU0fM+dsFD10qZ5UpcQ8AM22bYj0u/yaAykWnqXJDpd77ublcX6vdDsWLuweeuSNZk4yUxZwtw==", "cpu": [ "ppc64" ], @@ -365,13 +365,13 @@ "linux" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/linux-riscv64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.21.5.tgz", - "integrity": "sha512-2HdXDMd9GMgTGrPWnJzP2ALSokE/0O5HhTUvWIbD3YdjME8JwvSCnNGBnTThKGEB91OZhzrJ4qIIxk/SBmyDDA==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.23.0.tgz", + "integrity": "sha512-HEtaN7Y5UB4tZPeQmgz/UhzoEyYftbMXrBCUjINGjh3uil+rB/QzzpMshz3cNUxqXN7Vr93zzVtpIDL99t9aRw==", "cpu": [ "riscv64" ], @@ -381,13 +381,13 @@ "linux" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/linux-s390x": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.21.5.tgz", - "integrity": "sha512-zus5sxzqBJD3eXxwvjN1yQkRepANgxE9lgOW2qLnmr8ikMTphkjgXu1HR01K4FJg8h1kEEDAqDcZQtbrRnB41A==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.23.0.tgz", + "integrity": "sha512-WDi3+NVAuyjg/Wxi+o5KPqRbZY0QhI9TjrEEm+8dmpY9Xir8+HE/HNx2JoLckhKbFopW0RdO2D72w8trZOV+Wg==", "cpu": [ "s390x" ], @@ -397,13 +397,13 @@ "linux" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/linux-x64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.21.5.tgz", - "integrity": "sha512-1rYdTpyv03iycF1+BhzrzQJCdOuAOtaqHTWJZCWvijKD2N5Xu0TtVC8/+1faWqcP9iBCWOmjmhoH94dH82BxPQ==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.23.0.tgz", + "integrity": "sha512-a3pMQhUEJkITgAw6e0bWA+F+vFtCciMjW/LPtoj99MhVt+Mfb6bbL9hu2wmTZgNd994qTAEw+U/r6k3qHWWaOQ==", "cpu": [ "x64" ], @@ -413,13 +413,13 @@ "linux" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/netbsd-x64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.21.5.tgz", - "integrity": "sha512-Woi2MXzXjMULccIwMnLciyZH4nCIMpWQAs049KEeMvOcNADVxo0UBIQPfSmxB3CWKedngg7sWZdLvLczpe0tLg==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.23.0.tgz", + "integrity": "sha512-cRK+YDem7lFTs2Q5nEv/HHc4LnrfBCbH5+JHu6wm2eP+d8OZNoSMYgPZJq78vqQ9g+9+nMuIsAO7skzphRXHyw==", "cpu": [ "x64" ], @@ -429,13 +429,29 @@ "netbsd" ], "engines": { - "node": ">=12" + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.23.0.tgz", + "integrity": "sha512-suXjq53gERueVWu0OKxzWqk7NxiUWSUlrxoZK7usiF50C6ipColGR5qie2496iKGYNLhDZkPxBI3erbnYkU0rQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" } }, "node_modules/@esbuild/openbsd-x64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.21.5.tgz", - "integrity": "sha512-HLNNw99xsvx12lFBUwoT8EVCsSvRNDVxNpjZ7bPn947b8gJPzeHWyNVhFsaerc0n3TsbOINvRP2byTZ5LKezow==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.23.0.tgz", + "integrity": "sha512-6p3nHpby0DM/v15IFKMjAaayFhqnXV52aEmv1whZHX56pdkK+MEaLoQWj+H42ssFarP1PcomVhbsR4pkz09qBg==", "cpu": [ "x64" ], @@ -445,13 +461,13 @@ "openbsd" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/sunos-x64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.21.5.tgz", - "integrity": "sha512-6+gjmFpfy0BHU5Tpptkuh8+uw3mnrvgs+dSPQXQOv3ekbordwnzTVEb4qnIvQcYXq6gzkyTnoZ9dZG+D4garKg==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.23.0.tgz", + "integrity": "sha512-BFelBGfrBwk6LVrmFzCq1u1dZbG4zy/Kp93w2+y83Q5UGYF1d8sCzeLI9NXjKyujjBBniQa8R8PzLFAUrSM9OA==", "cpu": [ "x64" ], @@ -461,13 +477,13 @@ "sunos" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/win32-arm64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.21.5.tgz", - "integrity": "sha512-Z0gOTd75VvXqyq7nsl93zwahcTROgqvuAcYDUr+vOv8uHhNSKROyU961kgtCD1e95IqPKSQKH7tBTslnS3tA8A==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.23.0.tgz", + "integrity": "sha512-lY6AC8p4Cnb7xYHuIxQ6iYPe6MfO2CC43XXKo9nBXDb35krYt7KGhQnOkRGar5psxYkircpCqfbNDB4uJbS2jQ==", "cpu": [ "arm64" ], @@ -477,13 +493,13 @@ "win32" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/win32-ia32": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.21.5.tgz", - "integrity": "sha512-SWXFF1CL2RVNMaVs+BBClwtfZSvDgtL//G/smwAc5oVK/UPu2Gu9tIaRgFmYFFKrmg3SyAjSrElf0TiJ1v8fYA==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.23.0.tgz", + "integrity": "sha512-7L1bHlOTcO4ByvI7OXVI5pNN6HSu6pUQq9yodga8izeuB1KcT2UkHaH6118QJwopExPn0rMHIseCTx1CRo/uNA==", "cpu": [ "ia32" ], @@ -493,13 +509,13 @@ "win32" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/win32-x64": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.21.5.tgz", - "integrity": "sha512-tQd/1efJuzPC6rCFwEvLtci/xNFcTZknmXs98FYDfGE4wP9ClFV98nyKrzJKVPMhdDnjzLhdUyMX4PsQAPjwIw==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.23.0.tgz", + "integrity": "sha512-Arm+WgUFLUATuoxCJcahGuk6Yj9Pzxd6l11Zb/2aAuv5kWWvvfhLFo2fni4uSK5vzlUdCGZ/BdV5tH8klj8p8g==", "cpu": [ "x64" ], @@ -509,7 +525,7 @@ "win32" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@eslint-community/eslint-utils": { @@ -536,30 +552,21 @@ "node": "^12.0.0 || ^14.0.0 || >=16.0.0" } }, - "node_modules/@eslint/eslintrc": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.1.4.tgz", - "integrity": "sha512-269Z39MS6wVJtsoUl10L60WdkhJVdPG24Q4eZTH3nnF6lpvSShEK3wQjDX9JRWAUPvPh7COouPpU9IrqaZFvtQ==", + "node_modules/@eslint/config-array": { + "version": "0.17.1", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.17.1.tgz", + "integrity": "sha512-BlYOpej8AQ8Ev9xVqroV7a02JK3SkBAaN9GfMMH9W6Ch8FlQlkjGw4Ir7+FgYwfirivAf4t+GtzuAxqfukmISA==", "dev": true, "dependencies": { - "ajv": "^6.12.4", - "debug": "^4.3.2", - "espree": "^9.6.0", - "globals": "^13.19.0", - "ignore": "^5.2.0", - "import-fresh": "^3.2.1", - "js-yaml": "^4.1.0", - "minimatch": "^3.1.2", - "strip-json-comments": "^3.1.1" + "@eslint/object-schema": "^2.1.4", + "debug": "^4.3.1", + "minimatch": "^3.1.2" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, - "node_modules/@eslint/eslintrc/node_modules/brace-expansion": { + "node_modules/@eslint/config-array/node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", @@ -569,7 +576,7 @@ "concat-map": "0.0.1" } }, - "node_modules/@eslint/eslintrc/node_modules/minimatch": { + "node_modules/@eslint/config-array/node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", @@ -581,31 +588,30 @@ "node": "*" } }, - "node_modules/@eslint/js": { - "version": "8.57.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.57.0.tgz", - "integrity": "sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==", - "dev": true, - "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - } - }, - "node_modules/@humanwhocodes/config-array": { - "version": "0.11.14", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz", - "integrity": "sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg==", - "deprecated": "Use @eslint/config-array instead", + "node_modules/@eslint/eslintrc": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.1.0.tgz", + "integrity": "sha512-4Bfj15dVJdoy3RfZmmo86RK1Fwzn6SstsvK9JS+BaVKqC6QQQQyXekNaC+g+LKNgkQ+2VhGAzm6hO40AhMR3zQ==", "dev": true, "dependencies": { - "@humanwhocodes/object-schema": "^2.0.2", - "debug": "^4.3.1", - "minimatch": "^3.0.5" + "ajv": "^6.12.4", + "debug": "^4.3.2", + "espree": "^10.0.1", + "globals": "^14.0.0", + "ignore": "^5.2.0", + "import-fresh": "^3.2.1", + "js-yaml": "^4.1.0", + "minimatch": "^3.1.2", + "strip-json-comments": "^3.1.1" }, "engines": { - "node": ">=10.10.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" } }, - "node_modules/@humanwhocodes/config-array/node_modules/brace-expansion": { + "node_modules/@eslint/eslintrc/node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", @@ -615,7 +621,7 @@ "concat-map": "0.0.1" } }, - "node_modules/@humanwhocodes/config-array/node_modules/minimatch": { + "node_modules/@eslint/eslintrc/node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", @@ -627,6 +633,24 @@ "node": "*" } }, + "node_modules/@eslint/js": { + "version": "9.9.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.9.0.tgz", + "integrity": "sha512-hhetes6ZHP3BlXLxmd8K2SNgkhNSi+UcecbnwWKwpP7kyi/uC75DJ1lOOBO3xrC4jyojtGE3YxKZPHfk4yrgug==", + "dev": true, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, + "node_modules/@eslint/object-schema": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-2.1.4.tgz", + "integrity": "sha512-BsWiH1yFGjXXS2yvrf5LyuoSIIbPrGUWob917o+BTKuZ7qJdxX8aJLRxs1fS9n6r7vESrq1OUqb68dANcFXuQQ==", + "dev": true, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, "node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", @@ -640,12 +664,18 @@ "url": "https://github.com/sponsors/nzakas" } }, - "node_modules/@humanwhocodes/object-schema": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.3.tgz", - "integrity": "sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==", - "deprecated": "Use @eslint/object-schema instead", - "dev": true + "node_modules/@humanwhocodes/retry": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.3.0.tgz", + "integrity": "sha512-d2CGZR2o7fS6sWB7DG/3a95bGKQyHMACZ5aW8qGkkqQpUoZV6C0X7Pc7l4ZNMZkfNBf4VWNe9E1jRsf0G146Ew==", + "dev": true, + "engines": { + "node": ">=18.18" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } }, "node_modules/@hutson/parse-repository-url": { "version": "3.0.2", @@ -689,22 +719,22 @@ } }, "node_modules/@kontent-ai/core-sdk": { - "version": "10.6.0", - "resolved": "https://registry.npmjs.org/@kontent-ai/core-sdk/-/core-sdk-10.6.0.tgz", - "integrity": "sha512-l6BU48mGJZ3/ZoS/imav8VKElImeOyNBS8Az6O8FAHxG2kGTZJbHQpcc3+4g0wEG3seWA+W8M+VRUIgPc63zaw==", + "version": "10.7.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/core-sdk/-/core-sdk-10.7.0.tgz", + "integrity": "sha512-NNS1jatzMzp+XBWNc45bcbZjTFTs4szAFJxKn9oj/4p4+ZXucqYXBs88KCUotXmCCcoeUiFAFn8aQUF2aiTM+Q==", "dependencies": { - "axios": "1.7.2" + "axios": "1.7.4" }, "engines": { - "node": ">= 18" + "node": ">= 20" } }, "node_modules/@kontent-ai/delivery-sdk": { - "version": "14.10.0", - "resolved": "https://registry.npmjs.org/@kontent-ai/delivery-sdk/-/delivery-sdk-14.10.0.tgz", - "integrity": "sha512-k6RiWZzJ8TK3bgKjlwWRlKjO5V0frWqxp8RPG4/XvOhOmjXDNNuGBLMYFvAvWsZmEZODZ1KXfR1VGVjcdOq+Kg==", + "version": "14.11.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/delivery-sdk/-/delivery-sdk-14.11.0.tgz", + "integrity": "sha512-Te54qob53ls1Rr/cu8+5zRydHU++JX5Nj9U+RJ2ck9aVqpHvrqpNkuKDc2MoFyzC9tRvfF0w4LdBnWuLtFPrZg==", "dependencies": { - "@kontent-ai/core-sdk": "10.6.0", + "@kontent-ai/core-sdk": "10.7.0", "url-parse": "1.5.10", "uuid": "10.0.0" }, @@ -713,24 +743,24 @@ } }, "node_modules/@kontent-ai/management-sdk": { - "version": "6.5.0", - "resolved": "https://registry.npmjs.org/@kontent-ai/management-sdk/-/management-sdk-6.5.0.tgz", - "integrity": "sha512-ruRrKTYaNVASjrilXMbKnEHDHHvkmA2CO9zMoVjQdR34o7p5Lqp6aImKTIzTRipq2yyjWMW3yDuYRpkpRmAqWw==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/management-sdk/-/management-sdk-7.2.0.tgz", + "integrity": "sha512-vfEzmQDrDdKj+4evxoCjBE/Cpr5FT1L7KdOjwISk5MSaQsUxl8hrBYL7UDo8ln/J5LIO/6aOwxJ7aY4yAwI9yw==", "dependencies": { - "@kontent-ai/core-sdk": "10.6.0", + "@kontent-ai/core-sdk": "10.7.0", "mime": "3.0.0" }, "engines": { - "node": ">= 16" + "node": ">= 20" } }, "node_modules/@kontent-ai/migration-toolkit": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/@kontent-ai/migration-toolkit/-/migration-toolkit-1.3.0.tgz", - "integrity": "sha512-afaYzOtW6OeTv/Z0xUeVGDTV0WcizC3lag7UdQYVMlZ0nhnZssi59dcdwmjXW8H5iCcfhhETWdbm/weQeIEGKg==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/migration-toolkit/-/migration-toolkit-1.4.0.tgz", + "integrity": "sha512-GJc1ucF7tllWceS+ugtqHuHbzVsKvh2nxoKets3nGHQSzrwugS8gSlQ4Q/GdMVK0MvORvE0MTFysqITWVE9cOQ==", "dependencies": { "@kontent-ai-consulting/tools-analytics": "0.0.6", - "@kontent-ai/management-sdk": "6.5.0", + "@kontent-ai/management-sdk": "7.0.0", "browser-or-node": "3.0.0", "bytes": "3.1.2", "chalk": "5.3.0", @@ -751,15 +781,48 @@ "node": ">=20" } }, - "node_modules/@kontent-ai/migration-toolkit/node_modules/chalk": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", - "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", + "node_modules/@kontent-ai/migration-toolkit/node_modules/@kontent-ai/core-sdk": { + "version": "10.6.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/core-sdk/-/core-sdk-10.6.0.tgz", + "integrity": "sha512-l6BU48mGJZ3/ZoS/imav8VKElImeOyNBS8Az6O8FAHxG2kGTZJbHQpcc3+4g0wEG3seWA+W8M+VRUIgPc63zaw==", + "dependencies": { + "axios": "1.7.2" + }, "engines": { - "node": "^12.17.0 || ^14.13 || >=16.0.0" + "node": ">= 18" + } + }, + "node_modules/@kontent-ai/migration-toolkit/node_modules/@kontent-ai/management-sdk": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/management-sdk/-/management-sdk-7.0.0.tgz", + "integrity": "sha512-ADhgxzTjfU2tu9n0sU6W76G9FiFNwpKB3c767UeQU9A+cfmdRqs4onitg+cieMon1u6Bt7fk2iFUCWmZA3JAtA==", + "dependencies": { + "@kontent-ai/core-sdk": "10.6.0", + "mime": "3.0.0" }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" + "engines": { + "node": ">= 20" + } + }, + "node_modules/@kontent-ai/migration-toolkit/node_modules/@kontent-ai/management-sdk/node_modules/mime": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz", + "integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/@kontent-ai/migration-toolkit/node_modules/axios": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", + "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" } }, "node_modules/@kontent-ai/migration-toolkit/node_modules/mime": { @@ -812,9 +875,9 @@ } }, "node_modules/@types/eslint": { - "version": "8.56.10", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.56.10.tgz", - "integrity": "sha512-Shavhk87gCtY2fhXDctcfS3e6FdxWkCx1iUZ9eEUbh7rTqlZT0/IzOkCOVt0fCjcFuZ9FPYfuezTBImfHCDBGQ==", + "version": "9.6.0", + "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-9.6.0.tgz", + "integrity": "sha512-gi6WQJ7cHRgZxtkQEoyHMppPjq9Kxo5Tjn2prSKDSmZrCz8TZ3jSRCeTJm+WoM+oB0WG37bRqLzaaU3q7JypGg==", "dev": true, "dependencies": { "@types/estree": "*", @@ -849,12 +912,12 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.14.11", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.11.tgz", - "integrity": "sha512-kprQpL8MMeszbz6ojB5/tU8PLN4kesnN8Gjzw349rDlNgsSzg90lAVj3llK99Dh7JON+t9AuscPPFW6mPbTnSA==", + "version": "22.3.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.3.0.tgz", + "integrity": "sha512-nrWpWVaDZuaVc5X84xJ0vNrLvomM205oQyLsRt7OHNZbSHslcWsvgFR7O7hire2ZonjLrWBbedmotmIlJDVd6g==", "dev": true, "dependencies": { - "undici-types": "~5.26.4" + "undici-types": "~6.18.2" } }, "node_modules/@types/normalize-package-data": { @@ -864,9 +927,9 @@ "dev": true }, "node_modules/@types/yargs": { - "version": "17.0.32", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.32.tgz", - "integrity": "sha512-xQ67Yc/laOG5uMfX/093MRlGGCIBzZMarVa+gfNKJxWAIgykYpVGkBdbqEzGDDfCrVUj6Hiff4mTZ5BA6TmAog==", + "version": "17.0.33", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.33.tgz", + "integrity": "sha512-WpxBCKWPLr4xSsHgz511rFJAM+wS28w2zEO1QDNY5zM/S8ok70NNfztH0xwhqKyaK0OHCbN98LDAZuy1ctxDkA==", "dev": true, "dependencies": { "@types/yargs-parser": "*" @@ -879,31 +942,31 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "7.16.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.16.1.tgz", - "integrity": "sha512-SxdPak/5bO0EnGktV05+Hq8oatjAYVY3Zh2bye9pGZy6+jwyR3LG3YKkV4YatlsgqXP28BTeVm9pqwJM96vf2A==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.1.0.tgz", + "integrity": "sha512-LlNBaHFCEBPHyD4pZXb35mzjGkuGKXU5eeCA1SxvHfiRES0E82dOounfVpL4DCqYvJEKab0bZIA0gCRpdLKkCw==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "7.16.1", - "@typescript-eslint/type-utils": "7.16.1", - "@typescript-eslint/utils": "7.16.1", - "@typescript-eslint/visitor-keys": "7.16.1", + "@typescript-eslint/scope-manager": "8.1.0", + "@typescript-eslint/type-utils": "8.1.0", + "@typescript-eslint/utils": "8.1.0", + "@typescript-eslint/visitor-keys": "8.1.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", "ts-api-utils": "^1.3.0" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "@typescript-eslint/parser": "^7.0.0", - "eslint": "^8.56.0" + "@typescript-eslint/parser": "^8.0.0 || ^8.0.0-alpha.0", + "eslint": "^8.57.0 || ^9.0.0" }, "peerDependenciesMeta": { "typescript": { @@ -912,26 +975,26 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "7.16.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.16.1.tgz", - "integrity": "sha512-u+1Qx86jfGQ5i4JjK33/FnawZRpsLxRnKzGE6EABZ40KxVT/vWsiZFEBBHjFOljmmV3MBYOHEKi0Jm9hbAOClA==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.1.0.tgz", + "integrity": "sha512-U7iTAtGgJk6DPX9wIWPPOlt1gO57097G06gIcl0N0EEnNw8RGD62c+2/DiP/zL7KrkqnnqF7gtFGR7YgzPllTA==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "7.16.1", - "@typescript-eslint/types": "7.16.1", - "@typescript-eslint/typescript-estree": "7.16.1", - "@typescript-eslint/visitor-keys": "7.16.1", + "@typescript-eslint/scope-manager": "8.1.0", + "@typescript-eslint/types": "8.1.0", + "@typescript-eslint/typescript-estree": "8.1.0", + "@typescript-eslint/visitor-keys": "8.1.0", "debug": "^4.3.4" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "eslint": "^8.56.0" + "eslint": "^8.57.0 || ^9.0.0" }, "peerDependenciesMeta": { "typescript": { @@ -940,16 +1003,16 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "7.16.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.16.1.tgz", - "integrity": "sha512-nYpyv6ALte18gbMz323RM+vpFpTjfNdyakbf3nsLvF43uF9KeNC289SUEW3QLZ1xPtyINJ1dIsZOuWuSRIWygw==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.1.0.tgz", + "integrity": "sha512-DsuOZQji687sQUjm4N6c9xABJa7fjvfIdjqpSIIVOgaENf2jFXiM9hIBZOL3hb6DHK9Nvd2d7zZnoMLf9e0OtQ==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.16.1", - "@typescript-eslint/visitor-keys": "7.16.1" + "@typescript-eslint/types": "8.1.0", + "@typescript-eslint/visitor-keys": "8.1.0" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", @@ -957,26 +1020,23 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "7.16.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.16.1.tgz", - "integrity": "sha512-rbu/H2MWXN4SkjIIyWcmYBjlp55VT+1G3duFOIukTNFxr9PI35pLc2ydwAfejCEitCv4uztA07q0QWanOHC7dA==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.1.0.tgz", + "integrity": "sha512-oLYvTxljVvsMnldfl6jIKxTaU7ok7km0KDrwOt1RHYu6nxlhN3TIx8k5Q52L6wR33nOwDgM7VwW1fT1qMNfFIA==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "7.16.1", - "@typescript-eslint/utils": "7.16.1", + "@typescript-eslint/typescript-estree": "8.1.0", + "@typescript-eslint/utils": "8.1.0", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, - "peerDependencies": { - "eslint": "^8.56.0" - }, "peerDependenciesMeta": { "typescript": { "optional": true @@ -984,12 +1044,12 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "7.16.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.16.1.tgz", - "integrity": "sha512-AQn9XqCzUXd4bAVEsAXM/Izk11Wx2u4H3BAfQVhSfzfDOm/wAON9nP7J5rpkCxts7E5TELmN845xTUCQrD1xIQ==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.1.0.tgz", + "integrity": "sha512-q2/Bxa0gMOu/2/AKALI0tCKbG2zppccnRIRCW6BaaTlRVaPKft4oVYPp7WOPpcnsgbr0qROAVCVKCvIQ0tbWog==", "dev": true, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", @@ -997,13 +1057,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "7.16.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.16.1.tgz", - "integrity": "sha512-0vFPk8tMjj6apaAZ1HlwM8w7jbghC8jc1aRNJG5vN8Ym5miyhTQGMqU++kuBFDNKe9NcPeZ6x0zfSzV8xC1UlQ==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.1.0.tgz", + "integrity": "sha512-NTHhmufocEkMiAord/g++gWKb0Fr34e9AExBRdqgWdVBaKoei2dIyYKD9Q0jBnvfbEA5zaf8plUFMUH6kQ0vGg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.16.1", - "@typescript-eslint/visitor-keys": "7.16.1", + "@typescript-eslint/types": "8.1.0", + "@typescript-eslint/visitor-keys": "8.1.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -1012,7 +1072,7 @@ "ts-api-utils": "^1.3.0" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", @@ -1025,50 +1085,44 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "7.16.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.16.1.tgz", - "integrity": "sha512-WrFM8nzCowV0he0RlkotGDujx78xudsxnGMBHI88l5J8wEhED6yBwaSLP99ygfrzAjsQvcYQ94quDwI0d7E1fA==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.1.0.tgz", + "integrity": "sha512-ypRueFNKTIFwqPeJBfeIpxZ895PQhNyH4YID6js0UoBImWYoSjBsahUn9KMiJXh94uOjVBgHD9AmkyPsPnFwJA==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "7.16.1", - "@typescript-eslint/types": "7.16.1", - "@typescript-eslint/typescript-estree": "7.16.1" + "@typescript-eslint/scope-manager": "8.1.0", + "@typescript-eslint/types": "8.1.0", + "@typescript-eslint/typescript-estree": "8.1.0" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "eslint": "^8.56.0" + "eslint": "^8.57.0 || ^9.0.0" } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "7.16.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.16.1.tgz", - "integrity": "sha512-Qlzzx4sE4u3FsHTPQAAQFJFNOuqtuY0LFrZHwQ8IHK705XxBiWOFkfKRWu6niB7hwfgnwIpO4jTC75ozW1PHWg==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.1.0.tgz", + "integrity": "sha512-ba0lNI19awqZ5ZNKh6wCModMwoZs457StTebQ0q1NP58zSi2F6MOZRXwfKZy+jB78JNJ/WH8GSh2IQNzXX8Nag==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.16.1", + "@typescript-eslint/types": "8.1.0", "eslint-visitor-keys": "^3.4.3" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/@ungap/structured-clone": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", - "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==", - "dev": true - }, "node_modules/acorn": { "version": "8.12.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", @@ -1199,9 +1253,9 @@ } }, "node_modules/axios": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", - "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", + "version": "1.7.4", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.4.tgz", + "integrity": "sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -1308,9 +1362,9 @@ } }, "node_modules/chalk": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.0.0.tgz", - "integrity": "sha512-/duVOqst+luxCQRKEo4bNxinsOQtMP80ZYm7mMqzuh5PociNL0PvmHFvREJ9ueYL2TxlHjBcmLCdmocx9Vg+IQ==", + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", + "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", "engines": { "node": "^12.17.0 || ^14.13 || >=16.0.0" }, @@ -1745,9 +1799,9 @@ } }, "node_modules/debug": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.5.tgz", - "integrity": "sha512-pt0bNEmneDIvdL1Xsd9oDQ/wrQRkXDT4AUWlNZNPKvW5x/jyO9VFXkJUP07vQ2upmw5PlaITaPKc31jK13V+jg==", + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz", + "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==", "dev": true, "dependencies": { "ms": "2.1.2" @@ -1902,18 +1956,6 @@ "node": ">=8" } }, - "node_modules/doctrine": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", - "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", - "dev": true, - "dependencies": { - "esutils": "^2.0.2" - }, - "engines": { - "node": ">=6.0.0" - } - }, "node_modules/dot-prop": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-5.3.0.tgz", @@ -2110,41 +2152,42 @@ } }, "node_modules/esbuild": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.21.5.tgz", - "integrity": "sha512-mg3OPMV4hXywwpoDxu3Qda5xCKQi+vCTZq8S9J/EpkhB2HzKXq4SNFZE3+NK93JYxc8VMSep+lOUSC/RVKaBqw==", + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.23.0.tgz", + "integrity": "sha512-1lvV17H2bMYda/WaFb2jLPeHU3zml2k4/yagNMG8Q/YtfMjCwEUZa2eXXMgZTVSL5q1n4H7sQ0X6CdJDqqeCFA==", "dev": true, "hasInstallScript": true, "bin": { "esbuild": "bin/esbuild" }, "engines": { - "node": ">=12" + "node": ">=18" }, "optionalDependencies": { - "@esbuild/aix-ppc64": "0.21.5", - "@esbuild/android-arm": "0.21.5", - "@esbuild/android-arm64": "0.21.5", - "@esbuild/android-x64": "0.21.5", - "@esbuild/darwin-arm64": "0.21.5", - "@esbuild/darwin-x64": "0.21.5", - "@esbuild/freebsd-arm64": "0.21.5", - "@esbuild/freebsd-x64": "0.21.5", - "@esbuild/linux-arm": "0.21.5", - "@esbuild/linux-arm64": "0.21.5", - "@esbuild/linux-ia32": "0.21.5", - "@esbuild/linux-loong64": "0.21.5", - "@esbuild/linux-mips64el": "0.21.5", - "@esbuild/linux-ppc64": "0.21.5", - "@esbuild/linux-riscv64": "0.21.5", - "@esbuild/linux-s390x": "0.21.5", - "@esbuild/linux-x64": "0.21.5", - "@esbuild/netbsd-x64": "0.21.5", - "@esbuild/openbsd-x64": "0.21.5", - "@esbuild/sunos-x64": "0.21.5", - "@esbuild/win32-arm64": "0.21.5", - "@esbuild/win32-ia32": "0.21.5", - "@esbuild/win32-x64": "0.21.5" + "@esbuild/aix-ppc64": "0.23.0", + "@esbuild/android-arm": "0.23.0", + "@esbuild/android-arm64": "0.23.0", + "@esbuild/android-x64": "0.23.0", + "@esbuild/darwin-arm64": "0.23.0", + "@esbuild/darwin-x64": "0.23.0", + "@esbuild/freebsd-arm64": "0.23.0", + "@esbuild/freebsd-x64": "0.23.0", + "@esbuild/linux-arm": "0.23.0", + "@esbuild/linux-arm64": "0.23.0", + "@esbuild/linux-ia32": "0.23.0", + "@esbuild/linux-loong64": "0.23.0", + "@esbuild/linux-mips64el": "0.23.0", + "@esbuild/linux-ppc64": "0.23.0", + "@esbuild/linux-riscv64": "0.23.0", + "@esbuild/linux-s390x": "0.23.0", + "@esbuild/linux-x64": "0.23.0", + "@esbuild/netbsd-x64": "0.23.0", + "@esbuild/openbsd-arm64": "0.23.0", + "@esbuild/openbsd-x64": "0.23.0", + "@esbuild/sunos-x64": "0.23.0", + "@esbuild/win32-arm64": "0.23.0", + "@esbuild/win32-ia32": "0.23.0", + "@esbuild/win32-x64": "0.23.0" } }, "node_modules/escalade": { @@ -2168,41 +2211,37 @@ } }, "node_modules/eslint": { - "version": "8.57.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.0.tgz", - "integrity": "sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ==", + "version": "9.9.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.9.0.tgz", + "integrity": "sha512-JfiKJrbx0506OEerjK2Y1QlldtBxkAlLxT5OEcRF8uaQ86noDe2k31Vw9rnSWv+MXZHj7OOUV/dA0AhdLFcyvA==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", - "@eslint-community/regexpp": "^4.6.1", - "@eslint/eslintrc": "^2.1.4", - "@eslint/js": "8.57.0", - "@humanwhocodes/config-array": "^0.11.14", + "@eslint-community/regexpp": "^4.11.0", + "@eslint/config-array": "^0.17.1", + "@eslint/eslintrc": "^3.1.0", + "@eslint/js": "9.9.0", "@humanwhocodes/module-importer": "^1.0.1", + "@humanwhocodes/retry": "^0.3.0", "@nodelib/fs.walk": "^1.2.8", - "@ungap/structured-clone": "^1.2.0", "ajv": "^6.12.4", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", "debug": "^4.3.2", - "doctrine": "^3.0.0", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^7.2.2", - "eslint-visitor-keys": "^3.4.3", - "espree": "^9.6.1", - "esquery": "^1.4.2", + "eslint-scope": "^8.0.2", + "eslint-visitor-keys": "^4.0.0", + "espree": "^10.1.0", + "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", - "file-entry-cache": "^6.0.1", + "file-entry-cache": "^8.0.0", "find-up": "^5.0.0", "glob-parent": "^6.0.2", - "globals": "^13.19.0", - "graphemer": "^1.4.0", "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", "is-path-inside": "^3.0.3", - "js-yaml": "^4.1.0", "json-stable-stringify-without-jsonify": "^1.0.1", "levn": "^0.4.1", "lodash.merge": "^4.6.2", @@ -2216,23 +2255,31 @@ "eslint": "bin/eslint.js" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { - "url": "https://opencollective.com/eslint" + "url": "https://eslint.org/donate" + }, + "peerDependencies": { + "jiti": "*" + }, + "peerDependenciesMeta": { + "jiti": { + "optional": true + } } }, "node_modules/eslint-scope": { - "version": "7.2.2", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", - "integrity": "sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg==", + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.0.2.tgz", + "integrity": "sha512-6E4xmrTw5wtxnLA5wYL3WDfhZ/1bUBGOXV0zQvVRDOtrR8D0p6W7fs3JweNYhwRYeGvd/1CKX2se0/2s7Q/nJA==", "dev": true, "dependencies": { "esrecurse": "^4.3.0", "estraverse": "^5.2.0" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "url": "https://opencollective.com/eslint" @@ -2276,6 +2323,18 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, + "node_modules/eslint/node_modules/eslint-visitor-keys": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.0.0.tgz", + "integrity": "sha512-OtIRv/2GyiF6o/d8K7MYKKbXrOUBIK6SfkIRM4Z0dY3w+LiQ0vy3F57m0Z71bjbyeiWFiHJ8brqnmE6H6/jEuw==", + "dev": true, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, "node_modules/eslint/node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -2289,17 +2348,29 @@ } }, "node_modules/espree": { - "version": "9.6.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", - "integrity": "sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==", + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-10.1.0.tgz", + "integrity": "sha512-M1M6CpiE6ffoigIOWYO9UDP8TMUw9kqb21tf+08IgDYjCsOvCuDt4jQcZmoYxx+w7zlKw9/N0KXfto+I8/FrXA==", "dev": true, "dependencies": { - "acorn": "^8.9.0", + "acorn": "^8.12.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^3.4.1" + "eslint-visitor-keys": "^4.0.0" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/espree/node_modules/eslint-visitor-keys": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.0.0.tgz", + "integrity": "sha512-OtIRv/2GyiF6o/d8K7MYKKbXrOUBIK6SfkIRM4Z0dY3w+LiQ0vy3F57m0Z71bjbyeiWFiHJ8brqnmE6H6/jEuw==", + "dev": true, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "url": "https://opencollective.com/eslint" @@ -2427,15 +2498,15 @@ } }, "node_modules/file-entry-cache": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", - "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz", + "integrity": "sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ==", "dev": true, "dependencies": { - "flat-cache": "^3.0.4" + "flat-cache": "^4.0.0" }, "engines": { - "node": "^10.12.0 || >=12.0.0" + "node": ">=16.0.0" } }, "node_modules/fill-range": { @@ -2467,17 +2538,16 @@ } }, "node_modules/flat-cache": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.2.0.tgz", - "integrity": "sha512-CYcENa+FtcUKLmhhqyctpclsq7QF38pKjZHsGNiSQF5r4FtoKDWabFDl3hzaEQMvT1LHEysw5twgLvpYYb4vbw==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-4.0.1.tgz", + "integrity": "sha512-f7ccFPK3SXFHpx15UIGyRJ/FJQctuKZ0zVuN3frBo4HnK3cay9VEW0R6yPYFHC0AgqhukPzKjq22t5DmAyqGyw==", "dev": true, "dependencies": { "flatted": "^3.2.9", - "keyv": "^4.5.3", - "rimraf": "^3.0.2" + "keyv": "^4.5.4" }, "engines": { - "node": "^10.12.0 || >=12.0.0" + "node": ">=16" } }, "node_modules/flatted": { @@ -2526,12 +2596,6 @@ "node": ">= 6" } }, - "node_modules/fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", - "dev": true - }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", @@ -2754,27 +2818,6 @@ "ini": "^1.3.2" } }, - "node_modules/glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "deprecated": "Glob versions prior to v9 are no longer supported", - "dev": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/glob-parent": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", @@ -2787,38 +2830,13 @@ "node": ">=10.13.0" } }, - "node_modules/glob/node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "node_modules/glob/node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, "node_modules/globals": { - "version": "13.24.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", - "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", + "version": "14.0.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz", + "integrity": "sha512-oahGvuMGQlPw/ivIYBjVSrWAfWLBeku5tpPE2fOPLi+WHffIWbuh2tCjhyQhTBPMf5E9jDEH4FOmTYgYwbKwtQ==", "dev": true, - "dependencies": { - "type-fest": "^0.20.2" - }, "engines": { - "node": ">=8" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -2985,9 +3003,9 @@ } }, "node_modules/ignore": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.1.tgz", - "integrity": "sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", + "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", "dev": true, "engines": { "node": ">= 4" @@ -3032,17 +3050,6 @@ "node": ">=8" } }, - "node_modules/inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", - "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", - "dev": true, - "dependencies": { - "once": "^1.3.0", - "wrappy": "1" - } - }, "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", @@ -3613,17 +3620,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/log-symbols/node_modules/chalk": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", - "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", - "engines": { - "node": "^12.17.0 || ^14.13 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, "node_modules/log-symbols/node_modules/is-unicode-supported": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-1.3.0.tgz", @@ -3831,18 +3827,6 @@ "semver": "bin/semver" } }, - "node_modules/meow/node_modules/type-fest": { - "version": "0.18.1", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.18.1.tgz", - "integrity": "sha512-OIAYXk8+ISY+qTOwkHtKqzAuxchoMiD9Udx+FSGQDuiRR+PJKJHc2NJAXlbhkGwTt/4/nKZxELY1w3ReWOL8mw==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -4043,15 +4027,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", - "dev": true, - "dependencies": { - "wrappy": "1" - } - }, "node_modules/onetime": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", @@ -4116,17 +4091,6 @@ "url": "https://github.com/chalk/ansi-regex?sponsor=1" } }, - "node_modules/ora/node_modules/chalk": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", - "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", - "engines": { - "node": "^12.17.0 || ^14.13 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" - } - }, "node_modules/ora/node_modules/strip-ansi": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", @@ -4245,15 +4209,6 @@ "node": ">=8" } }, - "node_modules/path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/path-key": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", @@ -4676,22 +4631,6 @@ "node": ">=0.10.0" } }, - "node_modules/rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "deprecated": "Rimraf versions prior to v4 are no longer supported", - "dev": true, - "dependencies": { - "glob": "^7.1.3" - }, - "bin": { - "rimraf": "bin.js" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -5272,12 +5211,12 @@ } }, "node_modules/tsx": { - "version": "4.16.2", - "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.16.2.tgz", - "integrity": "sha512-C1uWweJDgdtX2x600HjaFaucXTilT7tgUZHbOE4+ypskZ1OP8CRCSDkCxG6Vya9EwaFIVagWwpaVAn5wzypaqQ==", + "version": "4.17.0", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.17.0.tgz", + "integrity": "sha512-eN4mnDA5UMKDt4YZixo9tBioibaMBpoxBkD+rIPAjVmYERSG0/dWEY1CEFuV89CgASlKL499q8AhmkMnnjtOJg==", "dev": true, "dependencies": { - "esbuild": "~0.21.5", + "esbuild": "~0.23.0", "get-tsconfig": "^4.7.5" }, "bin": { @@ -5303,9 +5242,9 @@ } }, "node_modules/type-fest": { - "version": "0.20.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", - "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "version": "0.18.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.18.1.tgz", + "integrity": "sha512-OIAYXk8+ISY+qTOwkHtKqzAuxchoMiD9Udx+FSGQDuiRR+PJKJHc2NJAXlbhkGwTt/4/nKZxELY1w3ReWOL8mw==", "dev": true, "engines": { "node": ">=10" @@ -5321,9 +5260,9 @@ "dev": true }, "node_modules/typescript": { - "version": "5.5.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", - "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==", + "version": "5.5.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", + "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -5334,25 +5273,22 @@ } }, "node_modules/typescript-eslint": { - "version": "7.16.1", - "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-7.16.1.tgz", - "integrity": "sha512-889oE5qELj65q/tGeOSvlreNKhimitFwZqQ0o7PcWC7/lgRkAMknznsCsV8J8mZGTP/Z+cIbX8accf2DE33hrA==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.1.0.tgz", + "integrity": "sha512-prB2U3jXPJLpo1iVLN338Lvolh6OrcCZO+9Yv6AR+tvegPPptYCDBIHiEEUdqRi8gAv2bXNKfMUrgAd2ejn/ow==", "dev": true, "dependencies": { - "@typescript-eslint/eslint-plugin": "7.16.1", - "@typescript-eslint/parser": "7.16.1", - "@typescript-eslint/utils": "7.16.1" + "@typescript-eslint/eslint-plugin": "8.1.0", + "@typescript-eslint/parser": "8.1.0", + "@typescript-eslint/utils": "8.1.0" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, - "peerDependencies": { - "eslint": "^8.56.0" - }, "peerDependenciesMeta": { "typescript": { "optional": true @@ -5360,9 +5296,9 @@ } }, "node_modules/uglify-js": { - "version": "3.19.0", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.19.0.tgz", - "integrity": "sha512-wNKHUY2hYYkf6oSFfhwwiHo4WCHzHmzcXsqXYTN9ja3iApYIFbb2U6ics9hBcYLHcYGQoAlwnZlTrf3oF+BL/Q==", + "version": "3.19.2", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.19.2.tgz", + "integrity": "sha512-S8KA6DDI47nQXJSi2ctQ629YzwOVs+bQML6DAtvy0wgNdpi+0ySpQK0g2pxBq2xfF2z3YCscu7NNA8nXT9PlIQ==", "dev": true, "optional": true, "bin": { @@ -5373,9 +5309,9 @@ } }, "node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "version": "6.18.2", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.18.2.tgz", + "integrity": "sha512-5ruQbENj95yDYJNS3TvcaxPMshV7aizdv/hWYjGIKoANWKjhWNBsr2YEuYZKodQulB1b8l7ILOuDQep3afowQQ==", "dev": true }, "node_modules/uri-js": { @@ -5537,12 +5473,6 @@ "node": ">=8" } }, - "node_modules/wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", - "dev": true - }, "node_modules/xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", diff --git a/package.json b/package.json index 6fc2dda..8d4e5f6 100644 --- a/package.json +++ b/package.json @@ -50,22 +50,22 @@ "dependencies": { "yargs": "17.7.2", "prettier": "3.3.3", - "chalk": "5.0.0", - "@kontent-ai/delivery-sdk": "14.10.0", - "@kontent-ai/management-sdk": "6.5.0", - "@kontent-ai/migration-toolkit": "1.3.0" + "chalk": "5.3.0", + "@kontent-ai/delivery-sdk": "14.11.0", + "@kontent-ai/management-sdk": "7.2.0", + "@kontent-ai/migration-toolkit": "1.4.0" }, "devDependencies": { - "@types/yargs": "17.0.32", + "@types/yargs": "17.0.33", "standard-version": "9.5.0", - "typescript": "5.5.3", - "@types/node": "20.14.11", + "typescript": "5.5.4", + "@types/node": "22.3.0", "@types/eslint__js": "8.42.3", - "@typescript-eslint/eslint-plugin": "7.16.1", - "typescript-eslint": "7.16.1", - "@typescript-eslint/parser": "7.16.1", - "eslint": "8.57.0", - "tsx": "4.16.2", + "@typescript-eslint/eslint-plugin": "8.1.0", + "typescript-eslint": "8.1.0", + "@typescript-eslint/parser": "8.1.0", + "eslint": "9.9.0", + "tsx": "4.17.0", "dotenv-cli": "7.4.2" } } diff --git a/tsconfig.json b/tsconfig.json index b9abb4f..ca52053 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -27,6 +27,6 @@ "typeRoots": ["./node_modules/@types"], "lib": ["esnext"] }, - "include": ["lib/**/*", "sample/**/*", "scripts/**/*", "eslint.config.js"], + "include": ["lib/**/*", "sample/**/*", "scripts/**/*", "eslint.config.mjs"], "exclude": ["node_modules"] } From 65577bb8c84e503b6d32aab14cbae1c4dd8b785d Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 19 Aug 2024 09:05:16 +0200 Subject: [PATCH 011/183] updates deps --- package-lock.json | 107 +++++++++++----------------------------------- package.json | 4 +- 2 files changed, 26 insertions(+), 85 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7d81d9c..c2b4348 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@kontent-ai/delivery-sdk": "14.11.0", "@kontent-ai/management-sdk": "7.2.0", - "@kontent-ai/migration-toolkit": "1.4.0", + "@kontent-ai/migration-toolkit": "1.5.0", "chalk": "5.3.0", "prettier": "3.3.3", "yargs": "17.7.2" @@ -21,7 +21,7 @@ }, "devDependencies": { "@types/eslint__js": "8.42.3", - "@types/node": "22.3.0", + "@types/node": "22.4.1", "@types/yargs": "17.0.33", "@typescript-eslint/eslint-plugin": "8.1.0", "@typescript-eslint/parser": "8.1.0", @@ -687,37 +687,16 @@ } }, "node_modules/@kontent-ai-consulting/tools-analytics": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/@kontent-ai-consulting/tools-analytics/-/tools-analytics-0.0.6.tgz", - "integrity": "sha512-G9sT9udNVYbXiFOhaHPRU/WOgaa4k78lvOMlpIXkJ8WcsPGh3cW+USsAVA7rmBMlUOTVQ/WlHsD/MtTIkbBYsA==", + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/@kontent-ai-consulting/tools-analytics/-/tools-analytics-0.0.7.tgz", + "integrity": "sha512-grkW8hEe4vij3R5uZ0K4DuQiR1HvJhdPqoTF/z/q++8xA2X0X0orgRLbWNgyC9XYuSUiCbojmT64zBJf32RKkw==", "dependencies": { - "@kontent-ai/core-sdk": "10.3.1" + "@kontent-ai/core-sdk": "10.7.0" }, "engines": { "node": ">=16.0.0" } }, - "node_modules/@kontent-ai-consulting/tools-analytics/node_modules/@kontent-ai/core-sdk": { - "version": "10.3.1", - "resolved": "https://registry.npmjs.org/@kontent-ai/core-sdk/-/core-sdk-10.3.1.tgz", - "integrity": "sha512-t51FgHqJhIM1PnEIMGb5773W1waBFUpPgILQ03cUVEbO14nnhbTTpH5Wk1RJb5FV5KO9ONvSorU4uZjmTsxuNA==", - "dependencies": { - "axios": "1.6.2" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/@kontent-ai-consulting/tools-analytics/node_modules/axios": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", - "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", - "dependencies": { - "follow-redirects": "^1.15.0", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/@kontent-ai/core-sdk": { "version": "10.7.0", "resolved": "https://registry.npmjs.org/@kontent-ai/core-sdk/-/core-sdk-10.7.0.tgz", @@ -755,12 +734,12 @@ } }, "node_modules/@kontent-ai/migration-toolkit": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/@kontent-ai/migration-toolkit/-/migration-toolkit-1.4.0.tgz", - "integrity": "sha512-GJc1ucF7tllWceS+ugtqHuHbzVsKvh2nxoKets3nGHQSzrwugS8gSlQ4Q/GdMVK0MvORvE0MTFysqITWVE9cOQ==", + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/migration-toolkit/-/migration-toolkit-1.5.0.tgz", + "integrity": "sha512-PBvzI4Uos38C5AckfKXn0xWtKhHHRMxBtQ6I/7DkhTf4JTinfqIgKECCP7ZK8ksQWNvr6A5mod37ri7RN1tLAA==", "dependencies": { - "@kontent-ai-consulting/tools-analytics": "0.0.6", - "@kontent-ai/management-sdk": "7.0.0", + "@kontent-ai-consulting/tools-analytics": "0.0.7", + "@kontent-ai/management-sdk": "7.2.0", "browser-or-node": "3.0.0", "bytes": "3.1.2", "chalk": "5.3.0", @@ -771,6 +750,7 @@ "ora": "8.0.1", "p-limit": "6.1.0", "prompts": "2.4.2", + "ts-pattern": "5.3.1", "yargs": "17.7.2", "zod": "3.23.8" }, @@ -781,50 +761,6 @@ "node": ">=20" } }, - "node_modules/@kontent-ai/migration-toolkit/node_modules/@kontent-ai/core-sdk": { - "version": "10.6.0", - "resolved": "https://registry.npmjs.org/@kontent-ai/core-sdk/-/core-sdk-10.6.0.tgz", - "integrity": "sha512-l6BU48mGJZ3/ZoS/imav8VKElImeOyNBS8Az6O8FAHxG2kGTZJbHQpcc3+4g0wEG3seWA+W8M+VRUIgPc63zaw==", - "dependencies": { - "axios": "1.7.2" - }, - "engines": { - "node": ">= 18" - } - }, - "node_modules/@kontent-ai/migration-toolkit/node_modules/@kontent-ai/management-sdk": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@kontent-ai/management-sdk/-/management-sdk-7.0.0.tgz", - "integrity": "sha512-ADhgxzTjfU2tu9n0sU6W76G9FiFNwpKB3c767UeQU9A+cfmdRqs4onitg+cieMon1u6Bt7fk2iFUCWmZA3JAtA==", - "dependencies": { - "@kontent-ai/core-sdk": "10.6.0", - "mime": "3.0.0" - }, - "engines": { - "node": ">= 20" - } - }, - "node_modules/@kontent-ai/migration-toolkit/node_modules/@kontent-ai/management-sdk/node_modules/mime": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz", - "integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==", - "bin": { - "mime": "cli.js" - }, - "engines": { - "node": ">=10.0.0" - } - }, - "node_modules/@kontent-ai/migration-toolkit/node_modules/axios": { - "version": "1.7.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.2.tgz", - "integrity": "sha512-2A8QhOMrbomlDuiLeK9XibIBzuHeRcqqNOHp0Cyp5EoJ1IFDh+XZH3A6BkXtv0K4gFGCI0Y4BM7B1wOEi0Rmgw==", - "dependencies": { - "follow-redirects": "^1.15.6", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/@kontent-ai/migration-toolkit/node_modules/mime": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/mime/-/mime-4.0.4.tgz", @@ -912,12 +848,12 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.3.0", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.3.0.tgz", - "integrity": "sha512-nrWpWVaDZuaVc5X84xJ0vNrLvomM205oQyLsRt7OHNZbSHslcWsvgFR7O7hire2ZonjLrWBbedmotmIlJDVd6g==", + "version": "22.4.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.4.1.tgz", + "integrity": "sha512-1tbpb9325+gPnKK0dMm+/LMriX0vKxf6RnB0SZUqfyVkQ4fMgUSySqhxE/y8Jvs4NyF1yHzTfG9KlnkIODxPKg==", "dev": true, "dependencies": { - "undici-types": "~6.18.2" + "undici-types": "~6.19.2" } }, "node_modules/@types/normalize-package-data": { @@ -5210,6 +5146,11 @@ "typescript": ">=4.2.0" } }, + "node_modules/ts-pattern": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/ts-pattern/-/ts-pattern-5.3.1.tgz", + "integrity": "sha512-1RUMKa8jYQdNfmnK4jyzBK3/PS/tnjcZ1CW0v1vWDeYe5RBklc/nquw03MEoB66hVBm4BnlCfmOqDVxHyT1DpA==" + }, "node_modules/tsx": { "version": "4.17.0", "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.17.0.tgz", @@ -5309,9 +5250,9 @@ } }, "node_modules/undici-types": { - "version": "6.18.2", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.18.2.tgz", - "integrity": "sha512-5ruQbENj95yDYJNS3TvcaxPMshV7aizdv/hWYjGIKoANWKjhWNBsr2YEuYZKodQulB1b8l7ILOuDQep3afowQQ==", + "version": "6.19.6", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.6.tgz", + "integrity": "sha512-e/vggGopEfTKSvj4ihnOLTsqhrKRN3LeO6qSN/GxohhuRv8qH9bNQ4B8W7e/vFL+0XTnmHPB4/kegunZGA4Org==", "dev": true }, "node_modules/uri-js": { diff --git a/package.json b/package.json index 8d4e5f6..2eac685 100644 --- a/package.json +++ b/package.json @@ -53,13 +53,13 @@ "chalk": "5.3.0", "@kontent-ai/delivery-sdk": "14.11.0", "@kontent-ai/management-sdk": "7.2.0", - "@kontent-ai/migration-toolkit": "1.4.0" + "@kontent-ai/migration-toolkit": "1.5.0" }, "devDependencies": { "@types/yargs": "17.0.33", "standard-version": "9.5.0", "typescript": "5.5.4", - "@types/node": "22.3.0", + "@types/node": "22.4.1", "@types/eslint__js": "8.42.3", "@typescript-eslint/eslint-plugin": "8.1.0", "typescript-eslint": "8.1.0", From ab968fceb0376ed6d720d929885cae683eb1d1b2 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 19 Aug 2024 09:08:41 +0200 Subject: [PATCH 012/183] updates code samples --- sample/delivery/content-types/actor.ts | 2 +- sample/delivery/content-types/movie.ts | 2 +- sample/delivery/project/assetFolders.ts | 2 +- sample/delivery/project/collections.ts | 2 +- sample/delivery/project/contentTypeSnippets.ts | 2 +- sample/delivery/project/contentTypes.ts | 2 +- sample/delivery/project/languages.ts | 2 +- sample/delivery/project/roles.ts | 2 +- sample/delivery/project/taxonomies.ts | 2 +- sample/delivery/project/webhooks.ts | 2 +- sample/delivery/project/workflows.ts | 2 +- sample/delivery/taxonomies/movietype.ts | 2 +- sample/delivery/taxonomies/releasecategory.ts | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index bf70ade..9ed9753 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -1,6 +1,6 @@ import { type IContentItem, type Elements } from '@kontent-ai/delivery-sdk'; /** - * Generated by '@kontent-ai/model-generator@7.3.0' + * Generated by '@kontent-ai/model-generator@7.4.0' * * Actor * Id: 58099989-319f-495f-aa36-cb3710854e36 diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index c207dbb..989a4f5 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -3,7 +3,7 @@ import { type Actor } from './actor.js'; import { type ReleaseCategory } from '../taxonomies/releasecategory.js'; /** - * Generated by '@kontent-ai/model-generator@7.3.0' + * Generated by '@kontent-ai/model-generator@7.4.0' * * Movie * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c diff --git a/sample/delivery/project/assetFolders.ts b/sample/delivery/project/assetFolders.ts index b0f2148..4782f19 100644 --- a/sample/delivery/project/assetFolders.ts +++ b/sample/delivery/project/assetFolders.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.3.0' + * Generated by '@kontent-ai/model-generator@7.4.0' * * Project name: Movie Database * Environment: Production diff --git a/sample/delivery/project/collections.ts b/sample/delivery/project/collections.ts index 25c73ae..602d351 100644 --- a/sample/delivery/project/collections.ts +++ b/sample/delivery/project/collections.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.3.0' + * Generated by '@kontent-ai/model-generator@7.4.0' * * Project name: Movie Database * Environment: Production diff --git a/sample/delivery/project/contentTypeSnippets.ts b/sample/delivery/project/contentTypeSnippets.ts index ff834c5..6f607e6 100644 --- a/sample/delivery/project/contentTypeSnippets.ts +++ b/sample/delivery/project/contentTypeSnippets.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.3.0' + * Generated by '@kontent-ai/model-generator@7.4.0' * * Project name: Movie Database * Environment: Production diff --git a/sample/delivery/project/contentTypes.ts b/sample/delivery/project/contentTypes.ts index 6cd8dba..5b3e42a 100644 --- a/sample/delivery/project/contentTypes.ts +++ b/sample/delivery/project/contentTypes.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.3.0' + * Generated by '@kontent-ai/model-generator@7.4.0' * * Project name: Movie Database * Environment: Production diff --git a/sample/delivery/project/languages.ts b/sample/delivery/project/languages.ts index 4ffb90c..9c3db8e 100644 --- a/sample/delivery/project/languages.ts +++ b/sample/delivery/project/languages.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.3.0' + * Generated by '@kontent-ai/model-generator@7.4.0' * * Project name: Movie Database * Environment: Production diff --git a/sample/delivery/project/roles.ts b/sample/delivery/project/roles.ts index e8b2c51..52bcdac 100644 --- a/sample/delivery/project/roles.ts +++ b/sample/delivery/project/roles.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.3.0' + * Generated by '@kontent-ai/model-generator@7.4.0' * * Project name: Movie Database * Environment: Production diff --git a/sample/delivery/project/taxonomies.ts b/sample/delivery/project/taxonomies.ts index 33b55ec..6202bf7 100644 --- a/sample/delivery/project/taxonomies.ts +++ b/sample/delivery/project/taxonomies.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.3.0' + * Generated by '@kontent-ai/model-generator@7.4.0' * * Project name: Movie Database * Environment: Production diff --git a/sample/delivery/project/webhooks.ts b/sample/delivery/project/webhooks.ts index 8a669bc..18b2068 100644 --- a/sample/delivery/project/webhooks.ts +++ b/sample/delivery/project/webhooks.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.3.0' + * Generated by '@kontent-ai/model-generator@7.4.0' * * Project name: Movie Database * Environment: Production diff --git a/sample/delivery/project/workflows.ts b/sample/delivery/project/workflows.ts index b76e47e..5f9a296 100644 --- a/sample/delivery/project/workflows.ts +++ b/sample/delivery/project/workflows.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.3.0' + * Generated by '@kontent-ai/model-generator@7.4.0' * * Project name: Movie Database * Environment: Production diff --git a/sample/delivery/taxonomies/movietype.ts b/sample/delivery/taxonomies/movietype.ts index 6d0aa26..57afd78 100644 --- a/sample/delivery/taxonomies/movietype.ts +++ b/sample/delivery/taxonomies/movietype.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.3.0' + * Generated by '@kontent-ai/model-generator@7.4.0' * * MovieType * Id: 365a17e6-1929-27ab-9f67-a9273c846717 diff --git a/sample/delivery/taxonomies/releasecategory.ts b/sample/delivery/taxonomies/releasecategory.ts index 52b0860..9f478c3 100644 --- a/sample/delivery/taxonomies/releasecategory.ts +++ b/sample/delivery/taxonomies/releasecategory.ts @@ -1,5 +1,5 @@ /** - * Generated by '@kontent-ai/model-generator@7.3.0' + * Generated by '@kontent-ai/model-generator@7.4.0' * * ReleaseCategory * Id: 09b6a348-0f86-7a68-4af3-7cab9a5c60b7 From 48b135e90e3fb37696f1ffaed4f6d50eae6c8e50 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 19 Aug 2024 11:47:33 +0200 Subject: [PATCH 013/183] updates deps, adds ts-pattern, adds comments to migration models --- lib/comments/comments.manager.ts | 35 ++++++ lib/comments/index.ts | 1 + lib/core/core.config.ts | 8 ++ lib/core/core.models.ts | 11 +- lib/core/core.utils.ts | 33 +++++ lib/core/element.utils.ts | 53 ++++++++ lib/core/index.ts | 2 + lib/file-helper.ts | 4 +- lib/generator.ts | 25 ++-- .../migration/migration-generator.ts | 113 +++++++++++------- package-lock.json | 1 + package.json | 3 +- .../{migration-types.ts => core.models.ts} | 35 ++++++ sample/migration/index.ts | 2 +- sample/migration/items/actor.ts | 40 ++++++- sample/migration/items/movie.ts | 79 +++++++++++- 16 files changed, 383 insertions(+), 62 deletions(-) create mode 100644 lib/comments/comments.manager.ts create mode 100644 lib/comments/index.ts create mode 100644 lib/core/core.config.ts create mode 100644 lib/core/element.utils.ts rename sample/migration/{migration-types.ts => core.models.ts} (59%) diff --git a/lib/comments/comments.manager.ts b/lib/comments/comments.manager.ts new file mode 100644 index 0000000..aba98a0 --- /dev/null +++ b/lib/comments/comments.manager.ts @@ -0,0 +1,35 @@ +import { EnvironmentModels } from '@kontent-ai/management-sdk'; +import { libMetadata } from '../meta/index.js'; + +export function commentsManager(addTimestamp: boolean) { + const generatedBy = (): string => { + if (addTimestamp) { + return `Generated by '${libMetadata.name}@${libMetadata.version}' at '${new Date().toUTCString()}'`; + } + + return `Generated by '${libMetadata.name}@${libMetadata.version}'`; + }; + + const wrapComment = (comment: string, opts?: { addGeneratedBy: boolean }): string => { + if (opts?.addGeneratedBy) { + return `/** \n * ${generatedBy()} ${comment} \n*/`; + } + return `/** \n * ${comment} \n*/`; + }; + + const environmentInfo = (environmentInfo: Readonly): string => { + return wrapComment( + ` +* ${environmentInfo.name} +* +* Environment: ${environmentInfo.environment} +* Id: ${environmentInfo.id}`, + { addGeneratedBy: true } + ); + }; + + return { + wrapComment, + environmentInfo + }; +} diff --git a/lib/comments/index.ts b/lib/comments/index.ts new file mode 100644 index 0000000..63ec63f --- /dev/null +++ b/lib/comments/index.ts @@ -0,0 +1 @@ +export * from './comments.manager.js'; diff --git a/lib/core/core.config.ts b/lib/core/core.config.ts new file mode 100644 index 0000000..90e6237 --- /dev/null +++ b/lib/core/core.config.ts @@ -0,0 +1,8 @@ +export const coreConfig = { + barrelExportFilename: 'index.ts' +} as const; + +export const migrationConfig = { + migrationItemsFolderName: `items`, + migrationTypesFilename: `core.models.ts` +} as const; diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index 9157e4f..1bb3d2b 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -1,4 +1,4 @@ -import { IManagementClient } from '@kontent-ai/management-sdk'; +import { ElementModels, IManagementClient } from '@kontent-ai/management-sdk'; export type CliAction = 'delivery' | 'migration'; export type LibraryType = '@kontent-ai/migration-toolkit'; @@ -27,3 +27,12 @@ export interface OriginalManagementError { }; }; } + +export interface FlattenedElement { + readonly title: string; + readonly id: string; + readonly codename: string; + readonly type: ElementModels.ElementType; + readonly isRequired: boolean; + readonly guidelines?: string; +} diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 0bf5e4e..81383dd 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -1,3 +1,8 @@ +import { + camelCasePropertyNameResolver, + pascalCasePropertyNameResolver, + snakeCasePropertyNameResolver +} from '@kontent-ai/delivery-sdk'; import { ModuleResolution } from '../models.js'; import { LibraryType, LiteralUnion } from './index.js'; @@ -34,3 +39,31 @@ export function getImportStatement(data: { return `import type { ${data.importValue} } from '${resolvedFilePath}';`; } + +export function toPascalCase(text: string): string { + // use element resolver from SDK to keep it consistent + return toSafeString(pascalCasePropertyNameResolver('', text), 'nothing'); +} + +export function toCamelCase(text: string): string { + // use element resolver from SDK to keep it consistent + return toSafeString(camelCasePropertyNameResolver('', text), 'nothing'); +} + +export function toSnakeCase(text: string): string { + // use element resolver from SDK to keep it consistent + return toSafeString(snakeCasePropertyNameResolver('', text), 'nothing'); +} + +export function toAlphanumeric(value: string): string { + return value.replace(/\W/g, ''); +} + +export function removeLineEndings(value: string): string { + return value.replace(/(\r\n|\n|\r)/gm, ''); +} + +export function toSafeString(text: string, replaceWith: 'space' | 'nothing' = 'nothing'): string { + const replaceContent = replaceWith === 'space' ? ' ' : ''; + return text.replace(/[\s-]/g, replaceContent).replace(/[^a-zA-Z0-9_]/g, replaceContent); +} diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts new file mode 100644 index 0000000..46c2bac --- /dev/null +++ b/lib/core/element.utils.ts @@ -0,0 +1,53 @@ +import { ContentTypeElements, TaxonomyModels } from '@kontent-ai/management-sdk'; +import { FlattenedElement } from './core.models.js'; + +export function getFlattenedElement( + element: Readonly, + taxonomies: readonly Readonly[] +): Readonly | undefined { + if (!element.codename) { + return undefined; + } + if (!element.id) { + return undefined; + } + + return { + title: getElementTitle(element, taxonomies), + codename: element.codename, + id: element.id, + type: element.type, + isRequired: isElementRequired(element), + guidelines: getElementGuidelines(element) + }; +} + +function isElementRequired(element: Readonly): boolean { + return (<{ is_required?: boolean }>element)['is_required'] === true; +} + +function getElementGuidelines(element: Readonly): string | undefined { + return (<{ guidelines?: string }>element)['guidelines']; +} + +function getElementTitle( + element: Readonly, + taxonomies: readonly Readonly[] +): string { + if (element.type === 'taxonomy') { + const taxonomyGroupId = element.taxonomy_group?.id; + + if (!taxonomyGroupId) { + return element.type; + } + + const taxonomy = taxonomies.find((m) => m.id === taxonomyGroupId); + + if (!taxonomy) { + return element.type; + } + + return taxonomy.name; + } + return (<{ name?: string }>element).name ?? element.codename ?? 'n/a'; +} diff --git a/lib/core/index.ts b/lib/core/index.ts index f9d96f3..548cebf 100644 --- a/lib/core/index.ts +++ b/lib/core/index.ts @@ -1,3 +1,5 @@ export * from './core.utils.js'; export * from './error.utils.js'; export * from './core.models.js'; +export * from './element.utils.js'; +export * from './core.config.js'; diff --git a/lib/file-helper.ts b/lib/file-helper.ts index 5022390..c14e04a 100644 --- a/lib/file-helper.ts +++ b/lib/file-helper.ts @@ -14,7 +14,7 @@ export function fileProcessor(outputDir: string) { let fileContent = text; try { fileContent = await formatHelper.formatCodeAsync(fileContent, formatOptions); - } catch (error) { + } catch { console.log(`Failed to format file '${chalk.red(filePath)}'. Skipping prettier for this file.`); } finally { ensureDirectoryExistence(fullFilePath); @@ -51,7 +51,7 @@ export class FileHelper { this.ensureDirectoryExistence(fullFilePath); fs.writeFileSync('./' + fullFilePath, contentToStore, {}); console.log(`Created '${chalk.yellow(fullFilePath)}'`); - } catch (error) { + } catch { console.log(`Failed to format file '${chalk.red(filePath)}'. Skipping prettier for this file.`); const contentToStore = text; diff --git a/lib/generator.ts b/lib/generator.ts index d5db066..7d6f47b 100644 --- a/lib/generator.ts +++ b/lib/generator.ts @@ -19,8 +19,8 @@ import { deliveryTaxonomyGenerator } from './generators/delivery/delivery-taxono import { commonHelper } from './common-helper.js'; import { parse } from 'path'; import { fileHelper, fileProcessor } from './file-helper.js'; -import { migrationGenerator } from './generators/migration/migration-generator.js'; -import { GeneratorManagementClient } from './core/index.js'; +import { migrationGenerator as _migrationGenerator } from './generators/migration/migration-generator.js'; +import { coreConfig, GeneratorManagementClient, migrationConfig, toSafeString } from './core/index.js'; export async function generateDeliveryModelsAsync(config: IGenerateDeliveryModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); @@ -215,21 +215,22 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode const outputDir: string = config.outputDir ? `${config.outputDir}/`.replaceAll('//', '/') : `./`; const migrationFileProcessor = fileProcessor(outputDir); - const barrelExportFilename: string = 'index.ts'; - const migrationItemsFolderName: string = `items`; - const migrationTypesFilename: string = `migration-types.ts`; + const migrationItemsFolderName: string = migrationConfig.migrationItemsFolderName; + const migrationTypesFilename: string = migrationConfig.migrationTypesFilename; const projectInformation = await getEnvironmentInfoAsync(client); - console.log(`Project '${chalk.yellow(projectInformation.name)}'`); - console.log(`Environment '${chalk.yellow(projectInformation.environment)}'\n`); + console.log(`Project '${chalk.yellow(toSafeString(projectInformation.name))}'`); + console.log(`Environment '${chalk.yellow(toSafeString(projectInformation.environment))}'\n`); const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; console.log(`Module resolution '${chalk.yellow(moduleResolution)}'\n`); - const migrationGeneratorObj = migrationGenerator({ + const migrationGenerator = _migrationGenerator({ addTimestamp: config.addTimestamp, moduleResolution: config.moduleResolution, addEnvironmentInfo: config.addEnvironmentInfo, environmentData: { + environment: projectInformation, + taxonomies: await getTaxonomiesAsync(client), languages: await getLanguagesAsync(client), workflows: await getWorkflowsAsync(client), types: await getTypesAsync(client), @@ -238,8 +239,8 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode } }); - const migrationTypeFile = migrationGeneratorObj.getMigrationTypesFile(migrationTypesFilename); - const migrationItemFiles = migrationGeneratorObj.getMigrationItemFiles( + const migrationTypeFile = migrationGenerator.getMigrationTypesFile(migrationTypesFilename); + const migrationItemFiles = migrationGenerator.getMigrationItemFiles( migrationTypesFilename, migrationItemsFolderName ); @@ -260,7 +261,7 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode }) ] }), - `${migrationItemsFolderName}/${barrelExportFilename}`, + `${migrationItemsFolderName}/${coreConfig.barrelExportFilename}`, config.formatOptions ); @@ -270,7 +271,7 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode moduleResolution: moduleResolution, filenames: [`./${migrationItemsFolderName}/index`, `./${migrationTypeFile.filename}`] }), - `${barrelExportFilename}`, + `${coreConfig.barrelExportFilename}`, config.formatOptions ); diff --git a/lib/generators/migration/migration-generator.ts b/lib/generators/migration/migration-generator.ts index 16277cd..e08de90 100644 --- a/lib/generators/migration/migration-generator.ts +++ b/lib/generators/migration/migration-generator.ts @@ -1,15 +1,20 @@ import { CollectionModels, - ContentTypeElements, ContentTypeModels, ContentTypeSnippetModels, + EnvironmentModels, LanguageModels, + TaxonomyModels, WorkflowModels } from '@kontent-ai/management-sdk'; import { GeneratedFile } from '../../common-helper.js'; -import { getImportStatement, uniqueFilter } from '../../core/index.js'; +import { FlattenedElement, getImportStatement, toSafeString, uniqueFilter } from '../../core/index.js'; import { textHelper } from '../../text-helper.js'; import { ModuleResolution } from '../../models.js'; +import { commentsManager as _commentsManager } from '../../comments/index.js'; +import { match } from 'ts-pattern'; +import { isNotUndefined } from '@kontent-ai/migration-toolkit'; +import { getFlattenedElement } from 'lib/core/element.utils.js'; export interface MigrationGeneratorConfig { readonly addTimestamp: boolean; @@ -17,11 +22,13 @@ export interface MigrationGeneratorConfig { readonly moduleResolution: ModuleResolution; readonly environmentData: { + readonly environment: Readonly; readonly types: readonly ContentTypeModels.ContentType[]; readonly workflows: readonly WorkflowModels.Workflow[]; readonly languages: readonly LanguageModels.LanguageModel[]; readonly collections: readonly CollectionModels.Collection[]; readonly snippets: readonly ContentTypeSnippetModels.ContentTypeSnippet[]; + readonly taxonomies: readonly TaxonomyModels.Taxonomy[]; }; } @@ -43,6 +50,8 @@ const migrationTypeNames = { const migrationToolkitNpmPackage = '@kontent-ai/migration-toolkit'; export function migrationGenerator(config: MigrationGeneratorConfig) { + const commentsManager = _commentsManager(config.addTimestamp); + const getMigrationItemType = ( type: Readonly, migrationTypesFilename: string, @@ -62,11 +71,27 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { moduleResolution: config.moduleResolution })} + /** + * ${toSafeString(type.name)} + * + * Codename: ${type.codename} + * Id: ${type.id} + */ export type ${textHelper.toPascalCase(type.name)}Item = ${migrationTypeNames.item}< '${type.codename}', { - ${getFlattenedElements(type, config.environmentData.snippets) - .map((element) => `${element.codename}: ${getElementPropType(element)}`) + ${getFlattenedElements(type, config.environmentData.snippets, config.environmentData.taxonomies) + .map((element) => { + return ` + /** + * ${toSafeString(element.title)} (${element.type}) + * + * Required: ${element.isRequired ? 'true' : 'false'} + * Id: ${element.id} + * Codename: ${element.codename}${element.guidelines ? `\n* Guidelines: ${textHelper.removeLineEndings(element.guidelines)}` : ''} + */ + ${element.codename}: ${getElementPropType(element)}`; + }) .join(',\n')}, } >;` @@ -84,12 +109,27 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { moduleResolution: config.moduleResolution })} + ${commentsManager.environmentInfo(config.environmentData.environment)} + + ${commentsManager.wrapComment('Type representing all languages')} ${getLanguageCodenamesType(config.environmentData.languages)} + + ${commentsManager.wrapComment('Type representing all content types')} ${getContentTypeCodenamesType(config.environmentData.types)} + + ${commentsManager.wrapComment('Type representing all collections')} ${getCollectionCodenamesType(config.environmentData.collections)} + + ${commentsManager.wrapComment('Type representing all workflows')} ${getWorkflowCodenamesType(config.environmentData.workflows)} + + ${commentsManager.wrapComment('Type representing all worksflow steps across all workflows')} ${getWorkflowStepCodenamesType(config.environmentData.workflows)} + + ${commentsManager.wrapComment('System object shared by all individual content type models')} ${getSystemType()} + + ${commentsManager.wrapComment('Item object shared by all individual content type models')} ${getItemType()} ` }; @@ -104,13 +144,15 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { function getFlattenedElements( type: Readonly, - snippets: readonly ContentTypeSnippetModels.ContentTypeSnippet[] -): readonly ContentTypeElements.ContentTypeElementModel[] { + snippets: readonly ContentTypeSnippetModels.ContentTypeSnippet[], + taxonomies: readonly Readonly[] +): readonly FlattenedElement[] { return type.elements .filter((element) => { if (element.type === 'guidelines') { return false; } + return true; }) .flatMap((element) => { @@ -125,45 +167,30 @@ function getFlattenedElements( } return element; - }); + }) + .map((element) => { + return getFlattenedElement(element, taxonomies); + }) + .filter(isNotUndefined); } -function getElementPropType(element: Readonly): string { - if (element.type === 'text') { - return `${migrationTypeNames.migrationElementModels}.TextElement`; - } - if (element.type === 'asset') { - return `${migrationTypeNames.migrationElementModels}.AssetElement`; - } - if (element.type === 'custom') { - return `${migrationTypeNames.migrationElementModels}.CustomElement`; - } - if (element.type === 'date_time') { - return `${migrationTypeNames.migrationElementModels}.DateTimeElement`; - } - if (element.type === 'rich_text') { - return `${migrationTypeNames.migrationElementModels}.RichTextElement`; - } - if (element.type === 'number') { - return `${migrationTypeNames.migrationElementModels}.NumberElement`; - } - if (element.type === 'multiple_choice') { - return `${migrationTypeNames.migrationElementModels}.MultipleChoiceElement`; - } - if (element.type === 'subpages') { - return `${migrationTypeNames.migrationElementModels}.SubpagesElement`; - } - if (element.type === 'taxonomy') { - return `${migrationTypeNames.migrationElementModels}.TaxonomyElement`; - } - if (element.type === 'url_slug') { - return `${migrationTypeNames.migrationElementModels}.UrlSlugElement`; - } - if (element.type === 'modular_content') { - return `${migrationTypeNames.migrationElementModels}.LinkedItemsElement`; - } - - throw Error(`Element type '${element.type}' is not supported.`); +function getElementPropType(element: Readonly): string { + return match(element.type) + .returnType() + .with('text', () => `${migrationTypeNames.migrationElementModels}.TextElement`) + .with('asset', () => `${migrationTypeNames.migrationElementModels}.AssetElement`) + .with('custom', () => `${migrationTypeNames.migrationElementModels}.CustomElement`) + .with('date_time', () => `${migrationTypeNames.migrationElementModels}.DateTimeElement`) + .with('rich_text', () => `${migrationTypeNames.migrationElementModels}.RichTextElement`) + .with('number', () => `${migrationTypeNames.migrationElementModels}.NumberElement`) + .with('multiple_choice', () => `${migrationTypeNames.migrationElementModels}.MultipleChoiceElement`) + .with('subpages', () => `${migrationTypeNames.migrationElementModels}.SubpagesElement`) + .with('taxonomy', () => `${migrationTypeNames.migrationElementModels}.TaxonomyElement`) + .with('url_slug', () => `${migrationTypeNames.migrationElementModels}.UrlSlugElement`) + .with('modular_content', () => `${migrationTypeNames.migrationElementModels}.LinkedItemsElement`) + .otherwise((type) => { + throw Error(`Element type '${type}' is not supported.`); + }); } function getItemType(): string { diff --git a/package-lock.json b/package-lock.json index c2b4348..c13f338 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@kontent-ai/migration-toolkit": "1.5.0", "chalk": "5.3.0", "prettier": "3.3.3", + "ts-pattern": "5.3.1", "yargs": "17.7.2" }, "bin": { diff --git a/package.json b/package.json index 2eac685..85a96ec 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "chalk": "5.3.0", "@kontent-ai/delivery-sdk": "14.11.0", "@kontent-ai/management-sdk": "7.2.0", - "@kontent-ai/migration-toolkit": "1.5.0" + "@kontent-ai/migration-toolkit": "1.5.0", + "ts-pattern": "5.3.1" }, "devDependencies": { "@types/yargs": "17.0.33", diff --git a/sample/migration/migration-types.ts b/sample/migration/core.models.ts similarity index 59% rename from sample/migration/migration-types.ts rename to sample/migration/core.models.ts index 114548c..e48ab95 100644 --- a/sample/migration/migration-types.ts +++ b/sample/migration/core.models.ts @@ -1,16 +1,51 @@ import type { MigrationItemSystem, MigrationItem, MigrationElements } from '@kontent-ai/migration-toolkit'; +/** + * Generated by '@kontent-ai/model-generator@7.4.0' + * Movie Database + * + * Environment: Production + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + */ + +/** + * Type representing all languages + */ export type LanguageCodenames = 'cz' | 'en' | 'German'; + +/** + * Type representing all content types + */ export type ContentTypeCodenames = 'actor' | 'movie'; + +/** + * Type representing all collections + */ export type CollectionCodenames = 'default'; + +/** + * Type representing all workflows + */ export type WorkflowCodenames = 'default'; + +/** + * Type representing all worksflow steps across all workflows + */ export type WorkflowStepCodenames = 'draft' | 'review' | 'ready_to_publish' | 'published' | 'archived' | 'scheduled'; + +/** + * System object shared by all individual content type models + */ export type System = MigrationItemSystem< Codename, LanguageCodenames, CollectionCodenames, WorkflowCodenames >; + +/** + * Item object shared by all individual content type models + */ export type Item< Codename extends ContentTypeCodenames, TElements extends MigrationElements = MigrationElements diff --git a/sample/migration/index.ts b/sample/migration/index.ts index 3347667..e83ebaf 100644 --- a/sample/migration/index.ts +++ b/sample/migration/index.ts @@ -1,2 +1,2 @@ export * from './items/index.js'; -export * from './migration-types.js'; +export * from './core.models.js'; diff --git a/sample/migration/items/actor.ts b/sample/migration/items/actor.ts index e2ff999..067b655 100644 --- a/sample/migration/items/actor.ts +++ b/sample/migration/items/actor.ts @@ -1,12 +1,50 @@ import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; -import type { Item } from '../migration-types.js'; +import type { Item } from '../core.models.js'; +/** + * Actor + * + * Codename: actor + * Id: 58099989-319f-495f-aa36-cb3710854e36 + */ export type ActorItem = Item< 'actor', { + /** + * Url (url_slug) + * + * Required: false + * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 + * Codename: url + */ url: MigrationElementModels.UrlSlugElement; + + /** + * Firstname (text) + * + * Required: true + * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d + * Codename: first_name + * Guidelines: This is the first name of the actor + */ first_name: MigrationElementModels.TextElement; + + /** + * Lastname (text) + * + * Required: true + * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 + * Codename: last_name + */ last_name: MigrationElementModels.TextElement; + + /** + * Photo (asset) + * + * Required: false + * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 + * Codename: photo + */ photo: MigrationElementModels.AssetElement; } >; diff --git a/sample/migration/items/movie.ts b/sample/migration/items/movie.ts index 9ce91d2..9b7a265 100644 --- a/sample/migration/items/movie.ts +++ b/sample/migration/items/movie.ts @@ -1,17 +1,94 @@ import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; -import type { Item } from '../migration-types.js'; +import type { Item } from '../core.models.js'; +/** + * Movie + * + * Codename: movie + * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c + */ export type MovieItem = Item< 'movie', { + /** + * Title (text) + * + * Required: true + * Id: 3473187e-dc78-eff2-7099-f690f7042d4a + * Codename: title + */ title: MigrationElementModels.TextElement; + + /** + * Plot (rich_text) + * + * Required: false + * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce + * Codename: plot + */ plot: MigrationElementModels.RichTextElement; + + /** + * Released (date_time) + * + * Required: false + * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 + * Codename: released + */ released: MigrationElementModels.DateTimeElement; + + /** + * Length (number) + * + * Required: false + * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c + * Codename: length + */ length: MigrationElementModels.NumberElement; + + /** + * Poster (asset) + * + * Required: false + * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d + * Codename: poster + */ poster: MigrationElementModels.AssetElement; + + /** + * Category (multiple_choice) + * + * Required: false + * Id: 9821c252-6414-f549-c17f-cc171dd87713 + * Codename: category + */ category: MigrationElementModels.MultipleChoiceElement; + + /** + * Stars (modular_content) + * + * Required: false + * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 + * Codename: stars + */ stars: MigrationElementModels.LinkedItemsElement; + + /** + * SeoName (url_slug) + * + * Required: false + * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c + * Codename: seoname + */ seoname: MigrationElementModels.UrlSlugElement; + + /** + * ReleaseCategory (taxonomy) + * + * Required: false + * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 + * Codename: releasecategory + */ releasecategory: MigrationElementModels.TaxonomyElement; } >; From 3e1c145ab285866b5eda8fba57c819081cbe1003 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 19 Aug 2024 14:09:04 +0200 Subject: [PATCH 014/183] Implements migration action and separates it from main generator --- lib/fetch/index.ts | 1 + lib/fetch/kontent-fetcher.ts | 111 ++++++++++ lib/generator.ts | 205 ++---------------- lib/generators/index.ts | 9 + lib/generators/migration/migration-func.ts | 81 +++++++ .../migration/migration-generator.ts | 4 +- lib/index.ts | 2 +- lib/models.ts | 2 +- lib/node/cli/actions/migrate-action.ts | 18 +- lib/node/cli/app.ts | 2 +- sample/migration/items/actor.ts | 8 +- sample/migration/items/movie.ts | 18 +- 12 files changed, 251 insertions(+), 210 deletions(-) create mode 100644 lib/fetch/index.ts create mode 100644 lib/fetch/kontent-fetcher.ts create mode 100644 lib/generators/migration/migration-func.ts diff --git a/lib/fetch/index.ts b/lib/fetch/index.ts new file mode 100644 index 0000000..cddf4da --- /dev/null +++ b/lib/fetch/index.ts @@ -0,0 +1 @@ +export * from './kontent-fetcher.js'; diff --git a/lib/fetch/kontent-fetcher.ts b/lib/fetch/kontent-fetcher.ts new file mode 100644 index 0000000..354cd79 --- /dev/null +++ b/lib/fetch/kontent-fetcher.ts @@ -0,0 +1,111 @@ +import { + AssetFolderModels, + CollectionModels, + ContentTypeModels, + ContentTypeSnippetModels, + createManagementClient, + EnvironmentModels, + LanguageModels, + RoleModels, + TaxonomyModels, + WebhookModels, + WorkflowModels +} from '@kontent-ai/management-sdk'; +import { GeneratorManagementClient } from '../core/index.js'; +import chalk from 'chalk'; +import { commonHelper } from '../common-helper.js'; + +interface KontentFetcherConfig { + environmentId: string; + apiKey: string; + baseUrl?: string; +} + +export function kontentFetcher(config: KontentFetcherConfig) { + const client: GeneratorManagementClient = createManagementClient({ + environmentId: config.environmentId, + apiKey: config.apiKey, + baseUrl: config.baseUrl + }); + + return { + async getEnvironmentInfoAsync(): Promise> { + const projectInformation = (await client.environmentInformation().toPromise()).data; + console.log(`Project '${chalk.yellow(projectInformation.project.name)}'`); + console.log(`Environment '${chalk.yellow(projectInformation.project.environment)}'\n`); + return projectInformation.project; + }, + async getWorkflowsAsync(): Promise { + const items = commonHelper.sortAlphabetically( + (await client.listWorkflows().toPromise()).data, + (item) => item.name + ); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' workflows`); + return items; + }, + async getRolesAsync(): Promise { + const items = commonHelper.sortAlphabetically( + (await client.listRoles().toPromise()).data.roles, + (item) => item.name + ); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' roles`); + return items; + }, + async getAssetFoldersAsync(): Promise { + const items = commonHelper.sortAlphabetically( + (await client.listAssetFolders().toPromise()).data.items, + (item) => item.name + ); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' asset folders`); + return items; + }, + async getCollectionsAsync(): Promise { + const items = commonHelper.sortAlphabetically( + (await client.listCollections().toPromise()).data.collections, + (item) => item.name + ); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' collections`); + return items; + }, + async getWebhooksAsync(): Promise { + const items = commonHelper.sortAlphabetically( + (await client.listWebhooks().toPromise()).data.webhooks, + (item) => item.name + ); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' webhooks`); + return items; + }, + async getLanguagesAsync(): Promise { + const items = commonHelper.sortAlphabetically( + (await client.listLanguages().toAllPromise()).data.items, + (item) => item.name + ); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' languages`); + return items; + }, + async getTypesAsync(): Promise { + const items = commonHelper.sortAlphabetically( + (await client.listContentTypes().toAllPromise()).data.items, + (item) => item.name + ); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' types`); + return items; + }, + async getSnippetsAsync(): Promise { + const items = commonHelper.sortAlphabetically( + (await client.listContentTypeSnippets().toAllPromise()).data.items, + (item) => item.name + ); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' snippets`); + return items; + }, + async getTaxonomiesAsync(): Promise { + const items = commonHelper.sortAlphabetically( + (await client.listTaxonomies().toAllPromise()).data.items, + (item) => item.name + ); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' taxonomies`); + return items; + } + }; +} diff --git a/lib/generator.ts b/lib/generator.ts index 7d6f47b..1860985 100644 --- a/lib/generator.ts +++ b/lib/generator.ts @@ -1,26 +1,12 @@ import chalk from 'chalk'; -import { GenerateMigrationModelsConfig, IGenerateDeliveryModelsConfig, ModuleResolution } from './models.js'; +import { IGenerateDeliveryModelsConfig, ModuleResolution } from './models.js'; import { deliveryContentTypeGenerator } from './generators/delivery/delivery-content-type.generator.js'; import { projectGenerator } from './generators/index.js'; -import { - AssetFolderModels, - CollectionModels, - ContentTypeModels, - ContentTypeSnippetModels, - EnvironmentModels, - LanguageModels, - RoleModels, - TaxonomyModels, - WebhookModels, - WorkflowModels, - createManagementClient -} from '@kontent-ai/management-sdk'; import { deliveryTaxonomyGenerator } from './generators/delivery/delivery-taxonomy.generator.js'; import { commonHelper } from './common-helper.js'; import { parse } from 'path'; -import { fileHelper, fileProcessor } from './file-helper.js'; -import { migrationGenerator as _migrationGenerator } from './generators/migration/migration-generator.js'; -import { coreConfig, GeneratorManagementClient, migrationConfig, toSafeString } from './core/index.js'; +import { fileHelper } from './file-helper.js'; +import { kontentFetcher as _kontentFetcher } from './fetch/kontent-fetcher.js'; export async function generateDeliveryModelsAsync(config: IGenerateDeliveryModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); @@ -44,25 +30,25 @@ export async function generateDeliveryModelsAsync(config: IGenerateDeliveryModel fileHelper.createDir(taxonomiesFolderPath); fileHelper.createDir(projectFolderPath); - const client = createManagementClient({ + const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, baseUrl: config.managementApiUrl }); const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; - const projectInformation = await getEnvironmentInfoAsync(client); + const projectInformation = await kontentFetcher.getEnvironmentInfoAsync(); - const types = await getTypesAsync(client); - const snippets = await getSnippetsAsync(client); - const taxonomies = await getTaxonomiesAsync(client); + const types = await kontentFetcher.getTypesAsync(); + const snippets = await kontentFetcher.getSnippetsAsync(); + const taxonomies = await kontentFetcher.getTaxonomiesAsync(); - const workflows = await getWorkflowsAsync(client); - const roles = config.isEnterpriseSubscription ? await getRolesAsync(client) : []; - const assetFolders = await getAssetFoldersAsync(client); - const collections = await getCollectionsAsync(client); - const webhooks = await getWebhooksAsync(client); - const languages = await getLanguagesAsync(client); + const workflows = await kontentFetcher.getWorkflowsAsync(); + const roles = config.isEnterpriseSubscription ? await kontentFetcher.getRolesAsync() : []; + const assetFolders = await kontentFetcher.getAssetFoldersAsync(); + const collections = await kontentFetcher.getCollectionsAsync(); + const webhooks = await kontentFetcher.getWebhooksAsync(); + const languages = await kontentFetcher.getLanguagesAsync(); console.log(''); @@ -205,166 +191,3 @@ export async function generateDeliveryModelsAsync(config: IGenerateDeliveryModel console.log(chalk.green(`\nCompleted`)); } - -export async function generateMigrationModelsAsync(config: GenerateMigrationModelsConfig): Promise { - const client = createManagementClient({ - environmentId: config.environmentId, - apiKey: config.apiKey, - baseUrl: config.managementApiUrl - }); - - const outputDir: string = config.outputDir ? `${config.outputDir}/`.replaceAll('//', '/') : `./`; - const migrationFileProcessor = fileProcessor(outputDir); - const migrationItemsFolderName: string = migrationConfig.migrationItemsFolderName; - const migrationTypesFilename: string = migrationConfig.migrationTypesFilename; - - const projectInformation = await getEnvironmentInfoAsync(client); - console.log(`Project '${chalk.yellow(toSafeString(projectInformation.name))}'`); - console.log(`Environment '${chalk.yellow(toSafeString(projectInformation.environment))}'\n`); - - const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; - console.log(`Module resolution '${chalk.yellow(moduleResolution)}'\n`); - const migrationGenerator = _migrationGenerator({ - addTimestamp: config.addTimestamp, - moduleResolution: config.moduleResolution, - addEnvironmentInfo: config.addEnvironmentInfo, - environmentData: { - environment: projectInformation, - taxonomies: await getTaxonomiesAsync(client), - languages: await getLanguagesAsync(client), - workflows: await getWorkflowsAsync(client), - types: await getTypesAsync(client), - snippets: await getSnippetsAsync(client), - collections: await getCollectionsAsync(client) - } - }); - - const migrationTypeFile = migrationGenerator.getMigrationTypesFile(migrationTypesFilename); - const migrationItemFiles = migrationGenerator.getMigrationItemFiles( - migrationTypesFilename, - migrationItemsFolderName - ); - const allFiles = [migrationTypeFile, ...migrationItemFiles]; - - // create all files on FS - for (const file of allFiles) { - await migrationFileProcessor.createFileOnFsAsync(file.text, file.filename, config.formatOptions); - } - - // migration items barrel - await migrationFileProcessor.createFileOnFsAsync( - commonHelper.getBarrelExportCode({ - moduleResolution: moduleResolution, - filenames: [ - ...migrationItemFiles.map((m) => { - return `./${parse(m.filename).name}`; - }) - ] - }), - `${migrationItemsFolderName}/${coreConfig.barrelExportFilename}`, - config.formatOptions - ); - - // main barrel - await migrationFileProcessor.createFileOnFsAsync( - commonHelper.getBarrelExportCode({ - moduleResolution: moduleResolution, - filenames: [`./${migrationItemsFolderName}/index`, `./${migrationTypeFile.filename}`] - }), - `${coreConfig.barrelExportFilename}`, - config.formatOptions - ); - - console.log(chalk.green(`\nCompleted`)); -} - -async function getEnvironmentInfoAsync( - client: GeneratorManagementClient -): Promise> { - const projectInformation = (await client.environmentInformation().toPromise()).data; - console.log(`Project '${chalk.yellow(projectInformation.project.name)}'`); - console.log(`Environment '${chalk.yellow(projectInformation.project.environment)}'\n`); - return projectInformation.project; -} - -async function getWorkflowsAsync(client: GeneratorManagementClient): Promise { - const items = commonHelper.sortAlphabetically((await client.listWorkflows().toPromise()).data, (item) => item.name); - console.log(`Fetched '${chalk.yellow(items.length.toString())}' workflows`); - return items; -} - -async function getRolesAsync(client: GeneratorManagementClient): Promise { - const items = commonHelper.sortAlphabetically( - (await client.listRoles().toPromise()).data.roles, - (item) => item.name - ); - console.log(`Fetched '${chalk.yellow(items.length.toString())}' roles`); - return items; -} - -async function getAssetFoldersAsync( - client: GeneratorManagementClient -): Promise { - const items = commonHelper.sortAlphabetically( - (await client.listAssetFolders().toPromise()).data.items, - (item) => item.name - ); - console.log(`Fetched '${chalk.yellow(items.length.toString())}' asset folders`); - return items; -} - -async function getCollectionsAsync(client: GeneratorManagementClient): Promise { - const items = commonHelper.sortAlphabetically( - (await client.listCollections().toPromise()).data.collections, - (item) => item.name - ); - console.log(`Fetched '${chalk.yellow(items.length.toString())}' collections`); - return items; -} - -async function getWebhooksAsync(client: GeneratorManagementClient): Promise { - const items = commonHelper.sortAlphabetically( - (await client.listWebhooks().toPromise()).data.webhooks, - (item) => item.name - ); - console.log(`Fetched '${chalk.yellow(items.length.toString())}' webhooks`); - return items; -} - -async function getLanguagesAsync(client: GeneratorManagementClient): Promise { - const items = commonHelper.sortAlphabetically( - (await client.listLanguages().toAllPromise()).data.items, - (item) => item.name - ); - console.log(`Fetched '${chalk.yellow(items.length.toString())}' languages`); - return items; -} - -async function getTypesAsync(client: GeneratorManagementClient): Promise { - const items = commonHelper.sortAlphabetically( - (await client.listContentTypes().toAllPromise()).data.items, - (item) => item.name - ); - console.log(`Fetched '${chalk.yellow(items.length.toString())}' types`); - return items; -} - -async function getSnippetsAsync( - client: GeneratorManagementClient -): Promise { - const items = commonHelper.sortAlphabetically( - (await client.listContentTypeSnippets().toAllPromise()).data.items, - (item) => item.name - ); - console.log(`Fetched '${chalk.yellow(items.length.toString())}' snippets`); - return items; -} - -async function getTaxonomiesAsync(client: GeneratorManagementClient): Promise { - const items = commonHelper.sortAlphabetically( - (await client.listTaxonomies().toAllPromise()).data.items, - (item) => item.name - ); - console.log(`Fetched '${chalk.yellow(items.length.toString())}' taxonomies`); - return items; -} diff --git a/lib/generators/index.ts b/lib/generators/index.ts index 21a4a69..4224f4d 100644 --- a/lib/generators/index.ts +++ b/lib/generators/index.ts @@ -1,2 +1,11 @@ +// delivery export * from './delivery/delivery-content-type.generator.js'; +export * from './delivery/delivery-mappers.js'; +export * from './delivery/delivery-taxonomy.generator.js'; + +// project export * from './project/project.generator.js'; + +// migration +export * from './migration/migration-generator.js'; +export * from './migration/migration-func.js'; diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts new file mode 100644 index 0000000..49df8ea --- /dev/null +++ b/lib/generators/migration/migration-func.ts @@ -0,0 +1,81 @@ +import chalk from 'chalk'; +import { commonHelper } from '../../common-helper.js'; +import { migrationConfig, coreConfig } from '../../core/core.config.js'; +import { toSafeString } from '../../core/core.utils.js'; +import { fileProcessor } from '../../file-helper.js'; +import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; +import { migrationGenerator as _migrationGenerator } from '../../generators/migration/migration-generator.js'; +import { GenerateMigrationModelsConfig, ModuleResolution } from '../../models.js'; +import { parse } from 'path'; + +export async function generateMigrationModelsAsync(config: GenerateMigrationModelsConfig): Promise { + const kontentFetcher = _kontentFetcher({ + environmentId: config.environmentId, + apiKey: config.apiKey, + baseUrl: config.baseUrl + }); + + const outputDir: string = config.outputDir ? `${config.outputDir}/`.replaceAll('//', '/') : `./`; + const migrationFileProcessor = fileProcessor(outputDir); + const migrationItemsFolderName: string = migrationConfig.migrationItemsFolderName; + const migrationTypesFilename: string = migrationConfig.migrationTypesFilename; + + const projectInformation = await kontentFetcher.getEnvironmentInfoAsync(); + console.log(`Project '${chalk.yellow(toSafeString(projectInformation.name))}'`); + console.log(`Environment '${chalk.yellow(toSafeString(projectInformation.environment))}'\n`); + + const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; + console.log(`Module resolution '${chalk.yellow(moduleResolution)}'\n`); + const migrationGenerator = _migrationGenerator({ + addTimestamp: config.addTimestamp, + moduleResolution: config.moduleResolution, + addEnvironmentInfo: config.addEnvironmentInfo, + environmentData: { + environment: projectInformation, + taxonomies: await kontentFetcher.getTaxonomiesAsync(), + languages: await kontentFetcher.getLanguagesAsync(), + workflows: await kontentFetcher.getWorkflowsAsync(), + types: await kontentFetcher.getTypesAsync(), + snippets: await kontentFetcher.getSnippetsAsync(), + collections: await kontentFetcher.getCollectionsAsync() + } + }); + + const migrationTypeFile = migrationGenerator.getMigrationTypesFile(migrationTypesFilename); + const migrationItemFiles = migrationGenerator.getMigrationItemFiles( + migrationTypesFilename, + migrationItemsFolderName + ); + const allFiles = [migrationTypeFile, ...migrationItemFiles]; + + // create all files on FS + for (const file of allFiles) { + await migrationFileProcessor.createFileOnFsAsync(file.text, file.filename, config.formatOptions); + } + + // migration items barrel + await migrationFileProcessor.createFileOnFsAsync( + commonHelper.getBarrelExportCode({ + moduleResolution: moduleResolution, + filenames: [ + ...migrationItemFiles.map((m) => { + return `./${parse(m.filename).name}`; + }) + ] + }), + `${migrationItemsFolderName}/${coreConfig.barrelExportFilename}`, + config.formatOptions + ); + + // main barrel + await migrationFileProcessor.createFileOnFsAsync( + commonHelper.getBarrelExportCode({ + moduleResolution: moduleResolution, + filenames: [`./${migrationItemsFolderName}/index`, `./${migrationTypeFile.filename}`] + }), + `${coreConfig.barrelExportFilename}`, + config.formatOptions + ); + + console.log(chalk.green(`\nCompleted`)); +} diff --git a/lib/generators/migration/migration-generator.ts b/lib/generators/migration/migration-generator.ts index e08de90..64aba81 100644 --- a/lib/generators/migration/migration-generator.ts +++ b/lib/generators/migration/migration-generator.ts @@ -87,8 +87,8 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { * ${toSafeString(element.title)} (${element.type}) * * Required: ${element.isRequired ? 'true' : 'false'} - * Id: ${element.id} - * Codename: ${element.codename}${element.guidelines ? `\n* Guidelines: ${textHelper.removeLineEndings(element.guidelines)}` : ''} + * Codename: ${element.codename} + * Id: ${element.id}${element.guidelines ? `\n* Guidelines: ${textHelper.removeLineEndings(element.guidelines)}` : ''} */ ${element.codename}: ${getElementPropType(element)}`; }) diff --git a/lib/index.ts b/lib/index.ts index dd37f13..aa47c6f 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -4,5 +4,5 @@ export * from './name-helper.js'; export * from './models.js'; export * from './generator.js'; export * from './core/index.js'; - +export * from './comments/index.js'; export * from './generators/index.js'; diff --git a/lib/models.ts b/lib/models.ts index ebc6618..46f5ba1 100644 --- a/lib/models.ts +++ b/lib/models.ts @@ -53,6 +53,6 @@ export interface GenerateMigrationModelsConfig { readonly apiKey: string; readonly moduleResolution: ModuleResolution; readonly outputDir: string; - readonly managementApiUrl?: string; + readonly baseUrl?: string; readonly formatOptions?: Options; } diff --git a/lib/node/cli/actions/migrate-action.ts b/lib/node/cli/actions/migrate-action.ts index de2066a..c2f269d 100644 --- a/lib/node/cli/actions/migrate-action.ts +++ b/lib/node/cli/actions/migrate-action.ts @@ -1 +1,17 @@ -export async function migrateActionAsync(): Promise {} +import { generateMigrationModelsAsync } from '../../../generators/index.js'; +import { ModuleResolution } from '../../../models.js'; +import { CliArgumentsFetcher } from '../cli.models.js'; + +export async function migrateActionAsync(cliFetcher: CliArgumentsFetcher): Promise { + await generateMigrationModelsAsync({ + environmentId: cliFetcher.getRequiredArgumentValue('environmentId'), + baseUrl: cliFetcher.getRequiredArgumentValue('managementApiUrl'), + apiKey: cliFetcher.getRequiredArgumentValue('apiKey'), + outputDir: cliFetcher.getRequiredArgumentValue('outputDir'), + addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), + addEnvironmentInfo: cliFetcher.getBooleanArgumentValue('addEnvironmentInfo', false), + formatOptions: undefined, + moduleResolution: + cliFetcher.getRequiredArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' + }); +} diff --git a/lib/node/cli/app.ts b/lib/node/cli/app.ts index 53ed668..92ea738 100644 --- a/lib/node/cli/app.ts +++ b/lib/node/cli/app.ts @@ -19,7 +19,7 @@ const run = async () => { } if (action === 'migration') { - return await migrateActionAsync(); + return await migrateActionAsync(argsFetcher); } exitProgram({ diff --git a/sample/migration/items/actor.ts b/sample/migration/items/actor.ts index 067b655..5a8d022 100644 --- a/sample/migration/items/actor.ts +++ b/sample/migration/items/actor.ts @@ -14,8 +14,8 @@ export type ActorItem = Item< * Url (url_slug) * * Required: false - * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 * Codename: url + * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 */ url: MigrationElementModels.UrlSlugElement; @@ -23,8 +23,8 @@ export type ActorItem = Item< * Firstname (text) * * Required: true - * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d * Codename: first_name + * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d * Guidelines: This is the first name of the actor */ first_name: MigrationElementModels.TextElement; @@ -33,8 +33,8 @@ export type ActorItem = Item< * Lastname (text) * * Required: true - * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 * Codename: last_name + * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 */ last_name: MigrationElementModels.TextElement; @@ -42,8 +42,8 @@ export type ActorItem = Item< * Photo (asset) * * Required: false - * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 * Codename: photo + * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 */ photo: MigrationElementModels.AssetElement; } diff --git a/sample/migration/items/movie.ts b/sample/migration/items/movie.ts index 9b7a265..2b5bacd 100644 --- a/sample/migration/items/movie.ts +++ b/sample/migration/items/movie.ts @@ -14,8 +14,8 @@ export type MovieItem = Item< * Title (text) * * Required: true - * Id: 3473187e-dc78-eff2-7099-f690f7042d4a * Codename: title + * Id: 3473187e-dc78-eff2-7099-f690f7042d4a */ title: MigrationElementModels.TextElement; @@ -23,8 +23,8 @@ export type MovieItem = Item< * Plot (rich_text) * * Required: false - * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce * Codename: plot + * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce */ plot: MigrationElementModels.RichTextElement; @@ -32,8 +32,8 @@ export type MovieItem = Item< * Released (date_time) * * Required: false - * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 * Codename: released + * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 */ released: MigrationElementModels.DateTimeElement; @@ -41,8 +41,8 @@ export type MovieItem = Item< * Length (number) * * Required: false - * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c * Codename: length + * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c */ length: MigrationElementModels.NumberElement; @@ -50,8 +50,8 @@ export type MovieItem = Item< * Poster (asset) * * Required: false - * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d * Codename: poster + * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d */ poster: MigrationElementModels.AssetElement; @@ -59,8 +59,8 @@ export type MovieItem = Item< * Category (multiple_choice) * * Required: false - * Id: 9821c252-6414-f549-c17f-cc171dd87713 * Codename: category + * Id: 9821c252-6414-f549-c17f-cc171dd87713 */ category: MigrationElementModels.MultipleChoiceElement; @@ -68,8 +68,8 @@ export type MovieItem = Item< * Stars (modular_content) * * Required: false - * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 * Codename: stars + * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 */ stars: MigrationElementModels.LinkedItemsElement; @@ -77,8 +77,8 @@ export type MovieItem = Item< * SeoName (url_slug) * * Required: false - * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c * Codename: seoname + * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c */ seoname: MigrationElementModels.UrlSlugElement; @@ -86,8 +86,8 @@ export type MovieItem = Item< * ReleaseCategory (taxonomy) * * Required: false - * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 * Codename: releasecategory + * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 */ releasecategory: MigrationElementModels.TaxonomyElement; } From a28ec195fe0c361a2e75316fd2ea732d1aea1c05 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 19 Aug 2024 14:32:51 +0200 Subject: [PATCH 015/183] feat!: Separates Delivery & Project models --- sample/delivery/project/index.ts => index.ts | 0 lib/core/core.config.ts | 2 +- lib/fetch/kontent-fetcher.ts | 6 +- .../delivery/delivery-func.ts} | 70 +++--------------- lib/generators/index.ts | 2 + lib/generators/migration/migration-func.ts | 3 - lib/generators/project/project-func.ts | 74 +++++++++++++++++++ lib/generators/project/project.generator.ts | 13 ++-- lib/index.ts | 1 - lib/models.ts | 25 +++++-- lib/node/cli/actions/delivery-action.ts | 8 +- lib/node/cli/actions/project-action.ts | 20 +++++ package.json | 1 + sample/delivery/index.ts | 1 - .../{items => content-types}/actor.ts | 0 .../{items => content-types}/index.ts | 0 .../{items => content-types}/movie.ts | 0 sample/migration/index.ts | 2 +- sample/{delivery => }/project/assetFolders.ts | 0 sample/{delivery => }/project/collections.ts | 0 .../project/contentTypeSnippets.ts | 0 sample/{delivery => }/project/contentTypes.ts | 0 sample/{delivery => }/project/languages.ts | 0 sample/{delivery => }/project/roles.ts | 0 sample/{delivery => }/project/taxonomies.ts | 0 sample/{delivery => }/project/webhooks.ts | 0 sample/{delivery => }/project/workflows.ts | 0 scripts/tests/delivery-models.ts | 6 +- scripts/tests/project-models.ts | 44 +++++++++++ 29 files changed, 183 insertions(+), 95 deletions(-) rename sample/delivery/project/index.ts => index.ts (100%) rename lib/{generator.ts => generators/delivery/delivery-func.ts} (66%) create mode 100644 lib/generators/project/project-func.ts create mode 100644 lib/node/cli/actions/project-action.ts rename sample/migration/{items => content-types}/actor.ts (100%) rename sample/migration/{items => content-types}/index.ts (100%) rename sample/migration/{items => content-types}/movie.ts (100%) rename sample/{delivery => }/project/assetFolders.ts (100%) rename sample/{delivery => }/project/collections.ts (100%) rename sample/{delivery => }/project/contentTypeSnippets.ts (100%) rename sample/{delivery => }/project/contentTypes.ts (100%) rename sample/{delivery => }/project/languages.ts (100%) rename sample/{delivery => }/project/roles.ts (100%) rename sample/{delivery => }/project/taxonomies.ts (100%) rename sample/{delivery => }/project/webhooks.ts (100%) rename sample/{delivery => }/project/workflows.ts (100%) create mode 100644 scripts/tests/project-models.ts diff --git a/sample/delivery/project/index.ts b/index.ts similarity index 100% rename from sample/delivery/project/index.ts rename to index.ts diff --git a/lib/core/core.config.ts b/lib/core/core.config.ts index 90e6237..64baa36 100644 --- a/lib/core/core.config.ts +++ b/lib/core/core.config.ts @@ -3,6 +3,6 @@ export const coreConfig = { } as const; export const migrationConfig = { - migrationItemsFolderName: `items`, + migrationItemsFolderName: `content-types`, migrationTypesFilename: `core.models.ts` } as const; diff --git a/lib/fetch/kontent-fetcher.ts b/lib/fetch/kontent-fetcher.ts index 354cd79..2652275 100644 --- a/lib/fetch/kontent-fetcher.ts +++ b/lib/fetch/kontent-fetcher.ts @@ -11,7 +11,7 @@ import { WebhookModels, WorkflowModels } from '@kontent-ai/management-sdk'; -import { GeneratorManagementClient } from '../core/index.js'; +import { GeneratorManagementClient, toSafeString } from '../core/index.js'; import chalk from 'chalk'; import { commonHelper } from '../common-helper.js'; @@ -31,8 +31,8 @@ export function kontentFetcher(config: KontentFetcherConfig) { return { async getEnvironmentInfoAsync(): Promise> { const projectInformation = (await client.environmentInformation().toPromise()).data; - console.log(`Project '${chalk.yellow(projectInformation.project.name)}'`); - console.log(`Environment '${chalk.yellow(projectInformation.project.environment)}'\n`); + console.log(`Project '${chalk.yellow(toSafeString(projectInformation.project.name))}'`); + console.log(`Environment '${chalk.yellow(toSafeString(projectInformation.project.environment))}'\n`); return projectInformation.project; }, async getWorkflowsAsync(): Promise { diff --git a/lib/generator.ts b/lib/generators/delivery/delivery-func.ts similarity index 66% rename from lib/generator.ts rename to lib/generators/delivery/delivery-func.ts index 1860985..d9df36f 100644 --- a/lib/generator.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -1,14 +1,13 @@ import chalk from 'chalk'; -import { IGenerateDeliveryModelsConfig, ModuleResolution } from './models.js'; -import { deliveryContentTypeGenerator } from './generators/delivery/delivery-content-type.generator.js'; -import { projectGenerator } from './generators/index.js'; -import { deliveryTaxonomyGenerator } from './generators/delivery/delivery-taxonomy.generator.js'; -import { commonHelper } from './common-helper.js'; +import { GenerateDeliveryModelsConfig, ModuleResolution } from '../../models.js'; +import { deliveryContentTypeGenerator } from '../../generators/delivery/delivery-content-type.generator.js'; +import { deliveryTaxonomyGenerator } from '../../generators/delivery/delivery-taxonomy.generator.js'; +import { commonHelper } from '../../common-helper.js'; import { parse } from 'path'; -import { fileHelper } from './file-helper.js'; -import { kontentFetcher as _kontentFetcher } from './fetch/kontent-fetcher.js'; +import { fileHelper } from '../../file-helper.js'; +import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; -export async function generateDeliveryModelsAsync(config: IGenerateDeliveryModelsConfig): Promise { +export async function generateDeliveryModelsAsync(config: GenerateDeliveryModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('delivery')}' models\n`); @@ -17,41 +16,29 @@ export async function generateDeliveryModelsAsync(config: IGenerateDeliveryModel const contentTypesFolderName: string = `content-types/`; const contentTypeSnippetsFolderName: string = `content-type-snippets/`; const taxonomiesFolderName: string = `taxonomies/`; - const projectFolderName: string = `project/`; const contentTypesFolderPath: string = `${outputDir}${contentTypesFolderName}`; const contentTypeSnippetsFolderPath: string = `${outputDir}${contentTypeSnippetsFolderName}`; const taxonomiesFolderPath: string = `${outputDir}${taxonomiesFolderName}`; - const projectFolderPath: string = `${outputDir}${projectFolderName}`; // prepare directories fileHelper.createDir(contentTypesFolderPath); fileHelper.createDir(contentTypeSnippetsFolderPath); fileHelper.createDir(taxonomiesFolderPath); - fileHelper.createDir(projectFolderPath); const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, - baseUrl: config.managementApiUrl + baseUrl: config.baseUrl }); const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; - const projectInformation = await kontentFetcher.getEnvironmentInfoAsync(); + await kontentFetcher.getEnvironmentInfoAsync(); const types = await kontentFetcher.getTypesAsync(); const snippets = await kontentFetcher.getSnippetsAsync(); const taxonomies = await kontentFetcher.getTaxonomiesAsync(); - const workflows = await kontentFetcher.getWorkflowsAsync(); - const roles = config.isEnterpriseSubscription ? await kontentFetcher.getRolesAsync() : []; - const assetFolders = await kontentFetcher.getAssetFoldersAsync(); - const collections = await kontentFetcher.getCollectionsAsync(); - const webhooks = await kontentFetcher.getWebhooksAsync(); - const languages = await kontentFetcher.getLanguagesAsync(); - - console.log(''); - // create content type models const deliveryModels = deliveryContentTypeGenerator.generateModels({ outputDir: outputDir, @@ -83,28 +70,6 @@ export async function generateDeliveryModelsAsync(config: IGenerateDeliveryModel taxonomyResolver: config.taxonomyTypeResolver }); - // create project structure - const projectFiles = projectGenerator.generateProjectModel({ - outputDir: outputDir, - environmentInfo: projectInformation, - addTimestamp: config.addTimestamp, - formatOptions: config.formatOptions, - addEnvironmentInfo: config.addEnvironmentInfo, - languages: languages, - taxonomies: taxonomies, - types: types, - workflows: workflows, - assetFolders: assetFolders, - collections: collections, - roles: roles, - snippets: snippets, - webhooks: webhooks, - projectFolderName: projectFolderName, - sortConfig: config.sortConfig ?? { - sortTaxonomyTerms: true - } - }); - // create barrel export const barrelExportFilename: string = 'index.ts'; @@ -160,27 +125,10 @@ export async function generateDeliveryModelsAsync(config: IGenerateDeliveryModel const taxonomiesBarrelExportPath: string = `${taxonomiesFolderPath}${barrelExportFilename}`; await fileHelper.createFileOnFsAsync(taxonomiesBarrelCode, taxonomiesBarrelExportPath, config.formatOptions); - // project barrel - for (const file of projectFiles) { - await fileHelper.createFileOnFsAsync(file.text, file.filename, config.formatOptions); - } - const projectBarrelCode = commonHelper.getBarrelExportCode({ - moduleResolution: moduleResolution, - filenames: [ - ...projectFiles.map((m) => { - const path = parse(m.filename); - return `./${path.name}`; - }) - ] - }); - const projectBarrelExportPath: string = `${projectFolderPath}${barrelExportFilename}`; - await fileHelper.createFileOnFsAsync(projectBarrelCode, projectBarrelExportPath, config.formatOptions); - // main barrel const mainBarrelCode = commonHelper.getBarrelExportCode({ moduleResolution: moduleResolution, filenames: [ - `./${projectFolderName}index`, `./${contentTypesFolderName}index`, `./${contentTypeSnippetsFolderName}index`, `./${taxonomiesFolderName}index` diff --git a/lib/generators/index.ts b/lib/generators/index.ts index 4224f4d..65c5043 100644 --- a/lib/generators/index.ts +++ b/lib/generators/index.ts @@ -2,9 +2,11 @@ export * from './delivery/delivery-content-type.generator.js'; export * from './delivery/delivery-mappers.js'; export * from './delivery/delivery-taxonomy.generator.js'; +export * from './delivery/delivery-func.js'; // project export * from './project/project.generator.js'; +export * from './project/project-func.js'; // migration export * from './migration/migration-generator.js'; diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index 49df8ea..c2bdcd8 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -1,7 +1,6 @@ import chalk from 'chalk'; import { commonHelper } from '../../common-helper.js'; import { migrationConfig, coreConfig } from '../../core/core.config.js'; -import { toSafeString } from '../../core/core.utils.js'; import { fileProcessor } from '../../file-helper.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; import { migrationGenerator as _migrationGenerator } from '../../generators/migration/migration-generator.js'; @@ -21,8 +20,6 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode const migrationTypesFilename: string = migrationConfig.migrationTypesFilename; const projectInformation = await kontentFetcher.getEnvironmentInfoAsync(); - console.log(`Project '${chalk.yellow(toSafeString(projectInformation.name))}'`); - console.log(`Environment '${chalk.yellow(toSafeString(projectInformation.environment))}'\n`); const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; console.log(`Module resolution '${chalk.yellow(moduleResolution)}'\n`); diff --git a/lib/generators/project/project-func.ts b/lib/generators/project/project-func.ts new file mode 100644 index 0000000..cd8295c --- /dev/null +++ b/lib/generators/project/project-func.ts @@ -0,0 +1,74 @@ +import chalk from 'chalk'; +import { GeneratProjectModelsConfig, ModuleResolution } from '../../models.js'; +import { projectGenerator } from '../../generators/index.js'; +import { commonHelper } from '../../common-helper.js'; +import { parse } from 'path'; +import { fileHelper } from '../../file-helper.js'; +import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; + +export async function generateProjectModelsAsync(config: GeneratProjectModelsConfig): Promise { + console.log(chalk.green(`Model generator started \n`)); + console.log(`Generating '${chalk.yellow('delivery')}' models\n`); + + const outputDir: string = config.outputDir ? `${config.outputDir}/`.replaceAll('//', '/') : `./`; + + const kontentFetcher = _kontentFetcher({ + environmentId: config.environmentId, + apiKey: config.apiKey, + baseUrl: config.baseUrl + }); + + const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; + const projectInformation = await kontentFetcher.getEnvironmentInfoAsync(); + + const types = await kontentFetcher.getTypesAsync(); + const snippets = await kontentFetcher.getSnippetsAsync(); + const taxonomies = await kontentFetcher.getTaxonomiesAsync(); + + const workflows = await kontentFetcher.getWorkflowsAsync(); + const roles = config.isEnterpriseSubscription ? await kontentFetcher.getRolesAsync() : []; + const assetFolders = await kontentFetcher.getAssetFoldersAsync(); + const collections = await kontentFetcher.getCollectionsAsync(); + const webhooks = await kontentFetcher.getWebhooksAsync(); + const languages = await kontentFetcher.getLanguagesAsync(); + + const projectFiles = projectGenerator.generateProjectModel({ + outputDir: outputDir, + environmentInfo: projectInformation, + addTimestamp: config.addTimestamp, + formatOptions: config.formatOptions, + addEnvironmentInfo: config.addEnvironmentInfo, + languages: languages, + taxonomies: taxonomies, + types: types, + workflows: workflows, + assetFolders: assetFolders, + collections: collections, + roles: roles, + snippets: snippets, + webhooks: webhooks, + sortConfig: config.sortConfig ?? { + sortTaxonomyTerms: true + } + }); + + // create barrel export + const barrelExportFilename: string = 'index.ts'; + + // project barrel + for (const file of projectFiles) { + await fileHelper.createFileOnFsAsync(file.text, file.filename, config.formatOptions); + } + const projectBarrelCode = commonHelper.getBarrelExportCode({ + moduleResolution: moduleResolution, + filenames: [ + ...projectFiles.map((m) => { + const path = parse(m.filename); + return `./${path.name}`; + }) + ] + }); + await fileHelper.createFileOnFsAsync(projectBarrelCode, barrelExportFilename, config.formatOptions); + + console.log(chalk.green(`\nCompleted`)); +} diff --git a/lib/generators/project/project.generator.ts b/lib/generators/project/project.generator.ts index 6aabd8a..b5a9b3e 100644 --- a/lib/generators/project/project.generator.ts +++ b/lib/generators/project/project.generator.ts @@ -15,7 +15,7 @@ import { WorkflowModels } from '@kontent-ai/management-sdk'; import { camelCasePropertyNameResolver } from '@kontent-ai/delivery-sdk'; -import { ISortConfig } from '../../models.js'; +import { SortConfig } from '../../models.js'; interface IProjectCodeResult { filename: string; @@ -49,8 +49,7 @@ export class ProjectGenerator { webhooks: WebhookModels.Webhook[]; addTimestamp: boolean; addEnvironmentInfo: boolean; - projectFolderName: string; - sortConfig: ISortConfig; + sortConfig: SortConfig; formatOptions?: Options; }): IGeneratedFile[] { const projectCodes = this.getProjectModelCode({ @@ -85,7 +84,7 @@ export class ProjectGenerator { const generatedFiles: IGeneratedFile[] = []; for (const projectCode of projectCodes) { - const filePath = `${data.outputDir}${data.projectFolderName}${projectCode.filename}`; + const filePath = `${data.outputDir}${projectCode.filename}`; generatedFiles.push({ filename: filePath, @@ -257,7 +256,7 @@ export class ProjectGenerator { roles: RoleModels.Role[]; webhooks: WebhookModels.Webhook[]; addTimestamp: boolean; - sortConfig: ISortConfig; + sortConfig: SortConfig; formatOptions?: Options; }): IProjectCodeResult[] { const result: IProjectCodeResult[] = [ @@ -595,7 +594,7 @@ export class ProjectGenerator { return commonHelper.sortAlphabetically(extendedElements, (item) => item.mappedName ?? ''); } - private getProjectTaxonomies(taxonomies: TaxonomyModels.Taxonomy[], sortConfig: ISortConfig): string { + private getProjectTaxonomies(taxonomies: TaxonomyModels.Taxonomy[], sortConfig: SortConfig): string { let code: string = ``; for (let i = 0; i < taxonomies.length; i++) { const taxonomy = taxonomies[i]; @@ -669,7 +668,7 @@ export class ProjectGenerator { return code; } - private getProjectTaxonomiesTerms(terms: TaxonomyModels.Taxonomy[], sortConfig: ISortConfig): string { + private getProjectTaxonomiesTerms(terms: TaxonomyModels.Taxonomy[], sortConfig: SortConfig): string { if (terms.length === 0) { return `terms: {}`; } diff --git a/lib/index.ts b/lib/index.ts index aa47c6f..ca157d5 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -2,7 +2,6 @@ export * from './common-helper.js'; export * from './text-helper.js'; export * from './name-helper.js'; export * from './models.js'; -export * from './generator.js'; export * from './core/index.js'; export * from './comments/index.js'; export * from './generators/index.js'; diff --git a/lib/models.ts b/lib/models.ts index 46f5ba1..06d7403 100644 --- a/lib/models.ts +++ b/lib/models.ts @@ -21,17 +21,15 @@ export type ContentTypeSnippetResolver = | ((contentTypeSnippet: ContentTypeSnippetModels.ContentTypeSnippet) => string); export type TaxonomyTypeResolver = DefaultResolverType | ((taxonomy: TaxonomyModels.Taxonomy) => string); -export interface IGenerateDeliveryModelsConfig { +export interface GenerateDeliveryModelsConfig { environmentId: string; addTimestamp: boolean; addEnvironmentInfo: boolean; - isEnterpriseSubscription: boolean; apiKey: string; - moduleResolution?: ModuleResolution; - managementApiUrl?: string; + moduleResolution?: ModuleResolution; + baseUrl?: string; outputDir?: string; - sortConfig?: ISortConfig; contentTypeFileResolver?: ContentTypeFileNameResolver; contentTypeSnippetFileResolver?: ContentTypeSnippetFileNameResolver; taxonomyTypeFileResolver?: TaxonomyTypeFileNameResolver; @@ -42,10 +40,24 @@ export interface IGenerateDeliveryModelsConfig { formatOptions?: Options; } -export interface ISortConfig { +export interface SortConfig { sortTaxonomyTerms: boolean; } +export interface GeneratProjectModelsConfig { + environmentId: string; + addTimestamp: boolean; + addEnvironmentInfo: boolean; + isEnterpriseSubscription: boolean; + apiKey: string; + + moduleResolution?: ModuleResolution; + baseUrl?: string; + outputDir?: string; + sortConfig?: SortConfig; + formatOptions?: Options; +} + export interface GenerateMigrationModelsConfig { readonly addEnvironmentInfo: boolean; readonly environmentId: string; @@ -53,6 +65,7 @@ export interface GenerateMigrationModelsConfig { readonly apiKey: string; readonly moduleResolution: ModuleResolution; readonly outputDir: string; + readonly baseUrl?: string; readonly formatOptions?: Options; } diff --git a/lib/node/cli/actions/delivery-action.ts b/lib/node/cli/actions/delivery-action.ts index 811b378..1497852 100644 --- a/lib/node/cli/actions/delivery-action.ts +++ b/lib/node/cli/actions/delivery-action.ts @@ -1,14 +1,13 @@ +import { generateDeliveryModelsAsync } from '../../../generators/index.js'; import { ModuleResolution } from '../../../models.js'; -import { generateDeliveryModelsAsync } from '../../../generator.js'; import { CliArgumentsFetcher } from '../cli.models.js'; export async function deliveryActionAsync(cliFetcher: CliArgumentsFetcher): Promise { await generateDeliveryModelsAsync({ environmentId: cliFetcher.getRequiredArgumentValue('environmentId'), - managementApiUrl: cliFetcher.getRequiredArgumentValue('managementApiUrl'), + baseUrl: cliFetcher.getRequiredArgumentValue('managementApiUrl'), apiKey: cliFetcher.getRequiredArgumentValue('apiKey'), outputDir: cliFetcher.getRequiredArgumentValue('outputDir'), - isEnterpriseSubscription: cliFetcher.getBooleanArgumentValue('isEnterpriseSubscription', false), addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), addEnvironmentInfo: cliFetcher.getBooleanArgumentValue('addEnvironmentInfo', false), elementResolver: undefined, @@ -19,9 +18,6 @@ export async function deliveryActionAsync(cliFetcher: CliArgumentsFetcher): Prom contentTypeSnippetFileResolver: undefined, contentTypeSnippetResolver: undefined, formatOptions: undefined, - sortConfig: { - sortTaxonomyTerms: cliFetcher.getBooleanArgumentValue('sortTaxonomyTerms', true) - }, moduleResolution: cliFetcher.getRequiredArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' }); diff --git a/lib/node/cli/actions/project-action.ts b/lib/node/cli/actions/project-action.ts new file mode 100644 index 0000000..3e25ab1 --- /dev/null +++ b/lib/node/cli/actions/project-action.ts @@ -0,0 +1,20 @@ +import { generateProjectModelsAsync } from '../../../generators/index.js'; +import { ModuleResolution } from '../../../models.js'; +import { CliArgumentsFetcher } from '../cli.models.js'; + +export async function projectActionAsync(cliFetcher: CliArgumentsFetcher): Promise { + await generateProjectModelsAsync({ + environmentId: cliFetcher.getRequiredArgumentValue('environmentId'), + baseUrl: cliFetcher.getRequiredArgumentValue('managementApiUrl'), + apiKey: cliFetcher.getRequiredArgumentValue('apiKey'), + outputDir: cliFetcher.getRequiredArgumentValue('outputDir'), + isEnterpriseSubscription: cliFetcher.getBooleanArgumentValue('isEnterpriseSubscription', false), + addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), + addEnvironmentInfo: cliFetcher.getBooleanArgumentValue('addEnvironmentInfo', false), + sortConfig: { + sortTaxonomyTerms: cliFetcher.getBooleanArgumentValue('sortTaxonomyTerms', true) + }, + moduleResolution: + cliFetcher.getRequiredArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' + }); +} diff --git a/package.json b/package.json index 85a96ec..eb6b06a 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "build": "npm run lint && npm run clean && npm run build:es2022", "test:all": "npm run build && npm run test:delivery-models", "test:delivery": "tsx scripts/tests/delivery-models", + "test:project": "tsx scripts/tests/project-models", "test:migration": "tsx scripts/tests/migration-models", "test:help:command": "tsx lib/node/cli/app delivery --help", "lint": "npx eslint lib", diff --git a/sample/delivery/index.ts b/sample/delivery/index.ts index 855039b..5e8dc5a 100644 --- a/sample/delivery/index.ts +++ b/sample/delivery/index.ts @@ -1,4 +1,3 @@ -export * from './project/index.js'; export * from './content-types/index.js'; export * from './content-type-snippets/index.js'; export * from './taxonomies/index.js'; diff --git a/sample/migration/items/actor.ts b/sample/migration/content-types/actor.ts similarity index 100% rename from sample/migration/items/actor.ts rename to sample/migration/content-types/actor.ts diff --git a/sample/migration/items/index.ts b/sample/migration/content-types/index.ts similarity index 100% rename from sample/migration/items/index.ts rename to sample/migration/content-types/index.ts diff --git a/sample/migration/items/movie.ts b/sample/migration/content-types/movie.ts similarity index 100% rename from sample/migration/items/movie.ts rename to sample/migration/content-types/movie.ts diff --git a/sample/migration/index.ts b/sample/migration/index.ts index e83ebaf..1e05f1f 100644 --- a/sample/migration/index.ts +++ b/sample/migration/index.ts @@ -1,2 +1,2 @@ -export * from './items/index.js'; +export * from './content-types/index.js'; export * from './core.models.js'; diff --git a/sample/delivery/project/assetFolders.ts b/sample/project/assetFolders.ts similarity index 100% rename from sample/delivery/project/assetFolders.ts rename to sample/project/assetFolders.ts diff --git a/sample/delivery/project/collections.ts b/sample/project/collections.ts similarity index 100% rename from sample/delivery/project/collections.ts rename to sample/project/collections.ts diff --git a/sample/delivery/project/contentTypeSnippets.ts b/sample/project/contentTypeSnippets.ts similarity index 100% rename from sample/delivery/project/contentTypeSnippets.ts rename to sample/project/contentTypeSnippets.ts diff --git a/sample/delivery/project/contentTypes.ts b/sample/project/contentTypes.ts similarity index 100% rename from sample/delivery/project/contentTypes.ts rename to sample/project/contentTypes.ts diff --git a/sample/delivery/project/languages.ts b/sample/project/languages.ts similarity index 100% rename from sample/delivery/project/languages.ts rename to sample/project/languages.ts diff --git a/sample/delivery/project/roles.ts b/sample/project/roles.ts similarity index 100% rename from sample/delivery/project/roles.ts rename to sample/project/roles.ts diff --git a/sample/delivery/project/taxonomies.ts b/sample/project/taxonomies.ts similarity index 100% rename from sample/delivery/project/taxonomies.ts rename to sample/project/taxonomies.ts diff --git a/sample/delivery/project/webhooks.ts b/sample/project/webhooks.ts similarity index 100% rename from sample/delivery/project/webhooks.ts rename to sample/project/webhooks.ts diff --git a/sample/delivery/project/workflows.ts b/sample/project/workflows.ts similarity index 100% rename from sample/delivery/project/workflows.ts rename to sample/project/workflows.ts diff --git a/scripts/tests/delivery-models.ts b/scripts/tests/delivery-models.ts index 4590c94..ea00564 100644 --- a/scripts/tests/delivery-models.ts +++ b/scripts/tests/delivery-models.ts @@ -30,12 +30,8 @@ const run = async () => { environmentId: environmentId, apiKey: apiKey, moduleResolution: moduleResolution?.toLowerCase() === 'node' ? 'node' : 'nodeNext', - isEnterpriseSubscription: true, addEnvironmentInfo: true, - outputDir: outputDir, - sortConfig: { - sortTaxonomyTerms: true - } + outputDir: outputDir }); }; diff --git a/scripts/tests/project-models.ts b/scripts/tests/project-models.ts new file mode 100644 index 0000000..be9761c --- /dev/null +++ b/scripts/tests/project-models.ts @@ -0,0 +1,44 @@ +import * as dotenv from 'dotenv'; +import { rmSync } from 'fs'; +import { ModuleResolution, generateProjectModelsAsync, handleError } from '../../lib/index.js'; +import chalk from 'chalk'; +import { getEnvironmentRequiredValue } from 'scripts/utils/test.utils.js'; + +const outputDir: string = './sample/project'; + +const run = async () => { + // needed to load .env environment to current process when run via package.json script + dotenv.config({ + path: './.env' + }); + + // delete existing models + console.log(`Deleting existing folder '${chalk.yellow(outputDir)}'`); + rmSync(outputDir, { + recursive: true, + force: true + }); + + console.log(`Folder '${chalk.yellow(outputDir)}' deleted successfully`); + + const environmentId = getEnvironmentRequiredValue('ENVIRONMENT_ID'); + const apiKey = getEnvironmentRequiredValue('API_KEY'); + const moduleResolution = getEnvironmentRequiredValue('MODULE_RESOLUTION'); + + await generateProjectModelsAsync({ + addTimestamp: false, + environmentId: environmentId, + apiKey: apiKey, + moduleResolution: moduleResolution?.toLowerCase() === 'node' ? 'node' : 'nodeNext', + isEnterpriseSubscription: true, + addEnvironmentInfo: true, + outputDir: outputDir, + sortConfig: { + sortTaxonomyTerms: true + } + }); +}; + +run().catch((err) => { + handleError(err); +}); From 5f69ea2c9a5a3f7950248331c414bb189a68c2eb Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 19 Aug 2024 14:54:26 +0200 Subject: [PATCH 016/183] Makes project models readonly --- lib/common-helper.ts | 16 +- lib/core/core.models.ts | 5 + .../delivery-content-type.generator.ts | 13 +- .../delivery/delivery-taxonomy.generator.ts | 8 +- .../migration/migration-generator.ts | 3 +- lib/generators/project/project.generator.ts | 181 +++++++++--------- lib/models.ts | 66 ++++--- 7 files changed, 149 insertions(+), 143 deletions(-) diff --git a/lib/common-helper.ts b/lib/common-helper.ts index 595e59a..301ce38 100644 --- a/lib/common-helper.ts +++ b/lib/common-helper.ts @@ -3,19 +3,9 @@ import { ContentTypeElements, TaxonomyModels } from '@kontent-ai/management-sdk' import { libMetadata } from './meta/index.js'; import { ModuleResolution } from './models.js'; -export interface IGeneratedFile { - filename: string; - text: string; -} - -export interface GeneratedFile { - readonly filename: string; - readonly text: string; -} - export class CommonHelper { - sortAlphabetically(arrayToSort: T[], propertySelector: (item: T) => string): T[] { - return arrayToSort.sort((a, b) => + sortAlphabetically(arrayToSort: readonly T[], propertySelector: (item: T) => string): readonly T[] { + return arrayToSort.toSorted((a, b) => propertySelector(a).toLowerCase().localeCompare(propertySelector(b).toLowerCase()) ); } @@ -67,7 +57,7 @@ export class CommonHelper { getElementTitle( element: ContentTypeElements.ContentTypeElementModel, - taxonomies: TaxonomyModels.Taxonomy[] + taxonomies: readonly Readonly[] ): string | null { if (element.type === 'taxonomy') { const taxonomyGroupId = element.taxonomy_group?.id; diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index 1bb3d2b..08ec510 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -36,3 +36,8 @@ export interface FlattenedElement { readonly isRequired: boolean; readonly guidelines?: string; } + +export interface GeneratedFile { + readonly filename: string; + readonly text: string; +} diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index cf4da57..77a59a2 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -1,5 +1,5 @@ import chalk from 'chalk'; -import { commonHelper, IGeneratedFile } from '../../common-helper.js'; +import { commonHelper } from '../../common-helper.js'; import { ContentTypeResolver, ElementResolver, @@ -40,6 +40,7 @@ import { getMapContentTypeSnippetIdToObject } from './delivery-mappers.js'; import { textHelper } from '../../text-helper.js'; +import { GeneratedFile } from '../../core/index.js'; interface IExtendedContentTypeElement { type: ElementModels.ElementType; @@ -76,9 +77,9 @@ export class DeliveryContentTypeGenerator { taxonomyFileResolver?: TaxonomyTypeFileNameResolver; taxonomyResolver?: TaxonomyTypeResolver; moduleResolution: ModuleResolution; - }): { contentTypeFiles: IGeneratedFile[]; snippetFiles: IGeneratedFile[] } { - const typeFiles: IGeneratedFile[] = []; - const snippetFiles: IGeneratedFile[] = []; + }): { contentTypeFiles: GeneratedFile[]; snippetFiles: GeneratedFile[] } { + const typeFiles: GeneratedFile[] = []; + const snippetFiles: GeneratedFile[] = []; let addNewLineAfterResolvers: boolean = false; @@ -458,7 +459,7 @@ export type ${typeName} = IContentItem<{ addTimestamp: boolean; addEnvironmentInfo: boolean; moduleResolution: ModuleResolution; - }): IGeneratedFile { + }): GeneratedFile { const filename: string = `${data.outputDir}${data.typeFolderName}${data.contentTypeFileNameMap( data.type, true @@ -513,7 +514,7 @@ export type ${typeName} = IContentItem<{ addTimestamp: boolean; addEnvironmentInfo: boolean; moduleResolution: ModuleResolution; - }): IGeneratedFile { + }): GeneratedFile { const filename: string = `${data.outputDir}${data.typeSnippetsFolderName}${data.contentTypeSnippetFileNameMap( data.snippet, true diff --git a/lib/generators/delivery/delivery-taxonomy.generator.ts b/lib/generators/delivery/delivery-taxonomy.generator.ts index e3ed6c3..0ac0c35 100644 --- a/lib/generators/delivery/delivery-taxonomy.generator.ts +++ b/lib/generators/delivery/delivery-taxonomy.generator.ts @@ -1,6 +1,6 @@ import { TaxonomyTypeFileNameResolver, TaxonomyTypeResolver } from '../../models.js'; import chalk from 'chalk'; -import { commonHelper, IGeneratedFile } from '../../common-helper.js'; +import { commonHelper, GeneratedFile } from '../../common-helper.js'; import { TaxonomyModels } from '@kontent-ai/management-sdk'; import { MapTaxonomyToFileName, @@ -17,8 +17,8 @@ export class DeliveryTaxonomyGenerator { addTimestamp: boolean; fileResolver?: TaxonomyTypeFileNameResolver; taxonomyResolver?: TaxonomyTypeResolver; - }): IGeneratedFile[] { - const files: IGeneratedFile[] = []; + }): GeneratedFile[] { + const files: GeneratedFile[] = []; if (config.taxonomyResolver) { console.log( @@ -72,7 +72,7 @@ export class DeliveryTaxonomyGenerator { addTimestamp: boolean; taxonomyFileNameMap: MapTaxonomyToFileName; taxonomyNameMap: MapTaxonomyName; - }): IGeneratedFile { + }): GeneratedFile { const filename = `${data.outputDir}${data.taxonomyFolderName}${data.taxonomyFileNameMap(data.taxonomy, true)}`; const code = this.getModelCode({ taxonomy: data.taxonomy, diff --git a/lib/generators/migration/migration-generator.ts b/lib/generators/migration/migration-generator.ts index 64aba81..f55d44a 100644 --- a/lib/generators/migration/migration-generator.ts +++ b/lib/generators/migration/migration-generator.ts @@ -7,8 +7,7 @@ import { TaxonomyModels, WorkflowModels } from '@kontent-ai/management-sdk'; -import { GeneratedFile } from '../../common-helper.js'; -import { FlattenedElement, getImportStatement, toSafeString, uniqueFilter } from '../../core/index.js'; +import { FlattenedElement, getImportStatement, toSafeString, uniqueFilter, GeneratedFile } from '../../core/index.js'; import { textHelper } from '../../text-helper.js'; import { ModuleResolution } from '../../models.js'; import { commentsManager as _commentsManager } from '../../comments/index.js'; diff --git a/lib/generators/project/project.generator.ts b/lib/generators/project/project.generator.ts index b5a9b3e..1523806 100644 --- a/lib/generators/project/project.generator.ts +++ b/lib/generators/project/project.generator.ts @@ -1,5 +1,5 @@ import { Options } from 'prettier'; -import { commonHelper, IGeneratedFile } from '../../common-helper.js'; +import { commonHelper } from '../../common-helper.js'; import { textHelper } from '../../text-helper.js'; import { AssetFolderModels, @@ -16,42 +16,43 @@ import { } from '@kontent-ai/management-sdk'; import { camelCasePropertyNameResolver } from '@kontent-ai/delivery-sdk'; import { SortConfig } from '../../models.js'; +import { GeneratedFile } from '../../core/index.js'; -interface IProjectCodeResult { - filename: string; - code: string; +interface ProjectCodeResult { + readonly filename: string; + readonly code: string; } -interface IWorkflowStep { - name: string; - codename: string; - id: string; +interface WorkflowStep { + readonly name: string; + readonly codename: string; + readonly id: string; } -interface IExtendedContentTypeElement { - element: ContentTypeElements.ContentTypeElementModel; - snippet?: ContentTypeSnippetModels.ContentTypeSnippet; - mappedName: string | undefined; +interface ExtendedContentTypeElement { + readonly element: Readonly; + readonly snippet?: Readonly; + readonly mappedName: string | undefined; } export class ProjectGenerator { generateProjectModel(data: { - outputDir: string; - environmentInfo: EnvironmentModels.EnvironmentInformationModel; - types: ContentTypeModels.ContentType[]; - languages: LanguageModels.LanguageModel[]; - taxonomies: TaxonomyModels.Taxonomy[]; - workflows: WorkflowModels.Workflow[]; - assetFolders: AssetFolderModels.AssetFolder[]; - collections: CollectionModels.Collection[]; - roles: RoleModels.Role[]; - snippets: ContentTypeSnippetModels.ContentTypeSnippet[]; - webhooks: WebhookModels.Webhook[]; - addTimestamp: boolean; - addEnvironmentInfo: boolean; - sortConfig: SortConfig; - formatOptions?: Options; - }): IGeneratedFile[] { + readonly outputDir: string; + readonly environmentInfo: Readonly; + readonly types: readonly Readonly[]; + readonly languages: readonly Readonly[]; + readonly taxonomies: readonly Readonly[]; + readonly workflows: readonly Readonly[]; + readonly assetFolders: readonly Readonly[]; + readonly collections: readonly Readonly[]; + readonly roles: readonly Readonly[]; + readonly snippets: readonly Readonly[]; + readonly webhooks: readonly Readonly[]; + readonly addTimestamp: boolean; + readonly addEnvironmentInfo: boolean; + readonly sortConfig: SortConfig; + readonly formatOptions?: Options; + }): GeneratedFile[] { const projectCodes = this.getProjectModelCode({ environmentInfo: data.environmentInfo, types: data.types, @@ -81,7 +82,7 @@ export class ProjectGenerator { headerCode += ` */`; - const generatedFiles: IGeneratedFile[] = []; + const generatedFiles: GeneratedFile[] = []; for (const projectCode of projectCodes) { const filePath = `${data.outputDir}${projectCode.filename}`; @@ -95,7 +96,7 @@ export class ProjectGenerator { return generatedFiles; } - getAssetFoldersCount(folders: AssetFolderModels.AssetFolder[], count: number = 0): number { + getAssetFoldersCount(folders: readonly Readonly[], count: number = 0): number { count += folders.length; for (const folder of folders) { @@ -107,7 +108,7 @@ export class ProjectGenerator { return count; } - private getEnvironmentComment(environmentInfo: EnvironmentModels.EnvironmentInformationModel): string { + private getEnvironmentComment(environmentInfo: Readonly): string { let comment: string = `Project name: ${textHelper.toSafeName(environmentInfo.name, 'space')}`; comment += `\n* Environment: ${environmentInfo.environment}`; @@ -116,7 +117,7 @@ export class ProjectGenerator { return comment; } - private getContentTypeComment(contentType: ContentTypeModels.ContentType): string { + private getContentTypeComment(contentType: Readonly): string { let comment: string = `/**`; comment += `\n* ${textHelper.toSafeName(contentType.name, 'space')}`; @@ -125,7 +126,7 @@ export class ProjectGenerator { return comment; } - private getContentTypeSnippetComment(snippet: ContentTypeSnippetModels.ContentTypeSnippet): string { + private getContentTypeSnippetComment(snippet: Readonly): string { let comment: string = `/**`; comment += `\n* ${textHelper.toSafeName(snippet.name, 'space')}`; @@ -134,7 +135,7 @@ export class ProjectGenerator { return comment; } - private getWorkflowComment(workflow: WorkflowModels.Workflow): string { + private getWorkflowComment(workflow: Readonly): string { let comment: string = `/**`; comment += `\n* ${textHelper.toSafeName(workflow.name, 'space')}`; @@ -145,7 +146,7 @@ export class ProjectGenerator { return comment; } - private getAssetFolderComment(assetFolder: AssetFolderModels.AssetFolder): string { + private getAssetFolderComment(assetFolder: Readonly): string { let comment: string = `/**`; comment += `\n* ${textHelper.toSafeName(assetFolder.name, 'space')}`; @@ -154,7 +155,7 @@ export class ProjectGenerator { return comment; } - private getLanguageComment(language: LanguageModels.LanguageModel): string { + private getLanguageComment(language: Readonly): string { let comment: string = `/**`; comment += `\n* ${textHelper.toSafeName(language.name, 'space')}`; @@ -164,8 +165,8 @@ export class ProjectGenerator { } private getElementName( - element: ContentTypeElements.ContentTypeElementModel, - taxonomies: TaxonomyModels.Taxonomy[] + element: Readonly, + taxonomies: readonly Readonly[] ): string | undefined { if ((element as { name?: string })['name']) { return (element as { name: string })['name']; @@ -187,8 +188,8 @@ export class ProjectGenerator { } private getElementComment( - element: ContentTypeElements.ContentTypeElementModel, - taxonomies: TaxonomyModels.Taxonomy[] + element: Readonly, + taxonomies: readonly Readonly[] ): string { let comment: string = `/**`; const guidelines = commonHelper.getElementGuidelines(element); @@ -208,7 +209,7 @@ export class ProjectGenerator { return comment; } - private getTaxonomyComment(taxonomy: TaxonomyModels.Taxonomy): string { + private getTaxonomyComment(taxonomy: Readonly): string { let comment: string = `/**`; comment += `\n* ${textHelper.toSafeName(taxonomy.name, 'space')}`; @@ -217,7 +218,7 @@ export class ProjectGenerator { return comment; } - private getCollectionComment(collection: CollectionModels.Collection): string { + private getCollectionComment(collection: Readonly): string { let comment: string = `/**`; comment += `\n* ${textHelper.toSafeName(collection.name, 'space')}`; @@ -226,7 +227,7 @@ export class ProjectGenerator { return comment; } - private getRoleComment(role: RoleModels.Role): string { + private getRoleComment(role: Readonly): string { let comment: string = `/**`; comment += `\n* ${textHelper.toSafeName(role.name, 'space')}`; @@ -235,7 +236,7 @@ export class ProjectGenerator { return comment; } - private getWebhookComment(webhook: WebhookModels.Webhook): string { + private getWebhookComment(webhook: Readonly): string { let comment: string = `/**`; comment += `\n* ${textHelper.toSafeName(webhook.name, 'space')}`; @@ -245,21 +246,21 @@ export class ProjectGenerator { } private getProjectModelCode(data: { - environmentInfo: EnvironmentModels.EnvironmentInformationModel; - types: ContentTypeModels.ContentType[]; - languages: LanguageModels.LanguageModel[]; - taxonomies: TaxonomyModels.Taxonomy[]; - workflows: WorkflowModels.Workflow[]; - snippets: ContentTypeSnippetModels.ContentTypeSnippet[]; - assetFolders: AssetFolderModels.AssetFolder[]; - collections: CollectionModels.Collection[]; - roles: RoleModels.Role[]; - webhooks: WebhookModels.Webhook[]; - addTimestamp: boolean; - sortConfig: SortConfig; - formatOptions?: Options; - }): IProjectCodeResult[] { - const result: IProjectCodeResult[] = [ + readonly environmentInfo: Readonly; + readonly types: readonly ContentTypeModels.ContentType[]; + readonly languages: readonly LanguageModels.LanguageModel[]; + readonly taxonomies: readonly TaxonomyModels.Taxonomy[]; + readonly workflows: readonly WorkflowModels.Workflow[]; + readonly snippets: readonly ContentTypeSnippetModels.ContentTypeSnippet[]; + readonly assetFolders: readonly AssetFolderModels.AssetFolder[]; + readonly collections: readonly CollectionModels.Collection[]; + readonly roles: readonly RoleModels.Role[]; + readonly webhooks: readonly WebhookModels.Webhook[]; + readonly addTimestamp: boolean; + readonly sortConfig: SortConfig; + readonly formatOptions?: Options; + }): ProjectCodeResult[] { + const result: ProjectCodeResult[] = [ { code: `export const languages = { ${this.getProjectLanguages(data.languages)} @@ -317,7 +318,7 @@ export class ProjectGenerator { return result; } - private getProjectLanguages(languages: LanguageModels.LanguageModel[]): string { + private getProjectLanguages(languages: readonly LanguageModels.LanguageModel[]): string { let code: string = ``; for (let i = 0; i < languages.length; i++) { const language = languages[i]; @@ -345,7 +346,7 @@ export class ProjectGenerator { return `'${text}'`; } - private getProjectWorkflows(workflows: WorkflowModels.Workflow[]): string { + private getProjectWorkflows(workflows: readonly WorkflowModels.Workflow[]): string { let code: string = ``; for (let i = 0; i < workflows.length; i++) { const workflow = workflows[i]; @@ -364,7 +365,7 @@ export class ProjectGenerator { return code; } - private getAssetFolders(assetFolders: AssetFolderModels.AssetFolder[]): string { + private getAssetFolders(assetFolders: readonly AssetFolderModels.AssetFolder[]): string { let code: string = `{`; for (let i = 0; i < assetFolders.length; i++) { const assetFolder = assetFolders[i]; @@ -385,8 +386,8 @@ export class ProjectGenerator { } private getProjectContentTypeSnippets( - snippets: ContentTypeSnippetModels.ContentTypeSnippet[], - taxonomies: TaxonomyModels.Taxonomy[] + snippets: readonly ContentTypeSnippetModels.ContentTypeSnippet[], + taxonomies: readonly TaxonomyModels.Taxonomy[] ): string { let code: string = ``; for (let i = 0; i < snippets.length; i++) { @@ -408,9 +409,9 @@ export class ProjectGenerator { } private getProjectContentTypes( - contentTypes: ContentTypeModels.ContentType[], - snippets: ContentTypeSnippetModels.ContentTypeSnippet[], - taxonomies: TaxonomyModels.Taxonomy[] + contentTypes: readonly ContentTypeModels.ContentType[], + snippets: readonly ContentTypeSnippetModels.ContentTypeSnippet[], + taxonomies: readonly TaxonomyModels.Taxonomy[] ): string { let code: string = ``; for (let i = 0; i < contentTypes.length; i++) { @@ -432,13 +433,13 @@ export class ProjectGenerator { } private getContentTypeElements( - contentType: ContentTypeModels.ContentType, - snippets: ContentTypeSnippetModels.ContentTypeSnippet[], - taxonomies: TaxonomyModels.Taxonomy[] + contentType: Readonly, + snippets: readonly Readonly[], + taxonomies: readonly Readonly[] ): string { let code: string = ''; - const extendedElements: IExtendedContentTypeElement[] = this.getExtendedElements( + const extendedElements: readonly ExtendedContentTypeElement[] = this.getExtendedElements( contentType, snippets, taxonomies @@ -515,8 +516,8 @@ export class ProjectGenerator { } private getContentTypeSnippetElements( - snippet: ContentTypeSnippetModels.ContentTypeSnippet, - taxonomies: TaxonomyModels.Taxonomy[] + snippet: Readonly, + taxonomies: readonly Readonly[] ): string { let code: string = ''; @@ -555,11 +556,11 @@ export class ProjectGenerator { } private getExtendedElements( - contentType: ContentTypeModels.ContentType, - snippets: ContentTypeSnippetModels.ContentTypeSnippet[], - taxonomies: TaxonomyModels.Taxonomy[] - ): IExtendedContentTypeElement[] { - const extendedElements: IExtendedContentTypeElement[] = []; + contentType: Readonly, + snippets: readonly Readonly[], + taxonomies: readonly Readonly[] + ): readonly ExtendedContentTypeElement[] { + const extendedElements: ExtendedContentTypeElement[] = []; for (const element of contentType.elements) { if (element.type === 'snippet') { // get snippet elements @@ -573,7 +574,7 @@ export class ProjectGenerator { } extendedElements.push( ...snippet.elements.map((mElement) => { - const extendedElement: IExtendedContentTypeElement = { + const extendedElement: ExtendedContentTypeElement = { element: mElement, snippet: snippet, mappedName: this.getElementName(mElement, taxonomies) @@ -594,7 +595,10 @@ export class ProjectGenerator { return commonHelper.sortAlphabetically(extendedElements, (item) => item.mappedName ?? ''); } - private getProjectTaxonomies(taxonomies: TaxonomyModels.Taxonomy[], sortConfig: SortConfig): string { + private getProjectTaxonomies( + taxonomies: readonly Readonly[], + sortConfig: SortConfig + ): string { let code: string = ``; for (let i = 0; i < taxonomies.length; i++) { const taxonomy = taxonomies[i]; @@ -614,7 +618,7 @@ export class ProjectGenerator { return code; } - private getCollections(collections: CollectionModels.Collection[]): string { + private getCollections(collections: readonly Readonly[]): string { let code: string = ``; for (let i = 0; i < collections.length; i++) { const collection = collections[i]; @@ -632,7 +636,7 @@ export class ProjectGenerator { return code; } - private getRoles(roles: RoleModels.Role[]): string { + private getRoles(roles: readonly Readonly[]): string { let code: string = ``; for (let i = 0; i < roles.length; i++) { const role = roles[i]; @@ -650,7 +654,7 @@ export class ProjectGenerator { return code; } - private getWebhooks(webhooks: WebhookModels.Webhook[]): string { + private getWebhooks(webhooks: readonly Readonly[]): string { let code: string = ``; for (let i = 0; i < webhooks.length; i++) { const webhook = webhooks[i]; @@ -668,12 +672,15 @@ export class ProjectGenerator { return code; } - private getProjectTaxonomiesTerms(terms: TaxonomyModels.Taxonomy[], sortConfig: SortConfig): string { + private getProjectTaxonomiesTerms( + terms: readonly Readonly[], + sortConfig: SortConfig + ): string { if (terms.length === 0) { return `terms: {}`; } - const sortedTerms: TaxonomyModels.Taxonomy[] = sortConfig.sortTaxonomyTerms + const sortedTerms = sortConfig.sortTaxonomyTerms ? commonHelper.sortAlphabetically(terms, (item) => item.name) : terms; @@ -694,8 +701,8 @@ export class ProjectGenerator { return code; } - private getProjectWorkflowSteps(workflow: WorkflowModels.Workflow): string { - const steps: IWorkflowStep[] = [ + private getProjectWorkflowSteps(workflow: Readonly): string { + const steps: WorkflowStep[] = [ { codename: workflow.archivedStep.codename, id: workflow.archivedStep.id, diff --git a/lib/models.ts b/lib/models.ts index 06d7403..920bb89 100644 --- a/lib/models.ts +++ b/lib/models.ts @@ -9,53 +9,57 @@ export type ElementResolver = DefaultResolverType | PropertyNameResolver; export type ContentTypeFileNameResolver = | DefaultResolverType - | ((contentType: ContentTypeModels.ContentType) => string); + | ((contentType: Readonly) => string); export type ContentTypeSnippetFileNameResolver = | DefaultResolverType - | ((contentTypeSnippet: ContentTypeSnippetModels.ContentTypeSnippet) => string); -export type TaxonomyTypeFileNameResolver = DefaultResolverType | ((taxonomy: TaxonomyModels.Taxonomy) => string); + | ((contentTypeSnippet: Readonly) => string); +export type TaxonomyTypeFileNameResolver = + | DefaultResolverType + | ((taxonomy: Readonly) => string); -export type ContentTypeResolver = DefaultResolverType | ((contentType: ContentTypeModels.ContentType) => string); +export type ContentTypeResolver = + | DefaultResolverType + | ((contentType: Readonly) => string); export type ContentTypeSnippetResolver = | DefaultResolverType | ((contentTypeSnippet: ContentTypeSnippetModels.ContentTypeSnippet) => string); -export type TaxonomyTypeResolver = DefaultResolverType | ((taxonomy: TaxonomyModels.Taxonomy) => string); +export type TaxonomyTypeResolver = DefaultResolverType | ((taxonomy: Readonly) => string); export interface GenerateDeliveryModelsConfig { - environmentId: string; - addTimestamp: boolean; - addEnvironmentInfo: boolean; - apiKey: string; + readonly environmentId: string; + readonly addTimestamp: boolean; + readonly addEnvironmentInfo: boolean; + readonly apiKey: string; - moduleResolution?: ModuleResolution; - baseUrl?: string; - outputDir?: string; - contentTypeFileResolver?: ContentTypeFileNameResolver; - contentTypeSnippetFileResolver?: ContentTypeSnippetFileNameResolver; - taxonomyTypeFileResolver?: TaxonomyTypeFileNameResolver; - contentTypeResolver?: ContentTypeResolver; - contentTypeSnippetResolver?: ContentTypeSnippetResolver; - taxonomyTypeResolver?: TaxonomyTypeResolver; - elementResolver?: ElementResolver; - formatOptions?: Options; + readonly moduleResolution?: ModuleResolution; + readonly baseUrl?: string; + readonly outputDir?: string; + readonly contentTypeFileResolver?: ContentTypeFileNameResolver; + readonly contentTypeSnippetFileResolver?: ContentTypeSnippetFileNameResolver; + readonly taxonomyTypeFileResolver?: TaxonomyTypeFileNameResolver; + readonly contentTypeResolver?: ContentTypeResolver; + readonly contentTypeSnippetResolver?: ContentTypeSnippetResolver; + readonly taxonomyTypeResolver?: TaxonomyTypeResolver; + readonly elementResolver?: ElementResolver; + readonly formatOptions?: Options; } export interface SortConfig { - sortTaxonomyTerms: boolean; + readonly sortTaxonomyTerms: boolean; } export interface GeneratProjectModelsConfig { - environmentId: string; - addTimestamp: boolean; - addEnvironmentInfo: boolean; - isEnterpriseSubscription: boolean; - apiKey: string; + readonly environmentId: string; + readonly addTimestamp: boolean; + readonly addEnvironmentInfo: boolean; + readonly isEnterpriseSubscription: boolean; + readonly apiKey: string; - moduleResolution?: ModuleResolution; - baseUrl?: string; - outputDir?: string; - sortConfig?: SortConfig; - formatOptions?: Options; + readonly moduleResolution?: ModuleResolution; + readonly baseUrl?: string; + readonly outputDir?: string; + readonly sortConfig?: SortConfig; + readonly formatOptions?: Options; } export interface GenerateMigrationModelsConfig { From 8c9bb6e2979e8d92d9f78b3cdaf282fb2e25a48b Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 20 Aug 2024 08:00:07 +0200 Subject: [PATCH 017/183] Adds readonly modifiers to remaining migration input props --- .../migration/migration-generator.ts | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/generators/migration/migration-generator.ts b/lib/generators/migration/migration-generator.ts index f55d44a..8d60b53 100644 --- a/lib/generators/migration/migration-generator.ts +++ b/lib/generators/migration/migration-generator.ts @@ -22,12 +22,12 @@ export interface MigrationGeneratorConfig { readonly environmentData: { readonly environment: Readonly; - readonly types: readonly ContentTypeModels.ContentType[]; - readonly workflows: readonly WorkflowModels.Workflow[]; - readonly languages: readonly LanguageModels.LanguageModel[]; - readonly collections: readonly CollectionModels.Collection[]; - readonly snippets: readonly ContentTypeSnippetModels.ContentTypeSnippet[]; - readonly taxonomies: readonly TaxonomyModels.Taxonomy[]; + readonly types: readonly Readonly[]; + readonly workflows: readonly Readonly[]; + readonly languages: readonly Readonly[]; + readonly collections: readonly Readonly[]; + readonly snippets: readonly Readonly[]; + readonly taxonomies: readonly Readonly[]; }; } @@ -143,7 +143,7 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { function getFlattenedElements( type: Readonly, - snippets: readonly ContentTypeSnippetModels.ContentTypeSnippet[], + snippets: readonly Readonly[], taxonomies: readonly Readonly[] ): readonly FlattenedElement[] { return type.elements @@ -208,23 +208,23 @@ function getSystemType(): string { >;`; } -function getLanguageCodenamesType(languages: readonly LanguageModels.LanguageModel[]): string { +function getLanguageCodenamesType(languages: readonly Readonly[]): string { return `export type ${migrationTypeNames.languageCodenames} = ${languages.map((language) => `'${language.codename}'`).join(' | ')};`; } -function getContentTypeCodenamesType(types: readonly ContentTypeModels.ContentType[]): string { +function getContentTypeCodenamesType(types: readonly Readonly[]): string { return `export type ${migrationTypeNames.contentTypeCodenames} = ${types.map((type) => `'${type.codename}'`).join(' | ')};`; } -function getWorkflowCodenamesType(workflows: readonly WorkflowModels.Workflow[]): string { +function getWorkflowCodenamesType(workflows: readonly Readonly[]): string { return `export type ${migrationTypeNames.workflowCodenames} = ${workflows.map((workflow) => `'${workflow.codename}'`).join(' | ')};`; } -function getCollectionCodenamesType(collections: readonly CollectionModels.Collection[]): string { +function getCollectionCodenamesType(collections: readonly Readonly[]): string { return `export type ${migrationTypeNames.collectionCodenames} = ${collections.map((collection) => `'${collection.codename}'`).join(' | ')};`; } -function getWorkflowStepCodenamesType(workflows: readonly WorkflowModels.Workflow[]): string { +function getWorkflowStepCodenamesType(workflows: readonly Readonly[]): string { return `export type ${migrationTypeNames.workflowStepCodenames} = ${workflows .flatMap((workflow) => [ ...workflow.steps, From 2f129cc7c325be3ca2527985b02f19f26d6db8a6 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 20 Aug 2024 11:50:17 +0200 Subject: [PATCH 018/183] Refactors project generator --- lib/comments/comments.manager.ts | 7 +- lib/core/core.models.ts | 4 +- lib/core/core.utils.ts | 21 +- lib/core/element.utils.ts | 39 +- lib/fetch/kontent-fetcher.ts | 27 +- lib/generators/migration/migration-func.ts | 1 - .../migration/migration-generator.ts | 57 +- lib/generators/project/project-func.ts | 48 +- lib/generators/project/project.generator.ts | 910 ++++++------------ lib/models.ts | 2 - lib/node/cli/actions/migrate-action.ts | 1 - lib/node/cli/actions/project-action.ts | 1 - sample/migration/content-types/actor.ts | 35 +- sample/migration/content-types/index.ts | 1 + sample/migration/content-types/movie.ts | 81 +- sample/migration/content-types/test.ts | 40 + sample/migration/core.models.ts | 21 +- sample/project/assetFolders.ts | 19 +- sample/project/collections.ts | 4 +- sample/project/contentTypeSnippets.ts | 4 +- sample/project/contentTypes.ts | 212 ++-- sample/project/languages.ts | 16 +- sample/project/roles.ts | 4 +- sample/project/taxonomies.ts | 45 +- sample/project/webhooks.ts | 4 +- sample/project/workflows.ts | 8 +- scripts/tests/migration-models.ts | 1 - scripts/tests/project-models.ts | 1 - 28 files changed, 700 insertions(+), 914 deletions(-) create mode 100644 sample/migration/content-types/test.ts diff --git a/lib/comments/comments.manager.ts b/lib/comments/comments.manager.ts index aba98a0..973c587 100644 --- a/lib/comments/comments.manager.ts +++ b/lib/comments/comments.manager.ts @@ -17,14 +17,17 @@ export function commentsManager(addTimestamp: boolean) { return `/** \n * ${comment} \n*/`; }; - const environmentInfo = (environmentInfo: Readonly): string => { + const environmentInfo = ( + environmentInfo: Readonly, + opts?: { addGeneratedBy: boolean } + ): string => { return wrapComment( ` * ${environmentInfo.name} * * Environment: ${environmentInfo.environment} * Id: ${environmentInfo.id}`, - { addGeneratedBy: true } + opts ); }; diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index 08ec510..6579cf2 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -1,4 +1,4 @@ -import { ElementModels, IManagementClient } from '@kontent-ai/management-sdk'; +import { ContentTypeElements, ElementModels, IManagementClient } from '@kontent-ai/management-sdk'; export type CliAction = 'delivery' | 'migration'; export type LibraryType = '@kontent-ai/migration-toolkit'; @@ -32,9 +32,11 @@ export interface FlattenedElement { readonly title: string; readonly id: string; readonly codename: string; + readonly externalId?: string; readonly type: ElementModels.ElementType; readonly isRequired: boolean; readonly guidelines?: string; + readonly originalElement: Readonly; } export interface GeneratedFile { diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 81383dd..618351e 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -26,6 +26,12 @@ export function getFileNameWithoutExtension(filePath: string): string { return filePath.substring(0, lastDotIndex); } +export function sortAlphabetically(arrayToSort: readonly T[], propertySelector: (item: T) => string): readonly T[] { + return arrayToSort.toSorted((a, b) => + propertySelector(a).toLowerCase().localeCompare(propertySelector(b).toLowerCase()) + ); +} + export function getImportStatement(data: { filePathOrPackage: LiteralUnion; importValue: string; @@ -42,17 +48,17 @@ export function getImportStatement(data: { export function toPascalCase(text: string): string { // use element resolver from SDK to keep it consistent - return toSafeString(pascalCasePropertyNameResolver('', text), 'nothing'); + return toSafeStringCode(pascalCasePropertyNameResolver('', text)); } export function toCamelCase(text: string): string { // use element resolver from SDK to keep it consistent - return toSafeString(camelCasePropertyNameResolver('', text), 'nothing'); + return toSafeStringCode(camelCasePropertyNameResolver('', text)); } export function toSnakeCase(text: string): string { // use element resolver from SDK to keep it consistent - return toSafeString(snakeCasePropertyNameResolver('', text), 'nothing'); + return toSafeStringCode(snakeCasePropertyNameResolver('', text)); } export function toAlphanumeric(value: string): string { @@ -63,7 +69,12 @@ export function removeLineEndings(value: string): string { return value.replace(/(\r\n|\n|\r)/gm, ''); } -export function toSafeString(text: string, replaceWith: 'space' | 'nothing' = 'nothing'): string { - const replaceContent = replaceWith === 'space' ? ' ' : ''; +export function toSafeStringCode(text: string): string { + const replaceContent = ''; + return text.replace(/[\s-]/g, replaceContent).replace(/[^a-zA-Z0-9_]/g, replaceContent); +} + +export function toSafeString(text: string): string { + const replaceContent = ' '; return text.replace(/[\s-]/g, replaceContent).replace(/[^a-zA-Z0-9_]/g, replaceContent); } diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts index 46c2bac..6fc05fd 100644 --- a/lib/core/element.utils.ts +++ b/lib/core/element.utils.ts @@ -1,5 +1,38 @@ -import { ContentTypeElements, TaxonomyModels } from '@kontent-ai/management-sdk'; +import { ContentTypeElements, ContentTypeSnippetModels, TaxonomyModels } from '@kontent-ai/management-sdk'; import { FlattenedElement } from './core.models.js'; +import { isNotUndefined } from '@kontent-ai/migration-toolkit'; + +export function getFlattenedElements( + elements: readonly Readonly[], + snippets: readonly Readonly[], + taxonomies: readonly Readonly[] +): readonly FlattenedElement[] { + return elements + .filter((element) => { + if (element.type === 'guidelines') { + return false; + } + + return true; + }) + .flatMap((element) => { + if (element.type === 'snippet') { + const snippet = snippets.find((snippet) => snippet.id === element.snippet.id); + + if (!snippet) { + throw Error(`Could not find snippet with id '${element.snippet.id}'`); + } + + return snippet.elements; + } + + return element; + }) + .map((element) => { + return getFlattenedElement(element, taxonomies); + }) + .filter(isNotUndefined); +} export function getFlattenedElement( element: Readonly, @@ -18,7 +51,9 @@ export function getFlattenedElement( id: element.id, type: element.type, isRequired: isElementRequired(element), - guidelines: getElementGuidelines(element) + guidelines: getElementGuidelines(element), + externalId: element.external_id, + originalElement: element }; } diff --git a/lib/fetch/kontent-fetcher.ts b/lib/fetch/kontent-fetcher.ts index 2652275..9e19217 100644 --- a/lib/fetch/kontent-fetcher.ts +++ b/lib/fetch/kontent-fetcher.ts @@ -11,9 +11,8 @@ import { WebhookModels, WorkflowModels } from '@kontent-ai/management-sdk'; -import { GeneratorManagementClient, toSafeString } from '../core/index.js'; +import { GeneratorManagementClient, sortAlphabetically, toSafeString } from '../core/index.js'; import chalk from 'chalk'; -import { commonHelper } from '../common-helper.js'; interface KontentFetcherConfig { environmentId: string; @@ -36,23 +35,17 @@ export function kontentFetcher(config: KontentFetcherConfig) { return projectInformation.project; }, async getWorkflowsAsync(): Promise { - const items = commonHelper.sortAlphabetically( - (await client.listWorkflows().toPromise()).data, - (item) => item.name - ); + const items = sortAlphabetically((await client.listWorkflows().toPromise()).data, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' workflows`); return items; }, async getRolesAsync(): Promise { - const items = commonHelper.sortAlphabetically( - (await client.listRoles().toPromise()).data.roles, - (item) => item.name - ); + const items = sortAlphabetically((await client.listRoles().toPromise()).data.roles, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' roles`); return items; }, async getAssetFoldersAsync(): Promise { - const items = commonHelper.sortAlphabetically( + const items = sortAlphabetically( (await client.listAssetFolders().toPromise()).data.items, (item) => item.name ); @@ -60,7 +53,7 @@ export function kontentFetcher(config: KontentFetcherConfig) { return items; }, async getCollectionsAsync(): Promise { - const items = commonHelper.sortAlphabetically( + const items = sortAlphabetically( (await client.listCollections().toPromise()).data.collections, (item) => item.name ); @@ -68,7 +61,7 @@ export function kontentFetcher(config: KontentFetcherConfig) { return items; }, async getWebhooksAsync(): Promise { - const items = commonHelper.sortAlphabetically( + const items = sortAlphabetically( (await client.listWebhooks().toPromise()).data.webhooks, (item) => item.name ); @@ -76,7 +69,7 @@ export function kontentFetcher(config: KontentFetcherConfig) { return items; }, async getLanguagesAsync(): Promise { - const items = commonHelper.sortAlphabetically( + const items = sortAlphabetically( (await client.listLanguages().toAllPromise()).data.items, (item) => item.name ); @@ -84,7 +77,7 @@ export function kontentFetcher(config: KontentFetcherConfig) { return items; }, async getTypesAsync(): Promise { - const items = commonHelper.sortAlphabetically( + const items = sortAlphabetically( (await client.listContentTypes().toAllPromise()).data.items, (item) => item.name ); @@ -92,7 +85,7 @@ export function kontentFetcher(config: KontentFetcherConfig) { return items; }, async getSnippetsAsync(): Promise { - const items = commonHelper.sortAlphabetically( + const items = sortAlphabetically( (await client.listContentTypeSnippets().toAllPromise()).data.items, (item) => item.name ); @@ -100,7 +93,7 @@ export function kontentFetcher(config: KontentFetcherConfig) { return items; }, async getTaxonomiesAsync(): Promise { - const items = commonHelper.sortAlphabetically( + const items = sortAlphabetically( (await client.listTaxonomies().toAllPromise()).data.items, (item) => item.name ); diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index c2bdcd8..650c4b6 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -26,7 +26,6 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode const migrationGenerator = _migrationGenerator({ addTimestamp: config.addTimestamp, moduleResolution: config.moduleResolution, - addEnvironmentInfo: config.addEnvironmentInfo, environmentData: { environment: projectInformation, taxonomies: await kontentFetcher.getTaxonomiesAsync(), diff --git a/lib/generators/migration/migration-generator.ts b/lib/generators/migration/migration-generator.ts index 8d60b53..204f259 100644 --- a/lib/generators/migration/migration-generator.ts +++ b/lib/generators/migration/migration-generator.ts @@ -7,17 +7,22 @@ import { TaxonomyModels, WorkflowModels } from '@kontent-ai/management-sdk'; -import { FlattenedElement, getImportStatement, toSafeString, uniqueFilter, GeneratedFile } from '../../core/index.js'; -import { textHelper } from '../../text-helper.js'; +import { + FlattenedElement, + getImportStatement, + uniqueFilter, + GeneratedFile, + toSafeString, + removeLineEndings, + toPascalCase +} from '../../core/index.js'; import { ModuleResolution } from '../../models.js'; import { commentsManager as _commentsManager } from '../../comments/index.js'; import { match } from 'ts-pattern'; -import { isNotUndefined } from '@kontent-ai/migration-toolkit'; -import { getFlattenedElement } from 'lib/core/element.utils.js'; +import { getFlattenedElements } from 'lib/core/element.utils.js'; export interface MigrationGeneratorConfig { readonly addTimestamp: boolean; - readonly addEnvironmentInfo: boolean; readonly moduleResolution: ModuleResolution; readonly environmentData: { @@ -76,10 +81,14 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { * Codename: ${type.codename} * Id: ${type.id} */ - export type ${textHelper.toPascalCase(type.name)}Item = ${migrationTypeNames.item}< + export type ${toPascalCase(type.name)}Item = ${migrationTypeNames.item}< '${type.codename}', { - ${getFlattenedElements(type, config.environmentData.snippets, config.environmentData.taxonomies) + ${getFlattenedElements( + type.elements, + config.environmentData.snippets, + config.environmentData.taxonomies + ) .map((element) => { return ` /** @@ -87,7 +96,7 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { * * Required: ${element.isRequired ? 'true' : 'false'} * Codename: ${element.codename} - * Id: ${element.id}${element.guidelines ? `\n* Guidelines: ${textHelper.removeLineEndings(element.guidelines)}` : ''} + * Id: ${element.id}${element.guidelines ? `\n* Guidelines: ${removeLineEndings(element.guidelines)}` : ''} */ ${element.codename}: ${getElementPropType(element)}`; }) @@ -141,38 +150,6 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { }; } -function getFlattenedElements( - type: Readonly, - snippets: readonly Readonly[], - taxonomies: readonly Readonly[] -): readonly FlattenedElement[] { - return type.elements - .filter((element) => { - if (element.type === 'guidelines') { - return false; - } - - return true; - }) - .flatMap((element) => { - if (element.type === 'snippet') { - const snippet = snippets.find((snippet) => snippet.id === element.snippet.id); - - if (!snippet) { - throw Error(`Could not find snippet with id '${element.snippet.id}'`); - } - - return snippet.elements; - } - - return element; - }) - .map((element) => { - return getFlattenedElement(element, taxonomies); - }) - .filter(isNotUndefined); -} - function getElementPropType(element: Readonly): string { return match(element.type) .returnType() diff --git a/lib/generators/project/project-func.ts b/lib/generators/project/project-func.ts index cd8295c..abf715c 100644 --- a/lib/generators/project/project-func.ts +++ b/lib/generators/project/project-func.ts @@ -1,14 +1,15 @@ import chalk from 'chalk'; import { GeneratProjectModelsConfig, ModuleResolution } from '../../models.js'; -import { projectGenerator } from '../../generators/index.js'; +import { projectGenerator as _projectGenerator } from '../../generators/index.js'; import { commonHelper } from '../../common-helper.js'; import { parse } from 'path'; import { fileHelper } from '../../file-helper.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; +import { coreConfig } from 'lib/core/core.config.js'; export async function generateProjectModelsAsync(config: GeneratProjectModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); - console.log(`Generating '${chalk.yellow('delivery')}' models\n`); + console.log(`Generating '${chalk.yellow('project')}' models\n`); const outputDir: string = config.outputDir ? `${config.outputDir}/`.replaceAll('//', '/') : `./`; @@ -21,39 +22,26 @@ export async function generateProjectModelsAsync(config: GeneratProjectModelsCon const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; const projectInformation = await kontentFetcher.getEnvironmentInfoAsync(); - const types = await kontentFetcher.getTypesAsync(); - const snippets = await kontentFetcher.getSnippetsAsync(); - const taxonomies = await kontentFetcher.getTaxonomiesAsync(); - - const workflows = await kontentFetcher.getWorkflowsAsync(); - const roles = config.isEnterpriseSubscription ? await kontentFetcher.getRolesAsync() : []; - const assetFolders = await kontentFetcher.getAssetFoldersAsync(); - const collections = await kontentFetcher.getCollectionsAsync(); - const webhooks = await kontentFetcher.getWebhooksAsync(); - const languages = await kontentFetcher.getLanguagesAsync(); - - const projectFiles = projectGenerator.generateProjectModel({ + const projectFiles = _projectGenerator({ outputDir: outputDir, - environmentInfo: projectInformation, addTimestamp: config.addTimestamp, formatOptions: config.formatOptions, - addEnvironmentInfo: config.addEnvironmentInfo, - languages: languages, - taxonomies: taxonomies, - types: types, - workflows: workflows, - assetFolders: assetFolders, - collections: collections, - roles: roles, - snippets: snippets, - webhooks: webhooks, sortConfig: config.sortConfig ?? { sortTaxonomyTerms: true + }, + environmentData: { + environmentInfo: projectInformation, + languages: await kontentFetcher.getLanguagesAsync(), + taxonomies: await kontentFetcher.getTaxonomiesAsync(), + types: await kontentFetcher.getTypesAsync(), + workflows: await kontentFetcher.getWorkflowsAsync(), + assetFolders: await kontentFetcher.getAssetFoldersAsync(), + collections: await kontentFetcher.getCollectionsAsync(), + roles: config.isEnterpriseSubscription ? await kontentFetcher.getRolesAsync() : [], + snippets: await kontentFetcher.getSnippetsAsync(), + webhooks: await kontentFetcher.getWebhooksAsync() } - }); - - // create barrel export - const barrelExportFilename: string = 'index.ts'; + }).generateProjectModel(); // project barrel for (const file of projectFiles) { @@ -68,7 +56,7 @@ export async function generateProjectModelsAsync(config: GeneratProjectModelsCon }) ] }); - await fileHelper.createFileOnFsAsync(projectBarrelCode, barrelExportFilename, config.formatOptions); + await fileHelper.createFileOnFsAsync(projectBarrelCode, coreConfig.barrelExportFilename, config.formatOptions); console.log(chalk.green(`\nCompleted`)); } diff --git a/lib/generators/project/project.generator.ts b/lib/generators/project/project.generator.ts index 1523806..47c1102 100644 --- a/lib/generators/project/project.generator.ts +++ b/lib/generators/project/project.generator.ts @@ -1,10 +1,7 @@ import { Options } from 'prettier'; -import { commonHelper } from '../../common-helper.js'; -import { textHelper } from '../../text-helper.js'; import { AssetFolderModels, CollectionModels, - ContentTypeElements, ContentTypeModels, ContentTypeSnippetModels, LanguageModels, @@ -12,11 +9,21 @@ import { RoleModels, TaxonomyModels, WebhookModels, - WorkflowModels + WorkflowModels, + ContentTypeElements } from '@kontent-ai/management-sdk'; -import { camelCasePropertyNameResolver } from '@kontent-ai/delivery-sdk'; +import { commentsManager as _commentsManager } from '../../comments/index.js'; import { SortConfig } from '../../models.js'; -import { GeneratedFile } from '../../core/index.js'; +import { + FlattenedElement, + GeneratedFile, + getFlattenedElements, + removeLineEndings, + sortAlphabetically, + toSafeString, + toCamelCase +} from '../../core/index.js'; +import { match } from 'ts-pattern'; interface ProjectCodeResult { readonly filename: string; @@ -29,15 +36,13 @@ interface WorkflowStep { readonly id: string; } -interface ExtendedContentTypeElement { - readonly element: Readonly; - readonly snippet?: Readonly; - readonly mappedName: string | undefined; -} +export interface ProjectGeneratorConfig { + readonly outputDir: string; + readonly addTimestamp: boolean; + readonly sortConfig: SortConfig; + readonly formatOptions?: Options; -export class ProjectGenerator { - generateProjectModel(data: { - readonly outputDir: string; + readonly environmentData: { readonly environmentInfo: Readonly; readonly types: readonly Readonly[]; readonly languages: readonly Readonly[]; @@ -48,692 +53,351 @@ export class ProjectGenerator { readonly roles: readonly Readonly[]; readonly snippets: readonly Readonly[]; readonly webhooks: readonly Readonly[]; - readonly addTimestamp: boolean; - readonly addEnvironmentInfo: boolean; - readonly sortConfig: SortConfig; - readonly formatOptions?: Options; - }): GeneratedFile[] { - const projectCodes = this.getProjectModelCode({ - environmentInfo: data.environmentInfo, - types: data.types, - addTimestamp: data.addTimestamp, - formatOptions: data.formatOptions, - languages: data.languages, - taxonomies: data.taxonomies, - workflows: data.workflows, - assetFolders: data.assetFolders, - collections: data.collections, - roles: data.roles, - snippets: data.snippets, - webhooks: data.webhooks, - sortConfig: data.sortConfig - }); - - let headerCode = ` -/** -* ${commonHelper.getAutogenerateNote(data.addTimestamp)}`; - - if (data.addEnvironmentInfo) { - headerCode += ` -* -* ${this.getEnvironmentComment(data.environmentInfo)}`; - } + }; +} - headerCode += ` -*/`; +export function projectGenerator(config: ProjectGeneratorConfig) { + const commentsManager = _commentsManager(config.addTimestamp); - const generatedFiles: GeneratedFile[] = []; + const getHeaderComment = (): string => { + return `${commentsManager.environmentInfo(config.environmentData.environmentInfo, { addGeneratedBy: true })}`; + }; - for (const projectCode of projectCodes) { - const filePath = `${data.outputDir}${projectCode.filename}`; + const generateProjectModel = (): readonly GeneratedFile[] => { + const headerCode = getHeaderComment(); - generatedFiles.push({ - filename: filePath, + return getProjectModelCode().map((projectCode) => { + return { + filename: `${config.outputDir}${projectCode.filename}`, text: headerCode + '\n' + projectCode.code - }); - } - - return generatedFiles; - } - - getAssetFoldersCount(folders: readonly Readonly[], count: number = 0): number { - count += folders.length; - - for (const folder of folders) { - if (folder.folders) { - count = this.getAssetFoldersCount(folder.folders, count); - } - } - - return count; - } - - private getEnvironmentComment(environmentInfo: Readonly): string { - let comment: string = `Project name: ${textHelper.toSafeName(environmentInfo.name, 'space')}`; - - comment += `\n* Environment: ${environmentInfo.environment}`; - comment += `\n* Environment Id: ${environmentInfo.id}`; - - return comment; - } - - private getContentTypeComment(contentType: Readonly): string { - let comment: string = `/**`; - - comment += `\n* ${textHelper.toSafeName(contentType.name, 'space')}`; - comment += `\n*/`; - - return comment; - } - - private getContentTypeSnippetComment(snippet: Readonly): string { - let comment: string = `/**`; - - comment += `\n* ${textHelper.toSafeName(snippet.name, 'space')}`; - comment += `\n*/`; - - return comment; - } - - private getWorkflowComment(workflow: Readonly): string { - let comment: string = `/**`; - - comment += `\n* ${textHelper.toSafeName(workflow.name, 'space')}`; - comment += `\n* Archived step Id: ${workflow.archivedStep.id}`; - comment += `\n* Published step Id: ${workflow.publishedStep.id}`; - comment += `\n*/`; - - return comment; - } - - private getAssetFolderComment(assetFolder: Readonly): string { - let comment: string = `/**`; - - comment += `\n* ${textHelper.toSafeName(assetFolder.name, 'space')}`; - comment += `\n*/`; - - return comment; - } - - private getLanguageComment(language: Readonly): string { - let comment: string = `/**`; - - comment += `\n* ${textHelper.toSafeName(language.name, 'space')}`; - comment += `\n*/`; - - return comment; - } - - private getElementName( - element: Readonly, - taxonomies: readonly Readonly[] - ): string | undefined { - if ((element as { name?: string })['name']) { - return (element as { name: string })['name']; - } - - if (element.type === 'taxonomy') { - const taxonomy = taxonomies.find( - (m) => m.id.toLowerCase() === element.taxonomy_group.id?.toLocaleLowerCase() - ); - - if (!taxonomy) { - throw Error(`Invalid taxonomy with id '${element.taxonomy_group.id}'`); - } - - return taxonomy.name; - } - - return undefined; - } - - private getElementComment( - element: Readonly, - taxonomies: readonly Readonly[] - ): string { - let comment: string = `/**`; - const guidelines = commonHelper.getElementGuidelines(element); - const name = commonHelper.getElementTitle(element, taxonomies); - - if (name) { - comment += `\n* ${textHelper.toSafeName(name, 'space')} (${element.type})`; - } - - if (guidelines) { - comment += `\n*`; - comment += `\n* ${textHelper.removeLineEndings(guidelines)}`; - } - - comment += `\n*/`; - - return comment; - } - - private getTaxonomyComment(taxonomy: Readonly): string { - let comment: string = `/**`; - - comment += `\n* ${textHelper.toSafeName(taxonomy.name, 'space')}`; - comment += `\n*/`; - - return comment; - } - - private getCollectionComment(collection: Readonly): string { - let comment: string = `/**`; - - comment += `\n* ${textHelper.toSafeName(collection.name, 'space')}`; - comment += `\n*/`; - - return comment; - } - - private getRoleComment(role: Readonly): string { - let comment: string = `/**`; - - comment += `\n* ${textHelper.toSafeName(role.name, 'space')}`; - comment += `\n*/`; - - return comment; - } - - private getWebhookComment(webhook: Readonly): string { - let comment: string = `/**`; - - comment += `\n* ${textHelper.toSafeName(webhook.name, 'space')}`; - comment += `\n*/`; - - return comment; - } + }; + }); + }; - private getProjectModelCode(data: { - readonly environmentInfo: Readonly; - readonly types: readonly ContentTypeModels.ContentType[]; - readonly languages: readonly LanguageModels.LanguageModel[]; - readonly taxonomies: readonly TaxonomyModels.Taxonomy[]; - readonly workflows: readonly WorkflowModels.Workflow[]; - readonly snippets: readonly ContentTypeSnippetModels.ContentTypeSnippet[]; - readonly assetFolders: readonly AssetFolderModels.AssetFolder[]; - readonly collections: readonly CollectionModels.Collection[]; - readonly roles: readonly RoleModels.Role[]; - readonly webhooks: readonly WebhookModels.Webhook[]; - readonly addTimestamp: boolean; - readonly sortConfig: SortConfig; - readonly formatOptions?: Options; - }): ProjectCodeResult[] { + const getProjectModelCode = (): ProjectCodeResult[] => { const result: ProjectCodeResult[] = [ { code: `export const languages = { - ${this.getProjectLanguages(data.languages)} + ${getProjectLanguages(config.environmentData.languages)} } as const;`, filename: 'languages.ts' }, { code: `export const collections = { - ${this.getCollections(data.collections)} + ${getCollections(config.environmentData.collections)} } as const;`, filename: 'collections.ts' }, { code: `export const contentTypes = { - ${this.getProjectContentTypes(data.types, data.snippets, data.taxonomies)} + ${getProjectContentTypes(config.environmentData.types, config.environmentData.snippets, config.environmentData.taxonomies)} } as const;`, filename: 'contentTypes.ts' }, { code: `export const contentTypeSnippets = { - ${this.getProjectContentTypeSnippets(data.snippets, data.taxonomies)} + ${getProjectContentTypeSnippets(config.environmentData.snippets, config.environmentData.taxonomies)} } as const;`, filename: 'contentTypeSnippets.ts' }, { code: `export const taxonomies = { - ${this.getProjectTaxonomies(data.taxonomies, data.sortConfig)} + ${getProjectTaxonomies(config.environmentData.taxonomies, config.sortConfig)} } as const;`, filename: 'taxonomies.ts' }, { code: `export const workflows = { - ${this.getProjectWorkflows(data.workflows)} + ${getProjectWorkflows(config.environmentData.workflows)} } as const;`, filename: 'workflows.ts' }, { code: `export const roles = { - ${this.getRoles(data.roles)} + ${getRoles(config.environmentData.roles)} } as const;`, filename: 'roles.ts' }, { - code: `export const assetFolders = ${this.getAssetFolders(data.assetFolders)} as const;`, + code: `export const assetFolders = ${getAssetFolders(config.environmentData.assetFolders)} as const;`, filename: 'assetFolders.ts' }, { code: `export const webhooks = { - ${this.getWebhooks(data.webhooks)} + ${getWebhooks(config.environmentData.webhooks)} } as const;`, filename: 'webhooks.ts' } ]; return result; - } - - private getProjectLanguages(languages: readonly LanguageModels.LanguageModel[]): string { - let code: string = ``; - for (let i = 0; i < languages.length; i++) { - const language = languages[i]; - const isLast = i === languages.length - 1; - code += `\n`; - code += `${this.getLanguageComment(language)}\n`; - code += `${camelCasePropertyNameResolver('', language.codename)}: { - codename: '${language.codename}', - id: '${language.id}', - isActive: ${language.isActive ? 'true' : 'false'}, - isDefault: ${language.isDefault ? 'true' : 'false'}, - fallbackLanguageId: ${this.getStringOrUndefined(language.fallbackLanguage?.id)}, - externalId: ${this.getStringOrUndefined(language.externalId)}, - name: '${commonHelper.escapeNameValue(language.name)}'}`; - code += `${!isLast ? ',\n' : ''}`; - } - - return code; - } - - private getStringOrUndefined(text?: string): string { + }; + + const getProjectLanguages = (languages: readonly LanguageModels.LanguageModel[]): string => { + return languages.reduce((code, language, index) => { + const isLast = index === languages.length - 1; + + return `${code}\n + /** + * ${toSafeString(language.name)} + */ + ${toCamelCase(language.codename)}: { + codename: '${language.codename}', + id: '${language.id}', + name: '${toSafeString(language.name)}', + isActive: ${language.isActive ? 'true' : 'false'}, + isDefault: ${language.isDefault ? 'true' : 'false'}, + fallbackLanguageId: ${getStringOrUndefined(language.fallbackLanguage?.id)}, + externalId: ${getStringOrUndefined(language.externalId)}, + }${!isLast ? ',\n' : ''}`; + }, ''); + }; + + const getStringOrUndefined = (text?: string): string => { if (!text) { return 'undefined'; } return `'${text}'`; - } - - private getProjectWorkflows(workflows: readonly WorkflowModels.Workflow[]): string { - let code: string = ``; - for (let i = 0; i < workflows.length; i++) { - const workflow = workflows[i]; - const isLast = i === workflows.length - 1; - - code += `\n`; - code += `${this.getWorkflowComment(workflow)}\n`; - code += `${workflow.codename}: { - codename: '${workflow.codename}', - id: '${workflow.id}', - name: '${commonHelper.escapeNameValue(workflow.name)}', - steps: ${this.getProjectWorkflowSteps(workflow)} - }${!isLast ? ',\n' : ''}`; - } - - return code; - } - - private getAssetFolders(assetFolders: readonly AssetFolderModels.AssetFolder[]): string { - let code: string = `{`; - for (let i = 0; i < assetFolders.length; i++) { - const assetFolder = assetFolders[i]; - const isLast = i === assetFolders.length - 1; - - code += `\n`; - code += `${this.getAssetFolderComment(assetFolder)}\n`; - code += `${camelCasePropertyNameResolver('', assetFolder.name)}: { - id: '${assetFolder.id}', - name: '${commonHelper.escapeNameValue(assetFolder.name)}', - externalId: ${this.getStringOrUndefined(assetFolder.externalId)}, - folders: ${this.getAssetFolders(assetFolder.folders)}}${!isLast ? ',\n' : ''}`; - } - - code += '}'; - - return code; - } + }; + + const getProjectWorkflows = (workflows: readonly WorkflowModels.Workflow[]): string => { + return workflows.reduce((code, workflow, index) => { + const isLast = index === workflows.length - 1; + + return `${code}\n + /** + * ${toSafeString(workflow.name)} + */ + ${toCamelCase(workflow.codename)}: { + codename: '${workflow.codename}', + id: '${workflow.id}', + name: '${toSafeString(workflow.name)}', + steps: ${getProjectWorkflowSteps(workflow)} + }${!isLast ? ',\n' : ''}`; + }, ''); + }; + + const getAssetFolders = (assetFolders: readonly AssetFolderModels.AssetFolder[]): string => { + return ( + assetFolders.reduce((code, assetFolder, index) => { + const isLast = index === assetFolders.length - 1; + + return `${code}\n + /** + * ${toSafeString(assetFolder.name)} + */ + ${toCamelCase(assetFolder.codename)}: { + codename: '${assetFolder.codename}', + id: '${assetFolder.id}', + externalId: ${getStringOrUndefined(assetFolder.externalId)}, + name: '${toSafeString(assetFolder.name)}', + folders: ${getAssetFolders(assetFolder.folders)}}${!isLast ? ',\n' : ''}`; + }, '{') + '}' + ); + }; - private getProjectContentTypeSnippets( + const getProjectContentTypeSnippets = ( snippets: readonly ContentTypeSnippetModels.ContentTypeSnippet[], taxonomies: readonly TaxonomyModels.Taxonomy[] - ): string { - let code: string = ``; - for (let i = 0; i < snippets.length; i++) { - const snippet = snippets[i]; - const isLast = i === snippets.length - 1; - - code += `\n`; - code += `${this.getContentTypeSnippetComment(snippet)}\n`; - code += `${snippet.codename}: { - codename: '${snippet.codename}', - id: '${snippet.id}', - externalId: ${this.getStringOrUndefined(snippet.externalId)}, - name: '${commonHelper.escapeNameValue(snippet.name)}', - elements: {${this.getContentTypeSnippetElements(snippet, taxonomies)}} - }${!isLast ? ',\n' : ''}`; - } - - return code; - } - - private getProjectContentTypes( + ): string => { + return snippets.reduce((code, snippet, index) => { + const isLast = index === snippets.length - 1; + + return `${code}\n + /** + * ${toSafeString(snippet.name)} + */ + ${toCamelCase(snippet.codename)}: { + codename: '${snippet.codename}', + id: '${snippet.id}', + externalId: ${getStringOrUndefined(snippet.externalId)}, + name: '${toSafeString(snippet.name)}', + elements: {${getContentTypeElements(snippet.elements, snippets, taxonomies)}} + }${!isLast ? ',\n' : ''}`; + }, ''); + }; + + const getProjectContentTypes = ( contentTypes: readonly ContentTypeModels.ContentType[], snippets: readonly ContentTypeSnippetModels.ContentTypeSnippet[], taxonomies: readonly TaxonomyModels.Taxonomy[] - ): string { - let code: string = ``; - for (let i = 0; i < contentTypes.length; i++) { - const contentType = contentTypes[i]; - const isLast = i === contentTypes.length - 1; - - code += `\n`; - code += `${this.getContentTypeComment(contentType)}\n`; - code += `${contentType.codename}: { - codename: '${contentType.codename}', - id: '${contentType.id}', - externalId: ${this.getStringOrUndefined(contentType.externalId)}, - name: '${commonHelper.escapeNameValue(contentType.name)}', - elements: {${this.getContentTypeElements(contentType, snippets, taxonomies)}} - }${!isLast ? ',\n' : ''}`; - } - - return code; - } - - private getContentTypeElements( - contentType: Readonly, + ): string => { + return contentTypes.reduce((code, contentType, index) => { + const isLast = index === contentTypes.length - 1; + + return `${code}\n + /** + * ${toSafeString(contentType.name)} + */ + ${toCamelCase(contentType.codename)}: { + codename: '${contentType.codename}', + id: '${contentType.id}', + externalId: ${getStringOrUndefined(contentType.externalId)}, + name: '${toSafeString(contentType.name)}', + elements: {${getContentTypeElements(contentType.elements, snippets, taxonomies)}} + }${!isLast ? ',\n' : ''}`; + }, ''); + }; + + const getContentTypeElements = ( + elements: readonly Readonly[], snippets: readonly Readonly[], taxonomies: readonly Readonly[] - ): string { - let code: string = ''; - - const extendedElements: readonly ExtendedContentTypeElement[] = this.getExtendedElements( - contentType, - snippets, - taxonomies - ); - - for (let i = 0; i < extendedElements.length; i++) { - const extendedElement = extendedElements[i]; - const element = extendedElement.element; - const codename = commonHelper.getElementCodename(element); - const name = this.getElementName(element, taxonomies); - - if (!name) { - // element does not have a name (e.g. guidelines) - continue; - } - - if (!codename) { - // element does not have codename - continue; - } - - const isLast = i === extendedElements.length - 1; - - const isRequired = commonHelper.isElementRequired(element); - - const elementOptions = this.getElementOptions(element); - - code += `\n`; - code += `${this.getElementComment(element, taxonomies)}\n`; - code += `${codename}: { - codename: '${codename}', - id: '${element.id}', - externalId: ${this.getStringOrUndefined(element.external_id)}, - name: '${commonHelper.escapeNameValue(name)}', - required: ${isRequired}, - type: '${element.type}' - ${elementOptions ? `, options: ${elementOptions}` : ''} - ${ - extendedElement.snippet - ? `, snippetCodename: ${this.getStringOrUndefined(extendedElement.snippet?.codename)}` - : '' - } - - }${!isLast ? ',\n' : ''}`; - } - - return code; - } - - private getElementOptions(element: ContentTypeElements.ContentTypeElementModel): string | undefined { - if (element.type === 'multiple_choice') { - let stronglyTypedOptions: string = `{`; - - for (let i = 0; i < element.options.length; i++) { - const isLast = i === element.options.length - 1; - const option = element.options[i]; - - stronglyTypedOptions += `${option.codename}: { - name: '${textHelper.toSafeName(option.name, 'space')}', + ): string => { + const flattenedElements = getFlattenedElements(elements, snippets, taxonomies); + + return flattenedElements.reduce((code, element, index) => { + const isLast = index === flattenedElements.length - 1; + const elementOptions = getElementOptionsCode(element); + + return `${code}\n + /** + * ${toSafeString(element.title)} (${element.type})${element.guidelines ? `\n* Guidelines: ${removeLineEndings(element.guidelines)}` : ''} + */ + ${toCamelCase(element.codename)}: { + codename: '${element.codename}', + id: '${element.id}', + externalId: ${getStringOrUndefined(element.externalId)}, + name: '${toSafeString(element.title)}', + required: ${element.isRequired}, + type: '${element.type}' + ${elementOptions ? `, options: ${elementOptions}` : ''} + }${!isLast ? ',\n' : ''}`; + }, ''); + }; + + const getElementOptionsCode = (flattenedElement: FlattenedElement): string | undefined => { + return match(flattenedElement.originalElement) + .returnType() + .with({ type: 'multiple_choice' }, (element) => { + return ( + element.options.reduce((code, option, index) => { + const isLast = index === element.options.length - 1; + + return `${code}\n + /** + * ${toSafeString(option.name)} + */ + ${toCamelCase(option.codename ?? option.name)}: { + name: '${toSafeString(option.name)}', id: '${option.id}', - codename: '${option.codename}', - externalId: ${this.getStringOrUndefined(option.external_id)} - }`; - - stronglyTypedOptions += !isLast ? ',\n' : ''; - } - - stronglyTypedOptions += `}`; - - return stronglyTypedOptions; - } - - return undefined; - } - - private getContentTypeSnippetElements( - snippet: Readonly, - taxonomies: readonly Readonly[] - ): string { - let code: string = ''; - - for (let i = 0; i < snippet.elements.length; i++) { - const element = snippet.elements[i]; - const codename = commonHelper.getElementCodename(element); - const name = this.getElementName(element, taxonomies); - - if (!name) { - // element does not have a name (e.g. guidelines) - continue; - } - - if (!codename) { - // element does not have codename - continue; - } - - const isLast = i === snippet.elements.length - 1; - - const isRequired = commonHelper.isElementRequired(element); - - code += `\n`; - code += `${this.getElementComment(element, taxonomies)}\n`; - code += `${codename}: { - codename: '${codename}', - id: '${element.id}', - externalId: ${this.getStringOrUndefined(element.external_id)}, - name: '${commonHelper.escapeNameValue(name)}', - required: ${isRequired}, - type: '${element.type}', - }${!isLast ? ',\n' : ''}`; - } - - return code; - } - - private getExtendedElements( - contentType: Readonly, - snippets: readonly Readonly[], - taxonomies: readonly Readonly[] - ): readonly ExtendedContentTypeElement[] { - const extendedElements: ExtendedContentTypeElement[] = []; - for (const element of contentType.elements) { - if (element.type === 'snippet') { - // get snippet elements - const snippetElement: ContentTypeElements.ISnippetElement = element; - const snippet = snippets.find((m) => m.id === snippetElement.snippet.id); - - if (!snippet) { - throw Error( - `Could not find content type snippet with id '${snippetElement.snippet.id}'. This snippet is used in type '${contentType.codename}'` - ); - } - extendedElements.push( - ...snippet.elements.map((mElement) => { - const extendedElement: ExtendedContentTypeElement = { - element: mElement, - snippet: snippet, - mappedName: this.getElementName(mElement, taxonomies) - }; - - return extendedElement; - }) + codename: ${getStringOrUndefined(option.codename)}, + externalId: ${getStringOrUndefined(option.external_id)} + }${!isLast ? ',\n' : ''}`; + }, '{') + '}' ); - } else { - extendedElements.push({ - element: element, - snippet: undefined, - mappedName: this.getElementName(element, taxonomies) - }); - } - } - - return commonHelper.sortAlphabetically(extendedElements, (item) => item.mappedName ?? ''); - } + }) + .otherwise(() => undefined); + }; - private getProjectTaxonomies( + const getProjectTaxonomies = ( taxonomies: readonly Readonly[], sortConfig: SortConfig - ): string { - let code: string = ``; - for (let i = 0; i < taxonomies.length; i++) { - const taxonomy = taxonomies[i]; - const isLast = i === taxonomies.length - 1; - - code += `\n`; - code += `${this.getTaxonomyComment(taxonomy)}\n`; - code += `${taxonomy.codename}: { - codename: '${taxonomy.codename}', - id: '${taxonomy.id}', - externalId: ${this.getStringOrUndefined(taxonomy.externalId)}, - name: '${commonHelper.escapeNameValue(taxonomy.name)}', - ${this.getProjectTaxonomiesTerms(taxonomy.terms, sortConfig)} + ): string => { + return taxonomies.reduce((code, taxonomy, index) => { + const isLast = index === taxonomies.length - 1; + + return `${code}\n + /** + * ${toSafeString(taxonomy.name)} + */ + ${toCamelCase(taxonomy.codename)}: { + codename: '${taxonomy.codename}', + externalId: ${getStringOrUndefined(taxonomy.externalId)}, + id: '${taxonomy.id}', + name: '${toSafeString(taxonomy.name)}', + ${getProjectTaxonomiesTerms(taxonomy.terms, sortConfig)} }${!isLast ? ',\n' : ''}`; - } - - return code; - } - - private getCollections(collections: readonly Readonly[]): string { - let code: string = ``; - for (let i = 0; i < collections.length; i++) { - const collection = collections[i]; - const isLast = i === collections.length - 1; - - code += `\n`; - code += `${this.getCollectionComment(collection)}\n`; - code += `${collection.codename}: { - codename: '${collection.codename}', - id: '${collection.id}', - name: '${commonHelper.escapeNameValue(collection.name)}' - }${!isLast ? ',\n' : ''}`; - } - - return code; - } - - private getRoles(roles: readonly Readonly[]): string { - let code: string = ``; - for (let i = 0; i < roles.length; i++) { - const role = roles[i]; - const isLast = i === roles.length - 1; - - code += `\n`; - code += `${this.getRoleComment(role)}\n`; - code += `${camelCasePropertyNameResolver('', role.name)}: { - codename: ${role.codename ? "'" + role.codename + "'" : undefined}, - id: '${role.id}', - name: '${commonHelper.escapeNameValue(role.name)}' - }${!isLast ? ',\n' : ''}`; - } - - return code; - } - - private getWebhooks(webhooks: readonly Readonly[]): string { - let code: string = ``; - for (let i = 0; i < webhooks.length; i++) { - const webhook = webhooks[i]; - const isLast = i === webhooks.length - 1; - - code += `\n`; - code += `${this.getWebhookComment(webhook)}\n`; - code += `${camelCasePropertyNameResolver('', webhook.name)}: { - url: '${webhook.url}', - id: '${webhook.id}', - name: '${commonHelper.escapeNameValue(webhook.name)}' - }${!isLast ? ',\n' : ''}`; - } - - return code; - } - - private getProjectTaxonomiesTerms( + }, ''); + }; + + const getCollections = (collections: readonly Readonly[]): string => { + return collections.reduce((code, collection, index) => { + const isLast = index === collections.length - 1; + + return `${code}\n + /** + * ${toSafeString(collection.name)} + */ + ${toCamelCase(collection.codename)}: { + codename: '${collection.codename}', + id: '${collection.id}', + name: '${toSafeString(collection.name)}' + }${!isLast ? ',\n' : ''}`; + }, ''); + }; + + const getRoles = (roles: readonly Readonly[]): string => { + return roles.reduce((code, role, index) => { + const isLast = index === roles.length - 1; + + return `${code}\n + /** + * ${toSafeString(role.name)} + */ + ${toCamelCase(role.codename ?? role.name)}: { + codename: ${getStringOrUndefined(role.codename)}, + id: '${role.id}', + name: '${toSafeString(role.name)}' + }${!isLast ? ',\n' : ''}`; + }, ''); + }; + + const getWebhooks = (webhooks: readonly Readonly[]): string => { + return webhooks.reduce((code, webhook, index) => { + const isLast = index === webhooks.length - 1; + + return `${code}\n + /** + * ${toSafeString(webhook.name)} + */ + ${toCamelCase(webhook.name)}: { + url: '${webhook.url}', + id: '${webhook.id}', + name: '${toSafeString(webhook.name)}' + }${!isLast ? ',\n' : ''}`; + }, ''); + }; + + const getProjectTaxonomiesTerms = ( terms: readonly Readonly[], sortConfig: SortConfig - ): string { - if (terms.length === 0) { - return `terms: {}`; - } - - const sortedTerms = sortConfig.sortTaxonomyTerms - ? commonHelper.sortAlphabetically(terms, (item) => item.name) - : terms; - - let code: string = `terms: {`; - for (let i = 0; i < sortedTerms.length; i++) { - const term = sortedTerms[i]; - const isLast = i === sortedTerms.length - 1; - code += `${term.codename}: { - codename: '${term.codename}', - id: '${term.id}', - externalId: ${this.getStringOrUndefined(term.externalId)}, - name: '${commonHelper.escapeNameValue(term.name)}', - ${this.getProjectTaxonomiesTerms(term.terms, sortConfig)} - }${!isLast ? ',\n' : ''}`; - } - code += '}'; - - return code; - } + ): string => { + const sortedTerms = sortConfig.sortTaxonomyTerms ? sortAlphabetically(terms, (item) => item.name) : terms; + + return ( + sortedTerms.reduce((code, term, index) => { + const isLast = index === sortedTerms.length - 1; + + return `${code}\n + /** + * ${toSafeString(term.name)} + */ + ${toCamelCase(term.codename)}: { + codename: '${term.codename}', + id: '${term.id}', + externalId: ${getStringOrUndefined(term.externalId)}, + name: '${toSafeString(term.name)}', + ${getProjectTaxonomiesTerms(term.terms, sortConfig)} + }${!isLast ? ',\n' : ''}`; + }, 'terms: {') + '}' + ); + }; - private getProjectWorkflowSteps(workflow: Readonly): string { + const getProjectWorkflowSteps = (workflow: Readonly): string => { const steps: WorkflowStep[] = [ - { - codename: workflow.archivedStep.codename, - id: workflow.archivedStep.id, - name: workflow.archivedStep.name - }, - { - codename: workflow.publishedStep.codename, - id: workflow.publishedStep.id, - name: workflow.publishedStep.name - }, - { - codename: workflow.scheduledStep.codename, - id: workflow.scheduledStep.id, - name: workflow.scheduledStep.name - } + workflow.archivedStep, + workflow.publishedStep, + workflow.scheduledStep, + ...workflow.steps ]; - for (const step of workflow.steps) { - steps.push({ - codename: step.codename, - id: step.id, - name: step.name - }); - } - const code = `{${steps.reduce((code, step) => { return ( code + ` - ${step.codename}: { - name: '${commonHelper.escapeNameValue(step.name)}', + ${toCamelCase(step.codename)}: { + name: '${toSafeString(step.name)}', codename: '${step.codename}', id: '${step.id}' },` @@ -741,7 +405,9 @@ export class ProjectGenerator { }, ``)}}`; return code; - } -} + }; -export const projectGenerator = new ProjectGenerator(); + return { + generateProjectModel + }; +} diff --git a/lib/models.ts b/lib/models.ts index 920bb89..4ca78ef 100644 --- a/lib/models.ts +++ b/lib/models.ts @@ -51,7 +51,6 @@ export interface SortConfig { export interface GeneratProjectModelsConfig { readonly environmentId: string; readonly addTimestamp: boolean; - readonly addEnvironmentInfo: boolean; readonly isEnterpriseSubscription: boolean; readonly apiKey: string; @@ -63,7 +62,6 @@ export interface GeneratProjectModelsConfig { } export interface GenerateMigrationModelsConfig { - readonly addEnvironmentInfo: boolean; readonly environmentId: string; readonly addTimestamp: boolean; readonly apiKey: string; diff --git a/lib/node/cli/actions/migrate-action.ts b/lib/node/cli/actions/migrate-action.ts index c2f269d..cc8c562 100644 --- a/lib/node/cli/actions/migrate-action.ts +++ b/lib/node/cli/actions/migrate-action.ts @@ -9,7 +9,6 @@ export async function migrateActionAsync(cliFetcher: CliArgumentsFetcher): Promi apiKey: cliFetcher.getRequiredArgumentValue('apiKey'), outputDir: cliFetcher.getRequiredArgumentValue('outputDir'), addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), - addEnvironmentInfo: cliFetcher.getBooleanArgumentValue('addEnvironmentInfo', false), formatOptions: undefined, moduleResolution: cliFetcher.getRequiredArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' diff --git a/lib/node/cli/actions/project-action.ts b/lib/node/cli/actions/project-action.ts index 3e25ab1..5b00196 100644 --- a/lib/node/cli/actions/project-action.ts +++ b/lib/node/cli/actions/project-action.ts @@ -10,7 +10,6 @@ export async function projectActionAsync(cliFetcher: CliArgumentsFetcher): Promi outputDir: cliFetcher.getRequiredArgumentValue('outputDir'), isEnterpriseSubscription: cliFetcher.getBooleanArgumentValue('isEnterpriseSubscription', false), addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), - addEnvironmentInfo: cliFetcher.getBooleanArgumentValue('addEnvironmentInfo', false), sortConfig: { sortTaxonomyTerms: cliFetcher.getBooleanArgumentValue('sortTaxonomyTerms', true) }, diff --git a/sample/migration/content-types/actor.ts b/sample/migration/content-types/actor.ts index 5a8d022..543ce67 100644 --- a/sample/migration/content-types/actor.ts +++ b/sample/migration/content-types/actor.ts @@ -5,46 +5,45 @@ import type { Item } from '../core.models.js'; * Actor * * Codename: actor - * Id: 58099989-319f-495f-aa36-cb3710854e36 + * Id: d8900ee2-82f4-4189-a994-4e121582aadf */ export type ActorItem = Item< 'actor', { /** - * Url (url_slug) + * photo (asset) * * Required: false - * Codename: url - * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 + * Codename: photo + * Id: 069b38ee-385c-410f-b7fe-53ec59a5f139 */ - url: MigrationElementModels.UrlSlugElement; + photo: MigrationElementModels.AssetElement; /** - * Firstname (text) + * url (url_slug) * - * Required: true - * Codename: first_name - * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d - * Guidelines: This is the first name of the actor + * Required: false + * Codename: url + * Id: c4b2d64f-af45-45a4-92d8-4829833563ff */ - first_name: MigrationElementModels.TextElement; + url: MigrationElementModels.UrlSlugElement; /** - * Lastname (text) + * last_name (text) * - * Required: true + * Required: false * Codename: last_name - * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 + * Id: 0f00b26e-60f3-462d-8110-18180137c3a0 */ last_name: MigrationElementModels.TextElement; /** - * Photo (asset) + * first_name (text) * * Required: false - * Codename: photo - * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 + * Codename: first_name + * Id: 4af5e7ce-88ef-4159-96ae-96a552992f91 */ - photo: MigrationElementModels.AssetElement; + first_name: MigrationElementModels.TextElement; } >; diff --git a/sample/migration/content-types/index.ts b/sample/migration/content-types/index.ts index 79e8008..e8c4f36 100644 --- a/sample/migration/content-types/index.ts +++ b/sample/migration/content-types/index.ts @@ -1,2 +1,3 @@ export * from './actor.js'; export * from './movie.js'; +export * from './test.js'; diff --git a/sample/migration/content-types/movie.ts b/sample/migration/content-types/movie.ts index 2b5bacd..f9684b5 100644 --- a/sample/migration/content-types/movie.ts +++ b/sample/migration/content-types/movie.ts @@ -5,90 +5,99 @@ import type { Item } from '../core.models.js'; * Movie * * Codename: movie - * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c + * Id: db7356f6-1d82-42a0-9ebb-07865cffa995 */ export type MovieItem = Item< 'movie', { /** - * Title (text) + * Category (taxonomy) * - * Required: true - * Codename: title - * Id: 3473187e-dc78-eff2-7099-f690f7042d4a + * Required: false + * Codename: taxonomy_snippet_test__test_taxonomy + * Id: c030e3ec-5031-4d7f-af88-5032365733c7 */ - title: MigrationElementModels.TextElement; + taxonomy_snippet_test__test_taxonomy: MigrationElementModels.TaxonomyElement; /** - * Plot (rich_text) + * Release category (taxonomy) * * Required: false - * Codename: plot - * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce + * Codename: releasecategory + * Id: 5faa827f-f262-43c3-8f58-0f354b8d393f */ - plot: MigrationElementModels.RichTextElement; + releasecategory: MigrationElementModels.TaxonomyElement; /** - * Released (date_time) + * Category (taxonomy) * * Required: false - * Codename: released - * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 + * Codename: category + * Id: 8c12be35-e3e7-447c-a185-7b5e101ebf12 */ - released: MigrationElementModels.DateTimeElement; + category: MigrationElementModels.TaxonomyElement; /** - * Length (number) + * length (number) * * Required: false * Codename: length - * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c + * Id: e3d07f3a-60c2-4072-846d-c23e51ec833e */ length: MigrationElementModels.NumberElement; /** - * Poster (asset) + * stars (modular_content) * * Required: false - * Codename: poster - * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d + * Codename: stars + * Id: 55596dd1-e808-415d-95aa-e2be34238d11 */ - poster: MigrationElementModels.AssetElement; + stars: MigrationElementModels.LinkedItemsElement; /** - * Category (multiple_choice) + * seoname (url_slug) * * Required: false - * Codename: category - * Id: 9821c252-6414-f549-c17f-cc171dd87713 + * Codename: seoname + * Id: 734f94be-5930-4bdf-b05b-f59f5a291675 */ - category: MigrationElementModels.MultipleChoiceElement; + seoname: MigrationElementModels.UrlSlugElement; /** - * Stars (modular_content) + * poster (asset) * * Required: false - * Codename: stars - * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 + * Codename: poster + * Id: 9b197f1e-0728-4d14-9814-97f7b8ef01fc */ - stars: MigrationElementModels.LinkedItemsElement; + poster: MigrationElementModels.AssetElement; /** - * SeoName (url_slug) + * released (date_time) * * Required: false - * Codename: seoname - * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c + * Codename: released + * Id: 656b9dc9-7bba-4f1f-a2b8-52f7f730a66f */ - seoname: MigrationElementModels.UrlSlugElement; + released: MigrationElementModels.DateTimeElement; /** - * ReleaseCategory (taxonomy) + * plot (rich_text) * * Required: false - * Codename: releasecategory - * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 + * Codename: plot + * Id: ad2e5dc7-8d08-4f74-afeb-25b475f1e6fc */ - releasecategory: MigrationElementModels.TaxonomyElement; + plot: MigrationElementModels.RichTextElement; + + /** + * title (text) + * + * Required: false + * Codename: title + * Id: 660c851a-a9a1-4378-97a3-1348bc2a4d76 + */ + title: MigrationElementModels.TextElement; } >; diff --git a/sample/migration/content-types/test.ts b/sample/migration/content-types/test.ts new file mode 100644 index 0000000..2a9f76e --- /dev/null +++ b/sample/migration/content-types/test.ts @@ -0,0 +1,40 @@ +import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; +import type { Item } from '../core.models.js'; + +/** + * Test + * + * Codename: test + * Id: 81ab0b2c-dd14-41e7-a1ed-868b249ad8bc + */ +export type TestItem = Item< + 'test', + { + /** + * Text (text) + * + * Required: false + * Codename: text + * Id: 65f61f6a-b69c-47dc-bc38-19855507bf14 + */ + text: MigrationElementModels.TextElement; + + /** + * Snippet elem1 (text) + * + * Required: false + * Codename: my_snippet__snippet_elem1 + * Id: 3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d + */ + my_snippet__snippet_elem1: MigrationElementModels.TextElement; + + /** + * Snippet elem 2 (number) + * + * Required: false + * Codename: my_snippet__snippet_elem_2 + * Id: b2f65646-3310-4a64-af2a-0d9d025a91d0 + */ + my_snippet__snippet_elem_2: MigrationElementModels.NumberElement; + } +>; diff --git a/sample/migration/core.models.ts b/sample/migration/core.models.ts index e48ab95..e8f2a6c 100644 --- a/sample/migration/core.models.ts +++ b/sample/migration/core.models.ts @@ -1,22 +1,22 @@ import type { MigrationItemSystem, MigrationItem, MigrationElements } from '@kontent-ai/migration-toolkit'; /** - * Generated by '@kontent-ai/model-generator@7.4.0' - * Movie Database + * + * Migration Toolkit - tests * * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 */ /** * Type representing all languages */ -export type LanguageCodenames = 'cz' | 'en' | 'German'; +export type LanguageCodenames = 'en' | 'es'; /** * Type representing all content types */ -export type ContentTypeCodenames = 'actor' | 'movie'; +export type ContentTypeCodenames = 'actor' | 'movie' | 'test'; /** * Type representing all collections @@ -26,12 +26,19 @@ export type CollectionCodenames = 'default'; /** * Type representing all workflows */ -export type WorkflowCodenames = 'default'; +export type WorkflowCodenames = 'default' | 'my_test_workflow'; /** * Type representing all worksflow steps across all workflows */ -export type WorkflowStepCodenames = 'draft' | 'review' | 'ready_to_publish' | 'published' | 'archived' | 'scheduled'; +export type WorkflowStepCodenames = + | 'draft' + | 'ready_to_publish' + | 'published' + | 'archived' + | 'scheduled' + | 'draft_3171da5' + | 'ready_for_review'; /** * System object shared by all individual content type models diff --git a/sample/project/assetFolders.ts b/sample/project/assetFolders.ts index 4782f19..3c7f907 100644 --- a/sample/project/assetFolders.ts +++ b/sample/project/assetFolders.ts @@ -1,34 +1,37 @@ /** * Generated by '@kontent-ai/model-generator@7.4.0' + * Movie Database * - * Project name: Movie Database * Environment: Production - * Environment Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 */ export const assetFolders = { /** * my folder A */ myFolderA: { + codename: 'my_folder_a', id: '6bb4814a-6a5c-4b8c-836e-7f83b008d5d1', - name: 'my folder A', externalId: undefined, + name: 'my folder A', folders: { /** * my folder nested A */ myFolderNestedA: { + codename: 'my_folder_nested_a', id: '555784e5-e92e-4a86-b40b-d642afbf7b4e', - name: 'my folder nested A', externalId: undefined, + name: 'my folder nested A', folders: { /** * even more nested A */ evenMoreNestedA: { + codename: 'even_more_nested_a', id: 'd26940cc-6c8d-41e6-93a0-0748c854b100', - name: 'even more nested A', externalId: undefined, + name: 'even more nested A', folders: {} }, @@ -36,9 +39,10 @@ export const assetFolders = { * even more nested B */ evenMoreNestedB: { + codename: 'even_more_nested_b', id: '97fc4b03-98d2-44b4-8e03-b223a013b0b6', - name: 'even more nested B', externalId: undefined, + name: 'even more nested B', folders: {} } } @@ -50,9 +54,10 @@ export const assetFolders = { * my folder B */ myFolderB: { + codename: 'my_folder_b', id: '58d1c135-42cb-43c2-a2cd-c615e0a36e83', - name: 'my folder B', externalId: undefined, + name: 'my folder B', folders: {} } } as const; diff --git a/sample/project/collections.ts b/sample/project/collections.ts index 602d351..417d017 100644 --- a/sample/project/collections.ts +++ b/sample/project/collections.ts @@ -1,9 +1,9 @@ /** * Generated by '@kontent-ai/model-generator@7.4.0' + * Movie Database * - * Project name: Movie Database * Environment: Production - * Environment Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 */ export const collections = { /** diff --git a/sample/project/contentTypeSnippets.ts b/sample/project/contentTypeSnippets.ts index 6f607e6..81119c3 100644 --- a/sample/project/contentTypeSnippets.ts +++ b/sample/project/contentTypeSnippets.ts @@ -1,8 +1,8 @@ /** * Generated by '@kontent-ai/model-generator@7.4.0' + * Movie Database * - * Project name: Movie Database * Environment: Production - * Environment Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 */ export const contentTypeSnippets = {} as const; diff --git a/sample/project/contentTypes.ts b/sample/project/contentTypes.ts index 5b3e42a..44df780 100644 --- a/sample/project/contentTypes.ts +++ b/sample/project/contentTypes.ts @@ -1,9 +1,9 @@ /** * Generated by '@kontent-ai/model-generator@7.4.0' + * Movie Database * - * Project name: Movie Database * Environment: Production - * Environment Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 */ export const contentTypes = { /** @@ -15,12 +15,23 @@ export const contentTypes = { externalId: undefined, name: 'Actor', elements: { + /** + * Url (url_slug) + */ + url: { + codename: 'url', + id: 'c8658782-f209-a573-9c85-430fb4e3e9f0', + externalId: undefined, + name: 'Url', + required: false, + type: 'url_slug' + }, + /** * First name (text) - * - * This is the first name of the actor + * Guidelines: This is the first name of the actor */ - first_name: { + firstName: { codename: 'first_name', id: '14dd70e5-c42d-f111-9640-c82b443edf1d', externalId: undefined, @@ -32,7 +43,7 @@ export const contentTypes = { /** * Last name (text) */ - last_name: { + lastName: { codename: 'last_name', id: '9f7a0dd4-af3a-95ca-0358-400c14ce7075', externalId: undefined, @@ -51,18 +62,6 @@ export const contentTypes = { name: 'Photo', required: false, type: 'asset' - }, - - /** - * Url (url_slug) - */ - url: { - codename: 'url', - id: 'c8658782-f209-a573-9c85-430fb4e3e9f0', - externalId: undefined, - name: 'Url', - required: false, - type: 'url_slug' } } }, @@ -76,6 +75,66 @@ export const contentTypes = { externalId: undefined, name: 'Movie', elements: { + /** + * Title (text) + */ + title: { + codename: 'title', + id: '3473187e-dc78-eff2-7099-f690f7042d4a', + externalId: undefined, + name: 'Title', + required: true, + type: 'text' + }, + + /** + * Plot (rich_text) + */ + plot: { + codename: 'plot', + id: 'f7ee4f27-27fd-a19b-3c5c-102aae1c50ce', + externalId: undefined, + name: 'Plot', + required: false, + type: 'rich_text' + }, + + /** + * Released (date_time) + */ + released: { + codename: 'released', + id: '5ccf4644-0d65-5d96-9a32-f4ea21974d51', + externalId: undefined, + name: 'Released', + required: false, + type: 'date_time' + }, + + /** + * Length (number) + */ + length: { + codename: 'length', + id: '7e8ecfab-a419-27ee-d8ec-8adb76fd007c', + externalId: undefined, + name: 'Length', + required: false, + type: 'number' + }, + + /** + * Poster (asset) + */ + poster: { + codename: 'poster', + id: 'a39a7237-9503-a1ae-8431-5b6cdb85ae9d', + externalId: undefined, + name: 'Poster', + required: false, + type: 'asset' + }, + /** * Category (multiple_choice) */ @@ -87,48 +146,79 @@ export const contentTypes = { required: false, type: 'multiple_choice', options: { - sci_fi: { + /** + * Sci fi + */ + sciFi: { name: 'Sci fi', id: 'b087f774-1f57-9aa8-dab5-2ca88a646824', codename: 'sci_fi', externalId: undefined }, + + /** + * Documentary + */ documentary: { name: 'Documentary', id: '19c5e959-c24a-4863-0b4d-453cdef8fe9d', codename: 'documentary', externalId: undefined }, + + /** + * Action + */ action: { name: 'Action', id: '7d453309-8d74-9607-80c4-36dcc1bd005f', codename: 'action', externalId: undefined }, + + /** + * Romance + */ romance: { name: 'Romance', id: '60550cc7-c986-a59f-b069-7565862fe1c1', codename: 'romance', externalId: undefined }, + + /** + * Animation + */ animation: { name: 'Animation', id: '54c0590d-6a94-a69a-902d-fceea4fa62f8', codename: 'animation', externalId: undefined }, + + /** + * Comedy + */ comedy: { name: 'Comedy', id: 'd2fe357f-894e-9bc3-550c-c2c400d99c6b', codename: 'comedy', externalId: undefined }, + + /** + * Adventure + */ adventure: { name: 'Adventure', id: 'cd8389b0-7628-7739-7b14-3225a50212c1', codename: 'adventure', externalId: undefined }, + + /** + * Drama + */ drama: { name: 'Drama', id: '051e74de-f2e0-f405-9ad5-5263221e46f2', @@ -139,63 +229,15 @@ export const contentTypes = { }, /** - * Length (number) - */ - length: { - codename: 'length', - id: '7e8ecfab-a419-27ee-d8ec-8adb76fd007c', - externalId: undefined, - name: 'Length', - required: false, - type: 'number' - }, - - /** - * Plot (rich_text) - */ - plot: { - codename: 'plot', - id: 'f7ee4f27-27fd-a19b-3c5c-102aae1c50ce', - externalId: undefined, - name: 'Plot', - required: false, - type: 'rich_text' - }, - - /** - * Poster (asset) - */ - poster: { - codename: 'poster', - id: 'a39a7237-9503-a1ae-8431-5b6cdb85ae9d', - externalId: undefined, - name: 'Poster', - required: false, - type: 'asset' - }, - - /** - * ReleaseCategory (taxonomy) - */ - releasecategory: { - codename: 'releasecategory', - id: '65f2fd44-1856-bc2b-17c2-decb0635e3d2', - externalId: undefined, - name: 'ReleaseCategory', - required: false, - type: 'taxonomy' - }, - - /** - * Released (date_time) + * Stars (modular_content) */ - released: { - codename: 'released', - id: '5ccf4644-0d65-5d96-9a32-f4ea21974d51', + stars: { + codename: 'stars', + id: 'aa26a55d-19f8-7501-fea3-b0d9b1eeac71', externalId: undefined, - name: 'Released', + name: 'Stars', required: false, - type: 'date_time' + type: 'modular_content' }, /** @@ -211,27 +253,15 @@ export const contentTypes = { }, /** - * Stars (modular_content) + * ReleaseCategory (taxonomy) */ - stars: { - codename: 'stars', - id: 'aa26a55d-19f8-7501-fea3-b0d9b1eeac71', + releasecategory: { + codename: 'releasecategory', + id: '65f2fd44-1856-bc2b-17c2-decb0635e3d2', externalId: undefined, - name: 'Stars', + name: 'ReleaseCategory', required: false, - type: 'modular_content' - }, - - /** - * Title (text) - */ - title: { - codename: 'title', - id: '3473187e-dc78-eff2-7099-f690f7042d4a', - externalId: undefined, - name: 'Title', - required: true, - type: 'text' + type: 'taxonomy' } } } diff --git a/sample/project/languages.ts b/sample/project/languages.ts index 9c3db8e..21577e9 100644 --- a/sample/project/languages.ts +++ b/sample/project/languages.ts @@ -1,9 +1,9 @@ /** * Generated by '@kontent-ai/model-generator@7.4.0' + * Movie Database * - * Project name: Movie Database * Environment: Production - * Environment Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 */ export const languages = { /** @@ -12,11 +12,11 @@ export const languages = { cz: { codename: 'cz', id: '41ccb26f-ceab-04d0-6ffa-9c7c5358aa8f', + name: 'cz', isActive: true, isDefault: false, fallbackLanguageId: '00000000-0000-0000-0000-000000000000', - externalId: undefined, - name: 'cz' + externalId: undefined }, /** @@ -25,11 +25,11 @@ export const languages = { en: { codename: 'en', id: '00000000-0000-0000-0000-000000000000', + name: 'English', isActive: true, isDefault: true, fallbackLanguageId: '00000000-0000-0000-0000-000000000000', - externalId: undefined, - name: 'English' + externalId: undefined }, /** @@ -38,10 +38,10 @@ export const languages = { german: { codename: 'German', id: '14f7bcc0-4fd6-4b77-8c22-70e5ccfdae1d', + name: 'German', isActive: false, isDefault: false, fallbackLanguageId: '00000000-0000-0000-0000-000000000000', - externalId: undefined, - name: 'German' + externalId: undefined } } as const; diff --git a/sample/project/roles.ts b/sample/project/roles.ts index 52bcdac..8caaf5b 100644 --- a/sample/project/roles.ts +++ b/sample/project/roles.ts @@ -1,9 +1,9 @@ /** * Generated by '@kontent-ai/model-generator@7.4.0' + * Movie Database * - * Project name: Movie Database * Environment: Production - * Environment Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 */ export const roles = { /** diff --git a/sample/project/taxonomies.ts b/sample/project/taxonomies.ts index 6202bf7..d095aff 100644 --- a/sample/project/taxonomies.ts +++ b/sample/project/taxonomies.ts @@ -1,9 +1,9 @@ /** * Generated by '@kontent-ai/model-generator@7.4.0' + * Movie Database * - * Project name: Movie Database * Environment: Production - * Environment Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 */ export const taxonomies = { /** @@ -11,16 +11,22 @@ export const taxonomies = { */ movietype: { codename: 'movietype', - id: '365a17e6-1929-27ab-9f67-a9273c846717', externalId: undefined, + id: '365a17e6-1929-27ab-9f67-a9273c846717', name: 'MovieType', terms: { + /** + * Film + */ film: { codename: 'film', id: '5a2a1927-41a4-294f-5d89-cf0cc045e943', externalId: undefined, name: 'Film', terms: { + /** + * Blockbuster + */ blockbuster: { codename: 'blockbuster', id: '875a4657-1dcd-0415-cb3a-892078f5991a', @@ -28,13 +34,21 @@ export const taxonomies = { name: 'Blockbuster', terms: {} }, - cinema_only: { + + /** + * Cinema only + */ + cinemaOnly: { codename: 'cinema_only', id: 'e15c4e32-ab7c-57a2-1b66-d8e3566a1dd2', externalId: undefined, name: 'Cinema only', terms: {} }, + + /** + * TV + */ tv: { codename: 'tv', id: '47511b09-6c39-fa04-ff59-7c47551e827f', @@ -44,6 +58,10 @@ export const taxonomies = { } } }, + + /** + * Student + */ student: { codename: 'student', id: 'b107e12c-124d-705f-1029-c0dfdd0b2438', @@ -59,25 +77,36 @@ export const taxonomies = { */ releasecategory: { codename: 'releasecategory', - id: '09b6a348-0f86-7a68-4af3-7cab9a5c60b7', externalId: undefined, + id: '09b6a348-0f86-7a68-4af3-7cab9a5c60b7', name: 'ReleaseCategory', terms: { - global_release: { + /** + * Global release + */ + globalRelease: { codename: 'global_release', id: '4acaf439-9f3a-f34a-6211-d3fc6ec7152e', externalId: undefined, name: 'Global release', terms: {} }, - local_release: { + + /** + * Local release + */ + localRelease: { codename: 'local_release', id: '37e55484-f0dc-14eb-bf2a-b0293a0d1b1f', externalId: undefined, name: 'Local release', terms: {} }, - us_only: { + + /** + * US only + */ + usOnly: { codename: 'us_only', id: 'b03d990a-55a9-601e-dd5c-aa2edc8698ca', externalId: undefined, diff --git a/sample/project/webhooks.ts b/sample/project/webhooks.ts index 18b2068..fc0272e 100644 --- a/sample/project/webhooks.ts +++ b/sample/project/webhooks.ts @@ -1,8 +1,8 @@ /** * Generated by '@kontent-ai/model-generator@7.4.0' + * Movie Database * - * Project name: Movie Database * Environment: Production - * Environment Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 */ export const webhooks = {} as const; diff --git a/sample/project/workflows.ts b/sample/project/workflows.ts index 5f9a296..a93b01b 100644 --- a/sample/project/workflows.ts +++ b/sample/project/workflows.ts @@ -1,15 +1,13 @@ /** * Generated by '@kontent-ai/model-generator@7.4.0' + * Movie Database * - * Project name: Movie Database * Environment: Production - * Environment Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 */ export const workflows = { /** * Default - * Archived step Id: 7a535a69-ad34-47f8-806a-def1fdf4d391 - * Published step Id: f05b8a85-c6cc-429a-ac6d-21d5edd268fe */ default: { codename: 'default', @@ -41,7 +39,7 @@ export const workflows = { codename: 'review', id: 'c5682935-f5a2-4514-8025-57d8bdf7558d' }, - ready_to_publish: { + readyToPublish: { name: 'Ready to publish', codename: 'ready_to_publish', id: 'aaee1d73-f0cc-4185-9e49-844d161c3634' diff --git a/scripts/tests/migration-models.ts b/scripts/tests/migration-models.ts index 0ad98af..8b1cf90 100644 --- a/scripts/tests/migration-models.ts +++ b/scripts/tests/migration-models.ts @@ -30,7 +30,6 @@ const run = async () => { environmentId: environmentId, apiKey: apiKey, moduleResolution: moduleResolution?.toLowerCase() === 'node' ? 'node' : 'nodeNext', - addEnvironmentInfo: true, outputDir: outputDir }); }; diff --git a/scripts/tests/project-models.ts b/scripts/tests/project-models.ts index be9761c..8d1d467 100644 --- a/scripts/tests/project-models.ts +++ b/scripts/tests/project-models.ts @@ -31,7 +31,6 @@ const run = async () => { apiKey: apiKey, moduleResolution: moduleResolution?.toLowerCase() === 'node' ? 'node' : 'nodeNext', isEnterpriseSubscription: true, - addEnvironmentInfo: true, outputDir: outputDir, sortConfig: { sortTaxonomyTerms: true From 26f1bd0a48c3800ca5f978f846ed2b9df10261e5 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 20 Aug 2024 11:54:55 +0200 Subject: [PATCH 019/183] Updates imports --- lib/generators/index.ts | 2 +- lib/generators/migration/migration-func.ts | 14 +++++++------- ...gration-generator.ts => migration.generator.ts} | 6 +++--- lib/generators/project/project-func.ts | 4 ++-- lib/generators/project/project.generator.ts | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) rename lib/generators/migration/{migration-generator.ts => migration.generator.ts} (99%) diff --git a/lib/generators/index.ts b/lib/generators/index.ts index 65c5043..43544e7 100644 --- a/lib/generators/index.ts +++ b/lib/generators/index.ts @@ -9,5 +9,5 @@ export * from './project/project.generator.js'; export * from './project/project-func.js'; // migration -export * from './migration/migration-generator.js'; +export * from './migration/migration.generator.js'; export * from './migration/migration-func.js'; diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index 650c4b6..d3c101f 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -1,9 +1,9 @@ import chalk from 'chalk'; import { commonHelper } from '../../common-helper.js'; -import { migrationConfig, coreConfig } from '../../core/core.config.js'; -import { fileProcessor } from '../../file-helper.js'; +import { migrationConfig, coreConfig } from '../../core/index.js'; +import { fileProcessor as _fileProcessor } from '../../file-helper.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; -import { migrationGenerator as _migrationGenerator } from '../../generators/migration/migration-generator.js'; +import { migrationGenerator as _migrationGenerator } from './migration.generator.js'; import { GenerateMigrationModelsConfig, ModuleResolution } from '../../models.js'; import { parse } from 'path'; @@ -15,7 +15,7 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode }); const outputDir: string = config.outputDir ? `${config.outputDir}/`.replaceAll('//', '/') : `./`; - const migrationFileProcessor = fileProcessor(outputDir); + const fileProcessor = _fileProcessor(outputDir); const migrationItemsFolderName: string = migrationConfig.migrationItemsFolderName; const migrationTypesFilename: string = migrationConfig.migrationTypesFilename; @@ -46,11 +46,11 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode // create all files on FS for (const file of allFiles) { - await migrationFileProcessor.createFileOnFsAsync(file.text, file.filename, config.formatOptions); + await fileProcessor.createFileOnFsAsync(file.text, file.filename, config.formatOptions); } // migration items barrel - await migrationFileProcessor.createFileOnFsAsync( + await fileProcessor.createFileOnFsAsync( commonHelper.getBarrelExportCode({ moduleResolution: moduleResolution, filenames: [ @@ -64,7 +64,7 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode ); // main barrel - await migrationFileProcessor.createFileOnFsAsync( + await fileProcessor.createFileOnFsAsync( commonHelper.getBarrelExportCode({ moduleResolution: moduleResolution, filenames: [`./${migrationItemsFolderName}/index`, `./${migrationTypeFile.filename}`] diff --git a/lib/generators/migration/migration-generator.ts b/lib/generators/migration/migration.generator.ts similarity index 99% rename from lib/generators/migration/migration-generator.ts rename to lib/generators/migration/migration.generator.ts index 204f259..8fdd009 100644 --- a/lib/generators/migration/migration-generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -7,6 +7,7 @@ import { TaxonomyModels, WorkflowModels } from '@kontent-ai/management-sdk'; +import { match } from 'ts-pattern'; import { FlattenedElement, getImportStatement, @@ -14,12 +15,11 @@ import { GeneratedFile, toSafeString, removeLineEndings, - toPascalCase + toPascalCase, + getFlattenedElements } from '../../core/index.js'; import { ModuleResolution } from '../../models.js'; import { commentsManager as _commentsManager } from '../../comments/index.js'; -import { match } from 'ts-pattern'; -import { getFlattenedElements } from 'lib/core/element.utils.js'; export interface MigrationGeneratorConfig { readonly addTimestamp: boolean; diff --git a/lib/generators/project/project-func.ts b/lib/generators/project/project-func.ts index abf715c..fbba9d5 100644 --- a/lib/generators/project/project-func.ts +++ b/lib/generators/project/project-func.ts @@ -1,11 +1,11 @@ import chalk from 'chalk'; import { GeneratProjectModelsConfig, ModuleResolution } from '../../models.js'; -import { projectGenerator as _projectGenerator } from '../../generators/index.js'; +import { projectGenerator as _projectGenerator } from './project.generator.js'; import { commonHelper } from '../../common-helper.js'; import { parse } from 'path'; import { fileHelper } from '../../file-helper.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; -import { coreConfig } from 'lib/core/core.config.js'; +import { coreConfig } from '../../core/index.js'; export async function generateProjectModelsAsync(config: GeneratProjectModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); diff --git a/lib/generators/project/project.generator.ts b/lib/generators/project/project.generator.ts index 47c1102..bfb619b 100644 --- a/lib/generators/project/project.generator.ts +++ b/lib/generators/project/project.generator.ts @@ -1,4 +1,5 @@ import { Options } from 'prettier'; +import { match } from 'ts-pattern'; import { AssetFolderModels, CollectionModels, @@ -23,7 +24,6 @@ import { toSafeString, toCamelCase } from '../../core/index.js'; -import { match } from 'ts-pattern'; interface ProjectCodeResult { readonly filename: string; From b7f0923b6799dfb6a1854b62db0e06f713058b28 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 21 Aug 2024 12:56:24 +0200 Subject: [PATCH 020/183] Delete index.ts --- index.ts | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 index.ts diff --git a/index.ts b/index.ts deleted file mode 100644 index 886cbf6..0000000 --- a/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -export * from './languages.js'; -export * from './collections.js'; -export * from './contentTypes.js'; -export * from './contentTypeSnippets.js'; -export * from './taxonomies.js'; -export * from './workflows.js'; -export * from './roles.js'; -export * from './assetFolders.js'; -export * from './webhooks.js'; From 635fe43cfc94c64d9c727d313fa64fa3965f3e12 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 21 Aug 2024 13:02:54 +0200 Subject: [PATCH 021/183] removes baseUrl tsconfig.json option, updates paths --- lib/core/core.utils.ts | 4 ++ lib/generators/delivery/delivery-func.ts | 3 +- lib/generators/migration/migration-func.ts | 4 +- lib/generators/project/project-func.ts | 4 +- sample/migration/content-types/actor.ts | 35 +++++----- sample/migration/content-types/index.ts | 1 - sample/migration/content-types/movie.ts | 81 ++++++++++------------ sample/migration/content-types/test.ts | 40 ----------- sample/migration/core.models.ts | 19 ++--- scripts/tests/delivery-models.ts | 2 +- scripts/tests/migration-models.ts | 2 +- scripts/tests/project-models.ts | 2 +- tsconfig.json | 1 - 13 files changed, 73 insertions(+), 125 deletions(-) delete mode 100644 sample/migration/content-types/test.ts diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 618351e..282679c 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -78,3 +78,7 @@ export function toSafeString(text: string): string { const replaceContent = ' '; return text.replace(/[\s-]/g, replaceContent).replace(/[^a-zA-Z0-9_]/g, replaceContent); } + +export function toOutputDirPath(outputDir?: string): string { + return outputDir ? `${outputDir}/`.replaceAll('//', '/') : `./`; +} diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index d9df36f..d426b04 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -6,12 +6,13 @@ import { commonHelper } from '../../common-helper.js'; import { parse } from 'path'; import { fileHelper } from '../../file-helper.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; +import { toOutputDirPath } from '../../core/index.js'; export async function generateDeliveryModelsAsync(config: GenerateDeliveryModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('delivery')}' models\n`); - const outputDir: string = config.outputDir ? `${config.outputDir}/`.replaceAll('//', '/') : `./`; + const outputDir: string = toOutputDirPath(config.outputDir); const contentTypesFolderName: string = `content-types/`; const contentTypeSnippetsFolderName: string = `content-type-snippets/`; diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index d3c101f..7adbf42 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -1,6 +1,6 @@ import chalk from 'chalk'; import { commonHelper } from '../../common-helper.js'; -import { migrationConfig, coreConfig } from '../../core/index.js'; +import { migrationConfig, coreConfig, toOutputDirPath } from '../../core/index.js'; import { fileProcessor as _fileProcessor } from '../../file-helper.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; import { migrationGenerator as _migrationGenerator } from './migration.generator.js'; @@ -14,7 +14,7 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode baseUrl: config.baseUrl }); - const outputDir: string = config.outputDir ? `${config.outputDir}/`.replaceAll('//', '/') : `./`; + const outputDir: string = toOutputDirPath(config.outputDir); const fileProcessor = _fileProcessor(outputDir); const migrationItemsFolderName: string = migrationConfig.migrationItemsFolderName; const migrationTypesFilename: string = migrationConfig.migrationTypesFilename; diff --git a/lib/generators/project/project-func.ts b/lib/generators/project/project-func.ts index fbba9d5..dfdc0f5 100644 --- a/lib/generators/project/project-func.ts +++ b/lib/generators/project/project-func.ts @@ -5,13 +5,13 @@ import { commonHelper } from '../../common-helper.js'; import { parse } from 'path'; import { fileHelper } from '../../file-helper.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; -import { coreConfig } from '../../core/index.js'; +import { coreConfig, toOutputDirPath } from '../../core/index.js'; export async function generateProjectModelsAsync(config: GeneratProjectModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('project')}' models\n`); - const outputDir: string = config.outputDir ? `${config.outputDir}/`.replaceAll('//', '/') : `./`; + const outputDir: string = toOutputDirPath(config.outputDir); const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, diff --git a/sample/migration/content-types/actor.ts b/sample/migration/content-types/actor.ts index 543ce67..7448f7f 100644 --- a/sample/migration/content-types/actor.ts +++ b/sample/migration/content-types/actor.ts @@ -5,45 +5,46 @@ import type { Item } from '../core.models.js'; * Actor * * Codename: actor - * Id: d8900ee2-82f4-4189-a994-4e121582aadf + * Id: 58099989-319f-495f-aa36-cb3710854e36 */ export type ActorItem = Item< 'actor', { /** - * photo (asset) + * Url (url_slug) * * Required: false - * Codename: photo - * Id: 069b38ee-385c-410f-b7fe-53ec59a5f139 + * Codename: url + * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 */ - photo: MigrationElementModels.AssetElement; + url: MigrationElementModels.UrlSlugElement; /** - * url (url_slug) + * First name (text) * - * Required: false - * Codename: url - * Id: c4b2d64f-af45-45a4-92d8-4829833563ff + * Required: true + * Codename: first_name + * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d + * Guidelines: This is the first name of the actor */ - url: MigrationElementModels.UrlSlugElement; + first_name: MigrationElementModels.TextElement; /** - * last_name (text) + * Last name (text) * - * Required: false + * Required: true * Codename: last_name - * Id: 0f00b26e-60f3-462d-8110-18180137c3a0 + * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 */ last_name: MigrationElementModels.TextElement; /** - * first_name (text) + * Photo (asset) * * Required: false - * Codename: first_name - * Id: 4af5e7ce-88ef-4159-96ae-96a552992f91 + * Codename: photo + * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 */ - first_name: MigrationElementModels.TextElement; + photo: MigrationElementModels.AssetElement; } >; diff --git a/sample/migration/content-types/index.ts b/sample/migration/content-types/index.ts index e8c4f36..79e8008 100644 --- a/sample/migration/content-types/index.ts +++ b/sample/migration/content-types/index.ts @@ -1,3 +1,2 @@ export * from './actor.js'; export * from './movie.js'; -export * from './test.js'; diff --git a/sample/migration/content-types/movie.ts b/sample/migration/content-types/movie.ts index f9684b5..2b5bacd 100644 --- a/sample/migration/content-types/movie.ts +++ b/sample/migration/content-types/movie.ts @@ -5,99 +5,90 @@ import type { Item } from '../core.models.js'; * Movie * * Codename: movie - * Id: db7356f6-1d82-42a0-9ebb-07865cffa995 + * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c */ export type MovieItem = Item< 'movie', { /** - * Category (taxonomy) + * Title (text) * - * Required: false - * Codename: taxonomy_snippet_test__test_taxonomy - * Id: c030e3ec-5031-4d7f-af88-5032365733c7 + * Required: true + * Codename: title + * Id: 3473187e-dc78-eff2-7099-f690f7042d4a */ - taxonomy_snippet_test__test_taxonomy: MigrationElementModels.TaxonomyElement; + title: MigrationElementModels.TextElement; /** - * Release category (taxonomy) + * Plot (rich_text) * * Required: false - * Codename: releasecategory - * Id: 5faa827f-f262-43c3-8f58-0f354b8d393f + * Codename: plot + * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce */ - releasecategory: MigrationElementModels.TaxonomyElement; + plot: MigrationElementModels.RichTextElement; /** - * Category (taxonomy) + * Released (date_time) * * Required: false - * Codename: category - * Id: 8c12be35-e3e7-447c-a185-7b5e101ebf12 + * Codename: released + * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 */ - category: MigrationElementModels.TaxonomyElement; + released: MigrationElementModels.DateTimeElement; /** - * length (number) + * Length (number) * * Required: false * Codename: length - * Id: e3d07f3a-60c2-4072-846d-c23e51ec833e + * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c */ length: MigrationElementModels.NumberElement; /** - * stars (modular_content) + * Poster (asset) * * Required: false - * Codename: stars - * Id: 55596dd1-e808-415d-95aa-e2be34238d11 - */ - stars: MigrationElementModels.LinkedItemsElement; - - /** - * seoname (url_slug) - * - * Required: false - * Codename: seoname - * Id: 734f94be-5930-4bdf-b05b-f59f5a291675 + * Codename: poster + * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d */ - seoname: MigrationElementModels.UrlSlugElement; + poster: MigrationElementModels.AssetElement; /** - * poster (asset) + * Category (multiple_choice) * * Required: false - * Codename: poster - * Id: 9b197f1e-0728-4d14-9814-97f7b8ef01fc + * Codename: category + * Id: 9821c252-6414-f549-c17f-cc171dd87713 */ - poster: MigrationElementModels.AssetElement; + category: MigrationElementModels.MultipleChoiceElement; /** - * released (date_time) + * Stars (modular_content) * * Required: false - * Codename: released - * Id: 656b9dc9-7bba-4f1f-a2b8-52f7f730a66f + * Codename: stars + * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 */ - released: MigrationElementModels.DateTimeElement; + stars: MigrationElementModels.LinkedItemsElement; /** - * plot (rich_text) + * SeoName (url_slug) * * Required: false - * Codename: plot - * Id: ad2e5dc7-8d08-4f74-afeb-25b475f1e6fc + * Codename: seoname + * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c */ - plot: MigrationElementModels.RichTextElement; + seoname: MigrationElementModels.UrlSlugElement; /** - * title (text) + * ReleaseCategory (taxonomy) * * Required: false - * Codename: title - * Id: 660c851a-a9a1-4378-97a3-1348bc2a4d76 + * Codename: releasecategory + * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 */ - title: MigrationElementModels.TextElement; + releasecategory: MigrationElementModels.TaxonomyElement; } >; diff --git a/sample/migration/content-types/test.ts b/sample/migration/content-types/test.ts deleted file mode 100644 index 2a9f76e..0000000 --- a/sample/migration/content-types/test.ts +++ /dev/null @@ -1,40 +0,0 @@ -import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; -import type { Item } from '../core.models.js'; - -/** - * Test - * - * Codename: test - * Id: 81ab0b2c-dd14-41e7-a1ed-868b249ad8bc - */ -export type TestItem = Item< - 'test', - { - /** - * Text (text) - * - * Required: false - * Codename: text - * Id: 65f61f6a-b69c-47dc-bc38-19855507bf14 - */ - text: MigrationElementModels.TextElement; - - /** - * Snippet elem1 (text) - * - * Required: false - * Codename: my_snippet__snippet_elem1 - * Id: 3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d - */ - my_snippet__snippet_elem1: MigrationElementModels.TextElement; - - /** - * Snippet elem 2 (number) - * - * Required: false - * Codename: my_snippet__snippet_elem_2 - * Id: b2f65646-3310-4a64-af2a-0d9d025a91d0 - */ - my_snippet__snippet_elem_2: MigrationElementModels.NumberElement; - } ->; diff --git a/sample/migration/core.models.ts b/sample/migration/core.models.ts index e8f2a6c..1cd7a53 100644 --- a/sample/migration/core.models.ts +++ b/sample/migration/core.models.ts @@ -2,21 +2,21 @@ import type { MigrationItemSystem, MigrationItem, MigrationElements } from '@kon /** * - * Migration Toolkit - tests + * Movie Database * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 */ /** * Type representing all languages */ -export type LanguageCodenames = 'en' | 'es'; +export type LanguageCodenames = 'cz' | 'en' | 'German'; /** * Type representing all content types */ -export type ContentTypeCodenames = 'actor' | 'movie' | 'test'; +export type ContentTypeCodenames = 'actor' | 'movie'; /** * Type representing all collections @@ -26,19 +26,12 @@ export type CollectionCodenames = 'default'; /** * Type representing all workflows */ -export type WorkflowCodenames = 'default' | 'my_test_workflow'; +export type WorkflowCodenames = 'default'; /** * Type representing all worksflow steps across all workflows */ -export type WorkflowStepCodenames = - | 'draft' - | 'ready_to_publish' - | 'published' - | 'archived' - | 'scheduled' - | 'draft_3171da5' - | 'ready_for_review'; +export type WorkflowStepCodenames = 'draft' | 'review' | 'ready_to_publish' | 'published' | 'archived' | 'scheduled'; /** * System object shared by all individual content type models diff --git a/scripts/tests/delivery-models.ts b/scripts/tests/delivery-models.ts index ea00564..254d4b4 100644 --- a/scripts/tests/delivery-models.ts +++ b/scripts/tests/delivery-models.ts @@ -2,7 +2,7 @@ import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; import { ModuleResolution, generateDeliveryModelsAsync, handleError } from '../../lib/index.js'; import chalk from 'chalk'; -import { getEnvironmentRequiredValue } from 'scripts/utils/test.utils.js'; +import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; const outputDir: string = './sample/delivery'; diff --git a/scripts/tests/migration-models.ts b/scripts/tests/migration-models.ts index 8b1cf90..32894ea 100644 --- a/scripts/tests/migration-models.ts +++ b/scripts/tests/migration-models.ts @@ -2,7 +2,7 @@ import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; import { ModuleResolution, generateMigrationModelsAsync, handleError } from '../../lib/index.js'; import chalk from 'chalk'; -import { getEnvironmentRequiredValue } from 'scripts/utils/test.utils.js'; +import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; const outputDir: string = './sample/migration'; diff --git a/scripts/tests/project-models.ts b/scripts/tests/project-models.ts index 8d1d467..953e3ef 100644 --- a/scripts/tests/project-models.ts +++ b/scripts/tests/project-models.ts @@ -2,7 +2,7 @@ import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; import { ModuleResolution, generateProjectModelsAsync, handleError } from '../../lib/index.js'; import chalk from 'chalk'; -import { getEnvironmentRequiredValue } from 'scripts/utils/test.utils.js'; +import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; const outputDir: string = './sample/project'; diff --git a/tsconfig.json b/tsconfig.json index ca52053..7d21266 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,6 @@ { "compileOnSave": true, "compilerOptions": { - "baseUrl": ".", "outDir": "dist", "sourceMap": true, "declaration": true, From 764b593144d1bb446b85d690dd444e1f4636f1a0 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 21 Aug 2024 13:09:49 +0200 Subject: [PATCH 022/183] Fixes output dir for project generator --- lib/generators/migration/migration-func.ts | 3 +-- lib/generators/project/project-func.ts | 9 ++++----- lib/generators/project/project.generator.ts | 3 +-- sample/project/index.ts | 9 +++++++++ 4 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 sample/project/index.ts diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index 7adbf42..c40299b 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -14,8 +14,7 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode baseUrl: config.baseUrl }); - const outputDir: string = toOutputDirPath(config.outputDir); - const fileProcessor = _fileProcessor(outputDir); + const fileProcessor = _fileProcessor(toOutputDirPath(config.outputDir)); const migrationItemsFolderName: string = migrationConfig.migrationItemsFolderName; const migrationTypesFilename: string = migrationConfig.migrationTypesFilename; diff --git a/lib/generators/project/project-func.ts b/lib/generators/project/project-func.ts index dfdc0f5..076c937 100644 --- a/lib/generators/project/project-func.ts +++ b/lib/generators/project/project-func.ts @@ -2,8 +2,8 @@ import chalk from 'chalk'; import { GeneratProjectModelsConfig, ModuleResolution } from '../../models.js'; import { projectGenerator as _projectGenerator } from './project.generator.js'; import { commonHelper } from '../../common-helper.js'; +import { fileProcessor as _fileProcessor } from '../../file-helper.js'; import { parse } from 'path'; -import { fileHelper } from '../../file-helper.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; import { coreConfig, toOutputDirPath } from '../../core/index.js'; @@ -11,7 +11,7 @@ export async function generateProjectModelsAsync(config: GeneratProjectModelsCon console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('project')}' models\n`); - const outputDir: string = toOutputDirPath(config.outputDir); + const fileProcessor = _fileProcessor(toOutputDirPath(config.outputDir)); const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, @@ -23,7 +23,6 @@ export async function generateProjectModelsAsync(config: GeneratProjectModelsCon const projectInformation = await kontentFetcher.getEnvironmentInfoAsync(); const projectFiles = _projectGenerator({ - outputDir: outputDir, addTimestamp: config.addTimestamp, formatOptions: config.formatOptions, sortConfig: config.sortConfig ?? { @@ -45,7 +44,7 @@ export async function generateProjectModelsAsync(config: GeneratProjectModelsCon // project barrel for (const file of projectFiles) { - await fileHelper.createFileOnFsAsync(file.text, file.filename, config.formatOptions); + await fileProcessor.createFileOnFsAsync(file.text, file.filename, config.formatOptions); } const projectBarrelCode = commonHelper.getBarrelExportCode({ moduleResolution: moduleResolution, @@ -56,7 +55,7 @@ export async function generateProjectModelsAsync(config: GeneratProjectModelsCon }) ] }); - await fileHelper.createFileOnFsAsync(projectBarrelCode, coreConfig.barrelExportFilename, config.formatOptions); + await fileProcessor.createFileOnFsAsync(projectBarrelCode, coreConfig.barrelExportFilename, config.formatOptions); console.log(chalk.green(`\nCompleted`)); } diff --git a/lib/generators/project/project.generator.ts b/lib/generators/project/project.generator.ts index bfb619b..7a82ec8 100644 --- a/lib/generators/project/project.generator.ts +++ b/lib/generators/project/project.generator.ts @@ -37,7 +37,6 @@ interface WorkflowStep { } export interface ProjectGeneratorConfig { - readonly outputDir: string; readonly addTimestamp: boolean; readonly sortConfig: SortConfig; readonly formatOptions?: Options; @@ -68,7 +67,7 @@ export function projectGenerator(config: ProjectGeneratorConfig) { return getProjectModelCode().map((projectCode) => { return { - filename: `${config.outputDir}${projectCode.filename}`, + filename: `${projectCode.filename}`, text: headerCode + '\n' + projectCode.code }; }); diff --git a/sample/project/index.ts b/sample/project/index.ts new file mode 100644 index 0000000..886cbf6 --- /dev/null +++ b/sample/project/index.ts @@ -0,0 +1,9 @@ +export * from './languages.js'; +export * from './collections.js'; +export * from './contentTypes.js'; +export * from './contentTypeSnippets.js'; +export * from './taxonomies.js'; +export * from './workflows.js'; +export * from './roles.js'; +export * from './assetFolders.js'; +export * from './webhooks.js'; From 358278a5104bef191fef871a5daba398f29fc22b Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 21 Aug 2024 13:41:17 +0200 Subject: [PATCH 023/183] Improves file creation, removes sort config --- lib/core/core.utils.ts | 23 ++++++++ lib/file-helper.ts | 15 ++++- lib/generators/delivery/delivery-func.ts | 2 +- lib/generators/migration/migration-func.ts | 61 ++++++++++----------- lib/generators/project/project-func.ts | 42 +++++++------- lib/generators/project/project.generator.ts | 22 +++----- lib/models.ts | 5 -- lib/node/cli/actions/project-action.ts | 3 - 8 files changed, 96 insertions(+), 77 deletions(-) diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 282679c..369ff20 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -5,6 +5,7 @@ import { } from '@kontent-ai/delivery-sdk'; import { ModuleResolution } from '../models.js'; import { LibraryType, LiteralUnion } from './index.js'; +import { parse } from 'path'; export function exitProgram(data: { readonly message: string }): never { throw Error(data.message); @@ -82,3 +83,25 @@ export function toSafeString(text: string): string { export function toOutputDirPath(outputDir?: string): string { return outputDir ? `${outputDir}/`.replaceAll('//', '/') : `./`; } + +export function getBarrelExportCode(data: { filenames: string[]; moduleResolution: ModuleResolution }): string { + let code = ''; + + if (data.filenames.length) { + for (let i = 0; i < data.filenames.length; i++) { + const isLast = i === data.filenames.length - 1; + const filename = data.filenames[i]; + const path = parse(filename); + const extension = data.moduleResolution === 'nodeNext' ? '.js' : ''; + code += `export * from '${path.dir}/${path.name}${extension}'`; + + if (!isLast) { + code += `\n`; + } + } + } else { + code = `export {}`; + } + + return code; +} diff --git a/lib/file-helper.ts b/lib/file-helper.ts index c14e04a..bbae34a 100644 --- a/lib/file-helper.ts +++ b/lib/file-helper.ts @@ -3,6 +3,7 @@ import { Options } from 'prettier'; import { formatHelper } from './format-helper.js'; import * as fs from 'fs'; import { dirname } from 'path'; +import { GeneratedFile } from './core/index.js'; export function fileProcessor(outputDir: string) { const createFileOnFsAsync = async ( @@ -36,9 +37,21 @@ export function fileProcessor(outputDir: string) { fs.mkdirSync(resolvedDirname); }; + const createFilesAsync = async ( + files: readonly GeneratedFile[], + formatOptions: Options | undefined + ): Promise => { + await Promise.all( + files.map((file) => { + return createFileOnFsAsync(file.text, file.filename, formatOptions); + }) + ); + }; + return { createDir, - createFileOnFsAsync + createFileOnFsAsync, + createFilesAsync }; } diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index d426b04..77f6efc 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -11,6 +11,7 @@ import { toOutputDirPath } from '../../core/index.js'; export async function generateDeliveryModelsAsync(config: GenerateDeliveryModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('delivery')}' models\n`); + const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; const outputDir: string = toOutputDirPath(config.outputDir); @@ -33,7 +34,6 @@ export async function generateDeliveryModelsAsync(config: GenerateDeliveryModels baseUrl: config.baseUrl }); - const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; await kontentFetcher.getEnvironmentInfoAsync(); const types = await kontentFetcher.getTypesAsync(); diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index c40299b..9831d66 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -1,6 +1,5 @@ import chalk from 'chalk'; -import { commonHelper } from '../../common-helper.js'; -import { migrationConfig, coreConfig, toOutputDirPath } from '../../core/index.js'; +import { migrationConfig, coreConfig, toOutputDirPath, getBarrelExportCode } from '../../core/index.js'; import { fileProcessor as _fileProcessor } from '../../file-helper.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; import { migrationGenerator as _migrationGenerator } from './migration.generator.js'; @@ -8,20 +7,22 @@ import { GenerateMigrationModelsConfig, ModuleResolution } from '../../models.js import { parse } from 'path'; export async function generateMigrationModelsAsync(config: GenerateMigrationModelsConfig): Promise { + console.log(chalk.green(`Model generator started \n`)); + console.log(`Generating '${chalk.yellow('migration')}' models\n`); + const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; + + const fileProcessor = _fileProcessor(toOutputDirPath(config.outputDir)); const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, baseUrl: config.baseUrl }); - const fileProcessor = _fileProcessor(toOutputDirPath(config.outputDir)); const migrationItemsFolderName: string = migrationConfig.migrationItemsFolderName; const migrationTypesFilename: string = migrationConfig.migrationTypesFilename; const projectInformation = await kontentFetcher.getEnvironmentInfoAsync(); - const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; - console.log(`Module resolution '${chalk.yellow(moduleResolution)}'\n`); const migrationGenerator = _migrationGenerator({ addTimestamp: config.addTimestamp, moduleResolution: config.moduleResolution, @@ -41,34 +42,32 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode migrationTypesFilename, migrationItemsFolderName ); - const allFiles = [migrationTypeFile, ...migrationItemFiles]; - // create all files on FS - for (const file of allFiles) { - await fileProcessor.createFileOnFsAsync(file.text, file.filename, config.formatOptions); - } - - // migration items barrel - await fileProcessor.createFileOnFsAsync( - commonHelper.getBarrelExportCode({ - moduleResolution: moduleResolution, - filenames: [ - ...migrationItemFiles.map((m) => { - return `./${parse(m.filename).name}`; + await fileProcessor.createFilesAsync( + [ + migrationTypeFile, + ...migrationItemFiles, + // types barrel file + { + filename: `${migrationItemsFolderName}/${coreConfig.barrelExportFilename}`, + text: getBarrelExportCode({ + moduleResolution: moduleResolution, + filenames: [ + ...migrationItemFiles.map((m) => { + return `./${parse(m.filename).name}`; + }) + ] }) - ] - }), - `${migrationItemsFolderName}/${coreConfig.barrelExportFilename}`, - config.formatOptions - ); - - // main barrel - await fileProcessor.createFileOnFsAsync( - commonHelper.getBarrelExportCode({ - moduleResolution: moduleResolution, - filenames: [`./${migrationItemsFolderName}/index`, `./${migrationTypeFile.filename}`] - }), - `${coreConfig.barrelExportFilename}`, + }, + // main barrel file + { + filename: coreConfig.barrelExportFilename, + text: getBarrelExportCode({ + moduleResolution: moduleResolution, + filenames: [`./${migrationItemsFolderName}/index`, `./${migrationTypeFile.filename}`] + }) + } + ], config.formatOptions ); diff --git a/lib/generators/project/project-func.ts b/lib/generators/project/project-func.ts index 076c937..517d596 100644 --- a/lib/generators/project/project-func.ts +++ b/lib/generators/project/project-func.ts @@ -1,33 +1,28 @@ import chalk from 'chalk'; import { GeneratProjectModelsConfig, ModuleResolution } from '../../models.js'; import { projectGenerator as _projectGenerator } from './project.generator.js'; -import { commonHelper } from '../../common-helper.js'; import { fileProcessor as _fileProcessor } from '../../file-helper.js'; import { parse } from 'path'; import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; -import { coreConfig, toOutputDirPath } from '../../core/index.js'; +import { coreConfig, getBarrelExportCode, toOutputDirPath } from '../../core/index.js'; export async function generateProjectModelsAsync(config: GeneratProjectModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('project')}' models\n`); + const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; const fileProcessor = _fileProcessor(toOutputDirPath(config.outputDir)); - const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, baseUrl: config.baseUrl }); - const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; const projectInformation = await kontentFetcher.getEnvironmentInfoAsync(); const projectFiles = _projectGenerator({ addTimestamp: config.addTimestamp, formatOptions: config.formatOptions, - sortConfig: config.sortConfig ?? { - sortTaxonomyTerms: true - }, environmentData: { environmentInfo: projectInformation, languages: await kontentFetcher.getLanguagesAsync(), @@ -42,20 +37,25 @@ export async function generateProjectModelsAsync(config: GeneratProjectModelsCon } }).generateProjectModel(); - // project barrel - for (const file of projectFiles) { - await fileProcessor.createFileOnFsAsync(file.text, file.filename, config.formatOptions); - } - const projectBarrelCode = commonHelper.getBarrelExportCode({ - moduleResolution: moduleResolution, - filenames: [ - ...projectFiles.map((m) => { - const path = parse(m.filename); - return `./${path.name}`; - }) - ] - }); - await fileProcessor.createFileOnFsAsync(projectBarrelCode, coreConfig.barrelExportFilename, config.formatOptions); + await fileProcessor.createFilesAsync( + [ + ...projectFiles, + // barrel file + { + filename: coreConfig.barrelExportFilename, + text: getBarrelExportCode({ + moduleResolution: moduleResolution, + filenames: [ + ...projectFiles.map((m) => { + const path = parse(m.filename); + return `./${path.name}`; + }) + ] + }) + } + ], + config.formatOptions + ); console.log(chalk.green(`\nCompleted`)); } diff --git a/lib/generators/project/project.generator.ts b/lib/generators/project/project.generator.ts index 7a82ec8..cf20aa2 100644 --- a/lib/generators/project/project.generator.ts +++ b/lib/generators/project/project.generator.ts @@ -14,7 +14,6 @@ import { ContentTypeElements } from '@kontent-ai/management-sdk'; import { commentsManager as _commentsManager } from '../../comments/index.js'; -import { SortConfig } from '../../models.js'; import { FlattenedElement, GeneratedFile, @@ -38,7 +37,6 @@ interface WorkflowStep { export interface ProjectGeneratorConfig { readonly addTimestamp: boolean; - readonly sortConfig: SortConfig; readonly formatOptions?: Options; readonly environmentData: { @@ -73,7 +71,7 @@ export function projectGenerator(config: ProjectGeneratorConfig) { }); }; - const getProjectModelCode = (): ProjectCodeResult[] => { + const getProjectModelCode = (): readonly ProjectCodeResult[] => { const result: ProjectCodeResult[] = [ { code: `export const languages = { @@ -101,7 +99,7 @@ export function projectGenerator(config: ProjectGeneratorConfig) { }, { code: `export const taxonomies = { - ${getProjectTaxonomies(config.environmentData.taxonomies, config.sortConfig)} + ${getProjectTaxonomies(config.environmentData.taxonomies)} } as const;`, filename: 'taxonomies.ts' }, @@ -289,10 +287,7 @@ export function projectGenerator(config: ProjectGeneratorConfig) { .otherwise(() => undefined); }; - const getProjectTaxonomies = ( - taxonomies: readonly Readonly[], - sortConfig: SortConfig - ): string => { + const getProjectTaxonomies = (taxonomies: readonly Readonly[]): string => { return taxonomies.reduce((code, taxonomy, index) => { const isLast = index === taxonomies.length - 1; @@ -305,7 +300,7 @@ export function projectGenerator(config: ProjectGeneratorConfig) { externalId: ${getStringOrUndefined(taxonomy.externalId)}, id: '${taxonomy.id}', name: '${toSafeString(taxonomy.name)}', - ${getProjectTaxonomiesTerms(taxonomy.terms, sortConfig)} + ${getProjectTaxonomiesTerms(taxonomy.terms)} }${!isLast ? ',\n' : ''}`; }, ''); }; @@ -358,11 +353,8 @@ export function projectGenerator(config: ProjectGeneratorConfig) { }, ''); }; - const getProjectTaxonomiesTerms = ( - terms: readonly Readonly[], - sortConfig: SortConfig - ): string => { - const sortedTerms = sortConfig.sortTaxonomyTerms ? sortAlphabetically(terms, (item) => item.name) : terms; + const getProjectTaxonomiesTerms = (terms: readonly Readonly[]): string => { + const sortedTerms = sortAlphabetically(terms, (item) => item.name); return ( sortedTerms.reduce((code, term, index) => { @@ -377,7 +369,7 @@ export function projectGenerator(config: ProjectGeneratorConfig) { id: '${term.id}', externalId: ${getStringOrUndefined(term.externalId)}, name: '${toSafeString(term.name)}', - ${getProjectTaxonomiesTerms(term.terms, sortConfig)} + ${getProjectTaxonomiesTerms(term.terms)} }${!isLast ? ',\n' : ''}`; }, 'terms: {') + '}' ); diff --git a/lib/models.ts b/lib/models.ts index 4ca78ef..df308b1 100644 --- a/lib/models.ts +++ b/lib/models.ts @@ -44,10 +44,6 @@ export interface GenerateDeliveryModelsConfig { readonly formatOptions?: Options; } -export interface SortConfig { - readonly sortTaxonomyTerms: boolean; -} - export interface GeneratProjectModelsConfig { readonly environmentId: string; readonly addTimestamp: boolean; @@ -57,7 +53,6 @@ export interface GeneratProjectModelsConfig { readonly moduleResolution?: ModuleResolution; readonly baseUrl?: string; readonly outputDir?: string; - readonly sortConfig?: SortConfig; readonly formatOptions?: Options; } diff --git a/lib/node/cli/actions/project-action.ts b/lib/node/cli/actions/project-action.ts index 5b00196..8909b51 100644 --- a/lib/node/cli/actions/project-action.ts +++ b/lib/node/cli/actions/project-action.ts @@ -10,9 +10,6 @@ export async function projectActionAsync(cliFetcher: CliArgumentsFetcher): Promi outputDir: cliFetcher.getRequiredArgumentValue('outputDir'), isEnterpriseSubscription: cliFetcher.getBooleanArgumentValue('isEnterpriseSubscription', false), addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), - sortConfig: { - sortTaxonomyTerms: cliFetcher.getBooleanArgumentValue('sortTaxonomyTerms', true) - }, moduleResolution: cliFetcher.getRequiredArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' }); From ecf995ce6d23811f5c74b502e758a0b54f1d40af Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 21 Aug 2024 13:58:02 +0200 Subject: [PATCH 024/183] adds readonly modifiers --- lib/generators/migration/migration.generator.ts | 2 +- lib/generators/project/project.generator.ts | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index 8fdd009..78ff273 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -142,7 +142,7 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { ` }; }, - getMigrationItemFiles(migrationTypesFilename: string, folderName: string): GeneratedFile[] { + getMigrationItemFiles(migrationTypesFilename: string, folderName: string): readonly GeneratedFile[] { return config.environmentData.types.map((type) => getMigrationItemType(type, migrationTypesFilename, folderName) ); diff --git a/lib/generators/project/project.generator.ts b/lib/generators/project/project.generator.ts index cf20aa2..25949d2 100644 --- a/lib/generators/project/project.generator.ts +++ b/lib/generators/project/project.generator.ts @@ -130,7 +130,7 @@ export function projectGenerator(config: ProjectGeneratorConfig) { return result; }; - const getProjectLanguages = (languages: readonly LanguageModels.LanguageModel[]): string => { + const getProjectLanguages = (languages: readonly Readonly[]): string => { return languages.reduce((code, language, index) => { const isLast = index === languages.length - 1; @@ -157,7 +157,7 @@ export function projectGenerator(config: ProjectGeneratorConfig) { return `'${text}'`; }; - const getProjectWorkflows = (workflows: readonly WorkflowModels.Workflow[]): string => { + const getProjectWorkflows = (workflows: readonly Readonly[]): string => { return workflows.reduce((code, workflow, index) => { const isLast = index === workflows.length - 1; @@ -174,7 +174,7 @@ export function projectGenerator(config: ProjectGeneratorConfig) { }, ''); }; - const getAssetFolders = (assetFolders: readonly AssetFolderModels.AssetFolder[]): string => { + const getAssetFolders = (assetFolders: readonly Readonly[]): string => { return ( assetFolders.reduce((code, assetFolder, index) => { const isLast = index === assetFolders.length - 1; @@ -194,8 +194,8 @@ export function projectGenerator(config: ProjectGeneratorConfig) { }; const getProjectContentTypeSnippets = ( - snippets: readonly ContentTypeSnippetModels.ContentTypeSnippet[], - taxonomies: readonly TaxonomyModels.Taxonomy[] + snippets: readonly Readonly[], + taxonomies: readonly Readonly[] ): string => { return snippets.reduce((code, snippet, index) => { const isLast = index === snippets.length - 1; @@ -215,9 +215,9 @@ export function projectGenerator(config: ProjectGeneratorConfig) { }; const getProjectContentTypes = ( - contentTypes: readonly ContentTypeModels.ContentType[], - snippets: readonly ContentTypeSnippetModels.ContentTypeSnippet[], - taxonomies: readonly TaxonomyModels.Taxonomy[] + contentTypes: readonly Readonly[], + snippets: readonly Readonly[], + taxonomies: readonly Readonly[] ): string => { return contentTypes.reduce((code, contentType, index) => { const isLast = index === contentTypes.length - 1; From ce3f22ba644544556fe7efc00e23ffdf787ce56f Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 21 Aug 2024 14:45:41 +0200 Subject: [PATCH 025/183] refactors delivery func, removes FIleHelper, updates file imports --- lib/core/core.config.ts | 6 + .../file-processor.ts} | 39 +--- lib/files/index.ts | 1 + .../delivery-content-type.generator.ts | 34 ++- lib/generators/delivery/delivery-func.ts | 193 ++++++++++-------- .../delivery/delivery-taxonomy.generator.ts | 13 +- lib/generators/migration/migration-func.ts | 2 +- lib/generators/project/project-func.ts | 4 +- lib/index.ts | 1 + 9 files changed, 136 insertions(+), 157 deletions(-) rename lib/{file-helper.ts => files/file-processor.ts} (56%) create mode 100644 lib/files/index.ts diff --git a/lib/core/core.config.ts b/lib/core/core.config.ts index 64baa36..f33c2f7 100644 --- a/lib/core/core.config.ts +++ b/lib/core/core.config.ts @@ -6,3 +6,9 @@ export const migrationConfig = { migrationItemsFolderName: `content-types`, migrationTypesFilename: `core.models.ts` } as const; + +export const deliveryConfig = { + contentTypesFolderName: `content-types`, + contentTypeSnippetsFolderName: `content-type-snippets`, + taxonomiesFolderName: `taxonomies` +} as const; diff --git a/lib/file-helper.ts b/lib/files/file-processor.ts similarity index 56% rename from lib/file-helper.ts rename to lib/files/file-processor.ts index bbae34a..64cac4f 100644 --- a/lib/file-helper.ts +++ b/lib/files/file-processor.ts @@ -1,9 +1,9 @@ import chalk from 'chalk'; import { Options } from 'prettier'; -import { formatHelper } from './format-helper.js'; +import { formatHelper } from '../format-helper.js'; import * as fs from 'fs'; import { dirname } from 'path'; -import { GeneratedFile } from './core/index.js'; +import { GeneratedFile } from '../core/index.js'; export function fileProcessor(outputDir: string) { const createFileOnFsAsync = async ( @@ -54,38 +54,3 @@ export function fileProcessor(outputDir: string) { createFilesAsync }; } - -export class FileHelper { - async createFileOnFsAsync(text: string, filePath: string, formatOptions: Options | undefined): Promise { - const fullFilePath = `${filePath}`; - try { - const contentToStore = await formatHelper.formatCodeAsync(text, formatOptions); - - this.ensureDirectoryExistence(fullFilePath); - fs.writeFileSync('./' + fullFilePath, contentToStore, {}); - console.log(`Created '${chalk.yellow(fullFilePath)}'`); - } catch { - console.log(`Failed to format file '${chalk.red(filePath)}'. Skipping prettier for this file.`); - - const contentToStore = text; - - fs.writeFileSync('./' + fullFilePath, contentToStore); - console.log(`Created '${chalk.yellow(fullFilePath)}'`); - } - } - - createDir(dirPath: string): void { - fs.mkdirSync(dirPath, { recursive: true }); - } - - private ensureDirectoryExistence(filePath: string): void { - const resolvedDirname = dirname(filePath); - if (fs.existsSync(resolvedDirname)) { - return; - } - this.ensureDirectoryExistence(resolvedDirname); - fs.mkdirSync(resolvedDirname); - } -} - -export const fileHelper = new FileHelper(); diff --git a/lib/files/index.ts b/lib/files/index.ts new file mode 100644 index 0000000..2cfa898 --- /dev/null +++ b/lib/files/index.ts @@ -0,0 +1 @@ +export * from './file-processor.js'; diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 77a59a2..8609d9a 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -40,7 +40,7 @@ import { getMapContentTypeSnippetIdToObject } from './delivery-mappers.js'; import { textHelper } from '../../text-helper.js'; -import { GeneratedFile } from '../../core/index.js'; +import { GeneratedFile, sortAlphabetically } from '../../core/index.js'; interface IExtendedContentTypeElement { type: ElementModels.ElementType; @@ -51,16 +51,15 @@ interface IExtendedContentTypeElement { } interface IExtractImportsResult { - imports: string[]; + imports: readonly string[]; contentTypeSnippetExtensions: string[]; - processedElements: IExtendedContentTypeElement[]; + processedElements: readonly IExtendedContentTypeElement[]; } export class DeliveryContentTypeGenerator { private readonly deliveryNpmPackageName: string = '@kontent-ai/delivery-sdk'; generateModels(data: { - outputDir: string; typeFolderName: string; typeSnippetsFolderName: string; taxonomyFolderName: string; @@ -77,7 +76,7 @@ export class DeliveryContentTypeGenerator { taxonomyFileResolver?: TaxonomyTypeFileNameResolver; taxonomyResolver?: TaxonomyTypeResolver; moduleResolution: ModuleResolution; - }): { contentTypeFiles: GeneratedFile[]; snippetFiles: GeneratedFile[] } { + }): { contentTypeFiles: readonly GeneratedFile[]; snippetFiles: readonly GeneratedFile[] } { const typeFiles: GeneratedFile[] = []; const snippetFiles: GeneratedFile[] = []; @@ -137,7 +136,6 @@ export class DeliveryContentTypeGenerator { for (const contentTypeSnippet of data.snippets) { try { const file = this.createContentTypeSnippetModel({ - outputDir: data.outputDir, snippet: contentTypeSnippet, snippets: data.snippets, taxonomies: data.taxonomies, @@ -175,7 +173,6 @@ export class DeliveryContentTypeGenerator { try { const file = this.createContentTypeModel({ moduleResolution: data.moduleResolution, - outputDir: data.outputDir, type: type, snippets: data.snippets, taxonomies: data.taxonomies, @@ -236,7 +233,7 @@ export class DeliveryContentTypeGenerator { const processedTypeIds: string[] = []; const processedTaxonomyIds: string[] = []; - const extendedElements: IExtendedContentTypeElement[] = this.getExtendedElements({ + const extendedElements: readonly IExtendedContentTypeElement[] = this.getExtendedElements({ elementNameMap: data.elementNameMap, contentType: data.contentType, contentTypeSnippet: data.contentTypeSnippet, @@ -263,7 +260,7 @@ export class DeliveryContentTypeGenerator { processedTaxonomyIds.push(taxonomy.id); const taxonomyName: string = data.taxonomyNameMap(taxonomy); - const fileName: string = `../${data.taxonomyFolderName}${data.taxonomyFileNameMap(taxonomy, false)}`; + const fileName: string = `../${data.taxonomyFolderName}/${data.taxonomyFileNameMap(taxonomy, false)}`; imports.push( commonHelper.getImportStatement({ @@ -294,7 +291,7 @@ export class DeliveryContentTypeGenerator { const fileName: string = `${data.contentTypeFileNameMap(referencedType, false)}`; const filePath: string = data.contentTypeSnippet - ? `../${data.typeFolderName}${fileName}` + ? `../${data.typeFolderName}/${fileName}` : `./${fileName}`; imports.push( @@ -329,7 +326,7 @@ export class DeliveryContentTypeGenerator { } return { - imports: commonHelper.sortAlphabetically(imports, (item) => item), + imports: sortAlphabetically(imports, (item) => item), contentTypeSnippetExtensions: contentTypeSnippetExtensions, processedElements: extendedElements }; @@ -439,7 +436,6 @@ export type ${typeName} = IContentItem<{ } private createContentTypeModel(data: { - outputDir: string; type: ContentTypeModels.ContentType; typeFolderName: string; typeSnippetsFolderName: string; @@ -460,10 +456,7 @@ export type ${typeName} = IContentItem<{ addEnvironmentInfo: boolean; moduleResolution: ModuleResolution; }): GeneratedFile { - const filename: string = `${data.outputDir}${data.typeFolderName}${data.contentTypeFileNameMap( - data.type, - true - )}`; + const filename: string = `${data.typeFolderName}/${data.contentTypeFileNameMap(data.type, true)}`; const code = this.getModelCode({ contentTypeFileNameMap: data.contentTypeFileNameMap, contentTypeSnippetFileNameMap: data.contentTypeSnippetFileNameMap, @@ -494,7 +487,6 @@ export type ${typeName} = IContentItem<{ } private createContentTypeSnippetModel(data: { - outputDir: string; snippet: ContentTypeSnippetModels.ContentTypeSnippet; typeSnippetsFolderName: string; taxonomyFolderName: string; @@ -515,7 +507,7 @@ export type ${typeName} = IContentItem<{ addEnvironmentInfo: boolean; moduleResolution: ModuleResolution; }): GeneratedFile { - const filename: string = `${data.outputDir}${data.typeSnippetsFolderName}${data.contentTypeSnippetFileNameMap( + const filename: string = `${data.typeSnippetsFolderName}/${data.contentTypeSnippetFileNameMap( data.snippet, true )}`; @@ -615,7 +607,7 @@ export type ${typeName} = IContentItem<{ taxonomyNameMap: MapTaxonomyName; taxonomies: TaxonomyModels.Taxonomy[]; }): string { - const extendedElements: IExtendedContentTypeElement[] = this.getExtendedElements({ + const extendedElements: readonly IExtendedContentTypeElement[] = this.getExtendedElements({ elementNameMap: data.elementNameMap, contentType: data.contentType, contentTypeSnippet: data.contentTypeSnippet, @@ -723,7 +715,7 @@ export type ${typeName} = IContentItem<{ contentTypeObjectMap: MapContentTypeIdToObject; taxonomyObjectMap: MapTaxonomyIdTobject; taxonomyNameMap: MapTaxonomyName; - }): IExtendedContentTypeElement[] { + }): readonly IExtendedContentTypeElement[] { const extendedElements: IExtendedContentTypeElement[] = []; const elements = data.contentType ? data.contentType.elements : (data.contentTypeSnippet?.elements ?? []); @@ -742,7 +734,7 @@ export type ${typeName} = IContentItem<{ ); } - return commonHelper.sortAlphabetically(extendedElements, (item) => item.mappedName ?? ''); + return sortAlphabetically(extendedElements, (item) => item.mappedName ?? ''); } private getTaxonomyTypeName( diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index 77f6efc..ff635f2 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -1,54 +1,40 @@ import chalk from 'chalk'; import { GenerateDeliveryModelsConfig, ModuleResolution } from '../../models.js'; -import { deliveryContentTypeGenerator } from '../../generators/delivery/delivery-content-type.generator.js'; -import { deliveryTaxonomyGenerator } from '../../generators/delivery/delivery-taxonomy.generator.js'; -import { commonHelper } from '../../common-helper.js'; +import { deliveryContentTypeGenerator } from './delivery-content-type.generator.js'; +import { deliveryTaxonomyGenerator } from './delivery-taxonomy.generator.js'; +import { fileProcessor as _fileProcessor } from '../../files/index.js'; import { parse } from 'path'; -import { fileHelper } from '../../file-helper.js'; -import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; -import { toOutputDirPath } from '../../core/index.js'; +import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; +import { coreConfig, deliveryConfig, GeneratedFile, getBarrelExportCode, toOutputDirPath } from '../../core/index.js'; +import { Options } from 'prettier'; export async function generateDeliveryModelsAsync(config: GenerateDeliveryModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('delivery')}' models\n`); const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; - const outputDir: string = toOutputDirPath(config.outputDir); - - const contentTypesFolderName: string = `content-types/`; - const contentTypeSnippetsFolderName: string = `content-type-snippets/`; - const taxonomiesFolderName: string = `taxonomies/`; - - const contentTypesFolderPath: string = `${outputDir}${contentTypesFolderName}`; - const contentTypeSnippetsFolderPath: string = `${outputDir}${contentTypeSnippetsFolderName}`; - const taxonomiesFolderPath: string = `${outputDir}${taxonomiesFolderName}`; - - // prepare directories - fileHelper.createDir(contentTypesFolderPath); - fileHelper.createDir(contentTypeSnippetsFolderPath); - fileHelper.createDir(taxonomiesFolderPath); - const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, baseUrl: config.baseUrl }); + const contentTypesFolderName: string = deliveryConfig.contentTypesFolderName; + const contentTypeSnippetsFolderName: string = deliveryConfig.contentTypeSnippetsFolderName; + const taxonomiesFolderName: string = deliveryConfig.taxonomiesFolderName; + await kontentFetcher.getEnvironmentInfoAsync(); - const types = await kontentFetcher.getTypesAsync(); - const snippets = await kontentFetcher.getSnippetsAsync(); const taxonomies = await kontentFetcher.getTaxonomiesAsync(); // create content type models const deliveryModels = deliveryContentTypeGenerator.generateModels({ - outputDir: outputDir, - types: types, + types: await kontentFetcher.getTypesAsync(), typeFolderName: contentTypesFolderName, taxonomyFolderName: taxonomiesFolderName, typeSnippetsFolderName: contentTypeSnippetsFolderName, taxonomies: taxonomies, - snippets: snippets, + snippets: await kontentFetcher.getSnippetsAsync(), addTimestamp: config.addTimestamp, addEnvironmentInfo: config.addEnvironmentInfo, elementResolver: config.elementResolver, @@ -64,79 +50,106 @@ export async function generateDeliveryModelsAsync(config: GenerateDeliveryModels // create taxonomy types const taxonomyFiles = deliveryTaxonomyGenerator.generateTaxonomyTypes({ taxonomies: taxonomies, - outputDir: outputDir, taxonomyFolderName: taxonomiesFolderName, addTimestamp: config.addTimestamp, fileResolver: config.taxonomyTypeFileResolver, taxonomyResolver: config.taxonomyTypeResolver }); - // create barrel export - const barrelExportFilename: string = 'index.ts'; + await createDeliveryFilesAsync( + { + contentTypeFiles: deliveryModels.contentTypeFiles, + snippetFiles: deliveryModels.snippetFiles, + taxonomyFiles: taxonomyFiles + }, + { + formatOptions: config.formatOptions, + moduleResolution: moduleResolution, + outputDir: config.outputDir + }, + { + contentTypesFolderName, + contentTypeSnippetsFolderName, + taxonomiesFolderName + } + ); - // content types - for (const file of deliveryModels.contentTypeFiles) { - await fileHelper.createFileOnFsAsync(file.text, file.filename, config.formatOptions); - } - const contentTypeBarrelCode = commonHelper.getBarrelExportCode({ - moduleResolution: moduleResolution, - filenames: [ - ...deliveryModels.contentTypeFiles.map((m) => { - const path = parse(m.filename); - return `./${path.name}`; - }) - ] - }); - const contentTypeBarrelExportPath: string = `${contentTypesFolderPath}${barrelExportFilename}`; - await fileHelper.createFileOnFsAsync(contentTypeBarrelCode, contentTypeBarrelExportPath, config.formatOptions); + console.log(chalk.green(`\nCompleted`)); +} - // content type snippets - for (const file of deliveryModels.snippetFiles) { - await fileHelper.createFileOnFsAsync(file.text, file.filename, config.formatOptions); +async function createDeliveryFilesAsync( + data: { + readonly contentTypeFiles: readonly GeneratedFile[]; + readonly snippetFiles: readonly GeneratedFile[]; + readonly taxonomyFiles: readonly GeneratedFile[]; + }, + config: { + readonly outputDir: string | undefined; + readonly moduleResolution: ModuleResolution; + readonly formatOptions: Options | undefined; + }, + folders: { + readonly contentTypesFolderName: string; + readonly contentTypeSnippetsFolderName: string; + readonly taxonomiesFolderName: string; } - const contentTypeSnippetsBarrelCode = commonHelper.getBarrelExportCode({ - moduleResolution: moduleResolution, - filenames: [ - ...deliveryModels.snippetFiles.map((m) => { - const path = parse(m.filename); - return `./${path.name}`; - }) - ] - }); - const contentTypeSnippetsBarrelExportPath: string = `${contentTypeSnippetsFolderPath}${barrelExportFilename}`; - await fileHelper.createFileOnFsAsync( - contentTypeSnippetsBarrelCode, - contentTypeSnippetsBarrelExportPath, +): Promise { + const fileProcessor = _fileProcessor(toOutputDirPath(config.outputDir)); + + await fileProcessor.createFilesAsync( + [ + ...data.contentTypeFiles, + ...data.snippetFiles, + ...data.taxonomyFiles, + // barrel files + { + filename: `${folders.contentTypesFolderName}/${coreConfig.barrelExportFilename}`, + text: getBarrelExportCode({ + moduleResolution: config.moduleResolution, + filenames: [ + ...data.contentTypeFiles.map((m) => { + const path = parse(m.filename); + return `./${path.name}`; + }) + ] + }) + }, + { + filename: `${folders.contentTypeSnippetsFolderName}/${coreConfig.barrelExportFilename}`, + text: getBarrelExportCode({ + moduleResolution: config.moduleResolution, + filenames: [ + ...data.snippetFiles.map((m) => { + const path = parse(m.filename); + return `./${path.name}`; + }) + ] + }) + }, + { + filename: `${folders.taxonomiesFolderName}/${coreConfig.barrelExportFilename}`, + text: getBarrelExportCode({ + moduleResolution: config.moduleResolution, + filenames: [ + ...data.taxonomyFiles.map((m) => { + const path = parse(m.filename); + return `./${path.name}`; + }) + ] + }) + }, + { + filename: coreConfig.barrelExportFilename, + text: getBarrelExportCode({ + moduleResolution: config.moduleResolution, + filenames: [ + `./${folders.contentTypesFolderName}/index`, + `./${folders.contentTypeSnippetsFolderName}/index`, + `./${folders.taxonomiesFolderName}/index` + ] + }) + } + ], config.formatOptions ); - - // taxonomies - for (const file of taxonomyFiles) { - await fileHelper.createFileOnFsAsync(file.text, file.filename, config.formatOptions); - } - const taxonomiesBarrelCode = commonHelper.getBarrelExportCode({ - moduleResolution: moduleResolution, - filenames: [ - ...taxonomyFiles.map((m) => { - const path = parse(m.filename); - return `./${path.name}`; - }) - ] - }); - const taxonomiesBarrelExportPath: string = `${taxonomiesFolderPath}${barrelExportFilename}`; - await fileHelper.createFileOnFsAsync(taxonomiesBarrelCode, taxonomiesBarrelExportPath, config.formatOptions); - - // main barrel - const mainBarrelCode = commonHelper.getBarrelExportCode({ - moduleResolution: moduleResolution, - filenames: [ - `./${contentTypesFolderName}index`, - `./${contentTypeSnippetsFolderName}index`, - `./${taxonomiesFolderName}index` - ] - }); - const mainBarrelExportPath: string = `${outputDir}${barrelExportFilename}`; - await fileHelper.createFileOnFsAsync(mainBarrelCode, mainBarrelExportPath, config.formatOptions); - - console.log(chalk.green(`\nCompleted`)); } diff --git a/lib/generators/delivery/delivery-taxonomy.generator.ts b/lib/generators/delivery/delivery-taxonomy.generator.ts index 0ac0c35..1f0083c 100644 --- a/lib/generators/delivery/delivery-taxonomy.generator.ts +++ b/lib/generators/delivery/delivery-taxonomy.generator.ts @@ -1,6 +1,6 @@ import { TaxonomyTypeFileNameResolver, TaxonomyTypeResolver } from '../../models.js'; import chalk from 'chalk'; -import { commonHelper, GeneratedFile } from '../../common-helper.js'; +import { commonHelper } from '../../common-helper.js'; import { TaxonomyModels } from '@kontent-ai/management-sdk'; import { MapTaxonomyToFileName, @@ -8,10 +8,10 @@ import { getMapTaxonomyToFileName, getMapTaxonomyName } from './delivery-mappers.js'; +import { GeneratedFile } from '../../core/index.js'; export class DeliveryTaxonomyGenerator { generateTaxonomyTypes(config: { - outputDir: string; taxonomies: TaxonomyModels.Taxonomy[]; taxonomyFolderName: string; addTimestamp: boolean; @@ -42,7 +42,6 @@ export class DeliveryTaxonomyGenerator { for (const taxonomy of config.taxonomies) { const file = this.generateModels({ - outputDir: config.outputDir, taxonomy: taxonomy, taxonomyFolderName: config.taxonomyFolderName, addTimestamp: config.addTimestamp, @@ -66,14 +65,13 @@ export class DeliveryTaxonomyGenerator { } private generateModels(data: { - outputDir: string; taxonomy: TaxonomyModels.Taxonomy; taxonomyFolderName: string; addTimestamp: boolean; taxonomyFileNameMap: MapTaxonomyToFileName; taxonomyNameMap: MapTaxonomyName; }): GeneratedFile { - const filename = `${data.outputDir}${data.taxonomyFolderName}${data.taxonomyFileNameMap(data.taxonomy, true)}`; + const filename = `${data.taxonomyFolderName}/${data.taxonomyFileNameMap(data.taxonomy, true)}`; const code = this.getModelCode({ taxonomy: data.taxonomy, addTimestamp: data.addTimestamp, @@ -112,7 +110,10 @@ export type ${config.taxonomyNameMap(config.taxonomy)} = ${this.getTaxonomyTerms let code: string = ''; - const sortedTaxonomyTerms: string[] = commonHelper.sortAlphabetically(taxonomyTermCodenames, (item) => item); + const sortedTaxonomyTerms: readonly string[] = commonHelper.sortAlphabetically( + taxonomyTermCodenames, + (item) => item + ); for (let i = 0; i < sortedTaxonomyTerms.length; i++) { const term = sortedTaxonomyTerms[i]; diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index 9831d66..e5f9082 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -1,6 +1,6 @@ import chalk from 'chalk'; import { migrationConfig, coreConfig, toOutputDirPath, getBarrelExportCode } from '../../core/index.js'; -import { fileProcessor as _fileProcessor } from '../../file-helper.js'; +import { fileProcessor as _fileProcessor } from '../../files/index.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; import { migrationGenerator as _migrationGenerator } from './migration.generator.js'; import { GenerateMigrationModelsConfig, ModuleResolution } from '../../models.js'; diff --git a/lib/generators/project/project-func.ts b/lib/generators/project/project-func.ts index 517d596..697edba 100644 --- a/lib/generators/project/project-func.ts +++ b/lib/generators/project/project-func.ts @@ -1,9 +1,9 @@ import chalk from 'chalk'; import { GeneratProjectModelsConfig, ModuleResolution } from '../../models.js'; import { projectGenerator as _projectGenerator } from './project.generator.js'; -import { fileProcessor as _fileProcessor } from '../../file-helper.js'; +import { fileProcessor as _fileProcessor } from '../../files/index.js'; import { parse } from 'path'; -import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; +import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; import { coreConfig, getBarrelExportCode, toOutputDirPath } from '../../core/index.js'; export async function generateProjectModelsAsync(config: GeneratProjectModelsConfig): Promise { diff --git a/lib/index.ts b/lib/index.ts index ca157d5..78c59f5 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -3,5 +3,6 @@ export * from './text-helper.js'; export * from './name-helper.js'; export * from './models.js'; export * from './core/index.js'; +export * from './files/index.js'; export * from './comments/index.js'; export * from './generators/index.js'; From 72207c724d19ee6d15bbe69f5130a99a5f4d4765 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 22 Aug 2024 09:59:26 +0200 Subject: [PATCH 026/183] refactors taxonomy generator --- lib/generators/delivery/delivery-func.ts | 12 +- .../delivery/delivery-taxonomy.generator.ts | 171 ++++++++---------- sample/delivery/taxonomies/movietype.ts | 11 +- sample/delivery/taxonomies/releasecategory.ts | 11 +- 4 files changed, 99 insertions(+), 106 deletions(-) diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index ff635f2..df21fd4 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -48,13 +48,17 @@ export async function generateDeliveryModelsAsync(config: GenerateDeliveryModels }); // create taxonomy types - const taxonomyFiles = deliveryTaxonomyGenerator.generateTaxonomyTypes({ - taxonomies: taxonomies, + const taxonomyFiles = deliveryTaxonomyGenerator({ taxonomyFolderName: taxonomiesFolderName, addTimestamp: config.addTimestamp, fileResolver: config.taxonomyTypeFileResolver, - taxonomyResolver: config.taxonomyTypeResolver - }); + taxonomyResolver: config.taxonomyTypeResolver, + moduleResolution: moduleResolution, + environmentData: { + environment: await kontentFetcher.getEnvironmentInfoAsync(), + taxonomies: taxonomies + } + }).generateTaxonomyTypes(); await createDeliveryFilesAsync( { diff --git a/lib/generators/delivery/delivery-taxonomy.generator.ts b/lib/generators/delivery/delivery-taxonomy.generator.ts index 1f0083c..0c818f0 100644 --- a/lib/generators/delivery/delivery-taxonomy.generator.ts +++ b/lib/generators/delivery/delivery-taxonomy.generator.ts @@ -1,25 +1,32 @@ -import { TaxonomyTypeFileNameResolver, TaxonomyTypeResolver } from '../../models.js'; +import { ModuleResolution, TaxonomyTypeFileNameResolver, TaxonomyTypeResolver } from '../../models.js'; import chalk from 'chalk'; -import { commonHelper } from '../../common-helper.js'; -import { TaxonomyModels } from '@kontent-ai/management-sdk'; +import { EnvironmentModels, TaxonomyModels } from '@kontent-ai/management-sdk'; import { MapTaxonomyToFileName, MapTaxonomyName, getMapTaxonomyToFileName, getMapTaxonomyName } from './delivery-mappers.js'; -import { GeneratedFile } from '../../core/index.js'; - -export class DeliveryTaxonomyGenerator { - generateTaxonomyTypes(config: { - taxonomies: TaxonomyModels.Taxonomy[]; - taxonomyFolderName: string; - addTimestamp: boolean; - fileResolver?: TaxonomyTypeFileNameResolver; - taxonomyResolver?: TaxonomyTypeResolver; - }): GeneratedFile[] { - const files: GeneratedFile[] = []; +import { GeneratedFile, sortAlphabetically, toSafeString } from '../../core/index.js'; +import { commentsManager as _commentsManager } from '../../comments/index.js'; + +export interface DeliveryTaxonomyGeneratorConfig { + readonly addTimestamp: boolean; + readonly moduleResolution: ModuleResolution; + readonly fileResolver?: TaxonomyTypeFileNameResolver; + readonly taxonomyResolver?: TaxonomyTypeResolver; + readonly taxonomyFolderName: string; + + readonly environmentData: { + readonly environment: Readonly; + readonly taxonomies: readonly Readonly[]; + }; +} + +export function deliveryTaxonomyGenerator(config: DeliveryTaxonomyGeneratorConfig) { + const commentsManager = _commentsManager(config.addTimestamp); + const generateTaxonomyTypes = (): readonly GeneratedFile[] => { if (config.taxonomyResolver) { console.log( `Using '${chalk.yellow( @@ -40,41 +47,23 @@ export class DeliveryTaxonomyGenerator { console.log('\n'); } - for (const taxonomy of config.taxonomies) { - const file = this.generateModels({ + return config.environmentData.taxonomies.map((taxonomy) => { + return getTaxonomyFile({ taxonomy: taxonomy, - taxonomyFolderName: config.taxonomyFolderName, - addTimestamp: config.addTimestamp, - taxonomyNameMap: getMapTaxonomyName(config.taxonomyResolver), - taxonomyFileNameMap: getMapTaxonomyToFileName(config.fileResolver) + taxonomyFileNameMap: getMapTaxonomyToFileName(config.fileResolver), + taxonomyNameMap: getMapTaxonomyName(config.taxonomyResolver) }); - - files.push(file); - } - - return files; - } - - private getTaxonomyComment(taxonomy: TaxonomyModels.Taxonomy): string { - let comment: string = `${taxonomy.name}`; - - comment += `\n* Id: ${taxonomy.id}`; - comment += `\n* Codename: ${taxonomy.codename}`; - - return comment; - } - - private generateModels(data: { - taxonomy: TaxonomyModels.Taxonomy; - taxonomyFolderName: string; - addTimestamp: boolean; - taxonomyFileNameMap: MapTaxonomyToFileName; - taxonomyNameMap: MapTaxonomyName; - }): GeneratedFile { - const filename = `${data.taxonomyFolderName}/${data.taxonomyFileNameMap(data.taxonomy, true)}`; - const code = this.getModelCode({ + }); + }; + + const getTaxonomyFile = (data: { + readonly taxonomy: Readonly; + readonly taxonomyFileNameMap: MapTaxonomyToFileName; + readonly taxonomyNameMap: MapTaxonomyName; + }): GeneratedFile => { + const filename = `${config.taxonomyFolderName}/${data.taxonomyFileNameMap(data.taxonomy, true)}`; + const code = getModelCode({ taxonomy: data.taxonomy, - addTimestamp: data.addTimestamp, taxonomyNameMap: data.taxonomyNameMap }); @@ -82,64 +71,50 @@ export class DeliveryTaxonomyGenerator { filename: filename, text: code }; - } - - private getModelCode(config: { - taxonomyNameMap: MapTaxonomyName; - taxonomy: TaxonomyModels.Taxonomy; - addTimestamp: boolean; - }): string { - const code = ` + }; + + const getModelCode = (data: { + readonly taxonomyNameMap: MapTaxonomyName; + readonly taxonomy: Readonly; + }): string => { + return ` +${commentsManager.environmentInfo(config.environmentData.environment)} + /** -* ${commonHelper.getAutogenerateNote(config.addTimestamp)} -* -* ${this.getTaxonomyComment(config.taxonomy)} -*/ -export type ${config.taxonomyNameMap(config.taxonomy)} = ${this.getTaxonomyTermsCode(config.taxonomy)}; + * ${toSafeString(data.taxonomy.name)} + * + * Codename: ${data.taxonomy.codename} + * Id: ${data.taxonomy.id} + */ +export type ${data.taxonomyNameMap(data.taxonomy)} = ${getTaxonomyTermsCode(data.taxonomy)}; `; - return code; - } + }; - private getTaxonomyTermsCode(taxonomy: TaxonomyModels.Taxonomy): string { - const taxonomyTermCodenames: string[] = []; - this.getTaxonomyTermCodenames(taxonomy.terms, taxonomyTermCodenames); + const getTaxonomyTermsCode = (taxonomy: Readonly): string => { + const taxonomyTermCodenames = sortAlphabetically( + getTaxonomyTermCodenames(taxonomy.terms), + (codename) => codename + ); if (!taxonomyTermCodenames.length) { return `''`; } - let code: string = ''; - - const sortedTaxonomyTerms: readonly string[] = commonHelper.sortAlphabetically( - taxonomyTermCodenames, - (item) => item - ); - - for (let i = 0; i < sortedTaxonomyTerms.length; i++) { - const term = sortedTaxonomyTerms[i]; - const isLast = i === sortedTaxonomyTerms.length - 1; - - code += `'${term}'`; - - if (!isLast) { - code += ` | `; - } - } - - return code; - } - - private getTaxonomyTermCodenames(taxonomyTerms: TaxonomyModels.Taxonomy[], resolvedCodenames: string[]): void { - for (const taxonomyTerm of taxonomyTerms) { - if (!resolvedCodenames.includes(taxonomyTerm.codename)) { - resolvedCodenames.push(taxonomyTerm.codename); - } - - if (taxonomyTerm.terms.length) { - this.getTaxonomyTermCodenames(taxonomyTerm.terms, resolvedCodenames); - } - } - } + return taxonomyTermCodenames.reduce((code, codename, index) => { + const isLast = index === taxonomyTermCodenames.length - 1; + return `${code} '${codename}'${isLast ? '' : ' | '}`; + }, ''); + }; + + const getTaxonomyTermCodenames = ( + taxonomyTerms: readonly Readonly[] + ): readonly string[] => { + return taxonomyTerms.reduce((codenames, taxonomyTerm) => { + return codenames.concat(getTaxonomyTermCodenames(taxonomyTerm.terms), taxonomyTerm.codename); + }, []); + }; + + return { + generateTaxonomyTypes + }; } - -export const deliveryTaxonomyGenerator = new DeliveryTaxonomyGenerator(); diff --git a/sample/delivery/taxonomies/movietype.ts b/sample/delivery/taxonomies/movietype.ts index 57afd78..8068946 100644 --- a/sample/delivery/taxonomies/movietype.ts +++ b/sample/delivery/taxonomies/movietype.ts @@ -1,8 +1,15 @@ /** - * Generated by '@kontent-ai/model-generator@7.4.0' * + * Movie Database + * + * Environment: Production + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + */ + +/** * MovieType - * Id: 365a17e6-1929-27ab-9f67-a9273c846717 + * * Codename: movietype + * Id: 365a17e6-1929-27ab-9f67-a9273c846717 */ export type MovieType = 'blockbuster' | 'cinema_only' | 'film' | 'student' | 'tv'; diff --git a/sample/delivery/taxonomies/releasecategory.ts b/sample/delivery/taxonomies/releasecategory.ts index 9f478c3..f32c2bf 100644 --- a/sample/delivery/taxonomies/releasecategory.ts +++ b/sample/delivery/taxonomies/releasecategory.ts @@ -1,8 +1,15 @@ /** - * Generated by '@kontent-ai/model-generator@7.4.0' * + * Movie Database + * + * Environment: Production + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + */ + +/** * ReleaseCategory - * Id: 09b6a348-0f86-7a68-4af3-7cab9a5c60b7 + * * Codename: releasecategory + * Id: 09b6a348-0f86-7a68-4af3-7cab9a5c60b7 */ export type ReleaseCategory = 'global_release' | 'local_release' | 'us_only'; From 424ff7ddda9f65e011cf6a5570784317b4df7eb0 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 22 Aug 2024 15:11:04 +0200 Subject: [PATCH 027/183] Delivery generator refactor #1 --- lib/core/core.config.ts | 2 + lib/core/core.models.ts | 10 +- lib/core/element.utils.ts | 50 +- .../delivery-content-type.generator.ts | 640 ++++++------------ lib/generators/delivery/delivery-func.ts | 17 +- .../migration/migration.generator.ts | 12 +- lib/generators/project/project.generator.ts | 28 +- sample/delivery/content-types/actor.ts | 25 +- sample/delivery/content-types/movie.ts | 75 +- 9 files changed, 351 insertions(+), 508 deletions(-) diff --git a/lib/core/core.config.ts b/lib/core/core.config.ts index f33c2f7..1348819 100644 --- a/lib/core/core.config.ts +++ b/lib/core/core.config.ts @@ -3,11 +3,13 @@ export const coreConfig = { } as const; export const migrationConfig = { + npmPackageName: '@kontent-ai/migration-toolkit', migrationItemsFolderName: `content-types`, migrationTypesFilename: `core.models.ts` } as const; export const deliveryConfig = { + npmPackageName: '@kontent-ai/delivery-sdk', contentTypesFolderName: `content-types`, contentTypeSnippetsFolderName: `content-type-snippets`, taxonomiesFolderName: `taxonomies` diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index 6579cf2..164b016 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -1,4 +1,10 @@ -import { ContentTypeElements, ElementModels, IManagementClient } from '@kontent-ai/management-sdk'; +import { + ContentTypeElements, + ContentTypeModels, + ElementModels, + IManagementClient, + TaxonomyModels +} from '@kontent-ai/management-sdk'; export type CliAction = 'delivery' | 'migration'; export type LibraryType = '@kontent-ai/migration-toolkit'; @@ -36,7 +42,9 @@ export interface FlattenedElement { readonly type: ElementModels.ElementType; readonly isRequired: boolean; readonly guidelines?: string; + readonly allowedContentTypes?: readonly Readonly[]; readonly originalElement: Readonly; + readonly assignedTaxonomy?: Readonly; } export interface GeneratedFile { diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts index 6fc05fd..fc62438 100644 --- a/lib/core/element.utils.ts +++ b/lib/core/element.utils.ts @@ -1,11 +1,18 @@ -import { ContentTypeElements, ContentTypeSnippetModels, TaxonomyModels } from '@kontent-ai/management-sdk'; +import { + ContentTypeElements, + ContentTypeModels, + ContentTypeSnippetModels, + TaxonomyModels +} from '@kontent-ai/management-sdk'; import { FlattenedElement } from './core.models.js'; import { isNotUndefined } from '@kontent-ai/migration-toolkit'; +import { match } from 'ts-pattern'; export function getFlattenedElements( elements: readonly Readonly[], snippets: readonly Readonly[], - taxonomies: readonly Readonly[] + taxonomies: readonly Readonly[], + types: readonly Readonly[] ): readonly FlattenedElement[] { return elements .filter((element) => { @@ -29,14 +36,15 @@ export function getFlattenedElements( return element; }) .map((element) => { - return getFlattenedElement(element, taxonomies); + return getFlattenedElement(element, taxonomies, types); }) .filter(isNotUndefined); } export function getFlattenedElement( element: Readonly, - taxonomies: readonly Readonly[] + taxonomies: readonly Readonly[], + types: readonly Readonly[] ): Readonly | undefined { if (!element.codename) { return undefined; @@ -53,7 +61,9 @@ export function getFlattenedElement( isRequired: isElementRequired(element), guidelines: getElementGuidelines(element), externalId: element.external_id, - originalElement: element + originalElement: element, + allowedContentTypes: extractLinkedItemsAllowedTypes(element, types), + assignedTaxonomy: extractTaxonomy(element, taxonomies) }; } @@ -86,3 +96,33 @@ function getElementTitle( } return (<{ name?: string }>element).name ?? element.codename ?? 'n/a'; } + +function extractLinkedItemsAllowedTypes( + element: Readonly, + types: readonly Readonly[] +): readonly Readonly[] { + const allowedTypeIds = match(element) + .returnType[]>() + .with({ type: 'modular_content' }, (linkedItemsElement) => { + return linkedItemsElement.allowed_content_types?.map((m) => m.id).filter(isNotUndefined) ?? []; + }) + .with({ type: 'subpages' }, (linkedItemsElement) => { + return linkedItemsElement.allowed_content_types?.map((m) => m.id).filter(isNotUndefined) ?? []; + }) + .otherwise(() => []); + + return allowedTypeIds.map((id) => types.find((m) => m.id === id)).filter(isNotUndefined); +} + +function extractTaxonomy( + element: Readonly, + taxonomies: readonly Readonly[] +): Readonly | undefined { + return match(element) + .returnType | undefined>() + .with({ type: 'taxonomy' }, (taxonomyElement) => { + return taxonomies.find((m) => m.id === taxonomyElement.taxonomy_group?.id); + }) + + .otherwise(() => undefined); +} diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 8609d9a..041caa2 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -15,6 +15,7 @@ import { ContentTypeModels, ContentTypeSnippetModels, ElementModels, + EnvironmentModels, TaxonomyModels } from '@kontent-ai/management-sdk'; import { @@ -39,92 +40,123 @@ import { MapContentTypeSnippetIdToObject, getMapContentTypeSnippetIdToObject } from './delivery-mappers.js'; +import { commentsManager as _commentsManager } from '../../comments/index.js'; import { textHelper } from '../../text-helper.js'; -import { GeneratedFile, sortAlphabetically } from '../../core/index.js'; - -interface IExtendedContentTypeElement { - type: ElementModels.ElementType; - element: ContentTypeElements.ContentTypeElementModel; - mappedType: string | undefined; - mappedName: string | undefined; - snippet?: ContentTypeSnippetModels.ContentTypeSnippet; -} +import { + deliveryConfig, + FlattenedElement, + GeneratedFile, + getFlattenedElements, + sortAlphabetically +} from '../../core/index.js'; + +// interface IExtendedContentTypeElement { +// readonly type: ElementModels.ElementType; +// readonly element: Readonly; +// readonly mappedType: string | undefined; +// readonly mappedName: string | undefined; +// readonly snippet?: Readonly; +// } interface IExtractImportsResult { - imports: readonly string[]; - contentTypeSnippetExtensions: string[]; - processedElements: readonly IExtendedContentTypeElement[]; + readonly imports: readonly string[]; + readonly contentTypeSnippetExtensions: string[]; + readonly processedElements: readonly FlattenedElement[]; +} + +export interface DeliveryContentTypeGeneratorConfig { + readonly typeFolderName: string; + readonly typeSnippetsFolderName: string; + readonly taxonomyFolderName: string; + + readonly addTimestamp: boolean; + readonly addEnvironmentInfo: boolean; + readonly elementResolver?: ElementResolver; + readonly contentTypeFileNameResolver?: ContentTypeFileNameResolver; + readonly contentTypeSnippetFileNameResolver?: ContentTypeSnippetFileNameResolver; + readonly contentTypeResolver?: ContentTypeResolver; + readonly contentTypeSnippetResolver?: ContentTypeSnippetResolver; + readonly taxonomyFileResolver?: TaxonomyTypeFileNameResolver; + readonly taxonomyResolver?: TaxonomyTypeResolver; + readonly moduleResolution: ModuleResolution; + + readonly environmentData: { + readonly environment: Readonly; + readonly types: readonly Readonly[]; + readonly taxonomies: readonly Readonly[]; + readonly snippets: readonly Readonly[]; + }; } -export class DeliveryContentTypeGenerator { - private readonly deliveryNpmPackageName: string = '@kontent-ai/delivery-sdk'; - - generateModels(data: { - typeFolderName: string; - typeSnippetsFolderName: string; - taxonomyFolderName: string; - types: ContentTypeModels.ContentType[]; - taxonomies: TaxonomyModels.Taxonomy[]; - snippets: ContentTypeSnippetModels.ContentTypeSnippet[]; - addTimestamp: boolean; - addEnvironmentInfo: boolean; - elementResolver?: ElementResolver; - contentTypeFileNameResolver?: ContentTypeFileNameResolver; - contentTypeSnippetFileNameResolver?: ContentTypeSnippetFileNameResolver; - contentTypeResolver?: ContentTypeResolver; - contentTypeSnippetResolver?: ContentTypeSnippetResolver; - taxonomyFileResolver?: TaxonomyTypeFileNameResolver; - taxonomyResolver?: TaxonomyTypeResolver; - moduleResolution: ModuleResolution; - }): { contentTypeFiles: readonly GeneratedFile[]; snippetFiles: readonly GeneratedFile[] } { +export function deliveryContentTypeGenerator(config: DeliveryContentTypeGeneratorConfig) { + const commentsManager = _commentsManager(config.addTimestamp); + + // prepare resolvers + const contentTypeSnippetNameMap = getMapContentTypeSnippetToDeliveryTypeName(config.contentTypeSnippetResolver); + const contentTypeSnippetFileNameMap = getMapContentTypeSnippetToFileName(config.contentTypeSnippetFileNameResolver); + const contentTypeNameMap = getMapContentTypeToDeliveryTypeName(config.contentTypeResolver); + const contentTypeObjectMap = getMapContentTypeIdToObject(config.environmentData.types); + const contentTypeSnippetObjectMap = getMapContentTypeSnippetIdToObject(config.environmentData.snippets); + const contentTypeFileNameMap = getMapContentTypeToFileName(config.contentTypeFileNameResolver); + const elementNameMap = getMapElementToName(config.elementResolver); + const taxonomyNameMap = getMapTaxonomyName(config.taxonomyResolver); + const taxonomyFileNameMap = getMapTaxonomyToFileName(config.taxonomyFileResolver); + const taxonomyObjectMap = getMapTaxonomyIdTobject(config.environmentData.taxonomies); + + const generateModels = (): { + contentTypeFiles: readonly GeneratedFile[]; + snippetFiles: readonly GeneratedFile[]; + } => { const typeFiles: GeneratedFile[] = []; const snippetFiles: GeneratedFile[] = []; let addNewLineAfterResolvers: boolean = false; - if (data.elementResolver) { + if (config.elementResolver) { addNewLineAfterResolvers = true; console.log( `Using '${chalk.yellow( - data.elementResolver instanceof Function ? 'custom' : data.elementResolver + config.elementResolver instanceof Function ? 'custom' : config.elementResolver )}' name resolver for content type elements` ); } - if (data.contentTypeFileNameResolver) { + if (config.contentTypeFileNameResolver) { addNewLineAfterResolvers = true; console.log( `Using '${chalk.yellow( - data.contentTypeFileNameResolver instanceof Function ? 'custom' : data.contentTypeFileNameResolver + config.contentTypeFileNameResolver instanceof Function + ? 'custom' + : config.contentTypeFileNameResolver )}' name resolver for content type filenames` ); } - if (data.contentTypeSnippetFileNameResolver) { + if (config.contentTypeSnippetFileNameResolver) { addNewLineAfterResolvers = true; console.log( `Using '${chalk.yellow( - data.contentTypeSnippetFileNameResolver instanceof Function + config.contentTypeSnippetFileNameResolver instanceof Function ? 'custom' - : data.contentTypeSnippetFileNameResolver + : config.contentTypeSnippetFileNameResolver )}' name resolver for content type snippet filenames` ); } - if (data.contentTypeResolver) { + if (config.contentTypeResolver) { addNewLineAfterResolvers = true; console.log( `Using '${chalk.yellow( - data.contentTypeResolver instanceof Function ? 'custom' : data.contentTypeResolver + config.contentTypeResolver instanceof Function ? 'custom' : config.contentTypeResolver )}' name resolver for content types` ); } - if (data.contentTypeSnippetResolver) { + if (config.contentTypeSnippetResolver) { addNewLineAfterResolvers = true; console.log( `Using '${chalk.yellow( - data.contentTypeSnippetResolver instanceof Function ? 'custom' : data.contentTypeSnippetResolver + config.contentTypeSnippetResolver instanceof Function ? 'custom' : config.contentTypeSnippetResolver )}' name resolver for content type snippets` ); } @@ -133,32 +165,10 @@ export class DeliveryContentTypeGenerator { console.log(''); } - for (const contentTypeSnippet of data.snippets) { + for (const contentTypeSnippet of config.environmentData.snippets) { try { - const file = this.createContentTypeSnippetModel({ - snippet: contentTypeSnippet, - snippets: data.snippets, - taxonomies: data.taxonomies, - typeFolderName: data.typeFolderName, - typeSnippetsFolderName: data.typeSnippetsFolderName, - taxonomyFolderName: data.taxonomyFolderName, - contentTypeSnippetNameMap: getMapContentTypeSnippetToDeliveryTypeName( - data.contentTypeSnippetResolver - ), - contentTypeSnippetFileNameMap: getMapContentTypeSnippetToFileName( - data.contentTypeSnippetFileNameResolver - ), - contentTypeNameMap: getMapContentTypeToDeliveryTypeName(data.contentTypeResolver), - contentTypeObjectMap: getMapContentTypeIdToObject(data.types), - contentTypeSnippetObjectMap: getMapContentTypeSnippetIdToObject(data.snippets), - contentTypeFileNameMap: getMapContentTypeToFileName(data.contentTypeFileNameResolver), - elementNameMap: getMapElementToName(data.elementResolver), - taxonomyNameMap: getMapTaxonomyName(data.taxonomyResolver), - taxonomyFileNameMap: getMapTaxonomyToFileName(data.taxonomyFileResolver), - taxonomyObjectMap: getMapTaxonomyIdTobject(data.taxonomies), - addTimestamp: data.addTimestamp, - addEnvironmentInfo: data.addEnvironmentInfo, - moduleResolution: data.moduleResolution + const file = createContentTypeSnippetModel({ + snippet: contentTypeSnippet }); snippetFiles.push(file); } catch (error) { @@ -169,32 +179,10 @@ export class DeliveryContentTypeGenerator { } } - for (const type of data.types) { + for (const type of config.environmentData.types) { try { - const file = this.createContentTypeModel({ - moduleResolution: data.moduleResolution, - type: type, - snippets: data.snippets, - taxonomies: data.taxonomies, - typeFolderName: data.typeFolderName, - typeSnippetsFolderName: data.typeSnippetsFolderName, - taxonomyFolderName: data.taxonomyFolderName, - contentTypeSnippetNameMap: getMapContentTypeSnippetToDeliveryTypeName( - data.contentTypeSnippetResolver - ), - contentTypeSnippetFileNameMap: getMapContentTypeSnippetToFileName( - data.contentTypeSnippetFileNameResolver - ), - contentTypeNameMap: getMapContentTypeToDeliveryTypeName(data.contentTypeResolver), - contentTypeObjectMap: getMapContentTypeIdToObject(data.types), - contentTypeFileNameMap: getMapContentTypeToFileName(data.contentTypeFileNameResolver), - contentTypeSnippetObjectMap: getMapContentTypeSnippetIdToObject(data.snippets), - elementNameMap: getMapElementToName(data.elementResolver), - taxonomyNameMap: getMapTaxonomyName(data.taxonomyResolver), - taxonomyFileNameMap: getMapTaxonomyToFileName(data.taxonomyFileResolver), - taxonomyObjectMap: getMapTaxonomyIdTobject(data.taxonomies), - addTimestamp: data.addTimestamp, - addEnvironmentInfo: data.addEnvironmentInfo + const file = createContentTypeModel({ + type: type }); typeFiles.push(file); } catch (error) { @@ -207,47 +195,28 @@ export class DeliveryContentTypeGenerator { contentTypeFiles: typeFiles, snippetFiles: snippetFiles }; - } - - private getContentTypeImports(data: { - contentTypeNameMap: MapContentTypeToDeliveryTypeName; - contentTypeSnippetNameMap: MapContentTypeSnippetToDeliveryTypeName; - contentTypeObjectMap: MapContentTypeIdToObject; - contentTypeSnippetObjectMap: MapContentTypeSnippetIdToObject; - contentTypeFileNameMap: MapContentTypeToFileName; - contentTypeSnippetFileNameMap: MapContentTypeSnippetToFileName; - taxonomyObjectMap: MapTaxonomyIdTobject; - taxonomyNameMap: MapTaxonomyName; - taxonomyFileNameMap: MapTaxonomyToFileName; - elementNameMap: MapElementToName; - snippets: ContentTypeSnippetModels.ContentTypeSnippet[]; - contentType?: ContentTypeModels.ContentType; - contentTypeSnippet?: ContentTypeSnippetModels.ContentTypeSnippet; - typeFolderName: string; - typeSnippetsFolderName: string; - taxonomyFolderName: string; - moduleResolution: ModuleResolution; - }): IExtractImportsResult { + }; + + const getContentTypeImports = (data: { + typeOrSnippet: ContentTypeModels.ContentType | ContentTypeSnippetModels.ContentTypeSnippet; + }): IExtractImportsResult => { const imports: string[] = []; const contentTypeSnippetExtensions: string[] = []; const processedTypeIds: string[] = []; const processedTaxonomyIds: string[] = []; - const extendedElements: readonly IExtendedContentTypeElement[] = this.getExtendedElements({ - elementNameMap: data.elementNameMap, - contentType: data.contentType, - contentTypeSnippet: data.contentTypeSnippet, - contentTypeNameMap: data.contentTypeNameMap, - contentTypeObjectMap: data.contentTypeObjectMap, - taxonomyNameMap: data.taxonomyNameMap, - taxonomyObjectMap: data.taxonomyObjectMap - }); + const flattenedElements = getFlattenedElements( + data.typeOrSnippet.elements, + config.environmentData.snippets, + config.environmentData.taxonomies, + config.environmentData.types + ); - for (const extendedElement of extendedElements) { - const element = extendedElement.element; + for (const extendedElement of flattenedElements) { + const element = extendedElement.originalElement; if (element.type === 'taxonomy') { - const taxonomy = this.extractUsedTaxonomy(element, data.taxonomyObjectMap); + const taxonomy = extractUsedTaxonomy(element, taxonomyObjectMap); if (!taxonomy) { continue; @@ -259,12 +228,12 @@ export class DeliveryContentTypeGenerator { processedTaxonomyIds.push(taxonomy.id); - const taxonomyName: string = data.taxonomyNameMap(taxonomy); - const fileName: string = `../${data.taxonomyFolderName}/${data.taxonomyFileNameMap(taxonomy, false)}`; + const taxonomyName: string = taxonomyNameMap(taxonomy); + const fileName: string = `../${config.taxonomyFolderName}/${taxonomyFileNameMap(taxonomy, false)}`; imports.push( commonHelper.getImportStatement({ - moduleResolution: data.moduleResolution, + moduleResolution: config.moduleResolution, filePathOrPackage: fileName, importValue: `type ${taxonomyName}`, isExternalLib: false @@ -272,7 +241,7 @@ export class DeliveryContentTypeGenerator { ); } else if (element.type === 'modular_content' || element.type === 'subpages') { // extract referenced types - const referencedTypes = this.extractLinkedItemsAllowedTypes(element, data.contentTypeObjectMap); + const referencedTypes = extractLinkedItemsAllowedTypes(element, contentTypeObjectMap); for (const referencedType of referencedTypes) { if (processedTypeIds.includes(referencedType.id)) { @@ -281,22 +250,23 @@ export class DeliveryContentTypeGenerator { } // filter 'self referencing' types as they don't need to be imported - if (data.contentType?.id === referencedType.id) { + if (data.typeOrSnippet?.id === referencedType.id) { continue; } processedTypeIds.push(referencedType.id); - const typeName: string = data.contentTypeNameMap(referencedType); - const fileName: string = `${data.contentTypeFileNameMap(referencedType, false)}`; + const typeName: string = contentTypeNameMap(referencedType); + const fileName: string = `${contentTypeFileNameMap(referencedType, false)}`; - const filePath: string = data.contentTypeSnippet - ? `../${data.typeFolderName}/${fileName}` - : `./${fileName}`; + const filePath: string = + data.typeOrSnippet instanceof ContentTypeModels.ContentType + ? `../${config.typeFolderName}/${fileName}` + : `./${fileName}`; imports.push( commonHelper.getImportStatement({ - moduleResolution: data.moduleResolution, + moduleResolution: config.moduleResolution, filePathOrPackage: filePath, importValue: `type ${typeName}`, isExternalLib: false @@ -304,17 +274,17 @@ export class DeliveryContentTypeGenerator { ); } } else if (element.type === 'snippet') { - const contentTypeSnipped = this.extractUsedSnippet(element, data.contentTypeSnippetObjectMap); + const contentTypeSnipped = extractUsedSnippet(element, contentTypeSnippetObjectMap); - const typeName: string = data.contentTypeSnippetNameMap(contentTypeSnipped); - const filePath: string = `../${data.typeSnippetsFolderName}${data.contentTypeSnippetFileNameMap( + const typeName: string = contentTypeSnippetNameMap(contentTypeSnipped); + const filePath: string = `../${config.typeSnippetsFolderName}${contentTypeSnippetFileNameMap( contentTypeSnipped, false )}`; imports.push( commonHelper.getImportStatement({ - moduleResolution: data.moduleResolution, + moduleResolution: config.moduleResolution, filePathOrPackage: filePath, importValue: `type ${typeName}`, isExternalLib: false @@ -328,52 +298,24 @@ export class DeliveryContentTypeGenerator { return { imports: sortAlphabetically(imports, (item) => item), contentTypeSnippetExtensions: contentTypeSnippetExtensions, - processedElements: extendedElements + processedElements: flattenedElements }; - } - - private getModelCode(data: { - contentTypeNameMap: MapContentTypeToDeliveryTypeName; - contentTypeSnippetNameMap: MapContentTypeSnippetToDeliveryTypeName; - contentTypeObjectMap: MapContentTypeIdToObject; - contentTypeSnippetObjectMap: MapContentTypeSnippetIdToObject; - contentTypeFileNameMap: MapContentTypeToFileName; - contentTypeSnippetFileNameMap: MapContentTypeSnippetToFileName; - elementNameMap: MapElementToName; - taxonomyObjectMap: MapTaxonomyIdTobject; - taxonomyNameMap: MapTaxonomyName; - taxonomyFileNameMap: MapTaxonomyToFileName; - contentType?: ContentTypeModels.ContentType; - contentTypeSnippet?: ContentTypeSnippetModels.ContentTypeSnippet; - taxonomies: TaxonomyModels.Taxonomy[]; - snippets: ContentTypeSnippetModels.ContentTypeSnippet[]; - typeFolderName: string; - typeSnippetsFolderName: string; - taxonomyFolderName: string; - addTimestamp: boolean; - addEnvironmentInfo: boolean; - moduleResolution: ModuleResolution; - }): string { - const importResult = this.getContentTypeImports({ - elementNameMap: data.elementNameMap, - contentTypeNameMap: data.contentTypeNameMap, - contentTypeSnippetNameMap: data.contentTypeSnippetNameMap, - contentTypeObjectMap: data.contentTypeObjectMap, - contentTypeFileNameMap: data.contentTypeFileNameMap, - contentTypeSnippetFileNameMap: data.contentTypeSnippetFileNameMap, - contentTypeSnippetObjectMap: data.contentTypeSnippetObjectMap, - taxonomyFileNameMap: data.taxonomyFileNameMap, - taxonomyNameMap: data.taxonomyNameMap, - taxonomyObjectMap: data.taxonomyObjectMap, - snippets: data.snippets, - contentType: data.contentType, - contentTypeSnippet: data.contentTypeSnippet, - typeFolderName: data.typeFolderName, - typeSnippetsFolderName: data.typeSnippetsFolderName, - taxonomyFolderName: data.taxonomyFolderName, - moduleResolution: data.moduleResolution + }; + + const getModelCode = (data: { + typeOrSnippet: ContentTypeModels.ContentType | ContentTypeSnippetModels.ContentTypeSnippet; + }): string => { + const importResult = getContentTypeImports({ + typeOrSnippet: data.typeOrSnippet }); + const flattenedElements = getFlattenedElements( + data.typeOrSnippet.elements, + config.environmentData.snippets, + config.environmentData.taxonomies, + config.environmentData.types + ); + const topLevelImports: string[] = ['type IContentItem']; if (importResult.processedElements.filter((m) => m.type !== 'snippet' && m.type !== 'guidelines').length) { @@ -382,8 +324,8 @@ export class DeliveryContentTypeGenerator { } let code = commonHelper.getImportStatement({ - moduleResolution: data.moduleResolution, - filePathOrPackage: this.deliveryNpmPackageName, + moduleResolution: config.moduleResolution, + filePathOrPackage: deliveryConfig.npmPackageName, importValue: `${topLevelImports.join(', ')}`, isExternalLib: true }); @@ -400,169 +342,86 @@ export class DeliveryContentTypeGenerator { let typeName: string = ''; let typeExtends: string = ''; - if (data.contentType) { - comment = this.getContentTypeComment(data.contentType); - typeName = data.contentTypeNameMap(data.contentType); + if (data.typeOrSnippet instanceof ContentTypeModels.ContentType) { + comment = getContentTypeComment(data.typeOrSnippet); + typeName = contentTypeNameMap(data.typeOrSnippet); if (importResult.contentTypeSnippetExtensions.length) { typeExtends = `& ${importResult.contentTypeSnippetExtensions.join(' & ')}`; } - } else if (data.contentTypeSnippet) { - comment = this.getContentTypeSnippetComment(data.contentTypeSnippet); - typeName = data.contentTypeSnippetNameMap(data.contentTypeSnippet); + } else if (data.typeOrSnippet instanceof ContentTypeSnippetModels.ContentTypeSnippet) { + comment = getContentTypeSnippetComment(data.typeOrSnippet); + typeName = contentTypeSnippetNameMap(data.typeOrSnippet); } code += ` +${commentsManager.environmentInfo(config.environmentData.environment)} + /** -* ${commonHelper.getAutogenerateNote(data.addTimestamp)} -* +* * ${comment} */ export type ${typeName} = IContentItem<{ - ${this.getElementsCode({ - contentTypeObjectMap: data.contentTypeObjectMap, - contentTypeNameMap: data.contentTypeNameMap, - contentType: data.contentType, - contentTypeSnippet: data.contentTypeSnippet, - snippets: data.snippets, - elementNameMap: data.elementNameMap, - taxonomyNameMap: data.taxonomyNameMap, - taxonomyObjectMap: data.taxonomyObjectMap, - taxonomies: data.taxonomies + ${getElementsCode({ + flattenedElements: flattenedElements })} }>${typeExtends}; `; return code; - } - - private createContentTypeModel(data: { - type: ContentTypeModels.ContentType; - typeFolderName: string; - typeSnippetsFolderName: string; - taxonomyFolderName: string; - taxonomies: TaxonomyModels.Taxonomy[]; - contentTypeNameMap: MapContentTypeToDeliveryTypeName; - contentTypeSnippetNameMap: MapContentTypeSnippetToDeliveryTypeName; - contentTypeObjectMap: MapContentTypeIdToObject; - contentTypeFileNameMap: MapContentTypeToFileName; - contentTypeSnippetFileNameMap: MapContentTypeSnippetToFileName; - contentTypeSnippetObjectMap: MapContentTypeSnippetIdToObject; - elementNameMap: MapElementToName; - taxonomyObjectMap: MapTaxonomyIdTobject; - taxonomyNameMap: MapTaxonomyName; - taxonomyFileNameMap: MapTaxonomyToFileName; - snippets: ContentTypeSnippetModels.ContentTypeSnippet[]; - addTimestamp: boolean; - addEnvironmentInfo: boolean; - moduleResolution: ModuleResolution; - }): GeneratedFile { - const filename: string = `${data.typeFolderName}/${data.contentTypeFileNameMap(data.type, true)}`; - const code = this.getModelCode({ - contentTypeFileNameMap: data.contentTypeFileNameMap, - contentTypeSnippetFileNameMap: data.contentTypeSnippetFileNameMap, - contentTypeSnippetNameMap: data.contentTypeSnippetNameMap, - contentTypeNameMap: data.contentTypeNameMap, - contentTypeObjectMap: data.contentTypeObjectMap, - contentTypeSnippetObjectMap: data.contentTypeSnippetObjectMap, - contentType: data.type, - contentTypeSnippet: undefined, - snippets: data.snippets, - taxonomies: data.taxonomies, - typeFolderName: data.typeFolderName, - typeSnippetsFolderName: data.typeSnippetsFolderName, - taxonomyFolderName: data.taxonomyFolderName, - addTimestamp: data.addTimestamp, - addEnvironmentInfo: data.addEnvironmentInfo, - elementNameMap: data.elementNameMap, - taxonomyFileNameMap: data.taxonomyFileNameMap, - taxonomyNameMap: data.taxonomyNameMap, - taxonomyObjectMap: data.taxonomyObjectMap, - moduleResolution: data.moduleResolution + }; + + const createContentTypeModel = (data: { type: ContentTypeModels.ContentType }): GeneratedFile => { + const filename: string = `${config.typeFolderName}/${contentTypeFileNameMap(data.type, true)}`; + const code = getModelCode({ + typeOrSnippet: data.type }); return { filename: filename, text: code }; - } - - private createContentTypeSnippetModel(data: { - snippet: ContentTypeSnippetModels.ContentTypeSnippet; - typeSnippetsFolderName: string; - taxonomyFolderName: string; - typeFolderName: string; - taxonomies: TaxonomyModels.Taxonomy[]; - contentTypeSnippetNameMap: MapContentTypeSnippetToDeliveryTypeName; - contentTypeNameMap: MapContentTypeToDeliveryTypeName; - contentTypeFileNameMap: MapContentTypeToFileName; - contentTypeObjectMap: MapContentTypeIdToObject; - contentTypeSnippetFileNameMap: MapContentTypeSnippetToFileName; - contentTypeSnippetObjectMap: MapContentTypeSnippetIdToObject; - elementNameMap: MapElementToName; - taxonomyObjectMap: MapTaxonomyIdTobject; - taxonomyNameMap: MapTaxonomyName; - taxonomyFileNameMap: MapTaxonomyToFileName; - snippets: ContentTypeSnippetModels.ContentTypeSnippet[]; - addTimestamp: boolean; - addEnvironmentInfo: boolean; - moduleResolution: ModuleResolution; - }): GeneratedFile { - const filename: string = `${data.typeSnippetsFolderName}/${data.contentTypeSnippetFileNameMap( + }; + + const createContentTypeSnippetModel = (data: { + readonly snippet: ContentTypeSnippetModels.ContentTypeSnippet; + }): GeneratedFile => { + const filename: string = `${config.typeSnippetsFolderName}/${contentTypeSnippetFileNameMap( data.snippet, true )}`; - const code = this.getModelCode({ - contentTypeFileNameMap: data.contentTypeFileNameMap, - contentTypeSnippetFileNameMap: data.contentTypeSnippetFileNameMap, - contentTypeSnippetNameMap: data.contentTypeSnippetNameMap, - contentTypeNameMap: data.contentTypeNameMap, - contentTypeObjectMap: data.contentTypeObjectMap, - contentTypeSnippetObjectMap: data.contentTypeSnippetObjectMap, - contentType: undefined, - contentTypeSnippet: data.snippet, - snippets: data.snippets, - taxonomies: data.taxonomies, - typeFolderName: data.typeFolderName, - typeSnippetsFolderName: data.typeSnippetsFolderName, - taxonomyFolderName: data.taxonomyFolderName, - addTimestamp: data.addTimestamp, - addEnvironmentInfo: data.addEnvironmentInfo, - elementNameMap: data.elementNameMap, - taxonomyFileNameMap: data.taxonomyFileNameMap, - taxonomyNameMap: data.taxonomyNameMap, - taxonomyObjectMap: data.taxonomyObjectMap, - moduleResolution: data.moduleResolution + const code = getModelCode({ + typeOrSnippet: data.snippet }); return { filename: filename, text: code }; - } + }; - private getContentTypeComment(contentType: ContentTypeModels.ContentType): string { + const getContentTypeComment = (contentType: ContentTypeModels.ContentType): string => { let comment: string = `${contentType.name}`; comment += `\n* Id: ${contentType.id}`; comment += `\n* Codename: ${contentType.codename}`; return comment; - } + }; - private getContentTypeSnippetComment(contentTypeSnippet: ContentTypeSnippetModels.ContentTypeSnippet): string { + const getContentTypeSnippetComment = (contentTypeSnippet: ContentTypeSnippetModels.ContentTypeSnippet): string => { let comment: string = `${contentTypeSnippet.name}`; comment += `\n* Id: ${contentTypeSnippet.id}`; comment += `\n* Codename: ${contentTypeSnippet.codename}`; return comment; - } + }; - private getElementComment( - extendedElement: IExtendedContentTypeElement, - taxonomies: TaxonomyModels.Taxonomy[] - ): string { - const element = extendedElement.element; + const getElementComment = ( + flattenedElement: FlattenedElement, + taxonomies: readonly Readonly[] + ): string => { + const element = flattenedElement.originalElement; const isRequired = commonHelper.isElementRequired(element); const guidelines = commonHelper.getElementGuidelines(element); const name = commonHelper.getElementTitle(element, taxonomies); @@ -581,10 +440,10 @@ export type ${typeName} = IContentItem<{ comment += `\n* Codename: ${codename}`; } - if (extendedElement.snippet) { - comment += `\n* From snippet: ${extendedElement.snippet.name}`; - comment += `\n* Snippet codename: ${extendedElement.snippet.codename}`; - } + // if (flattenedElement.snippet) { + // comment += `\n* From snippet: ${flattenedElement.snippet.name}`; + // comment += `\n* Snippet codename: ${flattenedElement.snippet.codename}`; + // } if (guidelines) { comment += `\n*`; @@ -594,33 +453,14 @@ export type ${typeName} = IContentItem<{ comment += '\n*/'; return comment; - } - - private getElementsCode(data: { - contentTypeNameMap: MapContentTypeToDeliveryTypeName; - contentTypeObjectMap: MapContentTypeIdToObject; - elementNameMap: MapElementToName; - contentType?: ContentTypeModels.ContentType; - contentTypeSnippet?: ContentTypeSnippetModels.ContentTypeSnippet; - snippets: ContentTypeSnippetModels.ContentTypeSnippet[]; - taxonomyObjectMap: MapTaxonomyIdTobject; - taxonomyNameMap: MapTaxonomyName; - taxonomies: TaxonomyModels.Taxonomy[]; - }): string { - const extendedElements: readonly IExtendedContentTypeElement[] = this.getExtendedElements({ - elementNameMap: data.elementNameMap, - contentType: data.contentType, - contentTypeSnippet: data.contentTypeSnippet, - contentTypeNameMap: data.contentTypeNameMap, - contentTypeObjectMap: data.contentTypeObjectMap, - taxonomyNameMap: data.taxonomyNameMap, - taxonomyObjectMap: data.taxonomyObjectMap - }); + }; + const getElementsCode = (data: { flattenedElements: readonly FlattenedElement[] }): string => { let code = ''; - for (let i = 0; i < extendedElements.length; i++) { - const extendedElement = extendedElements[i]; - const element = extendedElement.element; + for (let i = 0; i < data.flattenedElements.length; i++) { + const flattenedElement = data.flattenedElements[i]; + const element = flattenedElement.originalElement; + const mappedType = mapElementType({ element: flattenedElement }); const codename = commonHelper.getElementCodename(element); @@ -628,38 +468,30 @@ export type ${typeName} = IContentItem<{ throw Error(`Invalid codename for element '${element.id}'`); } - const elementName = extendedElement.mappedName; + const elementName = elementNameMap(element); if (!elementName) { // skip element if its not resolver continue; } - if (!extendedElement.mappedType) { - // element type not supported - continue; - } + // if (!extendedElement.mappedType) { + // // element type not supported + // continue; + // } - code += `${this.getElementComment(extendedElement, data.taxonomies)}\n`; - code += `${elementName}: Elements.${extendedElement.mappedType};`; + code += `${getElementComment(flattenedElement, config.environmentData.taxonomies)}\n`; + code += `${elementName}: Elements.${mappedType};`; - if (i !== extendedElements.length - 1) { + if (i !== data.flattenedElements.length - 1) { code += '\n\n'; } } return code; - } - - private mapElementType(data: { - snippet?: ContentTypeSnippetModels.ContentTypeSnippet; - element: ContentTypeElements.ContentTypeElementModel; - elementNameMap: MapElementToName; - contentTypeNameMap: MapContentTypeToDeliveryTypeName; - contentTypeObjectMap: MapContentTypeIdToObject; - taxonomyObjectMap: MapTaxonomyIdTobject; - taxonomyNameMap: MapTaxonomyName; - }): IExtendedContentTypeElement { + }; + + const mapElementType = (data: { element: FlattenedElement }): string | undefined => { const elementType = data.element.type; let mappedType: string | undefined; @@ -668,11 +500,7 @@ export type ${typeName} = IContentItem<{ } else if (elementType === 'number') { mappedType = 'NumberElement'; } else if (elementType === 'modular_content' || elementType === 'subpages') { - mappedType = `LinkedItemsElement<${this.getLinkedItemsAllowedTypes( - data.element, - data.contentTypeNameMap, - data.contentTypeObjectMap - ).join(' | ')}>`; + mappedType = `LinkedItemsElement<${getLinkedItemsAllowedTypes(data.element.allowedContentTypes ?? []).join(' | ')}>`; } else if (elementType === 'asset') { mappedType = 'AssetsElement'; } else if (elementType === 'date_time') { @@ -684,7 +512,7 @@ export type ${typeName} = IContentItem<{ } else if (elementType === 'url_slug') { mappedType = 'UrlSlugElement'; } else if (elementType === 'taxonomy') { - const taxonomyName = this.getTaxonomyTypeName(data.element, data.taxonomyNameMap, data.taxonomyObjectMap); + const taxonomyName = getTaxonomyTypeName(data.element); if (taxonomyName) { mappedType = `TaxonomyElement<${taxonomyName}>`; @@ -698,79 +526,27 @@ export type ${typeName} = IContentItem<{ } else { mappedType = undefined; } - return { - mappedType: mappedType, - type: elementType, - snippet: data.snippet, - element: data.element, - mappedName: data.elementNameMap(data.element) - }; - } - - private getExtendedElements(data: { - contentType?: ContentTypeModels.ContentType; - contentTypeSnippet?: ContentTypeSnippetModels.ContentTypeSnippet; - elementNameMap: MapElementToName; - contentTypeNameMap: MapContentTypeToDeliveryTypeName; - contentTypeObjectMap: MapContentTypeIdToObject; - taxonomyObjectMap: MapTaxonomyIdTobject; - taxonomyNameMap: MapTaxonomyName; - }): readonly IExtendedContentTypeElement[] { - const extendedElements: IExtendedContentTypeElement[] = []; - - const elements = data.contentType ? data.contentType.elements : (data.contentTypeSnippet?.elements ?? []); - - for (const element of elements) { - extendedElements.push( - this.mapElementType({ - element: element, - elementNameMap: data.elementNameMap, - contentTypeNameMap: data.contentTypeNameMap, - contentTypeObjectMap: data.contentTypeObjectMap, - taxonomyNameMap: data.taxonomyNameMap, - taxonomyObjectMap: data.taxonomyObjectMap, - snippet: undefined - }) - ); - } - - return sortAlphabetically(extendedElements, (item) => item.mappedName ?? ''); - } - - private getTaxonomyTypeName( - element: ContentTypeElements.ContentTypeElementModel, - taxonomyNameMap: MapTaxonomyName, - taxonomyObjectMap: MapTaxonomyIdTobject - ): string | undefined { - const taxonomy = this.extractUsedTaxonomy(element, taxonomyObjectMap); - - if (!taxonomy) { - return undefined; - } - - return taxonomyNameMap(taxonomy); - } + return mappedType; + }; - private getLinkedItemsAllowedTypes( - element: ContentTypeElements.ContentTypeElementModel, - contentTypeNameMap: MapContentTypeToDeliveryTypeName, - contentTypeObjectMap: MapContentTypeIdToObject - ): string[] { - const allowedTypes = this.extractLinkedItemsAllowedTypes(element, contentTypeObjectMap); + const getTaxonomyTypeName = (element: FlattenedElement): string | undefined => { + return element.assignedTaxonomy ? taxonomyNameMap(element.assignedTaxonomy) : undefined; + }; - if (!allowedTypes.length) { + const getLinkedItemsAllowedTypes = (types: readonly Readonly[]): string[] => { + if (!types.length) { return ['IContentItem']; } - const allowedTypeNames: string[] = allowedTypes.map((m) => contentTypeNameMap(m)) ?? []; + const allowedTypeNames: string[] = types.map((m) => contentTypeNameMap(m)) ?? []; return allowedTypeNames; - } + }; - private extractLinkedItemsAllowedTypes( + const extractLinkedItemsAllowedTypes = ( element: ContentTypeElements.ContentTypeElementModel, contentTypeObjectMap: MapContentTypeIdToObject - ): ContentTypeModels.ContentType[] { + ): ContentTypeModels.ContentType[] => { const allowedTypeIds: string[] = []; const codename = commonHelper.getElementCodename(element); @@ -794,12 +570,12 @@ export type ${typeName} = IContentItem<{ } return allowedTypeIds.map((id) => contentTypeObjectMap(id)); - } + }; - private extractUsedSnippet( + const extractUsedSnippet = ( element: ContentTypeElements.ContentTypeElementModel, contentTypeSnippetObjectMap: MapContentTypeSnippetIdToObject - ): ContentTypeSnippetModels.ContentTypeSnippet { + ): ContentTypeSnippetModels.ContentTypeSnippet => { if (element.type !== 'snippet') { throw Error(`Expected 'snippet' but got '${element.type}' for element '${element.codename}'`); } @@ -812,12 +588,12 @@ export type ${typeName} = IContentItem<{ } return contentTypeSnippetObjectMap(snippedId); - } + }; - private extractUsedTaxonomy( + const extractUsedTaxonomy = ( element: ContentTypeElements.ContentTypeElementModel, taxonomyObjectMap: MapTaxonomyIdTobject - ): TaxonomyModels.Taxonomy | undefined { + ): TaxonomyModels.Taxonomy | undefined => { const codename = commonHelper.getElementCodename(element); if (element.type !== 'taxonomy') { @@ -834,7 +610,9 @@ export type ${typeName} = IContentItem<{ } return taxonomyObjectMap(taxonomyGroupId); - } -} + }; -export const deliveryContentTypeGenerator = new DeliveryContentTypeGenerator(); + return { + generateModels + }; +} diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index df21fd4..3dcdecd 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -23,18 +23,15 @@ export async function generateDeliveryModelsAsync(config: GenerateDeliveryModels const contentTypeSnippetsFolderName: string = deliveryConfig.contentTypeSnippetsFolderName; const taxonomiesFolderName: string = deliveryConfig.taxonomiesFolderName; - await kontentFetcher.getEnvironmentInfoAsync(); + const environment = await kontentFetcher.getEnvironmentInfoAsync(); const taxonomies = await kontentFetcher.getTaxonomiesAsync(); // create content type models - const deliveryModels = deliveryContentTypeGenerator.generateModels({ - types: await kontentFetcher.getTypesAsync(), + const deliveryModels = deliveryContentTypeGenerator({ typeFolderName: contentTypesFolderName, taxonomyFolderName: taxonomiesFolderName, typeSnippetsFolderName: contentTypeSnippetsFolderName, - taxonomies: taxonomies, - snippets: await kontentFetcher.getSnippetsAsync(), addTimestamp: config.addTimestamp, addEnvironmentInfo: config.addEnvironmentInfo, elementResolver: config.elementResolver, @@ -44,8 +41,14 @@ export async function generateDeliveryModelsAsync(config: GenerateDeliveryModels taxonomyResolver: config.taxonomyTypeResolver, contentTypeSnippetFileNameResolver: config.contentTypeSnippetFileResolver, contentTypeSnippetResolver: config.contentTypeSnippetResolver, - moduleResolution: moduleResolution - }); + moduleResolution: moduleResolution, + environmentData: { + environment: environment, + types: await kontentFetcher.getTypesAsync(), + snippets: await kontentFetcher.getSnippetsAsync(), + taxonomies: taxonomies + } + }).generateModels(); // create taxonomy types const taxonomyFiles = deliveryTaxonomyGenerator({ diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index 78ff273..ca0d07a 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -16,7 +16,8 @@ import { toSafeString, removeLineEndings, toPascalCase, - getFlattenedElements + getFlattenedElements, + migrationConfig } from '../../core/index.js'; import { ModuleResolution } from '../../models.js'; import { commentsManager as _commentsManager } from '../../comments/index.js'; @@ -51,8 +52,6 @@ const migrationTypeNames = { codename: 'Codename' } as const; -const migrationToolkitNpmPackage = '@kontent-ai/migration-toolkit'; - export function migrationGenerator(config: MigrationGeneratorConfig) { const commentsManager = _commentsManager(config.addTimestamp); @@ -65,7 +64,7 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { filename: `${folderName}/${type.codename}.ts`, text: ` ${getImportStatement({ - filePathOrPackage: migrationToolkitNpmPackage, + filePathOrPackage: migrationConfig.npmPackageName, importValue: migrationTypeNames.migrationElementModels, moduleResolution: config.moduleResolution })} @@ -87,7 +86,8 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { ${getFlattenedElements( type.elements, config.environmentData.snippets, - config.environmentData.taxonomies + config.environmentData.taxonomies, + config.environmentData.types ) .map((element) => { return ` @@ -112,7 +112,7 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { filename: filename, text: ` ${getImportStatement({ - filePathOrPackage: migrationToolkitNpmPackage, + filePathOrPackage: migrationConfig.npmPackageName, importValue: `${migrationTypeNames.migrationItemSystem}, ${migrationTypeNames.migrationItem}, ${migrationTypeNames.migrationElements}`, moduleResolution: config.moduleResolution })} diff --git a/lib/generators/project/project.generator.ts b/lib/generators/project/project.generator.ts index 25949d2..15c23b6 100644 --- a/lib/generators/project/project.generator.ts +++ b/lib/generators/project/project.generator.ts @@ -87,13 +87,13 @@ export function projectGenerator(config: ProjectGeneratorConfig) { }, { code: `export const contentTypes = { - ${getProjectContentTypes(config.environmentData.types, config.environmentData.snippets, config.environmentData.taxonomies)} + ${getProjectContentTypes(config.environmentData.types)} } as const;`, filename: 'contentTypes.ts' }, { code: `export const contentTypeSnippets = { - ${getProjectContentTypeSnippets(config.environmentData.snippets, config.environmentData.taxonomies)} + ${getProjectContentTypeSnippets(config.environmentData.snippets)} } as const;`, filename: 'contentTypeSnippets.ts' }, @@ -194,8 +194,7 @@ export function projectGenerator(config: ProjectGeneratorConfig) { }; const getProjectContentTypeSnippets = ( - snippets: readonly Readonly[], - taxonomies: readonly Readonly[] + snippets: readonly Readonly[] ): string => { return snippets.reduce((code, snippet, index) => { const isLast = index === snippets.length - 1; @@ -209,16 +208,12 @@ export function projectGenerator(config: ProjectGeneratorConfig) { id: '${snippet.id}', externalId: ${getStringOrUndefined(snippet.externalId)}, name: '${toSafeString(snippet.name)}', - elements: {${getContentTypeElements(snippet.elements, snippets, taxonomies)}} + elements: {${getContentTypeElements(snippet.elements)}} }${!isLast ? ',\n' : ''}`; }, ''); }; - const getProjectContentTypes = ( - contentTypes: readonly Readonly[], - snippets: readonly Readonly[], - taxonomies: readonly Readonly[] - ): string => { + const getProjectContentTypes = (contentTypes: readonly Readonly[]): string => { return contentTypes.reduce((code, contentType, index) => { const isLast = index === contentTypes.length - 1; @@ -231,17 +226,20 @@ export function projectGenerator(config: ProjectGeneratorConfig) { id: '${contentType.id}', externalId: ${getStringOrUndefined(contentType.externalId)}, name: '${toSafeString(contentType.name)}', - elements: {${getContentTypeElements(contentType.elements, snippets, taxonomies)}} + elements: {${getContentTypeElements(contentType.elements)}} }${!isLast ? ',\n' : ''}`; }, ''); }; const getContentTypeElements = ( - elements: readonly Readonly[], - snippets: readonly Readonly[], - taxonomies: readonly Readonly[] + elements: readonly Readonly[] ): string => { - const flattenedElements = getFlattenedElements(elements, snippets, taxonomies); + const flattenedElements = getFlattenedElements( + elements, + config.environmentData.snippets, + config.environmentData.taxonomies, + config.environmentData.types + ); return flattenedElements.reduce((code, element, index) => { const isLast = index === flattenedElements.length - 1; diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index 9ed9753..9ac2e07 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -1,12 +1,27 @@ import { type IContentItem, type Elements } from '@kontent-ai/delivery-sdk'; /** - * Generated by '@kontent-ai/model-generator@7.4.0' + * + * Movie Database + * + * Environment: Production + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + */ + +/** * * Actor * Id: 58099989-319f-495f-aa36-cb3710854e36 * Codename: actor */ export type Actor = IContentItem<{ + /** + * Url (url_slug) + * Required: false + * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 + * Codename: url + */ + url: Elements.UrlSlugElement; + /** * First name (text) * Required: true @@ -32,12 +47,4 @@ export type Actor = IContentItem<{ * Codename: photo */ photo: Elements.AssetsElement; - - /** - * Url (url_slug) - * Required: false - * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 - * Codename: url - */ - url: Elements.UrlSlugElement; }>; diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 989a4f5..84a39f8 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -1,9 +1,16 @@ import { type IContentItem, type Elements } from '@kontent-ai/delivery-sdk'; -import { type Actor } from './actor.js'; +import { type Actor } from '../content-types/actor.js'; import { type ReleaseCategory } from '../taxonomies/releasecategory.js'; /** - * Generated by '@kontent-ai/model-generator@7.4.0' + * + * Movie Database + * + * Environment: Production + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + */ + +/** * * Movie * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c @@ -11,28 +18,36 @@ import { type ReleaseCategory } from '../taxonomies/releasecategory.js'; */ export type Movie = IContentItem<{ /** - * Category (multiple_choice) + * Title (text) + * Required: true + * Id: 3473187e-dc78-eff2-7099-f690f7042d4a + * Codename: title + */ + title: Elements.TextElement; + + /** + * Plot (rich_text) * Required: false - * Id: 9821c252-6414-f549-c17f-cc171dd87713 - * Codename: category + * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce + * Codename: plot */ - category: Elements.MultipleChoiceElement; + plot: Elements.RichTextElement; /** - * Length (number) + * Released (date_time) * Required: false - * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c - * Codename: length + * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 + * Codename: released */ - length: Elements.NumberElement; + released: Elements.DateTimeElement; /** - * Plot (rich_text) + * Length (number) * Required: false - * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce - * Codename: plot + * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c + * Codename: length */ - plot: Elements.RichTextElement; + length: Elements.NumberElement; /** * Poster (asset) @@ -43,20 +58,20 @@ export type Movie = IContentItem<{ poster: Elements.AssetsElement; /** - * ReleaseCategory (taxonomy) + * Category (multiple_choice) * Required: false - * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 - * Codename: releasecategory + * Id: 9821c252-6414-f549-c17f-cc171dd87713 + * Codename: category */ - releasecategory: Elements.TaxonomyElement; + category: Elements.MultipleChoiceElement; /** - * Released (date_time) + * Stars (modular_content) * Required: false - * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 - * Codename: released + * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 + * Codename: stars */ - released: Elements.DateTimeElement; + stars: Elements.LinkedItemsElement; /** * SeoName (url_slug) @@ -67,18 +82,10 @@ export type Movie = IContentItem<{ seoname: Elements.UrlSlugElement; /** - * Stars (modular_content) + * ReleaseCategory (taxonomy) * Required: false - * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 - * Codename: stars - */ - stars: Elements.LinkedItemsElement; - - /** - * Title (text) - * Required: true - * Id: 3473187e-dc78-eff2-7099-f690f7042d4a - * Codename: title + * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 + * Codename: releasecategory */ - title: Elements.TextElement; + releasecategory: Elements.TaxonomyElement; }>; From 94cf57bbc9ee310676e21ec47236d6baced2a576 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 27 Aug 2024 11:33:30 +0200 Subject: [PATCH 028/183] Refactors content type imports, extends flattened element with snippet info --- lib/core/core.models.ts | 4 +- lib/core/element.utils.ts | 47 ++- .../delivery-content-type.generator.ts | 352 ++++++------------ .../delivery/content-type-snippets/index.ts | 3 +- .../content-type-snippets/my_snippet.ts | 33 ++ .../taxonomy_snippet_test.ts | 26 ++ sample/delivery/content-types/actor.ts | 45 ++- sample/delivery/content-types/index.ts | 1 + sample/delivery/content-types/movie.ts | 92 ++--- sample/delivery/content-types/test.ts | 27 ++ sample/delivery/taxonomies/category.ts | 15 + sample/delivery/taxonomies/index.ts | 4 +- sample/delivery/taxonomies/movietype.ts | 15 - .../delivery/taxonomies/release_category.ts | 15 + sample/delivery/taxonomies/releasecategory.ts | 15 - 15 files changed, 342 insertions(+), 352 deletions(-) create mode 100644 sample/delivery/content-type-snippets/my_snippet.ts create mode 100644 sample/delivery/content-type-snippets/taxonomy_snippet_test.ts create mode 100644 sample/delivery/content-types/test.ts create mode 100644 sample/delivery/taxonomies/category.ts delete mode 100644 sample/delivery/taxonomies/movietype.ts create mode 100644 sample/delivery/taxonomies/release_category.ts delete mode 100644 sample/delivery/taxonomies/releasecategory.ts diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index 164b016..95dfe4e 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -1,13 +1,14 @@ import { ContentTypeElements, ContentTypeModels, + ContentTypeSnippetModels, ElementModels, IManagementClient, TaxonomyModels } from '@kontent-ai/management-sdk'; export type CliAction = 'delivery' | 'migration'; -export type LibraryType = '@kontent-ai/migration-toolkit'; +export type LibraryType = '@kontent-ai/migration-toolkit' | '@kontent-ai/delivery-sdk'; export type GeneratorManagementClient = Readonly>; @@ -45,6 +46,7 @@ export interface FlattenedElement { readonly allowedContentTypes?: readonly Readonly[]; readonly originalElement: Readonly; readonly assignedTaxonomy?: Readonly; + readonly fromSnippet?: Readonly; } export interface GeneratedFile { diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts index fc62438..17377ef 100644 --- a/lib/core/element.utils.ts +++ b/lib/core/element.utils.ts @@ -8,6 +8,11 @@ import { FlattenedElement } from './core.models.js'; import { isNotUndefined } from '@kontent-ai/migration-toolkit'; import { match } from 'ts-pattern'; +interface ElementWrapper { + readonly element: Readonly; + readonly fromSnippet: Readonly | undefined; +} + export function getFlattenedElements( elements: readonly Readonly[], snippets: readonly Readonly[], @@ -22,7 +27,7 @@ export function getFlattenedElements( return true; }) - .flatMap((element) => { + .flatMap((element) => { if (element.type === 'snippet') { const snippet = snippets.find((snippet) => snippet.id === element.snippet.id); @@ -30,10 +35,18 @@ export function getFlattenedElements( throw Error(`Could not find snippet with id '${element.snippet.id}'`); } - return snippet.elements; + return snippet.elements.map((snippetElement) => { + return { + element: snippetElement, + fromSnippet: snippet + }; + }); } - return element; + return { + element: element, + fromSnippet: undefined + }; }) .map((element) => { return getFlattenedElement(element, taxonomies, types); @@ -42,28 +55,29 @@ export function getFlattenedElements( } export function getFlattenedElement( - element: Readonly, + wrapper: ElementWrapper, taxonomies: readonly Readonly[], types: readonly Readonly[] ): Readonly | undefined { - if (!element.codename) { + if (!wrapper.element.codename) { return undefined; } - if (!element.id) { + if (!wrapper.element.id) { return undefined; } return { - title: getElementTitle(element, taxonomies), - codename: element.codename, - id: element.id, - type: element.type, - isRequired: isElementRequired(element), - guidelines: getElementGuidelines(element), - externalId: element.external_id, - originalElement: element, - allowedContentTypes: extractLinkedItemsAllowedTypes(element, types), - assignedTaxonomy: extractTaxonomy(element, taxonomies) + title: getElementTitle(wrapper.element, taxonomies), + codename: wrapper.element.codename, + id: wrapper.element.id, + type: wrapper.element.type, + isRequired: isElementRequired(wrapper.element), + guidelines: getElementGuidelines(wrapper.element), + externalId: wrapper.element.external_id, + originalElement: wrapper.element, + allowedContentTypes: extractLinkedItemsAllowedTypes(wrapper.element, types), + assignedTaxonomy: extractTaxonomy(wrapper.element, taxonomies), + fromSnippet: wrapper.fromSnippet }; } @@ -123,6 +137,5 @@ function extractTaxonomy( .with({ type: 'taxonomy' }, (taxonomyElement) => { return taxonomies.find((m) => m.id === taxonomyElement.taxonomy_group?.id); }) - .otherwise(() => undefined); } diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 041caa2..d6c0316 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -47,8 +47,13 @@ import { FlattenedElement, GeneratedFile, getFlattenedElements, - sortAlphabetically + getImportStatement, + sortAlphabetically, + toSafeString, + uniqueFilter } from '../../core/index.js'; +import { match, P } from 'ts-pattern'; +import { isNotUndefined } from '@kontent-ai/migration-toolkit'; // interface IExtendedContentTypeElement { // readonly type: ElementModels.ElementType; @@ -59,9 +64,9 @@ import { // } interface IExtractImportsResult { + readonly typeName: string; readonly imports: readonly string[]; - readonly contentTypeSnippetExtensions: string[]; - readonly processedElements: readonly FlattenedElement[]; + readonly contentTypeExtends: string | undefined; } export interface DeliveryContentTypeGeneratorConfig { @@ -197,118 +202,108 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato }; }; - const getContentTypeImports = (data: { - typeOrSnippet: ContentTypeModels.ContentType | ContentTypeSnippetModels.ContentTypeSnippet; - }): IExtractImportsResult => { - const imports: string[] = []; - const contentTypeSnippetExtensions: string[] = []; - const processedTypeIds: string[] = []; - const processedTaxonomyIds: string[] = []; - - const flattenedElements = getFlattenedElements( - data.typeOrSnippet.elements, - config.environmentData.snippets, - config.environmentData.taxonomies, - config.environmentData.types - ); - - for (const extendedElement of flattenedElements) { - const element = extendedElement.originalElement; - - if (element.type === 'taxonomy') { - const taxonomy = extractUsedTaxonomy(element, taxonomyObjectMap); - - if (!taxonomy) { - continue; - } - - if (processedTaxonomyIds.includes(taxonomy.id)) { - continue; - } - - processedTaxonomyIds.push(taxonomy.id); - - const taxonomyName: string = taxonomyNameMap(taxonomy); - const fileName: string = `../${config.taxonomyFolderName}/${taxonomyFileNameMap(taxonomy, false)}`; + const snippetImports = ( + snippets: readonly Readonly[] + ): readonly string[] => { + return snippets.map((snippet) => { + return getImportStatement({ + moduleResolution: config.moduleResolution, + filePathOrPackage: `../${config.typeSnippetsFolderName}/${contentTypeSnippetFileNameMap( + snippet, + false + )}.ts`, + importValue: contentTypeSnippetNameMap(snippet) + }); + }); + }; - imports.push( - commonHelper.getImportStatement({ - moduleResolution: config.moduleResolution, - filePathOrPackage: fileName, - importValue: `type ${taxonomyName}`, - isExternalLib: false - }) - ); - } else if (element.type === 'modular_content' || element.type === 'subpages') { - // extract referenced types - const referencedTypes = extractLinkedItemsAllowedTypes(element, contentTypeObjectMap); - - for (const referencedType of referencedTypes) { - if (processedTypeIds.includes(referencedType.id)) { - // type was already processed, no need to import it multiple times - continue; - } - - // filter 'self referencing' types as they don't need to be imported - if (data.typeOrSnippet?.id === referencedType.id) { - continue; - } - - processedTypeIds.push(referencedType.id); - - const typeName: string = contentTypeNameMap(referencedType); - const fileName: string = `${contentTypeFileNameMap(referencedType, false)}`; - - const filePath: string = - data.typeOrSnippet instanceof ContentTypeModels.ContentType - ? `../${config.typeFolderName}/${fileName}` - : `./${fileName}`; - - imports.push( - commonHelper.getImportStatement({ - moduleResolution: config.moduleResolution, - filePathOrPackage: filePath, - importValue: `type ${typeName}`, - isExternalLib: false + const getElementImports = ( + typeOrSnippet: ContentTypeModels.ContentType | ContentTypeSnippetModels.ContentTypeSnippet, + elements: readonly FlattenedElement[] + ): readonly string[] => { + return ( + elements + // only take elements that are not from snippets + .filter((m) => !m.fromSnippet) + .map((flattenedElement) => + match(flattenedElement) + .returnType() + .with({ type: 'taxonomy' }, (taxonomyElement) => { + if (!taxonomyElement.assignedTaxonomy) { + throw Error(`Invalid taxonomy for element '${taxonomyElement.codename}'`); + } + return getImportStatement({ + moduleResolution: config.moduleResolution, + filePathOrPackage: `../${config.taxonomyFolderName}/${taxonomyFileNameMap(taxonomyElement.assignedTaxonomy, false)}.ts`, + importValue: taxonomyNameMap(taxonomyElement.assignedTaxonomy) + }); }) - ); - } - } else if (element.type === 'snippet') { - const contentTypeSnipped = extractUsedSnippet(element, contentTypeSnippetObjectMap); - - const typeName: string = contentTypeSnippetNameMap(contentTypeSnipped); - const filePath: string = `../${config.typeSnippetsFolderName}${contentTypeSnippetFileNameMap( - contentTypeSnipped, - false - )}`; - - imports.push( - commonHelper.getImportStatement({ - moduleResolution: config.moduleResolution, - filePathOrPackage: filePath, - importValue: `type ${typeName}`, - isExternalLib: false - }) - ); + .with( + P.union({ type: 'modular_content' }, { type: 'subpages' }), + (linkedItemsOrSubpagesElement) => { + return (linkedItemsOrSubpagesElement.allowedContentTypes ?? []) + .filter((allowedContentType) => { + // filter self-referencing types + if (allowedContentType.codename === typeOrSnippet.codename) { + return false; + } + return true; + }) + .map((allowedContentType) => { + const referencedTypeFilename: string = `${contentTypeFileNameMap(allowedContentType, false)}`; + + return getImportStatement({ + moduleResolution: config.moduleResolution, + filePathOrPackage: + typeOrSnippet instanceof ContentTypeModels.ContentType + ? `../${config.typeFolderName}/${referencedTypeFilename}.ts` + : `./${referencedTypeFilename}.ts`, + importValue: `${contentTypeNameMap(allowedContentType)}` + }); + }); + } + ) + .otherwise(() => []) + ) + .flatMap((m) => m) + .filter(isNotUndefined) + ); + }; - contentTypeSnippetExtensions.push(typeName); - } - } + const getContentTypeImports = (data: { + typeOrSnippet: ContentTypeModels.ContentType | ContentTypeSnippetModels.ContentTypeSnippet; + flattenedElements: readonly FlattenedElement[]; + }): IExtractImportsResult => { + const snippets = data.flattenedElements.map((m) => m.fromSnippet).filter(isNotUndefined); return { - imports: sortAlphabetically(imports, (item) => item), - contentTypeSnippetExtensions: contentTypeSnippetExtensions, - processedElements: flattenedElements + imports: sortAlphabetically( + [...getElementImports(data.typeOrSnippet, data.flattenedElements), ...snippetImports(snippets)] + .filter(isNotUndefined) + .filter(uniqueFilter), + (importValue) => importValue + ), + contentTypeExtends: + data.typeOrSnippet instanceof ContentTypeModels.ContentType && snippets.length + ? `& ${snippets + .map((snippet) => contentTypeSnippetNameMap(snippet)) + .filter(uniqueFilter) + .join(' & ')}` + : undefined, + typeName: + data.typeOrSnippet instanceof ContentTypeModels.ContentType + ? contentTypeNameMap(data.typeOrSnippet) + : contentTypeSnippetNameMap(data.typeOrSnippet) }; }; + const getDeliverySdkContentTypeImports = (flattenedElements: readonly FlattenedElement[]): string[] => { + return ['IContentItem', ...(flattenedElements.length ? ['Elements'] : [])]; + }; + const getModelCode = (data: { typeOrSnippet: ContentTypeModels.ContentType | ContentTypeSnippetModels.ContentTypeSnippet; }): string => { - const importResult = getContentTypeImports({ - typeOrSnippet: data.typeOrSnippet - }); - const flattenedElements = getFlattenedElements( data.typeOrSnippet.elements, config.environmentData.snippets, @@ -316,56 +311,32 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato config.environmentData.types ); - const topLevelImports: string[] = ['type IContentItem']; - - if (importResult.processedElements.filter((m) => m.type !== 'snippet' && m.type !== 'guidelines').length) { - // add 'Elements' import only if there is > 1 elements in content type - topLevelImports.push('type Elements'); - } - - let code = commonHelper.getImportStatement({ - moduleResolution: config.moduleResolution, - filePathOrPackage: deliveryConfig.npmPackageName, - importValue: `${topLevelImports.join(', ')}`, - isExternalLib: true + const contentTypeImports = getContentTypeImports({ + typeOrSnippet: data.typeOrSnippet, + flattenedElements: flattenedElements }); - if (importResult.imports.length) { - for (const importItem of importResult.imports) { - code += `${importItem}`; - } - - code += `\n`; - } - - let comment: string = ''; - let typeName: string = ''; - let typeExtends: string = ''; - - if (data.typeOrSnippet instanceof ContentTypeModels.ContentType) { - comment = getContentTypeComment(data.typeOrSnippet); - typeName = contentTypeNameMap(data.typeOrSnippet); - - if (importResult.contentTypeSnippetExtensions.length) { - typeExtends = `& ${importResult.contentTypeSnippetExtensions.join(' & ')}`; - } - } else if (data.typeOrSnippet instanceof ContentTypeSnippetModels.ContentTypeSnippet) { - comment = getContentTypeSnippetComment(data.typeOrSnippet); - typeName = contentTypeSnippetNameMap(data.typeOrSnippet); - } + const code = ` +${getImportStatement({ + moduleResolution: config.moduleResolution, + filePathOrPackage: deliveryConfig.npmPackageName, + importValue: `${getDeliverySdkContentTypeImports(flattenedElements).join(', ')}` +})} +${contentTypeImports.imports.join('\n')} - code += ` ${commentsManager.environmentInfo(config.environmentData.environment)} /** +* ${toSafeString(data.typeOrSnippet.name)} * -* ${comment} +* Id: ${data.typeOrSnippet.id} +* Codename: ${data.typeOrSnippet.codename} */ -export type ${typeName} = IContentItem<{ +export type ${contentTypeImports.typeName} = IContentItem<{ ${getElementsCode({ flattenedElements: flattenedElements })} -}>${typeExtends}; +}>${contentTypeImports.contentTypeExtends ? ` ${contentTypeImports.contentTypeExtends}` : ''}; `; return code; }; @@ -399,24 +370,6 @@ export type ${typeName} = IContentItem<{ }; }; - const getContentTypeComment = (contentType: ContentTypeModels.ContentType): string => { - let comment: string = `${contentType.name}`; - - comment += `\n* Id: ${contentType.id}`; - comment += `\n* Codename: ${contentType.codename}`; - - return comment; - }; - - const getContentTypeSnippetComment = (contentTypeSnippet: ContentTypeSnippetModels.ContentTypeSnippet): string => { - let comment: string = `${contentTypeSnippet.name}`; - - comment += `\n* Id: ${contentTypeSnippet.id}`; - comment += `\n* Codename: ${contentTypeSnippet.codename}`; - - return comment; - }; - const getElementComment = ( flattenedElement: FlattenedElement, taxonomies: readonly Readonly[] @@ -456,9 +409,11 @@ export type ${typeName} = IContentItem<{ }; const getElementsCode = (data: { flattenedElements: readonly FlattenedElement[] }): string => { + // filter out elements that are from snippets + const filteredElements = data.flattenedElements.filter((m) => !m.fromSnippet); let code = ''; - for (let i = 0; i < data.flattenedElements.length; i++) { - const flattenedElement = data.flattenedElements[i]; + for (let i = 0; i < filteredElements.length; i++) { + const flattenedElement = filteredElements[i]; const element = flattenedElement.originalElement; const mappedType = mapElementType({ element: flattenedElement }); @@ -483,7 +438,7 @@ export type ${typeName} = IContentItem<{ code += `${getElementComment(flattenedElement, config.environmentData.taxonomies)}\n`; code += `${elementName}: Elements.${mappedType};`; - if (i !== data.flattenedElements.length - 1) { + if (i !== filteredElements.length - 1) { code += '\n\n'; } } @@ -543,75 +498,6 @@ export type ${typeName} = IContentItem<{ return allowedTypeNames; }; - const extractLinkedItemsAllowedTypes = ( - element: ContentTypeElements.ContentTypeElementModel, - contentTypeObjectMap: MapContentTypeIdToObject - ): ContentTypeModels.ContentType[] => { - const allowedTypeIds: string[] = []; - - const codename = commonHelper.getElementCodename(element); - - if (element.type === 'modular_content') { - const linkedItemsElement: ContentTypeElements.ILinkedItemsElement = element; - - if (linkedItemsElement?.allowed_content_types?.length) { - allowedTypeIds.push(...(linkedItemsElement.allowed_content_types?.map((m) => m.id as string) ?? [])); - } - } else if (element.type === 'subpages') { - const subpagesItemsElement: ContentTypeElements.ISubpagesElement = element; - - if (subpagesItemsElement?.allowed_content_types?.length) { - allowedTypeIds.push(...(subpagesItemsElement.allowed_content_types?.map((m) => m.id as string) ?? [])); - } - } else { - throw Error( - `Expected 'modular_content' or 'subpages' but got '${element.type}' for element '${codename}' with id '${element.id}'` - ); - } - - return allowedTypeIds.map((id) => contentTypeObjectMap(id)); - }; - - const extractUsedSnippet = ( - element: ContentTypeElements.ContentTypeElementModel, - contentTypeSnippetObjectMap: MapContentTypeSnippetIdToObject - ): ContentTypeSnippetModels.ContentTypeSnippet => { - if (element.type !== 'snippet') { - throw Error(`Expected 'snippet' but got '${element.type}' for element '${element.codename}'`); - } - - const snippetElement: ContentTypeElements.ISnippetElement = element; - - const snippedId = snippetElement.snippet.id; - if (!snippedId) { - throw Error(`Invalid snippet id for taxonomy element '${element.id}'`); - } - - return contentTypeSnippetObjectMap(snippedId); - }; - - const extractUsedTaxonomy = ( - element: ContentTypeElements.ContentTypeElementModel, - taxonomyObjectMap: MapTaxonomyIdTobject - ): TaxonomyModels.Taxonomy | undefined => { - const codename = commonHelper.getElementCodename(element); - - if (element.type !== 'taxonomy') { - throw Error( - `Expected 'taxonomy' but got '${element.type}' for element '${codename}' with id '${element.id}'` - ); - } - - const taxonomyElement: ContentTypeElements.ITaxonomyElement = element; - - const taxonomyGroupId = taxonomyElement.taxonomy_group.id; - if (!taxonomyGroupId) { - throw Error(`Invalid taxonomy group id for taxonomy element '${element.id}'`); - } - - return taxonomyObjectMap(taxonomyGroupId); - }; - return { generateModels }; diff --git a/sample/delivery/content-type-snippets/index.ts b/sample/delivery/content-type-snippets/index.ts index cb0ff5c..bc0c90e 100644 --- a/sample/delivery/content-type-snippets/index.ts +++ b/sample/delivery/content-type-snippets/index.ts @@ -1 +1,2 @@ -export {}; +export * from './my_snippet.js'; +export * from './taxonomy_snippet_test.js'; diff --git a/sample/delivery/content-type-snippets/my_snippet.ts b/sample/delivery/content-type-snippets/my_snippet.ts new file mode 100644 index 0000000..fb7fd56 --- /dev/null +++ b/sample/delivery/content-type-snippets/my_snippet.ts @@ -0,0 +1,33 @@ +import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; + +/** + * + * Migration Toolkit - tests + * + * Environment: Production + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + */ + +/** + * My snippet + * + * Id: 3274f9e7-ff1b-43f8-aa32-29b53939cd3e + * Codename: my_snippet + */ +export type MySnippet = IContentItem<{ + /** + * Snippet elem1 (text) + * Required: false + * Id: 3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d + * Codename: my_snippet__snippet_elem1 + */ + my_snippet__snippet_elem1: Elements.TextElement; + + /** + * Snippet elem 2 (number) + * Required: false + * Id: b2f65646-3310-4a64-af2a-0d9d025a91d0 + * Codename: my_snippet__snippet_elem_2 + */ + my_snippet__snippet_elem_2: Elements.NumberElement; +}>; diff --git a/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts b/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts new file mode 100644 index 0000000..bd69817 --- /dev/null +++ b/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts @@ -0,0 +1,26 @@ +import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; +import type { Category } from '../taxonomies/category.js'; + +/** + * + * Migration Toolkit - tests + * + * Environment: Production + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + */ + +/** + * Taxonomy snippet test + * + * Id: e8219115-e629-4552-b79b-d9f813272573 + * Codename: taxonomy_snippet_test + */ +export type TaxonomySnippetTest = IContentItem<{ + /** + * Category (taxonomy) + * Required: false + * Id: c030e3ec-5031-4d7f-af88-5032365733c7 + * Codename: taxonomy_snippet_test__test_taxonomy + */ + taxonomy_snippet_test__test_taxonomy: Elements.TaxonomyElement; +}>; diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index 9ac2e07..3f22685 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -1,50 +1,49 @@ -import { type IContentItem, type Elements } from '@kontent-ai/delivery-sdk'; +import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; + /** * - * Movie Database + * Migration Toolkit - tests * * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 */ /** - * * Actor - * Id: 58099989-319f-495f-aa36-cb3710854e36 + * + * Id: d8900ee2-82f4-4189-a994-4e121582aadf * Codename: actor */ export type Actor = IContentItem<{ /** - * Url (url_slug) + * photo (asset) * Required: false - * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 - * Codename: url + * Id: 069b38ee-385c-410f-b7fe-53ec59a5f139 + * Codename: photo */ - url: Elements.UrlSlugElement; + photo: Elements.AssetsElement; /** - * First name (text) - * Required: true - * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d - * Codename: first_name - * - * This is the first name of the actor + * url (url_slug) + * Required: false + * Id: c4b2d64f-af45-45a4-92d8-4829833563ff + * Codename: url */ - first_name: Elements.TextElement; + url: Elements.UrlSlugElement; /** - * Last name (text) - * Required: true - * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 + * last_name (text) + * Required: false + * Id: 0f00b26e-60f3-462d-8110-18180137c3a0 * Codename: last_name */ last_name: Elements.TextElement; /** - * Photo (asset) + * first_name (text) * Required: false - * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 - * Codename: photo + * Id: 4af5e7ce-88ef-4159-96ae-96a552992f91 + * Codename: first_name */ - photo: Elements.AssetsElement; + first_name: Elements.TextElement; }>; diff --git a/sample/delivery/content-types/index.ts b/sample/delivery/content-types/index.ts index 79e8008..e8c4f36 100644 --- a/sample/delivery/content-types/index.ts +++ b/sample/delivery/content-types/index.ts @@ -1,2 +1,3 @@ export * from './actor.js'; export * from './movie.js'; +export * from './test.js'; diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 84a39f8..2e83b2f 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -1,91 +1,93 @@ -import { type IContentItem, type Elements } from '@kontent-ai/delivery-sdk'; -import { type Actor } from '../content-types/actor.js'; -import { type ReleaseCategory } from '../taxonomies/releasecategory.js'; +import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; +import type { Category } from '../taxonomies/category.js'; +import type { ReleaseCategory } from '../taxonomies/release_category.js'; +import type { TaxonomySnippetTest } from '../content-type-snippets/taxonomy_snippet_test.js'; /** * - * Movie Database + * Migration Toolkit - tests * * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 */ /** - * * Movie - * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c + * + * Id: db7356f6-1d82-42a0-9ebb-07865cffa995 * Codename: movie */ export type Movie = IContentItem<{ /** - * Title (text) - * Required: true - * Id: 3473187e-dc78-eff2-7099-f690f7042d4a - * Codename: title + * Release category (taxonomy) + * Required: false + * Id: 5faa827f-f262-43c3-8f58-0f354b8d393f + * Codename: releasecategory */ - title: Elements.TextElement; + releasecategory: Elements.TaxonomyElement; /** - * Plot (rich_text) + * Category (taxonomy) * Required: false - * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce - * Codename: plot + * Id: 8c12be35-e3e7-447c-a185-7b5e101ebf12 + * Codename: category */ - plot: Elements.RichTextElement; + category: Elements.TaxonomyElement; /** - * Released (date_time) + * length (number) * Required: false - * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 - * Codename: released + * Id: e3d07f3a-60c2-4072-846d-c23e51ec833e + * Codename: length */ - released: Elements.DateTimeElement; + length: Elements.NumberElement; /** - * Length (number) + * stars (modular_content) * Required: false - * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c - * Codename: length + * Id: 55596dd1-e808-415d-95aa-e2be34238d11 + * Codename: stars */ - length: Elements.NumberElement; + stars: Elements.LinkedItemsElement; /** - * Poster (asset) + * seoname (url_slug) * Required: false - * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d - * Codename: poster + * Id: 734f94be-5930-4bdf-b05b-f59f5a291675 + * Codename: seoname */ - poster: Elements.AssetsElement; + seoname: Elements.UrlSlugElement; /** - * Category (multiple_choice) + * poster (asset) * Required: false - * Id: 9821c252-6414-f549-c17f-cc171dd87713 - * Codename: category + * Id: 9b197f1e-0728-4d14-9814-97f7b8ef01fc + * Codename: poster */ - category: Elements.MultipleChoiceElement; + poster: Elements.AssetsElement; /** - * Stars (modular_content) + * released (date_time) * Required: false - * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 - * Codename: stars + * Id: 656b9dc9-7bba-4f1f-a2b8-52f7f730a66f + * Codename: released */ - stars: Elements.LinkedItemsElement; + released: Elements.DateTimeElement; /** - * SeoName (url_slug) + * plot (rich_text) * Required: false - * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c - * Codename: seoname + * Id: ad2e5dc7-8d08-4f74-afeb-25b475f1e6fc + * Codename: plot */ - seoname: Elements.UrlSlugElement; + plot: Elements.RichTextElement; /** - * ReleaseCategory (taxonomy) + * title (text) * Required: false - * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 - * Codename: releasecategory + * Id: 660c851a-a9a1-4378-97a3-1348bc2a4d76 + * Codename: title */ - releasecategory: Elements.TaxonomyElement; -}>; + title: Elements.TextElement; +}> & + TaxonomySnippetTest; diff --git a/sample/delivery/content-types/test.ts b/sample/delivery/content-types/test.ts new file mode 100644 index 0000000..0802824 --- /dev/null +++ b/sample/delivery/content-types/test.ts @@ -0,0 +1,27 @@ +import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; +import type { MySnippet } from '../content-type-snippets/my_snippet.js'; + +/** + * + * Migration Toolkit - tests + * + * Environment: Production + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + */ + +/** + * Test + * + * Id: 81ab0b2c-dd14-41e7-a1ed-868b249ad8bc + * Codename: test + */ +export type Test = IContentItem<{ + /** + * Text (text) + * Required: false + * Id: 65f61f6a-b69c-47dc-bc38-19855507bf14 + * Codename: text + */ + text: Elements.TextElement; +}> & + MySnippet; diff --git a/sample/delivery/taxonomies/category.ts b/sample/delivery/taxonomies/category.ts new file mode 100644 index 0000000..8c63181 --- /dev/null +++ b/sample/delivery/taxonomies/category.ts @@ -0,0 +1,15 @@ +/** + * + * Migration Toolkit - tests + * + * Environment: Production + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + */ + +/** + * Category + * + * Codename: category + * Id: c1b56389-f00a-4917-95c4-3b02ea3610ea + */ +export type Category = 'action' | 'animation' | 'comedy' | 'drama' | 'romance' | 'sci_fi'; diff --git a/sample/delivery/taxonomies/index.ts b/sample/delivery/taxonomies/index.ts index 40c15f1..116ed03 100644 --- a/sample/delivery/taxonomies/index.ts +++ b/sample/delivery/taxonomies/index.ts @@ -1,2 +1,2 @@ -export * from './movietype.js'; -export * from './releasecategory.js'; +export * from './category.js'; +export * from './release_category.js'; diff --git a/sample/delivery/taxonomies/movietype.ts b/sample/delivery/taxonomies/movietype.ts deleted file mode 100644 index 8068946..0000000 --- a/sample/delivery/taxonomies/movietype.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * - * Movie Database - * - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - */ - -/** - * MovieType - * - * Codename: movietype - * Id: 365a17e6-1929-27ab-9f67-a9273c846717 - */ -export type MovieType = 'blockbuster' | 'cinema_only' | 'film' | 'student' | 'tv'; diff --git a/sample/delivery/taxonomies/release_category.ts b/sample/delivery/taxonomies/release_category.ts new file mode 100644 index 0000000..448245b --- /dev/null +++ b/sample/delivery/taxonomies/release_category.ts @@ -0,0 +1,15 @@ +/** + * + * Migration Toolkit - tests + * + * Environment: Production + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + */ + +/** + * Release category + * + * Codename: release_category + * Id: 4dbfc78f-5ea2-4f33-880d-193c75e0b975 + */ +export type ReleaseCategory = 'global_release' | 'us_only'; diff --git a/sample/delivery/taxonomies/releasecategory.ts b/sample/delivery/taxonomies/releasecategory.ts deleted file mode 100644 index f32c2bf..0000000 --- a/sample/delivery/taxonomies/releasecategory.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * - * Movie Database - * - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - */ - -/** - * ReleaseCategory - * - * Codename: releasecategory - * Id: 09b6a348-0f86-7a68-4af3-7cab9a5c60b7 - */ -export type ReleaseCategory = 'global_release' | 'local_release' | 'us_only'; From a19525058ea31540624f33030fbe6207bb4c9ade Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 28 Aug 2024 15:37:06 +0200 Subject: [PATCH 029/183] refactors delivery file name resolvers, removes name/text helpers, simplifies content type generator --- lib/comments/comments.manager.ts | 5 +- lib/core/index.ts | 1 + lib/core/resolvers.ts | 264 +++++++++++++ .../delivery-content-type.generator.ts | 348 +++++------------- lib/generators/delivery/delivery-mappers.ts | 173 --------- .../delivery/delivery-taxonomy.generator.ts | 16 +- lib/index.ts | 2 - lib/models.ts | 15 +- lib/name-helper.ts | 117 ------ lib/text-helper.ts | 51 --- .../content-type-snippets/my_snippet.ts | 8 +- .../taxonomy_snippet_test.ts | 5 +- sample/delivery/content-types/actor.ts | 14 +- sample/delivery/content-types/movie.ts | 29 +- sample/delivery/content-types/test.ts | 5 +- sample/delivery/taxonomies/category.ts | 2 +- .../delivery/taxonomies/release_category.ts | 2 +- 17 files changed, 425 insertions(+), 632 deletions(-) create mode 100644 lib/core/resolvers.ts delete mode 100644 lib/name-helper.ts delete mode 100644 lib/text-helper.ts diff --git a/lib/comments/comments.manager.ts b/lib/comments/comments.manager.ts index 973c587..97f33c7 100644 --- a/lib/comments/comments.manager.ts +++ b/lib/comments/comments.manager.ts @@ -1,5 +1,6 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import { libMetadata } from '../meta/index.js'; +import { toSafeString } from '../core/index.js'; export function commentsManager(addTimestamp: boolean) { const generatedBy = (): string => { @@ -23,9 +24,9 @@ export function commentsManager(addTimestamp: boolean) { ): string => { return wrapComment( ` -* ${environmentInfo.name} +* ${toSafeString(environmentInfo.name)} * -* Environment: ${environmentInfo.environment} +* Environment: ${toSafeString(environmentInfo.environment)} * Id: ${environmentInfo.id}`, opts ); diff --git a/lib/core/index.ts b/lib/core/index.ts index 548cebf..98c063c 100644 --- a/lib/core/index.ts +++ b/lib/core/index.ts @@ -3,3 +3,4 @@ export * from './error.utils.js'; export * from './core.models.js'; export * from './element.utils.js'; export * from './core.config.js'; +export * from './resolvers.js'; diff --git a/lib/core/resolvers.ts b/lib/core/resolvers.ts new file mode 100644 index 0000000..c7b96db --- /dev/null +++ b/lib/core/resolvers.ts @@ -0,0 +1,264 @@ +import {} from '@kontent-ai/delivery-sdk'; +import { + ContentTypeModels, + ContentTypeSnippetModels, + ContentTypeElements, + TaxonomyModels +} from '@kontent-ai/management-sdk'; +import { commonHelper } from '../common-helper.js'; +import { + ContentTypeResolver, + ContentTypeSnippetResolver, + TaxonomyTypeResolver, + DefaultResolverType, + ElementResolver +} from '../models.js'; +import { toCamelCase, toPascalCase, toSnakeCase } from './core.utils.js'; +import { match } from 'ts-pattern'; + +export type ObjectWithCodename = { + readonly codename: string; +}; + +export type ContentTypeFileNameResolver = FilenameResolver; +export type ContentTypeSnippetFileNameResolver = FilenameResolver; +export type TaxonomyTypeFileNameResolver = FilenameResolver; + +export type FilenameResolver = + | undefined + | DefaultResolverType + | ((item: T & ObjectWithCodename) => string); + +export type MapContentTypeToDeliveryTypeName = (contentType: Readonly) => string; +export type MapContentTypeSnippetToDeliveryTypeName = ( + contentTypeSnippet: Readonly +) => string; +export type MapContentTypeToFileName = ( + contentType: Readonly, + addExtension: boolean +) => string; +export type MapContentTypeSnippetToFileName = ( + contentTypeSnippet: Readonly, + addExtension: boolean +) => string; + +export type MapObjectToFileName = ObjectWithCodename> = ( + item: T, + addExtension: boolean +) => string; + +export type MapElementToName = (element: Readonly) => string | undefined; +export type MapTaxonomyName = (taxonomy: Readonly) => string; +export type MapTaxonomyToFileName = (taxonomy: Readonly, addExtension: boolean) => string; + +export function getMapContentTypeToDeliveryTypeName(resolver?: ContentTypeResolver): MapContentTypeToDeliveryTypeName { + return (contentType) => { + return getDeliveryContentTypeName({ + type: contentType, + contentTypeResolver: resolver + }); + }; +} + +export function getMapContentTypeSnippetToDeliveryTypeName( + resolver?: ContentTypeSnippetResolver +): MapContentTypeSnippetToDeliveryTypeName { + return (contentTypeSnippet) => { + return getDeliveryContentTypeSnippetName({ + snippet: contentTypeSnippet, + contentTypeResolver: resolver + }); + }; +} + +export function getMapContentTypeToFileName(resolver?: ContentTypeFileNameResolver): MapContentTypeToFileName { + return (contentType, addExtension) => { + return match(resolver) + .returnType() + .when( + (resolver) => resolver instanceof Function, + (resolver) => `${resolver(contentType)}${addExtension ? '.ts' : ''}` + ) + .when( + (resolver) => resolver === undefined, + () => `${contentType.codename}` + ) + .otherwise((resolverType) => `${resolveTextWithDefaultResolver(contentType.codename, resolverType)}`); + }; +} + +export function getMapContentTypeSnippetToFileName( + resolver?: ContentTypeSnippetFileNameResolver +): MapContentTypeSnippetToFileName { + return (snippet, addExtension) => { + return addExtensionToFilename( + match(resolver) + .returnType() + .when( + (resolver) => resolver instanceof Function, + (resolver) => resolver(snippet) + ) + .when( + (resolver) => resolver === undefined, + () => snippet.codename + ) + .otherwise((resolverType) => `${resolveTextWithDefaultResolver(snippet.codename, resolverType)}`), + + addExtension + ); + }; +} + +export function mapFilename(resolver: FilenameResolver): MapObjectToFileName { + return (item, addExtension) => { + return addExtensionToFilename( + match(resolver) + .returnType() + .when( + (resolver) => resolver instanceof Function, + (resolver) => resolver(item) + ) + .when( + (resolver) => resolver === undefined, + () => item.codename + ) + .otherwise((resolverType) => `${resolveTextWithDefaultResolver(item.codename, resolverType)}`), + + addExtension + ); + }; +} + +function addExtensionToFilename(filename: string, addExtension: boolean): string { + return `${filename}${addExtension ? '.ts' : ''}`; +} + +export function getMapElementToName(resolver?: ElementResolver): MapElementToName { + return (element) => { + if (!element) { + return undefined; + } + + const codename = commonHelper.getElementCodename(element); + + if (!codename) { + return undefined; + } + const elementName = getElementName({ + elementCodename: codename, + elementResolver: resolver + }); + + return elementName; + }; +} + +export function getMapTaxonomyName(resolver?: TaxonomyTypeResolver): MapTaxonomyName { + return (taxonomy) => { + return getDeliveryTaxonomyTypeName({ + taxonomy: taxonomy, + taxonomyResolver: resolver + }); + }; +} + +export function getMapTaxonomyToFileName(resolver?: TaxonomyTypeFileNameResolver): MapTaxonomyToFileName { + return (taxonomy, addExtension) => { + const fileName = getDeliveryTaxonomyFilename({ + taxonomy: taxonomy, + addExtension: addExtension, + fileResolver: resolver + }); + return `${fileName}`; + }; +} + +function getDeliveryContentTypeName(data: { + readonly type: Readonly; + readonly contentTypeResolver?: ContentTypeResolver; +}): string { + if (!data.contentTypeResolver) { + return toPascalCase(data.type.name); + } + + if (data.contentTypeResolver instanceof Function) { + return `${data.contentTypeResolver(data.type)}`; + } + + return `${resolveTextWithDefaultResolver(data.type.name, data.contentTypeResolver)}`; +} + +function getDeliveryContentTypeSnippetName(data: { + readonly snippet: Readonly; + readonly contentTypeResolver?: ContentTypeResolver; +}): string { + if (!data.contentTypeResolver) { + return toPascalCase(data.snippet.name); + } + + if (data.contentTypeResolver instanceof Function) { + return `${data.contentTypeResolver(data.snippet)}`; + } + + return `${resolveTextWithDefaultResolver(data.snippet.name, data.contentTypeResolver)}`; +} + +function getDeliveryTaxonomyFilename(data: { + readonly taxonomy: Readonly; + readonly fileResolver?: TaxonomyTypeFileNameResolver; + readonly addExtension: boolean; +}): string { + if (data.fileResolver instanceof Function) { + return `${data.fileResolver(data.taxonomy)}${data.addExtension ? '.ts' : ''}`; + } + + let filename: string; + + if (!data.fileResolver) { + filename = `${data.taxonomy.codename}`; + } else { + filename = `${resolveTextWithDefaultResolver(data.taxonomy.codename, data.fileResolver)}`; + } + + return `${filename}${data.addExtension ? '.ts' : ''}`; +} + +function getDeliveryTaxonomyTypeName(data: { + readonly taxonomy: Readonly; + readonly taxonomyResolver?: TaxonomyTypeResolver; +}): string { + if (!data.taxonomyResolver) { + return toPascalCase(data.taxonomy.name); + } + + if (data.taxonomyResolver instanceof Function) { + return `${data.taxonomyResolver(data.taxonomy)}`; + } + + return `${resolveTextWithDefaultResolver(data.taxonomy.name, data.taxonomyResolver)}`; +} + +function getElementName(config: { elementCodename: string; elementResolver?: ElementResolver }): string { + if (!config.elementResolver) { + return config.elementCodename; + } + + if (config.elementResolver instanceof Function) { + return config.elementResolver('', config.elementCodename); + } + + return resolveTextWithDefaultResolver(config.elementCodename, config.elementResolver); +} + +function resolveTextWithDefaultResolver(text: string, resolverType: DefaultResolverType): string { + switch (resolverType) { + case 'camelCase': + return toCamelCase(text); + case 'pascalCase': + return toPascalCase(text); + case 'snakeCase': + return toSnakeCase(text); + default: + throw Error(`Invalid name resolver. Available options are: camelCase, pascalCase, snakeCase`); + } +} diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index d6c0316..2c702e4 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -1,69 +1,42 @@ import chalk from 'chalk'; -import { commonHelper } from '../../common-helper.js'; -import { - ContentTypeResolver, - ElementResolver, - ContentTypeFileNameResolver, - TaxonomyTypeFileNameResolver, - TaxonomyTypeResolver, - ContentTypeSnippetResolver, - ContentTypeSnippetFileNameResolver, - ModuleResolution -} from '../../models.js'; +import { match, P } from 'ts-pattern'; +import { isNotUndefined } from '@kontent-ai/migration-toolkit'; import { - ContentTypeElements, ContentTypeModels, ContentTypeSnippetModels, - ElementModels, EnvironmentModels, TaxonomyModels } from '@kontent-ai/management-sdk'; import { - MapContentTypeToDeliveryTypeName, - MapContentTypeIdToObject, - MapContentTypeToFileName, - MapElementToName, - getMapContentTypeToDeliveryTypeName, - getMapContentTypeIdToObject, - getMapContentTypeToFileName, - getMapElementToName, - MapTaxonomyToFileName, - MapTaxonomyName, - getMapTaxonomyName, - getMapTaxonomyToFileName, - MapTaxonomyIdTobject, - getMapTaxonomyIdTobject, - MapContentTypeSnippetToFileName, - MapContentTypeSnippetToDeliveryTypeName, - getMapContentTypeSnippetToDeliveryTypeName, - getMapContentTypeSnippetToFileName, - MapContentTypeSnippetIdToObject, - getMapContentTypeSnippetIdToObject -} from './delivery-mappers.js'; + ContentTypeResolver, + ElementResolver, + TaxonomyTypeResolver, + ContentTypeSnippetResolver, + ModuleResolution +} from '../../models.js'; + import { commentsManager as _commentsManager } from '../../comments/index.js'; -import { textHelper } from '../../text-helper.js'; import { + ContentTypeFileNameResolver, + ContentTypeSnippetFileNameResolver, deliveryConfig, FlattenedElement, GeneratedFile, getFlattenedElements, getImportStatement, + getMapContentTypeSnippetToDeliveryTypeName, + getMapContentTypeToDeliveryTypeName, + getMapElementToName, + getMapTaxonomyName, + mapFilename, + removeLineEndings, sortAlphabetically, + TaxonomyTypeFileNameResolver, toSafeString, uniqueFilter } from '../../core/index.js'; -import { match, P } from 'ts-pattern'; -import { isNotUndefined } from '@kontent-ai/migration-toolkit'; - -// interface IExtendedContentTypeElement { -// readonly type: ElementModels.ElementType; -// readonly element: Readonly; -// readonly mappedType: string | undefined; -// readonly mappedName: string | undefined; -// readonly snippet?: Readonly; -// } -interface IExtractImportsResult { +interface ExtractImportsResult { readonly typeName: string; readonly imports: readonly string[]; readonly contentTypeExtends: string | undefined; @@ -97,28 +70,20 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato const commentsManager = _commentsManager(config.addTimestamp); // prepare resolvers + const contentTypeSnippetFileNameMap = mapFilename(config.contentTypeSnippetFileNameResolver); + const contentTypeFileNameMap = mapFilename(config.contentTypeFileNameResolver); + const taxonomyFileNameMap = mapFilename(config.taxonomyFileResolver); + const contentTypeSnippetNameMap = getMapContentTypeSnippetToDeliveryTypeName(config.contentTypeSnippetResolver); - const contentTypeSnippetFileNameMap = getMapContentTypeSnippetToFileName(config.contentTypeSnippetFileNameResolver); const contentTypeNameMap = getMapContentTypeToDeliveryTypeName(config.contentTypeResolver); - const contentTypeObjectMap = getMapContentTypeIdToObject(config.environmentData.types); - const contentTypeSnippetObjectMap = getMapContentTypeSnippetIdToObject(config.environmentData.snippets); - const contentTypeFileNameMap = getMapContentTypeToFileName(config.contentTypeFileNameResolver); const elementNameMap = getMapElementToName(config.elementResolver); const taxonomyNameMap = getMapTaxonomyName(config.taxonomyResolver); - const taxonomyFileNameMap = getMapTaxonomyToFileName(config.taxonomyFileResolver); - const taxonomyObjectMap = getMapTaxonomyIdTobject(config.environmentData.taxonomies); const generateModels = (): { contentTypeFiles: readonly GeneratedFile[]; snippetFiles: readonly GeneratedFile[]; } => { - const typeFiles: GeneratedFile[] = []; - const snippetFiles: GeneratedFile[] = []; - - let addNewLineAfterResolvers: boolean = false; - if (config.elementResolver) { - addNewLineAfterResolvers = true; console.log( `Using '${chalk.yellow( config.elementResolver instanceof Function ? 'custom' : config.elementResolver @@ -127,7 +92,6 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato } if (config.contentTypeFileNameResolver) { - addNewLineAfterResolvers = true; console.log( `Using '${chalk.yellow( config.contentTypeFileNameResolver instanceof Function @@ -138,7 +102,6 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato } if (config.contentTypeSnippetFileNameResolver) { - addNewLineAfterResolvers = true; console.log( `Using '${chalk.yellow( config.contentTypeSnippetFileNameResolver instanceof Function @@ -149,7 +112,6 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato } if (config.contentTypeResolver) { - addNewLineAfterResolvers = true; console.log( `Using '${chalk.yellow( config.contentTypeResolver instanceof Function ? 'custom' : config.contentTypeResolver @@ -158,7 +120,6 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato } if (config.contentTypeSnippetResolver) { - addNewLineAfterResolvers = true; console.log( `Using '${chalk.yellow( config.contentTypeSnippetResolver instanceof Function ? 'custom' : config.contentTypeSnippetResolver @@ -166,43 +127,15 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato ); } - if (addNewLineAfterResolvers) { - console.log(''); - } - - for (const contentTypeSnippet of config.environmentData.snippets) { - try { - const file = createContentTypeSnippetModel({ - snippet: contentTypeSnippet - }); - snippetFiles.push(file); - } catch (error) { - console.error(error); - throw Error( - `Failed to process content type snippet '${contentTypeSnippet.codename}' (${contentTypeSnippet.name})` - ); - } - } - - for (const type of config.environmentData.types) { - try { - const file = createContentTypeModel({ - type: type - }); - typeFiles.push(file); - } catch (error) { - console.error(error); - throw Error(`Failed to process content type '${type.codename}' (${type.name})`); - } - } - return { - contentTypeFiles: typeFiles, - snippetFiles: snippetFiles + contentTypeFiles: config.environmentData.types.map((type) => createContentTypeModel(type)), + snippetFiles: config.environmentData.snippets.map((contentTypeSnippet) => + createContentTypeSnippetModel(contentTypeSnippet) + ) }; }; - const snippetImports = ( + const getSnippetImports = ( snippets: readonly Readonly[] ): readonly string[] => { return snippets.map((snippet) => { @@ -218,7 +151,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato }; const getElementImports = ( - typeOrSnippet: ContentTypeModels.ContentType | ContentTypeSnippetModels.ContentTypeSnippet, + typeOrSnippet: Readonly | Readonly, elements: readonly FlattenedElement[] ): readonly string[] => { return ( @@ -267,18 +200,21 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato ) .flatMap((m) => m) .filter(isNotUndefined) + .filter(uniqueFilter) ); }; const getContentTypeImports = (data: { - typeOrSnippet: ContentTypeModels.ContentType | ContentTypeSnippetModels.ContentTypeSnippet; - flattenedElements: readonly FlattenedElement[]; - }): IExtractImportsResult => { + readonly typeOrSnippet: + | Readonly + | Readonly; + readonly flattenedElements: readonly FlattenedElement[]; + }): ExtractImportsResult => { const snippets = data.flattenedElements.map((m) => m.fromSnippet).filter(isNotUndefined); return { imports: sortAlphabetically( - [...getElementImports(data.typeOrSnippet, data.flattenedElements), ...snippetImports(snippets)] + [...getElementImports(data.typeOrSnippet, data.flattenedElements), ...getSnippetImports(snippets)] .filter(isNotUndefined) .filter(uniqueFilter), (importValue) => importValue @@ -297,22 +233,22 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato }; }; - const getDeliverySdkContentTypeImports = (flattenedElements: readonly FlattenedElement[]): string[] => { + const getDeliverySdkContentTypeImports = (flattenedElements: readonly FlattenedElement[]): readonly string[] => { return ['IContentItem', ...(flattenedElements.length ? ['Elements'] : [])]; }; - const getModelCode = (data: { - typeOrSnippet: ContentTypeModels.ContentType | ContentTypeSnippetModels.ContentTypeSnippet; - }): string => { + const getModelCode = ( + typeOrSnippet: Readonly | Readonly + ): string => { const flattenedElements = getFlattenedElements( - data.typeOrSnippet.elements, + typeOrSnippet.elements, config.environmentData.snippets, config.environmentData.taxonomies, config.environmentData.types ); const contentTypeImports = getContentTypeImports({ - typeOrSnippet: data.typeOrSnippet, + typeOrSnippet, flattenedElements: flattenedElements }); @@ -327,175 +263,93 @@ ${contentTypeImports.imports.join('\n')} ${commentsManager.environmentInfo(config.environmentData.environment)} /** -* ${toSafeString(data.typeOrSnippet.name)} +* ${toSafeString(typeOrSnippet.name)} * -* Id: ${data.typeOrSnippet.id} -* Codename: ${data.typeOrSnippet.codename} +* Id: ${typeOrSnippet.id} +* Codename: ${typeOrSnippet.codename} */ export type ${contentTypeImports.typeName} = IContentItem<{ - ${getElementsCode({ - flattenedElements: flattenedElements - })} + ${getElementsCode(flattenedElements)} }>${contentTypeImports.contentTypeExtends ? ` ${contentTypeImports.contentTypeExtends}` : ''}; `; return code; }; - const createContentTypeModel = (data: { type: ContentTypeModels.ContentType }): GeneratedFile => { - const filename: string = `${config.typeFolderName}/${contentTypeFileNameMap(data.type, true)}`; - const code = getModelCode({ - typeOrSnippet: data.type - }); - + const createContentTypeModel = (type: Readonly): GeneratedFile => { return { - filename: filename, - text: code + filename: `${config.typeFolderName}/${contentTypeFileNameMap(type, true)}`, + text: getModelCode(type) }; }; - const createContentTypeSnippetModel = (data: { - readonly snippet: ContentTypeSnippetModels.ContentTypeSnippet; - }): GeneratedFile => { - const filename: string = `${config.typeSnippetsFolderName}/${contentTypeSnippetFileNameMap( - data.snippet, - true - )}`; - const code = getModelCode({ - typeOrSnippet: data.snippet - }); - + const createContentTypeSnippetModel = ( + snippet: Readonly + ): GeneratedFile => { return { - filename: filename, - text: code + filename: `${config.typeSnippetsFolderName}/${contentTypeSnippetFileNameMap(snippet, true)}`, + text: getModelCode(snippet) }; }; - const getElementComment = ( - flattenedElement: FlattenedElement, - taxonomies: readonly Readonly[] - ): string => { - const element = flattenedElement.originalElement; - const isRequired = commonHelper.isElementRequired(element); - const guidelines = commonHelper.getElementGuidelines(element); - const name = commonHelper.getElementTitle(element, taxonomies); - const codename = commonHelper.getElementCodename(element); - - let comment: string = '/**'; - - if (name) { - comment += `\n* ${name} (${element.type})`; - } - - comment += `\n* Required: ${isRequired ? 'true' : 'false'}`; - comment += `\n* Id: ${element.id}`; - - if (codename) { - comment += `\n* Codename: ${codename}`; - } - - // if (flattenedElement.snippet) { - // comment += `\n* From snippet: ${flattenedElement.snippet.name}`; - // comment += `\n* Snippet codename: ${flattenedElement.snippet.codename}`; - // } - - if (guidelines) { - comment += `\n*`; - comment += `\n* ${textHelper.removeLineEndings(guidelines)}`; - } - - comment += '\n*/'; - - return comment; - }; - - const getElementsCode = (data: { flattenedElements: readonly FlattenedElement[] }): string => { - // filter out elements that are from snippets - const filteredElements = data.flattenedElements.filter((m) => !m.fromSnippet); - let code = ''; - for (let i = 0; i < filteredElements.length; i++) { - const flattenedElement = filteredElements[i]; - const element = flattenedElement.originalElement; - const mappedType = mapElementType({ element: flattenedElement }); - - const codename = commonHelper.getElementCodename(element); - - if (!codename) { - throw Error(`Invalid codename for element '${element.id}'`); - } - - const elementName = elementNameMap(element); - - if (!elementName) { - // skip element if its not resolver - continue; - } - - // if (!extendedElement.mappedType) { - // // element type not supported - // continue; - // } - - code += `${getElementComment(flattenedElement, config.environmentData.taxonomies)}\n`; - code += `${elementName}: Elements.${mappedType};`; - - if (i !== filteredElements.length - 1) { - code += '\n\n'; - } - } - - return code; + const getElementsCode = (flattenedElements: readonly FlattenedElement[]): string => { + return ( + flattenedElements + // filter out elements that are from snippets + .filter((m) => !m.fromSnippet) + .reduce((code, element) => { + const mappedType = mapElementType(element); + const elementName = elementNameMap(element.originalElement); + + if (!mappedType || !elementName) { + return code; + } + + return (code += `\n + /** + * ${element.title} (${element.type}) + * + * Required: ${element.isRequired ? 'true' : 'false'} + * Codename: ${element.codename} + * Id: ${element.id}${element.guidelines ? `\n* Guidelines: ${toSafeString(removeLineEndings(element.guidelines))}` : ''} + */ + ${elementName}: Elements.${mappedType};`); + }, '') + ); }; - const mapElementType = (data: { element: FlattenedElement }): string | undefined => { - const elementType = data.element.type; - let mappedType: string | undefined; - - if (elementType === 'text') { - mappedType = 'TextElement'; - } else if (elementType === 'number') { - mappedType = 'NumberElement'; - } else if (elementType === 'modular_content' || elementType === 'subpages') { - mappedType = `LinkedItemsElement<${getLinkedItemsAllowedTypes(data.element.allowedContentTypes ?? []).join(' | ')}>`; - } else if (elementType === 'asset') { - mappedType = 'AssetsElement'; - } else if (elementType === 'date_time') { - mappedType = 'DateTimeElement'; - } else if (elementType === 'rich_text') { - mappedType = 'RichTextElement'; - } else if (elementType === 'multiple_choice') { - mappedType = 'MultipleChoiceElement'; - } else if (elementType === 'url_slug') { - mappedType = 'UrlSlugElement'; - } else if (elementType === 'taxonomy') { - const taxonomyName = getTaxonomyTypeName(data.element); - - if (taxonomyName) { - mappedType = `TaxonomyElement<${taxonomyName}>`; - } else { - mappedType = `TaxonomyElement`; - } - } else if (elementType === 'custom') { - mappedType = 'CustomElement'; - } else if (elementType === 'snippet') { - mappedType = undefined; - } else { - mappedType = undefined; - } - return mappedType; + const mapElementType = (element: FlattenedElement): string | undefined => { + return match(element) + .returnType() + .with({ type: 'text' }, () => 'TextElement') + .with({ type: 'number' }, () => 'NumberElement') + .with({ type: 'modular_content' }, (linkedItemsElement) => { + return `LinkedItemsElement<${getLinkedItemsAllowedTypes(linkedItemsElement.allowedContentTypes ?? []).join(' | ')}>`; + }) + .with({ type: 'asset' }, () => 'AssetsElement') + .with({ type: 'date_time' }, () => 'DateTimeElement') + .with({ type: 'rich_text' }, () => 'RichTextElement') + .with({ type: 'multiple_choice' }, () => 'MultipleChoiceElement') + .with({ type: 'url_slug' }, () => 'UrlSlugElement') + .with({ type: 'taxonomy' }, (taxonomyElement) => { + const taxonomyName = getTaxonomyTypeName(taxonomyElement); + return taxonomyName ? `TaxonomyElement<${taxonomyName}>` : `TaxonomyElement`; + }) + .with({ type: 'custom' }, () => 'CustomElement') + .otherwise(() => undefined); }; const getTaxonomyTypeName = (element: FlattenedElement): string | undefined => { return element.assignedTaxonomy ? taxonomyNameMap(element.assignedTaxonomy) : undefined; }; - const getLinkedItemsAllowedTypes = (types: readonly Readonly[]): string[] => { + const getLinkedItemsAllowedTypes = ( + types: readonly Readonly[] + ): readonly string[] => { if (!types.length) { return ['IContentItem']; } - const allowedTypeNames: string[] = types.map((m) => contentTypeNameMap(m)) ?? []; - - return allowedTypeNames; + return types.map((type) => contentTypeNameMap(type)); }; return { diff --git a/lib/generators/delivery/delivery-mappers.ts b/lib/generators/delivery/delivery-mappers.ts index 4b66dc1..e69de29 100644 --- a/lib/generators/delivery/delivery-mappers.ts +++ b/lib/generators/delivery/delivery-mappers.ts @@ -1,173 +0,0 @@ -import { - ContentTypeElements, - ContentTypeModels, - ContentTypeSnippetModels, - TaxonomyModels -} from '@kontent-ai/management-sdk'; -import { textHelper } from '../../text-helper.js'; -import { - ContentTypeFileNameResolver, - ContentTypeResolver, - ContentTypeSnippetFileNameResolver, - ContentTypeSnippetResolver, - ElementResolver, - TaxonomyTypeFileNameResolver, - TaxonomyTypeResolver -} from '../../models.js'; -import { nameHelper } from '../../name-helper.js'; -import { commonHelper } from '../../common-helper.js'; - -export type MapContentTypeToDeliveryTypeName = (contentType: ContentTypeModels.ContentType) => string; -export type MapContentTypeSnippetToDeliveryTypeName = ( - contentTypeSnippet: ContentTypeSnippetModels.ContentTypeSnippet -) => string; -export type MapContentTypeIdToObject = (id: string) => ContentTypeModels.ContentType; -export type MapContentTypeSnippetIdToObject = (id: string) => ContentTypeSnippetModels.ContentTypeSnippet; -export type MapContentTypeToFileName = (contentType: ContentTypeModels.ContentType, addExtension: boolean) => string; -export type MapContentTypeSnippetToFileName = ( - contentTypeSnippet: ContentTypeSnippetModels.ContentTypeSnippet, - addExtension: boolean -) => string; -export type MapElementToName = (element: ContentTypeElements.ContentTypeElementModel) => string | undefined; - -export type MapTaxonomyName = (taxonomy: TaxonomyModels.Taxonomy) => string; -export type MapTaxonomyIdTobject = (id: string) => TaxonomyModels.Taxonomy; -export type MapTaxonomyToFileName = (taxonomy: TaxonomyModels.Taxonomy, addExtension: boolean) => string; - -export function getMapContentTypeToDeliveryTypeName(resolver?: ContentTypeResolver): MapContentTypeToDeliveryTypeName { - return (contentType) => { - return nameHelper.getDeliveryContentTypeName({ - type: contentType, - contentTypeResolver: resolver - }); - }; -} - -export function getMapContentTypeSnippetToDeliveryTypeName( - resolver?: ContentTypeSnippetResolver -): MapContentTypeSnippetToDeliveryTypeName { - return (contentTypeSnippet) => { - return nameHelper.getDeliveryContentTypeSnippetName({ - snippet: contentTypeSnippet, - contentTypeResolver: resolver - }); - }; -} - -export function getMapContentTypeIdToObject(types: ContentTypeModels.ContentType[]): MapContentTypeIdToObject { - return (id) => { - const contentType = types.find((m) => m.id === id); - - if (!contentType) { - throw Error( - `Could not find content type with id '${id}'. This may be caused by references to deleted types and can be fixed within Kontent.ai app.` - ); - } - - return contentType; - }; -} - -export function getMapContentTypeSnippetIdToObject( - snippets: ContentTypeSnippetModels.ContentTypeSnippet[] -): MapContentTypeSnippetIdToObject { - return (id) => { - const snippet = snippets.find((m) => m.id === id); - - if (!snippet) { - throw Error( - `Could not find content type snippet with id '${id}'. This may be caused by references to deleted snippets and can be fixed within Kontent.ai app.` - ); - } - - return snippet; - }; -} - -export function getMapContentTypeToFileName(resolver?: ContentTypeFileNameResolver): MapContentTypeToFileName { - return (contentType, addExtension) => { - const fileName = nameHelper.getDeliveryContentTypeFilename({ - type: contentType, - addExtension: addExtension, - fileResolver: resolver - }); - return `${fileName}`; - }; -} - -export function getMapContentTypeSnippetToFileName( - resolver?: ContentTypeSnippetFileNameResolver -): MapContentTypeSnippetToFileName { - return (snippet, addExtension) => { - const fileName = nameHelper.getDeliveryContentTypeSnippetFilename({ - snippet: snippet, - addExtension: addExtension, - fileResolver: resolver - }); - return `${fileName}`; - }; -} - -export function getMapElementToName(resolver?: ElementResolver): MapElementToName { - return (element) => { - if (!element) { - return undefined; - } - - const codename = commonHelper.getElementCodename(element); - - if (!codename) { - return undefined; - } - const elementName = getElementName({ - elementCodename: codename, - elementResolver: resolver - }); - - return elementName; - }; -} - -export function getMapTaxonomyName(resolver?: TaxonomyTypeResolver): MapTaxonomyName { - return (taxonomy) => { - return nameHelper.getDeliveryTaxonomyTypeName({ - taxonomy: taxonomy, - taxonomyResolver: resolver - }); - }; -} - -export function getMapTaxonomyToFileName(resolver?: TaxonomyTypeFileNameResolver): MapTaxonomyToFileName { - return (taxonomy, addExtension) => { - const fileName = nameHelper.getDeliveryTaxonomyFilename({ - taxonomy: taxonomy, - addExtension: addExtension, - fileResolver: resolver - }); - return `${fileName}`; - }; -} - -export function getMapTaxonomyIdTobject(taxonomies: TaxonomyModels.Taxonomy[]): MapTaxonomyIdTobject { - return (id) => { - const taxonomy = taxonomies.find((m) => m.id === id); - - if (!taxonomy) { - throw Error(`Could not find taxonomy with id '${id}'`); - } - - return taxonomy; - }; -} - -function getElementName(config: { elementCodename: string; elementResolver?: ElementResolver }): string { - if (!config.elementResolver) { - return config.elementCodename; - } - - if (config.elementResolver instanceof Function) { - return config.elementResolver('', config.elementCodename); - } - - return textHelper.resolveTextWithDefaultResolver(config.elementCodename, config.elementResolver); -} diff --git a/lib/generators/delivery/delivery-taxonomy.generator.ts b/lib/generators/delivery/delivery-taxonomy.generator.ts index 0c818f0..739887f 100644 --- a/lib/generators/delivery/delivery-taxonomy.generator.ts +++ b/lib/generators/delivery/delivery-taxonomy.generator.ts @@ -1,13 +1,17 @@ -import { ModuleResolution, TaxonomyTypeFileNameResolver, TaxonomyTypeResolver } from '../../models.js'; +import { ModuleResolution, TaxonomyTypeResolver } from '../../models.js'; import chalk from 'chalk'; import { EnvironmentModels, TaxonomyModels } from '@kontent-ai/management-sdk'; + import { - MapTaxonomyToFileName, - MapTaxonomyName, + GeneratedFile, + getMapTaxonomyName, getMapTaxonomyToFileName, - getMapTaxonomyName -} from './delivery-mappers.js'; -import { GeneratedFile, sortAlphabetically, toSafeString } from '../../core/index.js'; + MapTaxonomyName, + MapTaxonomyToFileName, + sortAlphabetically, + TaxonomyTypeFileNameResolver, + toSafeString +} from '../../core/index.js'; import { commentsManager as _commentsManager } from '../../comments/index.js'; export interface DeliveryTaxonomyGeneratorConfig { diff --git a/lib/index.ts b/lib/index.ts index 78c59f5..f376a21 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,6 +1,4 @@ export * from './common-helper.js'; -export * from './text-helper.js'; -export * from './name-helper.js'; export * from './models.js'; export * from './core/index.js'; export * from './files/index.js'; diff --git a/lib/models.ts b/lib/models.ts index df308b1..477b6f6 100644 --- a/lib/models.ts +++ b/lib/models.ts @@ -1,22 +1,17 @@ import { PropertyNameResolver } from '@kontent-ai/delivery-sdk'; import { ContentTypeModels, ContentTypeSnippetModels, TaxonomyModels } from '@kontent-ai/management-sdk'; import { Options } from 'prettier'; +import { + ContentTypeFileNameResolver, + ContentTypeSnippetFileNameResolver, + TaxonomyTypeFileNameResolver +} from './core/index.js'; export type ModuleResolution = 'nodeNext' | 'node'; export type DefaultResolverType = 'camelCase' | 'pascalCase' | 'snakeCase'; export type ModelType = 'delivery' | 'migration'; export type ElementResolver = DefaultResolverType | PropertyNameResolver; -export type ContentTypeFileNameResolver = - | DefaultResolverType - | ((contentType: Readonly) => string); -export type ContentTypeSnippetFileNameResolver = - | DefaultResolverType - | ((contentTypeSnippet: Readonly) => string); -export type TaxonomyTypeFileNameResolver = - | DefaultResolverType - | ((taxonomy: Readonly) => string); - export type ContentTypeResolver = | DefaultResolverType | ((contentType: Readonly) => string); diff --git a/lib/name-helper.ts b/lib/name-helper.ts deleted file mode 100644 index 7b095a4..0000000 --- a/lib/name-helper.ts +++ /dev/null @@ -1,117 +0,0 @@ -import { ContentTypeModels, ContentTypeSnippetModels, TaxonomyModels } from '@kontent-ai/management-sdk'; -import { - ContentTypeFileNameResolver, - ContentTypeResolver, - TaxonomyTypeFileNameResolver, - TaxonomyTypeResolver -} from './models.js'; -import { textHelper } from './text-helper.js'; - -export class NameHelper { - getDeliveryContentTypeFilename(data: { - type: ContentTypeModels.ContentType; - addExtension: boolean; - fileResolver?: ContentTypeFileNameResolver; - }): string { - if (data.fileResolver instanceof Function) { - return `${data.fileResolver(data.type)}${data.addExtension ? '.ts' : ''}`; - } - - let filename: string; - - if (!data.fileResolver) { - filename = `${data.type.codename}`; - } else { - filename = `${textHelper.resolveTextWithDefaultResolver(data.type.codename, data.fileResolver)}`; - } - - return `${filename}${data.addExtension ? '.ts' : ''}`; - } - - getDeliveryContentTypeSnippetFilename(data: { - snippet: ContentTypeSnippetModels.ContentTypeSnippet; - addExtension: boolean; - fileResolver?: ContentTypeFileNameResolver; - }): string { - if (data.fileResolver instanceof Function) { - return `${data.fileResolver(data.snippet)}${data.addExtension ? '.ts' : ''}`; - } - - let filename: string; - - if (!data.fileResolver) { - filename = `${data.snippet.codename}`; - } else { - filename = `${textHelper.resolveTextWithDefaultResolver(data.snippet.codename, data.fileResolver)}`; - } - - return `${filename}${data.addExtension ? '.ts' : ''}`; - } - - getDeliveryContentTypeName(data: { - type: ContentTypeModels.ContentType; - contentTypeResolver?: ContentTypeResolver; - }): string { - if (!data.contentTypeResolver) { - return textHelper.toPascalCase(data.type.name); - } - - if (data.contentTypeResolver instanceof Function) { - return `${data.contentTypeResolver(data.type)}`; - } - - return `${textHelper.resolveTextWithDefaultResolver(data.type.name, data.contentTypeResolver)}`; - } - - getDeliveryContentTypeSnippetName(data: { - snippet: ContentTypeSnippetModels.ContentTypeSnippet; - contentTypeResolver?: ContentTypeResolver; - }): string { - if (!data.contentTypeResolver) { - return textHelper.toPascalCase(data.snippet.name); - } - - if (data.contentTypeResolver instanceof Function) { - return `${data.contentTypeResolver(data.snippet)}`; - } - - return `${textHelper.resolveTextWithDefaultResolver(data.snippet.name, data.contentTypeResolver)}`; - } - - getDeliveryTaxonomyFilename(data: { - taxonomy: TaxonomyModels.Taxonomy; - fileResolver?: TaxonomyTypeFileNameResolver; - addExtension: boolean; - }): string { - if (data.fileResolver instanceof Function) { - return `${data.fileResolver(data.taxonomy)}${data.addExtension ? '.ts' : ''}`; - } - - let filename: string; - - if (!data.fileResolver) { - filename = `${data.taxonomy.codename}`; - } else { - filename = `${textHelper.resolveTextWithDefaultResolver(data.taxonomy.codename, data.fileResolver)}`; - } - - return `${filename}${data.addExtension ? '.ts' : ''}`; - } - - getDeliveryTaxonomyTypeName(data: { - taxonomy: TaxonomyModels.Taxonomy; - taxonomyResolver?: TaxonomyTypeResolver; - }): string { - if (!data.taxonomyResolver) { - return textHelper.toPascalCase(data.taxonomy.name); - } - - if (data.taxonomyResolver instanceof Function) { - return `${data.taxonomyResolver(data.taxonomy)}`; - } - - return `${textHelper.resolveTextWithDefaultResolver(data.taxonomy.name, data.taxonomyResolver)}`; - } -} - -export const nameHelper = new NameHelper(); diff --git a/lib/text-helper.ts b/lib/text-helper.ts deleted file mode 100644 index bbf693f..0000000 --- a/lib/text-helper.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { - camelCasePropertyNameResolver, - pascalCasePropertyNameResolver, - snakeCasePropertyNameResolver -} from '@kontent-ai/delivery-sdk'; -import { DefaultResolverType } from './models.js'; - -export class TextHelper { - resolveTextWithDefaultResolver(text: string, resolverType: DefaultResolverType): string { - switch (resolverType) { - case 'camelCase': - return this.toCamelCase(text); - case 'pascalCase': - return this.toPascalCase(text); - case 'snakeCase': - return this.toSnakeCase(text); - default: - throw Error(`Invalid name resolver. Available options are: camelCase, pascalCase, snakeCase`); - } - } - - toPascalCase(text: string): string { - // use element resolver from SDK as it provides required functionality - return this.toSafeName(pascalCasePropertyNameResolver('', text), 'nothing'); - } - - toCamelCase(text: string): string { - // use element resolver from SDK as it provides required functionality - return this.toSafeName(camelCasePropertyNameResolver('', text), 'nothing'); - } - - toSnakeCase(text: string): string { - // use element resolver from SDK as it provides required functionality - return this.toSafeName(snakeCasePropertyNameResolver('', text), 'nothing'); - } - - toAlphanumeric(value: string): string { - return value.replace(/\W/g, ''); - } - - removeLineEndings(value: string): string { - return value.replace(/(\r\n|\n|\r)/gm, ''); - } - - toSafeName(text: string, replaceWith: 'space' | 'nothing'): string { - const replaceContent = replaceWith === 'space' ? ' ' : ''; - return text.replace(/[\s-]/g, replaceContent).replace(/[^a-zA-Z0-9_]/g, replaceContent); - } -} - -export const textHelper = new TextHelper(); diff --git a/sample/delivery/content-type-snippets/my_snippet.ts b/sample/delivery/content-type-snippets/my_snippet.ts index fb7fd56..855cafa 100644 --- a/sample/delivery/content-type-snippets/my_snippet.ts +++ b/sample/delivery/content-type-snippets/my_snippet.ts @@ -2,7 +2,7 @@ import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; /** * - * Migration Toolkit - tests + * Migration Toolkit tests * * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 @@ -17,17 +17,19 @@ import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; export type MySnippet = IContentItem<{ /** * Snippet elem1 (text) + * * Required: false - * Id: 3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d * Codename: my_snippet__snippet_elem1 + * Id: 3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d */ my_snippet__snippet_elem1: Elements.TextElement; /** * Snippet elem 2 (number) + * * Required: false - * Id: b2f65646-3310-4a64-af2a-0d9d025a91d0 * Codename: my_snippet__snippet_elem_2 + * Id: b2f65646-3310-4a64-af2a-0d9d025a91d0 */ my_snippet__snippet_elem_2: Elements.NumberElement; }>; diff --git a/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts b/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts index bd69817..2f25b78 100644 --- a/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts +++ b/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts @@ -3,7 +3,7 @@ import type { Category } from '../taxonomies/category.js'; /** * - * Migration Toolkit - tests + * Migration Toolkit tests * * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 @@ -18,9 +18,10 @@ import type { Category } from '../taxonomies/category.js'; export type TaxonomySnippetTest = IContentItem<{ /** * Category (taxonomy) + * * Required: false - * Id: c030e3ec-5031-4d7f-af88-5032365733c7 * Codename: taxonomy_snippet_test__test_taxonomy + * Id: c030e3ec-5031-4d7f-af88-5032365733c7 */ taxonomy_snippet_test__test_taxonomy: Elements.TaxonomyElement; }>; diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index 3f22685..72bddd0 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -2,7 +2,7 @@ import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; /** * - * Migration Toolkit - tests + * Migration Toolkit tests * * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 @@ -17,33 +17,37 @@ import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; export type Actor = IContentItem<{ /** * photo (asset) + * * Required: false - * Id: 069b38ee-385c-410f-b7fe-53ec59a5f139 * Codename: photo + * Id: 069b38ee-385c-410f-b7fe-53ec59a5f139 */ photo: Elements.AssetsElement; /** * url (url_slug) + * * Required: false - * Id: c4b2d64f-af45-45a4-92d8-4829833563ff * Codename: url + * Id: c4b2d64f-af45-45a4-92d8-4829833563ff */ url: Elements.UrlSlugElement; /** * last_name (text) + * * Required: false - * Id: 0f00b26e-60f3-462d-8110-18180137c3a0 * Codename: last_name + * Id: 0f00b26e-60f3-462d-8110-18180137c3a0 */ last_name: Elements.TextElement; /** * first_name (text) + * * Required: false - * Id: 4af5e7ce-88ef-4159-96ae-96a552992f91 * Codename: first_name + * Id: 4af5e7ce-88ef-4159-96ae-96a552992f91 */ first_name: Elements.TextElement; }>; diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 2e83b2f..2ddef1f 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -5,7 +5,7 @@ import type { TaxonomySnippetTest } from '../content-type-snippets/taxonomy_snip /** * - * Migration Toolkit - tests + * Migration Toolkit tests * * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 @@ -20,73 +20,82 @@ import type { TaxonomySnippetTest } from '../content-type-snippets/taxonomy_snip export type Movie = IContentItem<{ /** * Release category (taxonomy) + * * Required: false - * Id: 5faa827f-f262-43c3-8f58-0f354b8d393f * Codename: releasecategory + * Id: 5faa827f-f262-43c3-8f58-0f354b8d393f */ releasecategory: Elements.TaxonomyElement; /** * Category (taxonomy) + * * Required: false - * Id: 8c12be35-e3e7-447c-a185-7b5e101ebf12 * Codename: category + * Id: 8c12be35-e3e7-447c-a185-7b5e101ebf12 */ category: Elements.TaxonomyElement; /** * length (number) + * * Required: false - * Id: e3d07f3a-60c2-4072-846d-c23e51ec833e * Codename: length + * Id: e3d07f3a-60c2-4072-846d-c23e51ec833e */ length: Elements.NumberElement; /** * stars (modular_content) + * * Required: false - * Id: 55596dd1-e808-415d-95aa-e2be34238d11 * Codename: stars + * Id: 55596dd1-e808-415d-95aa-e2be34238d11 */ stars: Elements.LinkedItemsElement; /** * seoname (url_slug) + * * Required: false - * Id: 734f94be-5930-4bdf-b05b-f59f5a291675 * Codename: seoname + * Id: 734f94be-5930-4bdf-b05b-f59f5a291675 */ seoname: Elements.UrlSlugElement; /** * poster (asset) + * * Required: false - * Id: 9b197f1e-0728-4d14-9814-97f7b8ef01fc * Codename: poster + * Id: 9b197f1e-0728-4d14-9814-97f7b8ef01fc */ poster: Elements.AssetsElement; /** * released (date_time) + * * Required: false - * Id: 656b9dc9-7bba-4f1f-a2b8-52f7f730a66f * Codename: released + * Id: 656b9dc9-7bba-4f1f-a2b8-52f7f730a66f */ released: Elements.DateTimeElement; /** * plot (rich_text) + * * Required: false - * Id: ad2e5dc7-8d08-4f74-afeb-25b475f1e6fc * Codename: plot + * Id: ad2e5dc7-8d08-4f74-afeb-25b475f1e6fc */ plot: Elements.RichTextElement; /** * title (text) + * * Required: false - * Id: 660c851a-a9a1-4378-97a3-1348bc2a4d76 * Codename: title + * Id: 660c851a-a9a1-4378-97a3-1348bc2a4d76 */ title: Elements.TextElement; }> & diff --git a/sample/delivery/content-types/test.ts b/sample/delivery/content-types/test.ts index 0802824..8780150 100644 --- a/sample/delivery/content-types/test.ts +++ b/sample/delivery/content-types/test.ts @@ -3,7 +3,7 @@ import type { MySnippet } from '../content-type-snippets/my_snippet.js'; /** * - * Migration Toolkit - tests + * Migration Toolkit tests * * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 @@ -18,9 +18,10 @@ import type { MySnippet } from '../content-type-snippets/my_snippet.js'; export type Test = IContentItem<{ /** * Text (text) + * * Required: false - * Id: 65f61f6a-b69c-47dc-bc38-19855507bf14 * Codename: text + * Id: 65f61f6a-b69c-47dc-bc38-19855507bf14 */ text: Elements.TextElement; }> & diff --git a/sample/delivery/taxonomies/category.ts b/sample/delivery/taxonomies/category.ts index 8c63181..5bbcaa6 100644 --- a/sample/delivery/taxonomies/category.ts +++ b/sample/delivery/taxonomies/category.ts @@ -1,6 +1,6 @@ /** * - * Migration Toolkit - tests + * Migration Toolkit tests * * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 diff --git a/sample/delivery/taxonomies/release_category.ts b/sample/delivery/taxonomies/release_category.ts index 448245b..714a6bd 100644 --- a/sample/delivery/taxonomies/release_category.ts +++ b/sample/delivery/taxonomies/release_category.ts @@ -1,6 +1,6 @@ /** * - * Migration Toolkit - tests + * Migration Toolkit tests * * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 From 5aee75ccaea68003ec270c201245e6ad5fd091b4 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 29 Aug 2024 08:59:45 +0200 Subject: [PATCH 030/183] Completes resolvers refactoring, renames file processor, improves delivery generator config --- lib/common-helper.ts | 107 ------- lib/core/core.models.ts | 7 +- lib/core/core.utils.ts | 2 +- lib/core/resolvers.ts | 267 ++++-------------- .../{file-processor.ts => file-manager.ts} | 6 +- lib/files/index.ts | 2 +- .../delivery-content-type.generator.ts | 119 +++----- lib/generators/delivery/delivery-func.ts | 82 ++++-- .../delivery/delivery-taxonomy.generator.ts | 81 ++---- lib/generators/migration/migration-func.ts | 27 +- .../migration/migration.generator.ts | 4 +- lib/generators/project/project-func.ts | 24 +- lib/models.ts | 61 ---- lib/node/cli/actions/delivery-action.ts | 2 +- lib/node/cli/actions/migrate-action.ts | 2 +- lib/node/cli/actions/project-action.ts | 2 +- .../content-type-snippets/my_snippet.ts | 4 +- .../taxonomy_snippet_test.ts | 2 +- sample/delivery/content-types/actor.ts | 4 +- scripts/tests/project-models.ts | 5 +- 20 files changed, 250 insertions(+), 560 deletions(-) delete mode 100644 lib/common-helper.ts rename lib/files/{file-processor.ts => file-manager.ts} (91%) diff --git a/lib/common-helper.ts b/lib/common-helper.ts deleted file mode 100644 index 301ce38..0000000 --- a/lib/common-helper.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { parse } from 'path'; -import { ContentTypeElements, TaxonomyModels } from '@kontent-ai/management-sdk'; -import { libMetadata } from './meta/index.js'; -import { ModuleResolution } from './models.js'; - -export class CommonHelper { - sortAlphabetically(arrayToSort: readonly T[], propertySelector: (item: T) => string): readonly T[] { - return arrayToSort.toSorted((a, b) => - propertySelector(a).toLowerCase().localeCompare(propertySelector(b).toLowerCase()) - ); - } - - getAutogenerateNote(addTimestamp: boolean): string { - if (addTimestamp) { - return `Generated by '${libMetadata.name}@${libMetadata.version}' at '${new Date().toUTCString()}'`; - } - - return `Generated by '${libMetadata.name}@${libMetadata.version}'`; - } - - getElementCodename(element: ContentTypeElements.ContentTypeElementModel): string | undefined { - return element.codename; - } - - isElementRequired(element: ContentTypeElements.ContentTypeElementModel): boolean { - const isRequired = (<{ is_required?: boolean }>element)['is_required']; - - return isRequired === true; - } - - getElementGuidelines(element: ContentTypeElements.ContentTypeElementModel): string | null { - const guidelines = (<{ guidelines?: string }>element)['guidelines']; - - if (!guidelines) { - return null; - } - - return guidelines; - } - - getImportStatement(data: { - filePathOrPackage: string; - importValue: string; - moduleResolution: ModuleResolution; - isExternalLib: boolean; - }): string { - let resolvedFilePath: string; - - if (data.moduleResolution === 'nodeNext' && !data.isExternalLib) { - resolvedFilePath = `${data.filePathOrPackage}.js`; - } else { - resolvedFilePath = data.filePathOrPackage; - } - - return `import { ${data.importValue} } from '${resolvedFilePath}';`; - } - - getElementTitle( - element: ContentTypeElements.ContentTypeElementModel, - taxonomies: readonly Readonly[] - ): string | null { - if (element.type === 'taxonomy') { - const taxonomyGroupId = element.taxonomy_group?.id; - - if (!taxonomyGroupId) { - return element.type; - } - - const taxonomy = taxonomies.find((m) => m.id === taxonomyGroupId); - - if (!taxonomy) { - return element.type; - } - - return taxonomy.name; - } - return (<{ name?: string }>element).name ?? null; - } - - getBarrelExportCode(data: { filenames: string[]; moduleResolution: ModuleResolution }): string { - let code = ''; - - if (data.filenames.length) { - for (let i = 0; i < data.filenames.length; i++) { - const isLast = i === data.filenames.length - 1; - const filename = data.filenames[i]; - const path = parse(filename); - const extension = data.moduleResolution === 'nodeNext' ? '.js' : ''; - code += `export * from '${path.dir}/${path.name}${extension}'`; - - if (!isLast) { - code += `\n`; - } - } - } else { - code = `export {}`; - } - - return code; - } - - escapeNameValue(value: string): string { - return value.replaceAll(`'`, `\\'`); - } -} - -export const commonHelper = new CommonHelper(); diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index 95dfe4e..1913bd7 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -6,12 +6,15 @@ import { IManagementClient, TaxonomyModels } from '@kontent-ai/management-sdk'; +import { PropertyNameResolver } from '@kontent-ai/delivery-sdk'; export type CliAction = 'delivery' | 'migration'; export type LibraryType = '@kontent-ai/migration-toolkit' | '@kontent-ai/delivery-sdk'; - +export type ModuleResolution = 'nodeNext' | 'node'; +export type CaseType = 'camelCase' | 'pascalCase' | 'snakeCase'; +export type ModelType = 'delivery' | 'migration'; +export type GeneratorElementResolver = CaseType | PropertyNameResolver; export type GeneratorManagementClient = Readonly>; - export type LiteralUnion = T | (string & NonNullable); export interface ErrorData { diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 369ff20..cd1a5ff 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -3,9 +3,9 @@ import { pascalCasePropertyNameResolver, snakeCasePropertyNameResolver } from '@kontent-ai/delivery-sdk'; -import { ModuleResolution } from '../models.js'; import { LibraryType, LiteralUnion } from './index.js'; import { parse } from 'path'; +import { ModuleResolution } from './core.models.js'; export function exitProgram(data: { readonly message: string }): never { throw Error(data.message); diff --git a/lib/core/resolvers.ts b/lib/core/resolvers.ts index c7b96db..d886bc0 100644 --- a/lib/core/resolvers.ts +++ b/lib/core/resolvers.ts @@ -5,109 +5,43 @@ import { ContentTypeElements, TaxonomyModels } from '@kontent-ai/management-sdk'; -import { commonHelper } from '../common-helper.js'; -import { - ContentTypeResolver, - ContentTypeSnippetResolver, - TaxonomyTypeResolver, - DefaultResolverType, - ElementResolver -} from '../models.js'; import { toCamelCase, toPascalCase, toSnakeCase } from './core.utils.js'; import { match } from 'ts-pattern'; +import { CaseType, GeneratorElementResolver } from './core.models.js'; export type ObjectWithCodename = { readonly codename: string; }; -export type ContentTypeFileNameResolver = FilenameResolver; -export type ContentTypeSnippetFileNameResolver = FilenameResolver; -export type TaxonomyTypeFileNameResolver = FilenameResolver; - -export type FilenameResolver = +/** File name resolvers */ +export type FilenameResolver> = | undefined - | DefaultResolverType + | CaseType | ((item: T & ObjectWithCodename) => string); -export type MapContentTypeToDeliveryTypeName = (contentType: Readonly) => string; -export type MapContentTypeSnippetToDeliveryTypeName = ( - contentTypeSnippet: Readonly -) => string; -export type MapContentTypeToFileName = ( - contentType: Readonly, - addExtension: boolean -) => string; -export type MapContentTypeSnippetToFileName = ( - contentTypeSnippet: Readonly, - addExtension: boolean -) => string; - export type MapObjectToFileName = ObjectWithCodename> = ( item: T, addExtension: boolean ) => string; -export type MapElementToName = (element: Readonly) => string | undefined; -export type MapTaxonomyName = (taxonomy: Readonly) => string; -export type MapTaxonomyToFileName = (taxonomy: Readonly, addExtension: boolean) => string; - -export function getMapContentTypeToDeliveryTypeName(resolver?: ContentTypeResolver): MapContentTypeToDeliveryTypeName { - return (contentType) => { - return getDeliveryContentTypeName({ - type: contentType, - contentTypeResolver: resolver - }); - }; -} - -export function getMapContentTypeSnippetToDeliveryTypeName( - resolver?: ContentTypeSnippetResolver -): MapContentTypeSnippetToDeliveryTypeName { - return (contentTypeSnippet) => { - return getDeliveryContentTypeSnippetName({ - snippet: contentTypeSnippet, - contentTypeResolver: resolver - }); - }; -} +export type ContentTypeFileNameResolver = FilenameResolver; +export type ContentTypeSnippetFileNameResolver = FilenameResolver; +export type TaxonomyTypeFileNameResolver = FilenameResolver; -export function getMapContentTypeToFileName(resolver?: ContentTypeFileNameResolver): MapContentTypeToFileName { - return (contentType, addExtension) => { - return match(resolver) - .returnType() - .when( - (resolver) => resolver instanceof Function, - (resolver) => `${resolver(contentType)}${addExtension ? '.ts' : ''}` - ) - .when( - (resolver) => resolver === undefined, - () => `${contentType.codename}` - ) - .otherwise((resolverType) => `${resolveTextWithDefaultResolver(contentType.codename, resolverType)}`); - }; -} +/** Name resolvers */ +export type NameResolver> = + | undefined + | CaseType + | ((item: T & ObjectWithCodename) => string); -export function getMapContentTypeSnippetToFileName( - resolver?: ContentTypeSnippetFileNameResolver -): MapContentTypeSnippetToFileName { - return (snippet, addExtension) => { - return addExtensionToFilename( - match(resolver) - .returnType() - .when( - (resolver) => resolver instanceof Function, - (resolver) => resolver(snippet) - ) - .when( - (resolver) => resolver === undefined, - () => snippet.codename - ) - .otherwise((resolverType) => `${resolveTextWithDefaultResolver(snippet.codename, resolverType)}`), +export type MapObjectToName = ObjectWithCodename> = (item: T) => string; - addExtension - ); - }; -} +export type ElementNameResolver = ( + element: Readonly +) => string | undefined; +export type ContentTypeNameResolver = NameResolver; +export type ContentTypeSnippetNameResolver = NameResolver; +export type TaxonomyNameResolver = NameResolver; export function mapFilename(resolver: FilenameResolver): MapObjectToFileName { return (item, addExtension) => { @@ -122,143 +56,66 @@ export function mapFilename(resolver: FilenameReso (resolver) => resolver === undefined, () => item.codename ) - .otherwise((resolverType) => `${resolveTextWithDefaultResolver(item.codename, resolverType)}`), + .otherwise((resolverType) => resolveCase(item.codename, resolverType)), addExtension ); }; } -function addExtensionToFilename(filename: string, addExtension: boolean): string { - return `${filename}${addExtension ? '.ts' : ''}`; +export function mapName( + resolver: NameResolver, + defaultCase: CaseType +): MapObjectToName { + return (item) => { + return match(resolver) + .returnType() + .when( + (resolver) => resolver instanceof Function, + (resolver) => resolver(item) + ) + .when( + (resolver) => resolver === undefined, + () => resolveCase(item.codename, defaultCase) + ) + .otherwise((resolverType) => resolveCase(item.codename, resolverType)); + }; } -export function getMapElementToName(resolver?: ElementResolver): MapElementToName { +export function mapElementName( + resolver: GeneratorElementResolver | undefined, + defaultCase: CaseType +): ElementNameResolver { return (element) => { - if (!element) { - return undefined; - } - - const codename = commonHelper.getElementCodename(element); + const codename = element.codename; if (!codename) { return undefined; } - const elementName = getElementName({ - elementCodename: codename, - elementResolver: resolver - }); - return elementName; - }; -} - -export function getMapTaxonomyName(resolver?: TaxonomyTypeResolver): MapTaxonomyName { - return (taxonomy) => { - return getDeliveryTaxonomyTypeName({ - taxonomy: taxonomy, - taxonomyResolver: resolver - }); - }; -} - -export function getMapTaxonomyToFileName(resolver?: TaxonomyTypeFileNameResolver): MapTaxonomyToFileName { - return (taxonomy, addExtension) => { - const fileName = getDeliveryTaxonomyFilename({ - taxonomy: taxonomy, - addExtension: addExtension, - fileResolver: resolver - }); - return `${fileName}`; + return match(resolver) + .returnType() + .when( + (resolver) => resolver instanceof Function, + (resolver) => resolver('', codename) + ) + .when( + (resolver) => resolver === undefined, + () => resolveCase(codename, defaultCase) + ) + .otherwise((resolverType) => resolveCase(codename, resolverType)); }; } -function getDeliveryContentTypeName(data: { - readonly type: Readonly; - readonly contentTypeResolver?: ContentTypeResolver; -}): string { - if (!data.contentTypeResolver) { - return toPascalCase(data.type.name); - } - - if (data.contentTypeResolver instanceof Function) { - return `${data.contentTypeResolver(data.type)}`; - } - - return `${resolveTextWithDefaultResolver(data.type.name, data.contentTypeResolver)}`; -} - -function getDeliveryContentTypeSnippetName(data: { - readonly snippet: Readonly; - readonly contentTypeResolver?: ContentTypeResolver; -}): string { - if (!data.contentTypeResolver) { - return toPascalCase(data.snippet.name); - } - - if (data.contentTypeResolver instanceof Function) { - return `${data.contentTypeResolver(data.snippet)}`; - } - - return `${resolveTextWithDefaultResolver(data.snippet.name, data.contentTypeResolver)}`; -} - -function getDeliveryTaxonomyFilename(data: { - readonly taxonomy: Readonly; - readonly fileResolver?: TaxonomyTypeFileNameResolver; - readonly addExtension: boolean; -}): string { - if (data.fileResolver instanceof Function) { - return `${data.fileResolver(data.taxonomy)}${data.addExtension ? '.ts' : ''}`; - } - - let filename: string; - - if (!data.fileResolver) { - filename = `${data.taxonomy.codename}`; - } else { - filename = `${resolveTextWithDefaultResolver(data.taxonomy.codename, data.fileResolver)}`; - } - - return `${filename}${data.addExtension ? '.ts' : ''}`; -} - -function getDeliveryTaxonomyTypeName(data: { - readonly taxonomy: Readonly; - readonly taxonomyResolver?: TaxonomyTypeResolver; -}): string { - if (!data.taxonomyResolver) { - return toPascalCase(data.taxonomy.name); - } - - if (data.taxonomyResolver instanceof Function) { - return `${data.taxonomyResolver(data.taxonomy)}`; - } - - return `${resolveTextWithDefaultResolver(data.taxonomy.name, data.taxonomyResolver)}`; -} - -function getElementName(config: { elementCodename: string; elementResolver?: ElementResolver }): string { - if (!config.elementResolver) { - return config.elementCodename; - } - - if (config.elementResolver instanceof Function) { - return config.elementResolver('', config.elementCodename); - } - - return resolveTextWithDefaultResolver(config.elementCodename, config.elementResolver); +function addExtensionToFilename(filename: string, addExtension: boolean): string { + return `${filename}${addExtension ? '.ts' : ''}`; } -function resolveTextWithDefaultResolver(text: string, resolverType: DefaultResolverType): string { - switch (resolverType) { - case 'camelCase': - return toCamelCase(text); - case 'pascalCase': - return toPascalCase(text); - case 'snakeCase': - return toSnakeCase(text); - default: - throw Error(`Invalid name resolver. Available options are: camelCase, pascalCase, snakeCase`); - } +function resolveCase(text: string, resolverType: CaseType): string { + return match(resolverType) + .returnType() + .with('camelCase', () => toCamelCase(text)) + .with('pascalCase', () => toPascalCase(text)) + .with('snakeCase', () => toSnakeCase(text)) + .exhaustive(); } diff --git a/lib/files/file-processor.ts b/lib/files/file-manager.ts similarity index 91% rename from lib/files/file-processor.ts rename to lib/files/file-manager.ts index 64cac4f..5b8339e 100644 --- a/lib/files/file-processor.ts +++ b/lib/files/file-manager.ts @@ -5,11 +5,11 @@ import * as fs from 'fs'; import { dirname } from 'path'; import { GeneratedFile } from '../core/index.js'; -export function fileProcessor(outputDir: string) { +export function fileManager(outputDir: string) { const createFileOnFsAsync = async ( text: string, filePath: string, - formatOptions: Options | undefined + formatOptions: Readonly | undefined ): Promise => { const fullFilePath = `${outputDir.endsWith('/') ? outputDir : `${outputDir}/`}${filePath}`; let fileContent = text; @@ -39,7 +39,7 @@ export function fileProcessor(outputDir: string) { const createFilesAsync = async ( files: readonly GeneratedFile[], - formatOptions: Options | undefined + formatOptions: Readonly | undefined ): Promise => { await Promise.all( files.map((file) => { diff --git a/lib/files/index.ts b/lib/files/index.ts index 2cfa898..217fc65 100644 --- a/lib/files/index.ts +++ b/lib/files/index.ts @@ -1 +1 @@ -export * from './file-processor.js'; +export * from './file-manager.js'; diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 2c702e4..05b9bf5 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -1,4 +1,3 @@ -import chalk from 'chalk'; import { match, P } from 'ts-pattern'; import { isNotUndefined } from '@kontent-ai/migration-toolkit'; import { @@ -7,33 +6,29 @@ import { EnvironmentModels, TaxonomyModels } from '@kontent-ai/management-sdk'; -import { - ContentTypeResolver, - ElementResolver, - TaxonomyTypeResolver, - ContentTypeSnippetResolver, - ModuleResolution -} from '../../models.js'; import { commentsManager as _commentsManager } from '../../comments/index.js'; import { ContentTypeFileNameResolver, + ContentTypeNameResolver, ContentTypeSnippetFileNameResolver, + ContentTypeSnippetNameResolver, deliveryConfig, FlattenedElement, GeneratedFile, getFlattenedElements, getImportStatement, - getMapContentTypeSnippetToDeliveryTypeName, - getMapContentTypeToDeliveryTypeName, - getMapElementToName, - getMapTaxonomyName, + mapElementName, mapFilename, + mapName, removeLineEndings, sortAlphabetically, TaxonomyTypeFileNameResolver, + TaxonomyNameResolver, toSafeString, - uniqueFilter + uniqueFilter, + ModuleResolution, + GeneratorElementResolver } from '../../core/index.js'; interface ExtractImportsResult { @@ -43,21 +38,29 @@ interface ExtractImportsResult { } export interface DeliveryContentTypeGeneratorConfig { - readonly typeFolderName: string; - readonly typeSnippetsFolderName: string; - readonly taxonomyFolderName: string; - readonly addTimestamp: boolean; readonly addEnvironmentInfo: boolean; - readonly elementResolver?: ElementResolver; - readonly contentTypeFileNameResolver?: ContentTypeFileNameResolver; - readonly contentTypeSnippetFileNameResolver?: ContentTypeSnippetFileNameResolver; - readonly contentTypeResolver?: ContentTypeResolver; - readonly contentTypeSnippetResolver?: ContentTypeSnippetResolver; - readonly taxonomyFileResolver?: TaxonomyTypeFileNameResolver; - readonly taxonomyResolver?: TaxonomyTypeResolver; readonly moduleResolution: ModuleResolution; + readonly folders: { + readonly typeFolderName: string; + readonly typeSnippetsFolderName: string; + readonly taxonomyFolderName: string; + }; + + readonly fileResolvers: { + readonly contentTypeFileResolver?: ContentTypeFileNameResolver; + readonly contentTypeSnippetFileResolver?: ContentTypeSnippetFileNameResolver; + readonly taxonomyFileResolver?: TaxonomyTypeFileNameResolver; + }; + + readonly nameResolvers: { + readonly contentTypeNameResolver?: ContentTypeNameResolver; + readonly snippetNameResolver?: ContentTypeSnippetNameResolver; + readonly taxonomyNameResolver?: TaxonomyNameResolver; + readonly elementNameResolver?: GeneratorElementResolver; + }; + readonly environmentData: { readonly environment: Readonly; readonly types: readonly Readonly[]; @@ -70,63 +73,19 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato const commentsManager = _commentsManager(config.addTimestamp); // prepare resolvers - const contentTypeSnippetFileNameMap = mapFilename(config.contentTypeSnippetFileNameResolver); - const contentTypeFileNameMap = mapFilename(config.contentTypeFileNameResolver); - const taxonomyFileNameMap = mapFilename(config.taxonomyFileResolver); + const contentTypeSnippetFileNameMap = mapFilename(config.fileResolvers.contentTypeSnippetFileResolver); + const contentTypeFileNameMap = mapFilename(config.fileResolvers.contentTypeFileResolver); + const taxonomyFileNameMap = mapFilename(config.fileResolvers.taxonomyFileResolver); - const contentTypeSnippetNameMap = getMapContentTypeSnippetToDeliveryTypeName(config.contentTypeSnippetResolver); - const contentTypeNameMap = getMapContentTypeToDeliveryTypeName(config.contentTypeResolver); - const elementNameMap = getMapElementToName(config.elementResolver); - const taxonomyNameMap = getMapTaxonomyName(config.taxonomyResolver); + const contentTypeSnippetNameMap = mapName(config.nameResolvers.snippetNameResolver, 'pascalCase'); + const contentTypeNameMap = mapName(config.nameResolvers.contentTypeNameResolver, 'pascalCase'); + const elementNameMap = mapElementName(config.nameResolvers.elementNameResolver, 'camelCase'); + const taxonomyNameMap = mapName(config.nameResolvers.taxonomyNameResolver, 'pascalCase'); const generateModels = (): { contentTypeFiles: readonly GeneratedFile[]; snippetFiles: readonly GeneratedFile[]; } => { - if (config.elementResolver) { - console.log( - `Using '${chalk.yellow( - config.elementResolver instanceof Function ? 'custom' : config.elementResolver - )}' name resolver for content type elements` - ); - } - - if (config.contentTypeFileNameResolver) { - console.log( - `Using '${chalk.yellow( - config.contentTypeFileNameResolver instanceof Function - ? 'custom' - : config.contentTypeFileNameResolver - )}' name resolver for content type filenames` - ); - } - - if (config.contentTypeSnippetFileNameResolver) { - console.log( - `Using '${chalk.yellow( - config.contentTypeSnippetFileNameResolver instanceof Function - ? 'custom' - : config.contentTypeSnippetFileNameResolver - )}' name resolver for content type snippet filenames` - ); - } - - if (config.contentTypeResolver) { - console.log( - `Using '${chalk.yellow( - config.contentTypeResolver instanceof Function ? 'custom' : config.contentTypeResolver - )}' name resolver for content types` - ); - } - - if (config.contentTypeSnippetResolver) { - console.log( - `Using '${chalk.yellow( - config.contentTypeSnippetResolver instanceof Function ? 'custom' : config.contentTypeSnippetResolver - )}' name resolver for content type snippets` - ); - } - return { contentTypeFiles: config.environmentData.types.map((type) => createContentTypeModel(type)), snippetFiles: config.environmentData.snippets.map((contentTypeSnippet) => @@ -141,7 +100,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato return snippets.map((snippet) => { return getImportStatement({ moduleResolution: config.moduleResolution, - filePathOrPackage: `../${config.typeSnippetsFolderName}/${contentTypeSnippetFileNameMap( + filePathOrPackage: `../${config.folders.typeSnippetsFolderName}/${contentTypeSnippetFileNameMap( snippet, false )}.ts`, @@ -167,7 +126,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato } return getImportStatement({ moduleResolution: config.moduleResolution, - filePathOrPackage: `../${config.taxonomyFolderName}/${taxonomyFileNameMap(taxonomyElement.assignedTaxonomy, false)}.ts`, + filePathOrPackage: `../${config.folders.taxonomyFolderName}/${taxonomyFileNameMap(taxonomyElement.assignedTaxonomy, false)}.ts`, importValue: taxonomyNameMap(taxonomyElement.assignedTaxonomy) }); }) @@ -189,7 +148,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato moduleResolution: config.moduleResolution, filePathOrPackage: typeOrSnippet instanceof ContentTypeModels.ContentType - ? `../${config.typeFolderName}/${referencedTypeFilename}.ts` + ? `../${config.folders.typeFolderName}/${referencedTypeFilename}.ts` : `./${referencedTypeFilename}.ts`, importValue: `${contentTypeNameMap(allowedContentType)}` }); @@ -277,7 +236,7 @@ export type ${contentTypeImports.typeName} = IContentItem<{ const createContentTypeModel = (type: Readonly): GeneratedFile => { return { - filename: `${config.typeFolderName}/${contentTypeFileNameMap(type, true)}`, + filename: `${config.folders.typeFolderName}/${contentTypeFileNameMap(type, true)}`, text: getModelCode(type) }; }; @@ -286,7 +245,7 @@ export type ${contentTypeImports.typeName} = IContentItem<{ snippet: Readonly ): GeneratedFile => { return { - filename: `${config.typeSnippetsFolderName}/${contentTypeSnippetFileNameMap(snippet, true)}`, + filename: `${config.folders.typeSnippetsFolderName}/${contentTypeSnippetFileNameMap(snippet, true)}`, text: getModelCode(snippet) }; }; diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index 3dcdecd..8e44bff 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -1,13 +1,45 @@ import chalk from 'chalk'; -import { GenerateDeliveryModelsConfig, ModuleResolution } from '../../models.js'; import { deliveryContentTypeGenerator } from './delivery-content-type.generator.js'; import { deliveryTaxonomyGenerator } from './delivery-taxonomy.generator.js'; -import { fileProcessor as _fileProcessor } from '../../files/index.js'; +import { fileManager as _fileManager } from '../../files/index.js'; import { parse } from 'path'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; -import { coreConfig, deliveryConfig, GeneratedFile, getBarrelExportCode, toOutputDirPath } from '../../core/index.js'; +import { + ContentTypeFileNameResolver, + ContentTypeNameResolver, + ContentTypeSnippetFileNameResolver, + ContentTypeSnippetNameResolver, + coreConfig, + deliveryConfig, + GeneratorElementResolver, + GeneratedFile, + getBarrelExportCode, + ModuleResolution, + TaxonomyNameResolver, + TaxonomyTypeFileNameResolver, + toOutputDirPath +} from '../../core/index.js'; import { Options } from 'prettier'; +export interface GenerateDeliveryModelsConfig { + readonly environmentId: string; + readonly addTimestamp: boolean; + readonly addEnvironmentInfo: boolean; + readonly apiKey: string; + + readonly moduleResolution?: ModuleResolution; + readonly baseUrl?: string; + readonly outputDir?: string; + readonly contentTypeFileResolver?: ContentTypeFileNameResolver; + readonly contentTypeSnippetFileResolver?: ContentTypeSnippetFileNameResolver; + readonly taxonomyTypeFileResolver?: TaxonomyTypeFileNameResolver; + readonly contentTypeResolver?: ContentTypeNameResolver; + readonly contentTypeSnippetResolver?: ContentTypeSnippetNameResolver; + readonly taxonomyTypeResolver?: TaxonomyNameResolver; + readonly elementResolver?: GeneratorElementResolver; + readonly formatOptions?: Readonly; +} + export async function generateDeliveryModelsAsync(config: GenerateDeliveryModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('delivery')}' models\n`); @@ -29,37 +61,49 @@ export async function generateDeliveryModelsAsync(config: GenerateDeliveryModels // create content type models const deliveryModels = deliveryContentTypeGenerator({ - typeFolderName: contentTypesFolderName, - taxonomyFolderName: taxonomiesFolderName, - typeSnippetsFolderName: contentTypeSnippetsFolderName, addTimestamp: config.addTimestamp, addEnvironmentInfo: config.addEnvironmentInfo, - elementResolver: config.elementResolver, - contentTypeFileNameResolver: config.contentTypeFileResolver, - contentTypeResolver: config.contentTypeResolver, - taxonomyFileResolver: config.taxonomyTypeFileResolver, - taxonomyResolver: config.taxonomyTypeResolver, - contentTypeSnippetFileNameResolver: config.contentTypeSnippetFileResolver, - contentTypeSnippetResolver: config.contentTypeSnippetResolver, moduleResolution: moduleResolution, environmentData: { environment: environment, types: await kontentFetcher.getTypesAsync(), snippets: await kontentFetcher.getSnippetsAsync(), taxonomies: taxonomies + }, + folders: { + typeFolderName: contentTypesFolderName, + taxonomyFolderName: taxonomiesFolderName, + typeSnippetsFolderName: contentTypeSnippetsFolderName + }, + fileResolvers: { + taxonomyFileResolver: config.taxonomyTypeFileResolver, + contentTypeFileResolver: config.contentTypeFileResolver, + contentTypeSnippetFileResolver: config.contentTypeSnippetFileResolver + }, + nameResolvers: { + elementNameResolver: config.elementResolver, + contentTypeNameResolver: config.contentTypeResolver, + taxonomyNameResolver: config.taxonomyTypeResolver, + snippetNameResolver: config.contentTypeSnippetResolver } }).generateModels(); // create taxonomy types const taxonomyFiles = deliveryTaxonomyGenerator({ - taxonomyFolderName: taxonomiesFolderName, addTimestamp: config.addTimestamp, - fileResolver: config.taxonomyTypeFileResolver, - taxonomyResolver: config.taxonomyTypeResolver, moduleResolution: moduleResolution, environmentData: { environment: await kontentFetcher.getEnvironmentInfoAsync(), taxonomies: taxonomies + }, + fileResolvers: { + taxonomyFilenameResolver: config.taxonomyTypeFileResolver + }, + folders: { + taxonomyFolderName: taxonomiesFolderName + }, + nameResolvers: { + taxonomyNameResolver: config.taxonomyTypeResolver } }).generateTaxonomyTypes(); @@ -93,7 +137,7 @@ async function createDeliveryFilesAsync( config: { readonly outputDir: string | undefined; readonly moduleResolution: ModuleResolution; - readonly formatOptions: Options | undefined; + readonly formatOptions: Readonly | undefined; }, folders: { readonly contentTypesFolderName: string; @@ -101,9 +145,9 @@ async function createDeliveryFilesAsync( readonly taxonomiesFolderName: string; } ): Promise { - const fileProcessor = _fileProcessor(toOutputDirPath(config.outputDir)); + const fileManager = _fileManager(toOutputDirPath(config.outputDir)); - await fileProcessor.createFilesAsync( + await fileManager.createFilesAsync( [ ...data.contentTypeFiles, ...data.snippetFiles, diff --git a/lib/generators/delivery/delivery-taxonomy.generator.ts b/lib/generators/delivery/delivery-taxonomy.generator.ts index 739887f..3035129 100644 --- a/lib/generators/delivery/delivery-taxonomy.generator.ts +++ b/lib/generators/delivery/delivery-taxonomy.generator.ts @@ -1,26 +1,30 @@ -import { ModuleResolution, TaxonomyTypeResolver } from '../../models.js'; -import chalk from 'chalk'; import { EnvironmentModels, TaxonomyModels } from '@kontent-ai/management-sdk'; import { GeneratedFile, - getMapTaxonomyName, - getMapTaxonomyToFileName, - MapTaxonomyName, - MapTaxonomyToFileName, + mapFilename, + mapName, sortAlphabetically, TaxonomyTypeFileNameResolver, - toSafeString + TaxonomyNameResolver, + toSafeString, + ModuleResolution } from '../../core/index.js'; import { commentsManager as _commentsManager } from '../../comments/index.js'; export interface DeliveryTaxonomyGeneratorConfig { readonly addTimestamp: boolean; readonly moduleResolution: ModuleResolution; - readonly fileResolver?: TaxonomyTypeFileNameResolver; - readonly taxonomyResolver?: TaxonomyTypeResolver; - readonly taxonomyFolderName: string; + readonly folders: { + readonly taxonomyFolderName: string; + }; + readonly fileResolvers: { + readonly taxonomyFilenameResolver?: TaxonomyTypeFileNameResolver; + }; + readonly nameResolvers: { + readonly taxonomyNameResolver?: TaxonomyNameResolver; + }; readonly environmentData: { readonly environment: Readonly; readonly taxonomies: readonly Readonly[]; @@ -29,68 +33,33 @@ export interface DeliveryTaxonomyGeneratorConfig { export function deliveryTaxonomyGenerator(config: DeliveryTaxonomyGeneratorConfig) { const commentsManager = _commentsManager(config.addTimestamp); + const taxonomyFileNameMap = mapFilename(config.fileResolvers.taxonomyFilenameResolver); + const taxonomyNameMap = mapName(config.nameResolvers.taxonomyNameResolver, 'pascalCase'); const generateTaxonomyTypes = (): readonly GeneratedFile[] => { - if (config.taxonomyResolver) { - console.log( - `Using '${chalk.yellow( - config.taxonomyResolver instanceof Function ? 'custom' : config.taxonomyResolver - )}' name resolver for taxonomy type` - ); - } - - if (config.fileResolver) { - console.log( - `Using '${chalk.yellow( - config.fileResolver instanceof Function ? 'custom' : config.fileResolver - )}' name resolver for taxonomy filename` - ); - } - - if (config.fileResolver || config.taxonomyResolver) { - console.log('\n'); - } - return config.environmentData.taxonomies.map((taxonomy) => { - return getTaxonomyFile({ - taxonomy: taxonomy, - taxonomyFileNameMap: getMapTaxonomyToFileName(config.fileResolver), - taxonomyNameMap: getMapTaxonomyName(config.taxonomyResolver) - }); + return getTaxonomyFile(taxonomy); }); }; - const getTaxonomyFile = (data: { - readonly taxonomy: Readonly; - readonly taxonomyFileNameMap: MapTaxonomyToFileName; - readonly taxonomyNameMap: MapTaxonomyName; - }): GeneratedFile => { - const filename = `${config.taxonomyFolderName}/${data.taxonomyFileNameMap(data.taxonomy, true)}`; - const code = getModelCode({ - taxonomy: data.taxonomy, - taxonomyNameMap: data.taxonomyNameMap - }); - + const getTaxonomyFile = (taxonomy: Readonly): GeneratedFile => { return { - filename: filename, - text: code + filename: `${config.folders.taxonomyFolderName}/${taxonomyFileNameMap(taxonomy, true)}`, + text: getModelCode(taxonomy) }; }; - const getModelCode = (data: { - readonly taxonomyNameMap: MapTaxonomyName; - readonly taxonomy: Readonly; - }): string => { + const getModelCode = (taxonomy: Readonly): string => { return ` ${commentsManager.environmentInfo(config.environmentData.environment)} /** - * ${toSafeString(data.taxonomy.name)} + * ${toSafeString(taxonomy.name)} * - * Codename: ${data.taxonomy.codename} - * Id: ${data.taxonomy.id} + * Codename: ${taxonomy.codename} + * Id: ${taxonomy.id} */ -export type ${data.taxonomyNameMap(data.taxonomy)} = ${getTaxonomyTermsCode(data.taxonomy)}; +export type ${taxonomyNameMap(taxonomy)} = ${getTaxonomyTermsCode(taxonomy)}; `; }; diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index e5f9082..d9fc069 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -1,17 +1,34 @@ import chalk from 'chalk'; -import { migrationConfig, coreConfig, toOutputDirPath, getBarrelExportCode } from '../../core/index.js'; -import { fileProcessor as _fileProcessor } from '../../files/index.js'; +import { + migrationConfig, + coreConfig, + toOutputDirPath, + getBarrelExportCode, + ModuleResolution +} from '../../core/index.js'; +import { fileManager as _fileManager } from '../../files/index.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; import { migrationGenerator as _migrationGenerator } from './migration.generator.js'; -import { GenerateMigrationModelsConfig, ModuleResolution } from '../../models.js'; import { parse } from 'path'; +import { Options } from 'prettier'; + +export interface GenerateMigrationModelsConfig { + readonly environmentId: string; + readonly addTimestamp: boolean; + readonly apiKey: string; + readonly moduleResolution: ModuleResolution; + readonly outputDir: string; + + readonly baseUrl?: string; + readonly formatOptions?: Readonly; +} export async function generateMigrationModelsAsync(config: GenerateMigrationModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('migration')}' models\n`); const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; - const fileProcessor = _fileProcessor(toOutputDirPath(config.outputDir)); + const fileManager = _fileManager(toOutputDirPath(config.outputDir)); const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, @@ -43,7 +60,7 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode migrationItemsFolderName ); - await fileProcessor.createFilesAsync( + await fileManager.createFilesAsync( [ migrationTypeFile, ...migrationItemFiles, diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index ca0d07a..0b2db3a 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -17,9 +17,9 @@ import { removeLineEndings, toPascalCase, getFlattenedElements, - migrationConfig + migrationConfig, + ModuleResolution } from '../../core/index.js'; -import { ModuleResolution } from '../../models.js'; import { commentsManager as _commentsManager } from '../../comments/index.js'; export interface MigrationGeneratorConfig { diff --git a/lib/generators/project/project-func.ts b/lib/generators/project/project-func.ts index 697edba..35b8c0c 100644 --- a/lib/generators/project/project-func.ts +++ b/lib/generators/project/project-func.ts @@ -1,17 +1,29 @@ import chalk from 'chalk'; -import { GeneratProjectModelsConfig, ModuleResolution } from '../../models.js'; import { projectGenerator as _projectGenerator } from './project.generator.js'; -import { fileProcessor as _fileProcessor } from '../../files/index.js'; +import { fileManager as _fileManager } from '../../files/index.js'; import { parse } from 'path'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; -import { coreConfig, getBarrelExportCode, toOutputDirPath } from '../../core/index.js'; +import { coreConfig, getBarrelExportCode, ModuleResolution, toOutputDirPath } from '../../core/index.js'; +import { Options } from 'prettier'; -export async function generateProjectModelsAsync(config: GeneratProjectModelsConfig): Promise { +export interface GenerateProjectModelsConfig { + readonly environmentId: string; + readonly addTimestamp: boolean; + readonly isEnterpriseSubscription: boolean; + readonly apiKey: string; + + readonly moduleResolution?: ModuleResolution; + readonly baseUrl?: string; + readonly outputDir?: string; + readonly formatOptions?: Readonly; +} + +export async function generateProjectModelsAsync(config: GenerateProjectModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('project')}' models\n`); const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; - const fileProcessor = _fileProcessor(toOutputDirPath(config.outputDir)); + const fileManager = _fileManager(toOutputDirPath(config.outputDir)); const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, @@ -37,7 +49,7 @@ export async function generateProjectModelsAsync(config: GeneratProjectModelsCon } }).generateProjectModel(); - await fileProcessor.createFilesAsync( + await fileManager.createFilesAsync( [ ...projectFiles, // barrel file diff --git a/lib/models.ts b/lib/models.ts index 477b6f6..139597f 100644 --- a/lib/models.ts +++ b/lib/models.ts @@ -1,63 +1,2 @@ -import { PropertyNameResolver } from '@kontent-ai/delivery-sdk'; -import { ContentTypeModels, ContentTypeSnippetModels, TaxonomyModels } from '@kontent-ai/management-sdk'; -import { Options } from 'prettier'; -import { - ContentTypeFileNameResolver, - ContentTypeSnippetFileNameResolver, - TaxonomyTypeFileNameResolver -} from './core/index.js'; -export type ModuleResolution = 'nodeNext' | 'node'; -export type DefaultResolverType = 'camelCase' | 'pascalCase' | 'snakeCase'; -export type ModelType = 'delivery' | 'migration'; -export type ElementResolver = DefaultResolverType | PropertyNameResolver; -export type ContentTypeResolver = - | DefaultResolverType - | ((contentType: Readonly) => string); -export type ContentTypeSnippetResolver = - | DefaultResolverType - | ((contentTypeSnippet: ContentTypeSnippetModels.ContentTypeSnippet) => string); -export type TaxonomyTypeResolver = DefaultResolverType | ((taxonomy: Readonly) => string); - -export interface GenerateDeliveryModelsConfig { - readonly environmentId: string; - readonly addTimestamp: boolean; - readonly addEnvironmentInfo: boolean; - readonly apiKey: string; - - readonly moduleResolution?: ModuleResolution; - readonly baseUrl?: string; - readonly outputDir?: string; - readonly contentTypeFileResolver?: ContentTypeFileNameResolver; - readonly contentTypeSnippetFileResolver?: ContentTypeSnippetFileNameResolver; - readonly taxonomyTypeFileResolver?: TaxonomyTypeFileNameResolver; - readonly contentTypeResolver?: ContentTypeResolver; - readonly contentTypeSnippetResolver?: ContentTypeSnippetResolver; - readonly taxonomyTypeResolver?: TaxonomyTypeResolver; - readonly elementResolver?: ElementResolver; - readonly formatOptions?: Options; -} - -export interface GeneratProjectModelsConfig { - readonly environmentId: string; - readonly addTimestamp: boolean; - readonly isEnterpriseSubscription: boolean; - readonly apiKey: string; - - readonly moduleResolution?: ModuleResolution; - readonly baseUrl?: string; - readonly outputDir?: string; - readonly formatOptions?: Options; -} - -export interface GenerateMigrationModelsConfig { - readonly environmentId: string; - readonly addTimestamp: boolean; - readonly apiKey: string; - readonly moduleResolution: ModuleResolution; - readonly outputDir: string; - - readonly baseUrl?: string; - readonly formatOptions?: Options; -} diff --git a/lib/node/cli/actions/delivery-action.ts b/lib/node/cli/actions/delivery-action.ts index 1497852..3372b8e 100644 --- a/lib/node/cli/actions/delivery-action.ts +++ b/lib/node/cli/actions/delivery-action.ts @@ -1,5 +1,5 @@ +import { ModuleResolution } from '../../../core/index.js'; import { generateDeliveryModelsAsync } from '../../../generators/index.js'; -import { ModuleResolution } from '../../../models.js'; import { CliArgumentsFetcher } from '../cli.models.js'; export async function deliveryActionAsync(cliFetcher: CliArgumentsFetcher): Promise { diff --git a/lib/node/cli/actions/migrate-action.ts b/lib/node/cli/actions/migrate-action.ts index cc8c562..cc05967 100644 --- a/lib/node/cli/actions/migrate-action.ts +++ b/lib/node/cli/actions/migrate-action.ts @@ -1,5 +1,5 @@ +import { ModuleResolution } from '../../../core/index.js'; import { generateMigrationModelsAsync } from '../../../generators/index.js'; -import { ModuleResolution } from '../../../models.js'; import { CliArgumentsFetcher } from '../cli.models.js'; export async function migrateActionAsync(cliFetcher: CliArgumentsFetcher): Promise { diff --git a/lib/node/cli/actions/project-action.ts b/lib/node/cli/actions/project-action.ts index 8909b51..1331d92 100644 --- a/lib/node/cli/actions/project-action.ts +++ b/lib/node/cli/actions/project-action.ts @@ -1,5 +1,5 @@ +import { ModuleResolution } from '../../../core/index.js'; import { generateProjectModelsAsync } from '../../../generators/index.js'; -import { ModuleResolution } from '../../../models.js'; import { CliArgumentsFetcher } from '../cli.models.js'; export async function projectActionAsync(cliFetcher: CliArgumentsFetcher): Promise { diff --git a/sample/delivery/content-type-snippets/my_snippet.ts b/sample/delivery/content-type-snippets/my_snippet.ts index 855cafa..642b9b6 100644 --- a/sample/delivery/content-type-snippets/my_snippet.ts +++ b/sample/delivery/content-type-snippets/my_snippet.ts @@ -22,7 +22,7 @@ export type MySnippet = IContentItem<{ * Codename: my_snippet__snippet_elem1 * Id: 3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d */ - my_snippet__snippet_elem1: Elements.TextElement; + mySnippetSnippetElem1: Elements.TextElement; /** * Snippet elem 2 (number) @@ -31,5 +31,5 @@ export type MySnippet = IContentItem<{ * Codename: my_snippet__snippet_elem_2 * Id: b2f65646-3310-4a64-af2a-0d9d025a91d0 */ - my_snippet__snippet_elem_2: Elements.NumberElement; + mySnippetSnippetElem2: Elements.NumberElement; }>; diff --git a/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts b/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts index 2f25b78..29371a0 100644 --- a/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts +++ b/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts @@ -23,5 +23,5 @@ export type TaxonomySnippetTest = IContentItem<{ * Codename: taxonomy_snippet_test__test_taxonomy * Id: c030e3ec-5031-4d7f-af88-5032365733c7 */ - taxonomy_snippet_test__test_taxonomy: Elements.TaxonomyElement; + taxonomySnippetTestTestTaxonomy: Elements.TaxonomyElement; }>; diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index 72bddd0..bb7881c 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -40,7 +40,7 @@ export type Actor = IContentItem<{ * Codename: last_name * Id: 0f00b26e-60f3-462d-8110-18180137c3a0 */ - last_name: Elements.TextElement; + lastName: Elements.TextElement; /** * first_name (text) @@ -49,5 +49,5 @@ export type Actor = IContentItem<{ * Codename: first_name * Id: 4af5e7ce-88ef-4159-96ae-96a552992f91 */ - first_name: Elements.TextElement; + firstName: Elements.TextElement; }>; diff --git a/scripts/tests/project-models.ts b/scripts/tests/project-models.ts index 953e3ef..ca601f0 100644 --- a/scripts/tests/project-models.ts +++ b/scripts/tests/project-models.ts @@ -31,10 +31,7 @@ const run = async () => { apiKey: apiKey, moduleResolution: moduleResolution?.toLowerCase() === 'node' ? 'node' : 'nodeNext', isEnterpriseSubscription: true, - outputDir: outputDir, - sortConfig: { - sortTaxonomyTerms: true - } + outputDir: outputDir }); }; From ce3a64ad7bf22e567070d68b5ce23c7c2556cd96 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 29 Aug 2024 09:01:28 +0200 Subject: [PATCH 031/183] Refactors format helper --- lib/files/file-manager.ts | 4 ++-- lib/format-helper.ts | 22 ---------------------- lib/format/formatter.ts | 18 ++++++++++++++++++ lib/format/index.ts | 1 + lib/index.ts | 2 +- 5 files changed, 22 insertions(+), 25 deletions(-) delete mode 100644 lib/format-helper.ts create mode 100644 lib/format/formatter.ts create mode 100644 lib/format/index.ts diff --git a/lib/files/file-manager.ts b/lib/files/file-manager.ts index 5b8339e..ae3e0d5 100644 --- a/lib/files/file-manager.ts +++ b/lib/files/file-manager.ts @@ -1,6 +1,6 @@ import chalk from 'chalk'; import { Options } from 'prettier'; -import { formatHelper } from '../format-helper.js'; +import { formatCodeAsync } from '../format/formatter.js'; import * as fs from 'fs'; import { dirname } from 'path'; import { GeneratedFile } from '../core/index.js'; @@ -14,7 +14,7 @@ export function fileManager(outputDir: string) { const fullFilePath = `${outputDir.endsWith('/') ? outputDir : `${outputDir}/`}${filePath}`; let fileContent = text; try { - fileContent = await formatHelper.formatCodeAsync(fileContent, formatOptions); + fileContent = await formatCodeAsync(fileContent, formatOptions); } catch { console.log(`Failed to format file '${chalk.red(filePath)}'. Skipping prettier for this file.`); } finally { diff --git a/lib/format-helper.ts b/lib/format-helper.ts deleted file mode 100644 index 5617c8e..0000000 --- a/lib/format-helper.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Options, format } from 'prettier'; - -export class FormatHelper { - async formatCodeAsync(code: string, options?: Options): Promise { - const formatOptions: Options = options - ? options - : { - parser: 'typescript', - singleQuote: true, - printWidth: 120, - tabWidth: 4, - useTabs: false, - trailingComma: 'none', - bracketSpacing: true, - semi: true - }; - - return await format(code, formatOptions); - } -} - -export const formatHelper = new FormatHelper(); diff --git a/lib/format/formatter.ts b/lib/format/formatter.ts new file mode 100644 index 0000000..3032582 --- /dev/null +++ b/lib/format/formatter.ts @@ -0,0 +1,18 @@ +import { Options, format } from 'prettier'; + +export async function formatCodeAsync(code: string, options?: Readonly): Promise { + const formatOptions: Options = options + ? options + : { + parser: 'typescript', + singleQuote: true, + printWidth: 120, + tabWidth: 4, + useTabs: false, + trailingComma: 'none', + bracketSpacing: true, + semi: true + }; + + return await format(code, formatOptions); +} diff --git a/lib/format/index.ts b/lib/format/index.ts new file mode 100644 index 0000000..435d9c4 --- /dev/null +++ b/lib/format/index.ts @@ -0,0 +1 @@ +export * from './formatter.js'; diff --git a/lib/index.ts b/lib/index.ts index f376a21..d367190 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,6 +1,6 @@ -export * from './common-helper.js'; export * from './models.js'; export * from './core/index.js'; export * from './files/index.js'; +export * from './format/index.js'; export * from './comments/index.js'; export * from './generators/index.js'; From bc5de593acc14135c5a9a519a32898807efcc9bb Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 29 Aug 2024 09:03:01 +0200 Subject: [PATCH 032/183] Removes models file --- lib/index.ts | 1 - lib/models.ts | 2 -- 2 files changed, 3 deletions(-) delete mode 100644 lib/models.ts diff --git a/lib/index.ts b/lib/index.ts index d367190..91a18ed 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,4 +1,3 @@ -export * from './models.js'; export * from './core/index.js'; export * from './files/index.js'; export * from './format/index.js'; diff --git a/lib/models.ts b/lib/models.ts deleted file mode 100644 index 139597f..0000000 --- a/lib/models.ts +++ /dev/null @@ -1,2 +0,0 @@ - - From a0dd8b11607a547fad7122894fb32f4e0bbbcd6d Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 29 Aug 2024 09:05:29 +0200 Subject: [PATCH 033/183] Removes delivery mappers --- lib/generators/delivery/delivery-func.ts | 1 - lib/generators/delivery/delivery-mappers.ts | 0 2 files changed, 1 deletion(-) delete mode 100644 lib/generators/delivery/delivery-mappers.ts diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index 8e44bff..2e4ab11 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -56,7 +56,6 @@ export async function generateDeliveryModelsAsync(config: GenerateDeliveryModels const taxonomiesFolderName: string = deliveryConfig.taxonomiesFolderName; const environment = await kontentFetcher.getEnvironmentInfoAsync(); - const taxonomies = await kontentFetcher.getTaxonomiesAsync(); // create content type models diff --git a/lib/generators/delivery/delivery-mappers.ts b/lib/generators/delivery/delivery-mappers.ts deleted file mode 100644 index e69de29..0000000 From 679047d3bdbd0ed393f98c27e61f2a4a5738cbc0 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 29 Aug 2024 09:53:26 +0200 Subject: [PATCH 034/183] Unifies and simplifies generator functions --- lib/core/core.utils.ts | 7 + .../delivery-content-type.generator.ts | 80 ++++++----- lib/generators/delivery/delivery-func.ts | 126 ++++++++---------- .../delivery/delivery-taxonomy.generator.ts | 25 ++-- lib/generators/index.ts | 1 - lib/generators/migration/migration-func.ts | 68 +++++++--- .../migration/migration.generator.ts | 22 ++- lib/generators/project/project-func.ts | 74 ++++++---- lib/generators/project/project.generator.ts | 10 +- lib/node/cli/actions/delivery-action.ts | 10 +- lib/node/cli/actions/migrate-action.ts | 2 +- lib/node/cli/actions/project-action.ts | 2 +- sample/migration/content-types/actor.ts | 35 +++-- sample/migration/content-types/index.ts | 1 + sample/migration/content-types/movie.ts | 81 ++++++----- sample/migration/content-types/test.ts | 40 ++++++ sample/migration/core.models.ts | 19 ++- 17 files changed, 339 insertions(+), 264 deletions(-) create mode 100644 sample/migration/content-types/test.ts diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index cd1a5ff..8dbbc1f 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -70,6 +70,13 @@ export function removeLineEndings(value: string): string { return value.replace(/(\r\n|\n|\r)/gm, ''); } +export function getStringOrUndefined(text?: string): string { + if (!text) { + return 'undefined'; + } + return `'${text}'`; +} + export function toSafeStringCode(text: string): string { const replaceContent = ''; return text.replace(/[\s-]/g, replaceContent).replace(/[^a-zA-Z0-9_]/g, replaceContent); diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 05b9bf5..37f7b96 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -42,45 +42,43 @@ export interface DeliveryContentTypeGeneratorConfig { readonly addEnvironmentInfo: boolean; readonly moduleResolution: ModuleResolution; - readonly folders: { - readonly typeFolderName: string; - readonly typeSnippetsFolderName: string; - readonly taxonomyFolderName: string; - }; - - readonly fileResolvers: { - readonly contentTypeFileResolver?: ContentTypeFileNameResolver; - readonly contentTypeSnippetFileResolver?: ContentTypeSnippetFileNameResolver; - readonly taxonomyFileResolver?: TaxonomyTypeFileNameResolver; - }; - - readonly nameResolvers: { - readonly contentTypeNameResolver?: ContentTypeNameResolver; - readonly snippetNameResolver?: ContentTypeSnippetNameResolver; - readonly taxonomyNameResolver?: TaxonomyNameResolver; - readonly elementNameResolver?: GeneratorElementResolver; - }; - readonly environmentData: { readonly environment: Readonly; readonly types: readonly Readonly[]; readonly taxonomies: readonly Readonly[]; readonly snippets: readonly Readonly[]; }; + + readonly fileResolvers?: { + readonly contentType?: ContentTypeFileNameResolver; + readonly snippet?: ContentTypeSnippetFileNameResolver; + readonly taxonomy?: TaxonomyTypeFileNameResolver; + }; + + readonly nameResolvers?: { + readonly contentType?: ContentTypeNameResolver; + readonly snippet?: ContentTypeSnippetNameResolver; + readonly taxonomy?: TaxonomyNameResolver; + readonly element?: GeneratorElementResolver; + }; } export function deliveryContentTypeGenerator(config: DeliveryContentTypeGeneratorConfig) { const commentsManager = _commentsManager(config.addTimestamp); // prepare resolvers - const contentTypeSnippetFileNameMap = mapFilename(config.fileResolvers.contentTypeSnippetFileResolver); - const contentTypeFileNameMap = mapFilename(config.fileResolvers.contentTypeFileResolver); - const taxonomyFileNameMap = mapFilename(config.fileResolvers.taxonomyFileResolver); + const fileResolvers = { + snippet: mapFilename(config.fileResolvers?.snippet), + contentType: mapFilename(config.fileResolvers?.contentType), + taxonomy: mapFilename(config.fileResolvers?.taxonomy) + }; - const contentTypeSnippetNameMap = mapName(config.nameResolvers.snippetNameResolver, 'pascalCase'); - const contentTypeNameMap = mapName(config.nameResolvers.contentTypeNameResolver, 'pascalCase'); - const elementNameMap = mapElementName(config.nameResolvers.elementNameResolver, 'camelCase'); - const taxonomyNameMap = mapName(config.nameResolvers.taxonomyNameResolver, 'pascalCase'); + const nameResolvers = { + snippet: mapName(config.nameResolvers?.snippet, 'pascalCase'), + contentType: mapName(config.nameResolvers?.contentType, 'pascalCase'), + element: mapElementName(config.nameResolvers?.element, 'camelCase'), + taxonomy: mapName(config.nameResolvers?.taxonomy, 'pascalCase') + }; const generateModels = (): { contentTypeFiles: readonly GeneratedFile[]; @@ -100,11 +98,11 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato return snippets.map((snippet) => { return getImportStatement({ moduleResolution: config.moduleResolution, - filePathOrPackage: `../${config.folders.typeSnippetsFolderName}/${contentTypeSnippetFileNameMap( + filePathOrPackage: `../${deliveryConfig.contentTypeSnippetsFolderName}/${fileResolvers.snippet( snippet, false )}.ts`, - importValue: contentTypeSnippetNameMap(snippet) + importValue: nameResolvers.snippet(snippet) }); }); }; @@ -126,8 +124,8 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato } return getImportStatement({ moduleResolution: config.moduleResolution, - filePathOrPackage: `../${config.folders.taxonomyFolderName}/${taxonomyFileNameMap(taxonomyElement.assignedTaxonomy, false)}.ts`, - importValue: taxonomyNameMap(taxonomyElement.assignedTaxonomy) + filePathOrPackage: `../${deliveryConfig.taxonomiesFolderName}/${fileResolvers.taxonomy(taxonomyElement.assignedTaxonomy, false)}.ts`, + importValue: nameResolvers.taxonomy(taxonomyElement.assignedTaxonomy) }); }) .with( @@ -142,15 +140,15 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato return true; }) .map((allowedContentType) => { - const referencedTypeFilename: string = `${contentTypeFileNameMap(allowedContentType, false)}`; + const referencedTypeFilename: string = `${fileResolvers.contentType(allowedContentType, false)}`; return getImportStatement({ moduleResolution: config.moduleResolution, filePathOrPackage: typeOrSnippet instanceof ContentTypeModels.ContentType - ? `../${config.folders.typeFolderName}/${referencedTypeFilename}.ts` + ? `../${deliveryConfig.taxonomiesFolderName}/${referencedTypeFilename}.ts` : `./${referencedTypeFilename}.ts`, - importValue: `${contentTypeNameMap(allowedContentType)}` + importValue: `${nameResolvers.contentType(allowedContentType)}` }); }); } @@ -181,14 +179,14 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato contentTypeExtends: data.typeOrSnippet instanceof ContentTypeModels.ContentType && snippets.length ? `& ${snippets - .map((snippet) => contentTypeSnippetNameMap(snippet)) + .map((snippet) => nameResolvers.snippet(snippet)) .filter(uniqueFilter) .join(' & ')}` : undefined, typeName: data.typeOrSnippet instanceof ContentTypeModels.ContentType - ? contentTypeNameMap(data.typeOrSnippet) - : contentTypeSnippetNameMap(data.typeOrSnippet) + ? nameResolvers.contentType(data.typeOrSnippet) + : nameResolvers.snippet(data.typeOrSnippet) }; }; @@ -236,7 +234,7 @@ export type ${contentTypeImports.typeName} = IContentItem<{ const createContentTypeModel = (type: Readonly): GeneratedFile => { return { - filename: `${config.folders.typeFolderName}/${contentTypeFileNameMap(type, true)}`, + filename: `${deliveryConfig.contentTypesFolderName}/${fileResolvers.contentType(type, true)}`, text: getModelCode(type) }; }; @@ -245,7 +243,7 @@ export type ${contentTypeImports.typeName} = IContentItem<{ snippet: Readonly ): GeneratedFile => { return { - filename: `${config.folders.typeSnippetsFolderName}/${contentTypeSnippetFileNameMap(snippet, true)}`, + filename: `${deliveryConfig.contentTypeSnippetsFolderName}/${fileResolvers.snippet(snippet, true)}`, text: getModelCode(snippet) }; }; @@ -257,7 +255,7 @@ export type ${contentTypeImports.typeName} = IContentItem<{ .filter((m) => !m.fromSnippet) .reduce((code, element) => { const mappedType = mapElementType(element); - const elementName = elementNameMap(element.originalElement); + const elementName = nameResolvers.element(element.originalElement); if (!mappedType || !elementName) { return code; @@ -298,7 +296,7 @@ export type ${contentTypeImports.typeName} = IContentItem<{ }; const getTaxonomyTypeName = (element: FlattenedElement): string | undefined => { - return element.assignedTaxonomy ? taxonomyNameMap(element.assignedTaxonomy) : undefined; + return element.assignedTaxonomy ? nameResolvers.taxonomy(element.assignedTaxonomy) : undefined; }; const getLinkedItemsAllowedTypes = ( @@ -308,7 +306,7 @@ export type ${contentTypeImports.typeName} = IContentItem<{ return ['IContentItem']; } - return types.map((type) => contentTypeNameMap(type)); + return types.map((type) => nameResolvers.contentType(type)); }; return { diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index 2e4ab11..1e0e848 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -30,19 +30,50 @@ export interface GenerateDeliveryModelsConfig { readonly moduleResolution?: ModuleResolution; readonly baseUrl?: string; readonly outputDir?: string; - readonly contentTypeFileResolver?: ContentTypeFileNameResolver; - readonly contentTypeSnippetFileResolver?: ContentTypeSnippetFileNameResolver; - readonly taxonomyTypeFileResolver?: TaxonomyTypeFileNameResolver; - readonly contentTypeResolver?: ContentTypeNameResolver; - readonly contentTypeSnippetResolver?: ContentTypeSnippetNameResolver; - readonly taxonomyTypeResolver?: TaxonomyNameResolver; - readonly elementResolver?: GeneratorElementResolver; readonly formatOptions?: Readonly; + + readonly fileResolvers?: { + readonly taxonomy?: TaxonomyTypeFileNameResolver; + readonly contentType?: ContentTypeFileNameResolver; + readonly snippet?: ContentTypeSnippetFileNameResolver; + }; + + readonly nameResolvers?: { + readonly contentType?: ContentTypeNameResolver; + readonly snippet?: ContentTypeSnippetNameResolver; + readonly taxonomy?: TaxonomyNameResolver; + readonly element?: GeneratorElementResolver; + }; } export async function generateDeliveryModelsAsync(config: GenerateDeliveryModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('delivery')}' models\n`); + + const { contentTypeFiles, snippetFiles, taxonomyFiles, moduleResolution } = await getFilesAsync(config); + + await createFilesAsync( + { + contentTypeFiles, + snippetFiles, + taxonomyFiles + }, + { + formatOptions: config.formatOptions, + moduleResolution: moduleResolution, + outputDir: config.outputDir + } + ); + + console.log(chalk.green(`\nCompleted`)); +} + +async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ + readonly contentTypeFiles: readonly GeneratedFile[]; + readonly snippetFiles: readonly GeneratedFile[]; + readonly taxonomyFiles: readonly GeneratedFile[]; + readonly moduleResolution: ModuleResolution; +}> { const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; const kontentFetcher = _kontentFetcher({ @@ -51,15 +82,10 @@ export async function generateDeliveryModelsAsync(config: GenerateDeliveryModels baseUrl: config.baseUrl }); - const contentTypesFolderName: string = deliveryConfig.contentTypesFolderName; - const contentTypeSnippetsFolderName: string = deliveryConfig.contentTypeSnippetsFolderName; - const taxonomiesFolderName: string = deliveryConfig.taxonomiesFolderName; - const environment = await kontentFetcher.getEnvironmentInfoAsync(); const taxonomies = await kontentFetcher.getTaxonomiesAsync(); - // create content type models - const deliveryModels = deliveryContentTypeGenerator({ + const { contentTypeFiles, snippetFiles } = deliveryContentTypeGenerator({ addTimestamp: config.addTimestamp, addEnvironmentInfo: config.addEnvironmentInfo, moduleResolution: moduleResolution, @@ -69,25 +95,10 @@ export async function generateDeliveryModelsAsync(config: GenerateDeliveryModels snippets: await kontentFetcher.getSnippetsAsync(), taxonomies: taxonomies }, - folders: { - typeFolderName: contentTypesFolderName, - taxonomyFolderName: taxonomiesFolderName, - typeSnippetsFolderName: contentTypeSnippetsFolderName - }, - fileResolvers: { - taxonomyFileResolver: config.taxonomyTypeFileResolver, - contentTypeFileResolver: config.contentTypeFileResolver, - contentTypeSnippetFileResolver: config.contentTypeSnippetFileResolver - }, - nameResolvers: { - elementNameResolver: config.elementResolver, - contentTypeNameResolver: config.contentTypeResolver, - taxonomyNameResolver: config.taxonomyTypeResolver, - snippetNameResolver: config.contentTypeSnippetResolver - } + fileResolvers: config.fileResolvers, + nameResolvers: config.nameResolvers }).generateModels(); - // create taxonomy types const taxonomyFiles = deliveryTaxonomyGenerator({ addTimestamp: config.addTimestamp, moduleResolution: moduleResolution, @@ -95,39 +106,19 @@ export async function generateDeliveryModelsAsync(config: GenerateDeliveryModels environment: await kontentFetcher.getEnvironmentInfoAsync(), taxonomies: taxonomies }, - fileResolvers: { - taxonomyFilenameResolver: config.taxonomyTypeFileResolver - }, - folders: { - taxonomyFolderName: taxonomiesFolderName - }, - nameResolvers: { - taxonomyNameResolver: config.taxonomyTypeResolver - } + fileResolvers: config.fileResolvers, + nameResolvers: config.nameResolvers }).generateTaxonomyTypes(); - await createDeliveryFilesAsync( - { - contentTypeFiles: deliveryModels.contentTypeFiles, - snippetFiles: deliveryModels.snippetFiles, - taxonomyFiles: taxonomyFiles - }, - { - formatOptions: config.formatOptions, - moduleResolution: moduleResolution, - outputDir: config.outputDir - }, - { - contentTypesFolderName, - contentTypeSnippetsFolderName, - taxonomiesFolderName - } - ); - - console.log(chalk.green(`\nCompleted`)); + return { + contentTypeFiles, + snippetFiles, + taxonomyFiles, + moduleResolution + }; } -async function createDeliveryFilesAsync( +async function createFilesAsync( data: { readonly contentTypeFiles: readonly GeneratedFile[]; readonly snippetFiles: readonly GeneratedFile[]; @@ -137,11 +128,6 @@ async function createDeliveryFilesAsync( readonly outputDir: string | undefined; readonly moduleResolution: ModuleResolution; readonly formatOptions: Readonly | undefined; - }, - folders: { - readonly contentTypesFolderName: string; - readonly contentTypeSnippetsFolderName: string; - readonly taxonomiesFolderName: string; } ): Promise { const fileManager = _fileManager(toOutputDirPath(config.outputDir)); @@ -153,7 +139,7 @@ async function createDeliveryFilesAsync( ...data.taxonomyFiles, // barrel files { - filename: `${folders.contentTypesFolderName}/${coreConfig.barrelExportFilename}`, + filename: `${deliveryConfig.contentTypesFolderName}/${coreConfig.barrelExportFilename}`, text: getBarrelExportCode({ moduleResolution: config.moduleResolution, filenames: [ @@ -165,7 +151,7 @@ async function createDeliveryFilesAsync( }) }, { - filename: `${folders.contentTypeSnippetsFolderName}/${coreConfig.barrelExportFilename}`, + filename: `${deliveryConfig.contentTypeSnippetsFolderName}/${coreConfig.barrelExportFilename}`, text: getBarrelExportCode({ moduleResolution: config.moduleResolution, filenames: [ @@ -177,7 +163,7 @@ async function createDeliveryFilesAsync( }) }, { - filename: `${folders.taxonomiesFolderName}/${coreConfig.barrelExportFilename}`, + filename: `${deliveryConfig.taxonomiesFolderName}/${coreConfig.barrelExportFilename}`, text: getBarrelExportCode({ moduleResolution: config.moduleResolution, filenames: [ @@ -193,9 +179,9 @@ async function createDeliveryFilesAsync( text: getBarrelExportCode({ moduleResolution: config.moduleResolution, filenames: [ - `./${folders.contentTypesFolderName}/index`, - `./${folders.contentTypeSnippetsFolderName}/index`, - `./${folders.taxonomiesFolderName}/index` + `./${deliveryConfig.contentTypesFolderName}/index`, + `./${deliveryConfig.contentTypeSnippetsFolderName}/index`, + `./${deliveryConfig.taxonomiesFolderName}/index` ] }) } diff --git a/lib/generators/delivery/delivery-taxonomy.generator.ts b/lib/generators/delivery/delivery-taxonomy.generator.ts index 3035129..7ccdcc1 100644 --- a/lib/generators/delivery/delivery-taxonomy.generator.ts +++ b/lib/generators/delivery/delivery-taxonomy.generator.ts @@ -8,7 +8,8 @@ import { TaxonomyTypeFileNameResolver, TaxonomyNameResolver, toSafeString, - ModuleResolution + ModuleResolution, + deliveryConfig } from '../../core/index.js'; import { commentsManager as _commentsManager } from '../../comments/index.js'; @@ -16,25 +17,23 @@ export interface DeliveryTaxonomyGeneratorConfig { readonly addTimestamp: boolean; readonly moduleResolution: ModuleResolution; - readonly folders: { - readonly taxonomyFolderName: string; - }; - readonly fileResolvers: { - readonly taxonomyFilenameResolver?: TaxonomyTypeFileNameResolver; - }; - readonly nameResolvers: { - readonly taxonomyNameResolver?: TaxonomyNameResolver; - }; readonly environmentData: { readonly environment: Readonly; readonly taxonomies: readonly Readonly[]; }; + + readonly fileResolvers?: { + readonly taxonomy?: TaxonomyTypeFileNameResolver; + }; + readonly nameResolvers?: { + readonly taxonomy?: TaxonomyNameResolver; + }; } export function deliveryTaxonomyGenerator(config: DeliveryTaxonomyGeneratorConfig) { const commentsManager = _commentsManager(config.addTimestamp); - const taxonomyFileNameMap = mapFilename(config.fileResolvers.taxonomyFilenameResolver); - const taxonomyNameMap = mapName(config.nameResolvers.taxonomyNameResolver, 'pascalCase'); + const taxonomyFileNameMap = mapFilename(config.fileResolvers?.taxonomy); + const taxonomyNameMap = mapName(config.nameResolvers?.taxonomy, 'pascalCase'); const generateTaxonomyTypes = (): readonly GeneratedFile[] => { return config.environmentData.taxonomies.map((taxonomy) => { @@ -44,7 +43,7 @@ export function deliveryTaxonomyGenerator(config: DeliveryTaxonomyGeneratorConfi const getTaxonomyFile = (taxonomy: Readonly): GeneratedFile => { return { - filename: `${config.folders.taxonomyFolderName}/${taxonomyFileNameMap(taxonomy, true)}`, + filename: `${deliveryConfig.taxonomiesFolderName}/${taxonomyFileNameMap(taxonomy, true)}`, text: getModelCode(taxonomy) }; }; diff --git a/lib/generators/index.ts b/lib/generators/index.ts index 43544e7..d6e29d3 100644 --- a/lib/generators/index.ts +++ b/lib/generators/index.ts @@ -1,6 +1,5 @@ // delivery export * from './delivery/delivery-content-type.generator.js'; -export * from './delivery/delivery-mappers.js'; export * from './delivery/delivery-taxonomy.generator.js'; export * from './delivery/delivery-func.js'; diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index d9fc069..9d53c20 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -4,7 +4,8 @@ import { coreConfig, toOutputDirPath, getBarrelExportCode, - ModuleResolution + ModuleResolution, + GeneratedFile } from '../../core/index.js'; import { fileManager as _fileManager } from '../../files/index.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; @@ -26,18 +27,32 @@ export interface GenerateMigrationModelsConfig { export async function generateMigrationModelsAsync(config: GenerateMigrationModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('migration')}' models\n`); - const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; - const fileManager = _fileManager(toOutputDirPath(config.outputDir)); + const { migrationItemFiles, migrationTypeFile, moduleResolution } = await getFilesAsync(config); + + await createFilesAsync({ + migrationItemFiles, + migrationTypeFile, + moduleResolution, + outputDir: config.outputDir, + formatOptions: config.formatOptions + }); + + console.log(chalk.green(`\nCompleted`)); +} + +async function getFilesAsync(config: GenerateMigrationModelsConfig): Promise<{ + readonly migrationTypeFile: GeneratedFile; + readonly migrationItemFiles: readonly GeneratedFile[]; + readonly moduleResolution: ModuleResolution; +}> { + const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, baseUrl: config.baseUrl }); - const migrationItemsFolderName: string = migrationConfig.migrationItemsFolderName; - const migrationTypesFilename: string = migrationConfig.migrationTypesFilename; - const projectInformation = await kontentFetcher.getEnvironmentInfoAsync(); const migrationGenerator = _migrationGenerator({ @@ -54,23 +69,33 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode } }); - const migrationTypeFile = migrationGenerator.getMigrationTypesFile(migrationTypesFilename); - const migrationItemFiles = migrationGenerator.getMigrationItemFiles( - migrationTypesFilename, - migrationItemsFolderName - ); + return { + moduleResolution, + migrationTypeFile: migrationGenerator.getMigrationTypesFile(), + migrationItemFiles: migrationGenerator.getMigrationItemFiles() + }; +} + +async function createFilesAsync(data: { + readonly migrationTypeFile: GeneratedFile; + readonly migrationItemFiles: readonly GeneratedFile[]; + readonly moduleResolution: ModuleResolution; + readonly outputDir: string; + readonly formatOptions?: Readonly; +}): Promise { + const fileManager = _fileManager(toOutputDirPath(data.outputDir)); await fileManager.createFilesAsync( [ - migrationTypeFile, - ...migrationItemFiles, + data.migrationTypeFile, + ...data.migrationItemFiles, // types barrel file { - filename: `${migrationItemsFolderName}/${coreConfig.barrelExportFilename}`, + filename: `${migrationConfig.migrationItemsFolderName}/${coreConfig.barrelExportFilename}`, text: getBarrelExportCode({ - moduleResolution: moduleResolution, + moduleResolution: data.moduleResolution, filenames: [ - ...migrationItemFiles.map((m) => { + ...data.migrationItemFiles.map((m) => { return `./${parse(m.filename).name}`; }) ] @@ -80,13 +105,14 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode { filename: coreConfig.barrelExportFilename, text: getBarrelExportCode({ - moduleResolution: moduleResolution, - filenames: [`./${migrationItemsFolderName}/index`, `./${migrationTypeFile.filename}`] + moduleResolution: data.moduleResolution, + filenames: [ + `./${migrationConfig.migrationItemsFolderName}/index`, + `./${data.migrationTypeFile.filename}` + ] }) } ], - config.formatOptions + data.formatOptions ); - - console.log(chalk.green(`\nCompleted`)); } diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index 0b2db3a..893ae7d 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -55,13 +55,9 @@ const migrationTypeNames = { export function migrationGenerator(config: MigrationGeneratorConfig) { const commentsManager = _commentsManager(config.addTimestamp); - const getMigrationItemType = ( - type: Readonly, - migrationTypesFilename: string, - folderName: string - ): GeneratedFile => { + const getMigrationItemType = (type: Readonly): GeneratedFile => { return { - filename: `${folderName}/${type.codename}.ts`, + filename: `${migrationConfig.migrationItemsFolderName}/${type.codename}.ts`, text: ` ${getImportStatement({ filePathOrPackage: migrationConfig.npmPackageName, @@ -69,7 +65,7 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { moduleResolution: config.moduleResolution })} ${getImportStatement({ - filePathOrPackage: `../${migrationTypesFilename}`, + filePathOrPackage: `../${migrationConfig.migrationTypesFilename}`, importValue: migrationTypeNames.item, moduleResolution: config.moduleResolution })} @@ -96,7 +92,7 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { * * Required: ${element.isRequired ? 'true' : 'false'} * Codename: ${element.codename} - * Id: ${element.id}${element.guidelines ? `\n* Guidelines: ${removeLineEndings(element.guidelines)}` : ''} + * Id: ${element.id}${element.guidelines ? `\n* Guidelines: ${toSafeString(removeLineEndings(element.guidelines))}` : ''} */ ${element.codename}: ${getElementPropType(element)}`; }) @@ -107,9 +103,9 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { }; return { - getMigrationTypesFile(filename: string): GeneratedFile { + getMigrationTypesFile(): GeneratedFile { return { - filename: filename, + filename: migrationConfig.migrationTypesFilename, text: ` ${getImportStatement({ filePathOrPackage: migrationConfig.npmPackageName, @@ -142,10 +138,8 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { ` }; }, - getMigrationItemFiles(migrationTypesFilename: string, folderName: string): readonly GeneratedFile[] { - return config.environmentData.types.map((type) => - getMigrationItemType(type, migrationTypesFilename, folderName) - ); + getMigrationItemFiles(): readonly GeneratedFile[] { + return config.environmentData.types.map((type) => getMigrationItemType(type)); } }; } diff --git a/lib/generators/project/project-func.ts b/lib/generators/project/project-func.ts index 35b8c0c..3c4359d 100644 --- a/lib/generators/project/project-func.ts +++ b/lib/generators/project/project-func.ts @@ -3,7 +3,7 @@ import { projectGenerator as _projectGenerator } from './project.generator.js'; import { fileManager as _fileManager } from '../../files/index.js'; import { parse } from 'path'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; -import { coreConfig, getBarrelExportCode, ModuleResolution, toOutputDirPath } from '../../core/index.js'; +import { coreConfig, GeneratedFile, getBarrelExportCode, ModuleResolution, toOutputDirPath } from '../../core/index.js'; import { Options } from 'prettier'; export interface GenerateProjectModelsConfig { @@ -21,9 +21,23 @@ export interface GenerateProjectModelsConfig { export async function generateProjectModelsAsync(config: GenerateProjectModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('project')}' models\n`); - const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; - const fileManager = _fileManager(toOutputDirPath(config.outputDir)); + const { moduleResolution, projectFiles } = await getModelsAsync(config); + + await createFilesAsync({ + moduleResolution, + projectFiles, + outputDir: config.outputDir, + formatOptions: config.formatOptions + }); + + console.log(chalk.green(`\nCompleted`)); +} + +async function getModelsAsync( + config: GenerateProjectModelsConfig +): Promise<{ projectFiles: readonly GeneratedFile[]; moduleResolution: ModuleResolution }> { + const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, @@ -32,33 +46,45 @@ export async function generateProjectModelsAsync(config: GenerateProjectModelsCo const projectInformation = await kontentFetcher.getEnvironmentInfoAsync(); - const projectFiles = _projectGenerator({ - addTimestamp: config.addTimestamp, - formatOptions: config.formatOptions, - environmentData: { - environmentInfo: projectInformation, - languages: await kontentFetcher.getLanguagesAsync(), - taxonomies: await kontentFetcher.getTaxonomiesAsync(), - types: await kontentFetcher.getTypesAsync(), - workflows: await kontentFetcher.getWorkflowsAsync(), - assetFolders: await kontentFetcher.getAssetFoldersAsync(), - collections: await kontentFetcher.getCollectionsAsync(), - roles: config.isEnterpriseSubscription ? await kontentFetcher.getRolesAsync() : [], - snippets: await kontentFetcher.getSnippetsAsync(), - webhooks: await kontentFetcher.getWebhooksAsync() - } - }).generateProjectModel(); + return { + projectFiles: _projectGenerator({ + addTimestamp: config.addTimestamp, + formatOptions: config.formatOptions, + environmentData: { + environmentInfo: projectInformation, + languages: await kontentFetcher.getLanguagesAsync(), + taxonomies: await kontentFetcher.getTaxonomiesAsync(), + types: await kontentFetcher.getTypesAsync(), + workflows: await kontentFetcher.getWorkflowsAsync(), + assetFolders: await kontentFetcher.getAssetFoldersAsync(), + collections: await kontentFetcher.getCollectionsAsync(), + roles: config.isEnterpriseSubscription ? await kontentFetcher.getRolesAsync() : [], + snippets: await kontentFetcher.getSnippetsAsync(), + webhooks: await kontentFetcher.getWebhooksAsync() + } + }).generateProjectModel(), + moduleResolution: moduleResolution + }; +} + +async function createFilesAsync(data: { + readonly projectFiles: readonly GeneratedFile[]; + readonly moduleResolution: ModuleResolution; + readonly outputDir?: string; + readonly formatOptions?: Readonly; +}): Promise { + const fileManager = _fileManager(toOutputDirPath(data.outputDir)); await fileManager.createFilesAsync( [ - ...projectFiles, + ...data.projectFiles, // barrel file { filename: coreConfig.barrelExportFilename, text: getBarrelExportCode({ - moduleResolution: moduleResolution, + moduleResolution: data.moduleResolution, filenames: [ - ...projectFiles.map((m) => { + ...data.projectFiles.map((m) => { const path = parse(m.filename); return `./${path.name}`; }) @@ -66,8 +92,6 @@ export async function generateProjectModelsAsync(config: GenerateProjectModelsCo }) } ], - config.formatOptions + data.formatOptions ); - - console.log(chalk.green(`\nCompleted`)); } diff --git a/lib/generators/project/project.generator.ts b/lib/generators/project/project.generator.ts index 15c23b6..8bfb623 100644 --- a/lib/generators/project/project.generator.ts +++ b/lib/generators/project/project.generator.ts @@ -21,7 +21,8 @@ import { removeLineEndings, sortAlphabetically, toSafeString, - toCamelCase + toCamelCase, + getStringOrUndefined } from '../../core/index.js'; interface ProjectCodeResult { @@ -150,13 +151,6 @@ export function projectGenerator(config: ProjectGeneratorConfig) { }, ''); }; - const getStringOrUndefined = (text?: string): string => { - if (!text) { - return 'undefined'; - } - return `'${text}'`; - }; - const getProjectWorkflows = (workflows: readonly Readonly[]): string => { return workflows.reduce((code, workflow, index) => { const isLast = index === workflows.length - 1; diff --git a/lib/node/cli/actions/delivery-action.ts b/lib/node/cli/actions/delivery-action.ts index 3372b8e..2b96f08 100644 --- a/lib/node/cli/actions/delivery-action.ts +++ b/lib/node/cli/actions/delivery-action.ts @@ -10,15 +10,7 @@ export async function deliveryActionAsync(cliFetcher: CliArgumentsFetcher): Prom outputDir: cliFetcher.getRequiredArgumentValue('outputDir'), addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), addEnvironmentInfo: cliFetcher.getBooleanArgumentValue('addEnvironmentInfo', false), - elementResolver: undefined, - contentTypeFileResolver: undefined, - contentTypeResolver: undefined, - taxonomyTypeFileResolver: undefined, - taxonomyTypeResolver: undefined, - contentTypeSnippetFileResolver: undefined, - contentTypeSnippetResolver: undefined, - formatOptions: undefined, moduleResolution: - cliFetcher.getRequiredArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' + cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' }); } diff --git a/lib/node/cli/actions/migrate-action.ts b/lib/node/cli/actions/migrate-action.ts index cc05967..a8c2924 100644 --- a/lib/node/cli/actions/migrate-action.ts +++ b/lib/node/cli/actions/migrate-action.ts @@ -11,6 +11,6 @@ export async function migrateActionAsync(cliFetcher: CliArgumentsFetcher): Promi addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), formatOptions: undefined, moduleResolution: - cliFetcher.getRequiredArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' + cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' }); } diff --git a/lib/node/cli/actions/project-action.ts b/lib/node/cli/actions/project-action.ts index 1331d92..3b5306d 100644 --- a/lib/node/cli/actions/project-action.ts +++ b/lib/node/cli/actions/project-action.ts @@ -11,6 +11,6 @@ export async function projectActionAsync(cliFetcher: CliArgumentsFetcher): Promi isEnterpriseSubscription: cliFetcher.getBooleanArgumentValue('isEnterpriseSubscription', false), addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), moduleResolution: - cliFetcher.getRequiredArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' + cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' }); } diff --git a/sample/migration/content-types/actor.ts b/sample/migration/content-types/actor.ts index 7448f7f..543ce67 100644 --- a/sample/migration/content-types/actor.ts +++ b/sample/migration/content-types/actor.ts @@ -5,46 +5,45 @@ import type { Item } from '../core.models.js'; * Actor * * Codename: actor - * Id: 58099989-319f-495f-aa36-cb3710854e36 + * Id: d8900ee2-82f4-4189-a994-4e121582aadf */ export type ActorItem = Item< 'actor', { /** - * Url (url_slug) + * photo (asset) * * Required: false - * Codename: url - * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 + * Codename: photo + * Id: 069b38ee-385c-410f-b7fe-53ec59a5f139 */ - url: MigrationElementModels.UrlSlugElement; + photo: MigrationElementModels.AssetElement; /** - * First name (text) + * url (url_slug) * - * Required: true - * Codename: first_name - * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d - * Guidelines: This is the first name of the actor + * Required: false + * Codename: url + * Id: c4b2d64f-af45-45a4-92d8-4829833563ff */ - first_name: MigrationElementModels.TextElement; + url: MigrationElementModels.UrlSlugElement; /** - * Last name (text) + * last_name (text) * - * Required: true + * Required: false * Codename: last_name - * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 + * Id: 0f00b26e-60f3-462d-8110-18180137c3a0 */ last_name: MigrationElementModels.TextElement; /** - * Photo (asset) + * first_name (text) * * Required: false - * Codename: photo - * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 + * Codename: first_name + * Id: 4af5e7ce-88ef-4159-96ae-96a552992f91 */ - photo: MigrationElementModels.AssetElement; + first_name: MigrationElementModels.TextElement; } >; diff --git a/sample/migration/content-types/index.ts b/sample/migration/content-types/index.ts index 79e8008..e8c4f36 100644 --- a/sample/migration/content-types/index.ts +++ b/sample/migration/content-types/index.ts @@ -1,2 +1,3 @@ export * from './actor.js'; export * from './movie.js'; +export * from './test.js'; diff --git a/sample/migration/content-types/movie.ts b/sample/migration/content-types/movie.ts index 2b5bacd..f9684b5 100644 --- a/sample/migration/content-types/movie.ts +++ b/sample/migration/content-types/movie.ts @@ -5,90 +5,99 @@ import type { Item } from '../core.models.js'; * Movie * * Codename: movie - * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c + * Id: db7356f6-1d82-42a0-9ebb-07865cffa995 */ export type MovieItem = Item< 'movie', { /** - * Title (text) + * Category (taxonomy) * - * Required: true - * Codename: title - * Id: 3473187e-dc78-eff2-7099-f690f7042d4a + * Required: false + * Codename: taxonomy_snippet_test__test_taxonomy + * Id: c030e3ec-5031-4d7f-af88-5032365733c7 */ - title: MigrationElementModels.TextElement; + taxonomy_snippet_test__test_taxonomy: MigrationElementModels.TaxonomyElement; /** - * Plot (rich_text) + * Release category (taxonomy) * * Required: false - * Codename: plot - * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce + * Codename: releasecategory + * Id: 5faa827f-f262-43c3-8f58-0f354b8d393f */ - plot: MigrationElementModels.RichTextElement; + releasecategory: MigrationElementModels.TaxonomyElement; /** - * Released (date_time) + * Category (taxonomy) * * Required: false - * Codename: released - * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 + * Codename: category + * Id: 8c12be35-e3e7-447c-a185-7b5e101ebf12 */ - released: MigrationElementModels.DateTimeElement; + category: MigrationElementModels.TaxonomyElement; /** - * Length (number) + * length (number) * * Required: false * Codename: length - * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c + * Id: e3d07f3a-60c2-4072-846d-c23e51ec833e */ length: MigrationElementModels.NumberElement; /** - * Poster (asset) + * stars (modular_content) * * Required: false - * Codename: poster - * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d + * Codename: stars + * Id: 55596dd1-e808-415d-95aa-e2be34238d11 */ - poster: MigrationElementModels.AssetElement; + stars: MigrationElementModels.LinkedItemsElement; /** - * Category (multiple_choice) + * seoname (url_slug) * * Required: false - * Codename: category - * Id: 9821c252-6414-f549-c17f-cc171dd87713 + * Codename: seoname + * Id: 734f94be-5930-4bdf-b05b-f59f5a291675 */ - category: MigrationElementModels.MultipleChoiceElement; + seoname: MigrationElementModels.UrlSlugElement; /** - * Stars (modular_content) + * poster (asset) * * Required: false - * Codename: stars - * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 + * Codename: poster + * Id: 9b197f1e-0728-4d14-9814-97f7b8ef01fc */ - stars: MigrationElementModels.LinkedItemsElement; + poster: MigrationElementModels.AssetElement; /** - * SeoName (url_slug) + * released (date_time) * * Required: false - * Codename: seoname - * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c + * Codename: released + * Id: 656b9dc9-7bba-4f1f-a2b8-52f7f730a66f */ - seoname: MigrationElementModels.UrlSlugElement; + released: MigrationElementModels.DateTimeElement; /** - * ReleaseCategory (taxonomy) + * plot (rich_text) * * Required: false - * Codename: releasecategory - * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 + * Codename: plot + * Id: ad2e5dc7-8d08-4f74-afeb-25b475f1e6fc */ - releasecategory: MigrationElementModels.TaxonomyElement; + plot: MigrationElementModels.RichTextElement; + + /** + * title (text) + * + * Required: false + * Codename: title + * Id: 660c851a-a9a1-4378-97a3-1348bc2a4d76 + */ + title: MigrationElementModels.TextElement; } >; diff --git a/sample/migration/content-types/test.ts b/sample/migration/content-types/test.ts new file mode 100644 index 0000000..2a9f76e --- /dev/null +++ b/sample/migration/content-types/test.ts @@ -0,0 +1,40 @@ +import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; +import type { Item } from '../core.models.js'; + +/** + * Test + * + * Codename: test + * Id: 81ab0b2c-dd14-41e7-a1ed-868b249ad8bc + */ +export type TestItem = Item< + 'test', + { + /** + * Text (text) + * + * Required: false + * Codename: text + * Id: 65f61f6a-b69c-47dc-bc38-19855507bf14 + */ + text: MigrationElementModels.TextElement; + + /** + * Snippet elem1 (text) + * + * Required: false + * Codename: my_snippet__snippet_elem1 + * Id: 3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d + */ + my_snippet__snippet_elem1: MigrationElementModels.TextElement; + + /** + * Snippet elem 2 (number) + * + * Required: false + * Codename: my_snippet__snippet_elem_2 + * Id: b2f65646-3310-4a64-af2a-0d9d025a91d0 + */ + my_snippet__snippet_elem_2: MigrationElementModels.NumberElement; + } +>; diff --git a/sample/migration/core.models.ts b/sample/migration/core.models.ts index 1cd7a53..bd9997d 100644 --- a/sample/migration/core.models.ts +++ b/sample/migration/core.models.ts @@ -2,21 +2,21 @@ import type { MigrationItemSystem, MigrationItem, MigrationElements } from '@kon /** * - * Movie Database + * Migration Toolkit tests * * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 */ /** * Type representing all languages */ -export type LanguageCodenames = 'cz' | 'en' | 'German'; +export type LanguageCodenames = 'en' | 'es'; /** * Type representing all content types */ -export type ContentTypeCodenames = 'actor' | 'movie'; +export type ContentTypeCodenames = 'actor' | 'movie' | 'test'; /** * Type representing all collections @@ -26,12 +26,19 @@ export type CollectionCodenames = 'default'; /** * Type representing all workflows */ -export type WorkflowCodenames = 'default'; +export type WorkflowCodenames = 'default' | 'my_test_workflow'; /** * Type representing all worksflow steps across all workflows */ -export type WorkflowStepCodenames = 'draft' | 'review' | 'ready_to_publish' | 'published' | 'archived' | 'scheduled'; +export type WorkflowStepCodenames = + | 'draft' + | 'ready_to_publish' + | 'published' + | 'archived' + | 'scheduled' + | 'draft_3171da5' + | 'ready_for_review'; /** * System object shared by all individual content type models From 95733e08988376306d01005b8d93269dc4e5417f Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 29 Aug 2024 09:55:55 +0200 Subject: [PATCH 035/183] Unifies default module resolution --- lib/core/core.utils.ts | 4 ++++ lib/generators/delivery/delivery-func.ts | 6 +++--- lib/generators/migration/migration-func.ts | 5 +++-- lib/generators/project/project-func.ts | 11 +++++++++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 8dbbc1f..a383824 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -15,6 +15,10 @@ export function uniqueFilter(value: string, index: number, self: string[]) { return self.indexOf(value) === index; } +export function getDefaultModuleResolution(moduleResolution: ModuleResolution | undefined): ModuleResolution { + return moduleResolution ?? 'node'; +} + export function replaceTsExtensionWithJs(filePath: string): string { return filePath.replace('.ts', '.js'); } diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index 1e0e848..4f3ffc6 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -17,7 +17,8 @@ import { ModuleResolution, TaxonomyNameResolver, TaxonomyTypeFileNameResolver, - toOutputDirPath + toOutputDirPath, + getDefaultModuleResolution } from '../../core/index.js'; import { Options } from 'prettier'; @@ -74,8 +75,7 @@ async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ readonly taxonomyFiles: readonly GeneratedFile[]; readonly moduleResolution: ModuleResolution; }> { - const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; - + const moduleResolution: ModuleResolution = getDefaultModuleResolution(config.moduleResolution); const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index 9d53c20..c9fc7e3 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -5,7 +5,8 @@ import { toOutputDirPath, getBarrelExportCode, ModuleResolution, - GeneratedFile + GeneratedFile, + getDefaultModuleResolution } from '../../core/index.js'; import { fileManager as _fileManager } from '../../files/index.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; @@ -46,7 +47,7 @@ async function getFilesAsync(config: GenerateMigrationModelsConfig): Promise<{ readonly migrationItemFiles: readonly GeneratedFile[]; readonly moduleResolution: ModuleResolution; }> { - const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; + const moduleResolution: ModuleResolution = getDefaultModuleResolution(config.moduleResolution); const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, diff --git a/lib/generators/project/project-func.ts b/lib/generators/project/project-func.ts index 3c4359d..637fee1 100644 --- a/lib/generators/project/project-func.ts +++ b/lib/generators/project/project-func.ts @@ -3,7 +3,14 @@ import { projectGenerator as _projectGenerator } from './project.generator.js'; import { fileManager as _fileManager } from '../../files/index.js'; import { parse } from 'path'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; -import { coreConfig, GeneratedFile, getBarrelExportCode, ModuleResolution, toOutputDirPath } from '../../core/index.js'; +import { + coreConfig, + GeneratedFile, + getBarrelExportCode, + getDefaultModuleResolution, + ModuleResolution, + toOutputDirPath +} from '../../core/index.js'; import { Options } from 'prettier'; export interface GenerateProjectModelsConfig { @@ -37,7 +44,7 @@ export async function generateProjectModelsAsync(config: GenerateProjectModelsCo async function getModelsAsync( config: GenerateProjectModelsConfig ): Promise<{ projectFiles: readonly GeneratedFile[]; moduleResolution: ModuleResolution }> { - const moduleResolution: ModuleResolution = config.moduleResolution ?? 'node'; + const moduleResolution: ModuleResolution = getDefaultModuleResolution(config.moduleResolution); const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, From 4f921db91760af50237770a93707e229c6dcd1c2 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 29 Aug 2024 11:19:41 +0200 Subject: [PATCH 036/183] Adds autogenerated note with environment info to every file --- lib/comments/comments.manager.ts | 44 ++- lib/files/file-manager.ts | 29 +- .../delivery-content-type.generator.ts | 5 - lib/generators/delivery/delivery-func.ts | 137 ++++---- .../delivery/delivery-taxonomy.generator.ts | 4 - lib/generators/migration/migration-func.ts | 82 ++--- .../migration/migration.generator.ts | 4 +- lib/generators/project/project-func.ts | 69 ++-- lib/generators/project/project.generator.ts | 11 +- .../delivery/content-type-snippets/index.ts | 13 + .../content-type-snippets/my_snippet.ts | 13 +- .../taxonomy_snippet_test.ts | 15 +- sample/delivery/content-types/actor.ts | 13 +- sample/delivery/content-types/index.ts | 13 + sample/delivery/content-types/movie.ts | 19 +- sample/delivery/content-types/test.ts | 15 +- sample/delivery/index.ts | 13 + sample/delivery/taxonomies/category.ts | 9 +- sample/delivery/taxonomies/index.ts | 13 + .../delivery/taxonomies/release_category.ts | 9 +- sample/migration/content-types/actor.ts | 13 + sample/migration/content-types/index.ts | 13 + sample/migration/content-types/movie.ts | 13 + sample/migration/content-types/test.ts | 13 + sample/migration/core.models.ts | 13 +- sample/migration/index.ts | 13 + sample/project/assetFolders.ts | 68 ++-- sample/project/collections.ts | 13 +- sample/project/contentTypeSnippets.ts | 73 ++++- sample/project/contentTypes.ts | 300 ++++++++---------- sample/project/index.ts | 12 + sample/project/languages.ts | 42 +-- sample/project/roles.ts | 42 +-- sample/project/taxonomies.ts | 151 ++++----- sample/project/webhooks.ts | 13 +- sample/project/workflows.ts | 62 +++- 36 files changed, 801 insertions(+), 583 deletions(-) diff --git a/lib/comments/comments.manager.ts b/lib/comments/comments.manager.ts index 97f33c7..e5c4bd7 100644 --- a/lib/comments/comments.manager.ts +++ b/lib/comments/comments.manager.ts @@ -2,38 +2,32 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import { libMetadata } from '../meta/index.js'; import { toSafeString } from '../core/index.js'; -export function commentsManager(addTimestamp: boolean) { - const generatedBy = (): string => { - if (addTimestamp) { - return `Generated by '${libMetadata.name}@${libMetadata.version}' at '${new Date().toUTCString()}'`; - } - - return `Generated by '${libMetadata.name}@${libMetadata.version}'`; - }; - - const wrapComment = (comment: string, opts?: { addGeneratedBy: boolean }): string => { - if (opts?.addGeneratedBy) { - return `/** \n * ${generatedBy()} ${comment} \n*/`; - } +export function commentsManager() { + const wrapComment = (comment: string): string => { return `/** \n * ${comment} \n*/`; }; - const environmentInfo = ( - environmentInfo: Readonly, - opts?: { addGeneratedBy: boolean } - ): string => { - return wrapComment( - ` -* ${toSafeString(environmentInfo.name)} + const getEnvironmentInfoComment = (data: { + addTimestamp?: boolean; + environmentInfo: Readonly; + }): string => { + return ` +/** +* This file has been auto-generated by '${libMetadata.name}@${libMetadata.version}'. +* +* (c) Kontent.ai * -* Environment: ${toSafeString(environmentInfo.environment)} -* Id: ${environmentInfo.id}`, - opts - ); +* ------------------------------------------------------------------------------- +* +* Environment: ${toSafeString(data.environmentInfo.environment)} +* Id: ${data.environmentInfo.id}${data.addTimestamp ? `\n* Generated: ${new Date().toLocaleString()}` : ''} +* +* ------------------------------------------------------------------------------- +**/`; }; return { wrapComment, - environmentInfo + getEnvironmentInfoComment }; } diff --git a/lib/files/file-manager.ts b/lib/files/file-manager.ts index ae3e0d5..01e80e3 100644 --- a/lib/files/file-manager.ts +++ b/lib/files/file-manager.ts @@ -3,16 +3,30 @@ import { Options } from 'prettier'; import { formatCodeAsync } from '../format/formatter.js'; import * as fs from 'fs'; import { dirname } from 'path'; -import { GeneratedFile } from '../core/index.js'; +import { GeneratedFile, toOutputDirPath } from '../core/index.js'; +import { EnvironmentModels } from '@kontent-ai/management-sdk'; +import { commentsManager } from '../comments/index.js'; + +export function fileManager(config: { + outputDir: string | undefined; + formatOptions: Readonly | undefined; + environmentInfo: Readonly; + addTimestamp: boolean; +}) { + const fixedOutputDir = toOutputDirPath(config.outputDir); -export function fileManager(outputDir: string) { const createFileOnFsAsync = async ( text: string, filePath: string, formatOptions: Readonly | undefined ): Promise => { - const fullFilePath = `${outputDir.endsWith('/') ? outputDir : `${outputDir}/`}${filePath}`; - let fileContent = text; + const fullFilePath = `${fixedOutputDir.endsWith('/') ? fixedOutputDir : `${fixedOutputDir}/`}${filePath}`; + + let fileContent = + `${commentsManager().getEnvironmentInfoComment({ + environmentInfo: config.environmentInfo, + addTimestamp: config.addTimestamp + })}\n\n` + text; try { fileContent = await formatCodeAsync(fileContent, formatOptions); } catch { @@ -37,13 +51,10 @@ export function fileManager(outputDir: string) { fs.mkdirSync(resolvedDirname); }; - const createFilesAsync = async ( - files: readonly GeneratedFile[], - formatOptions: Readonly | undefined - ): Promise => { + const createFilesAsync = async (files: readonly GeneratedFile[]): Promise => { await Promise.all( files.map((file) => { - return createFileOnFsAsync(file.text, file.filename, formatOptions); + return createFileOnFsAsync(file.text, file.filename, config.formatOptions); }) ); }; diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 37f7b96..75fdf66 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -7,7 +7,6 @@ import { TaxonomyModels } from '@kontent-ai/management-sdk'; -import { commentsManager as _commentsManager } from '../../comments/index.js'; import { ContentTypeFileNameResolver, ContentTypeNameResolver, @@ -64,8 +63,6 @@ export interface DeliveryContentTypeGeneratorConfig { } export function deliveryContentTypeGenerator(config: DeliveryContentTypeGeneratorConfig) { - const commentsManager = _commentsManager(config.addTimestamp); - // prepare resolvers const fileResolvers = { snippet: mapFilename(config.fileResolvers?.snippet), @@ -217,8 +214,6 @@ ${getImportStatement({ })} ${contentTypeImports.imports.join('\n')} -${commentsManager.environmentInfo(config.environmentData.environment)} - /** * ${toSafeString(typeOrSnippet.name)} * diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index 4f3ffc6..3e2dbb5 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -17,10 +17,10 @@ import { ModuleResolution, TaxonomyNameResolver, TaxonomyTypeFileNameResolver, - toOutputDirPath, getDefaultModuleResolution } from '../../core/index.js'; import { Options } from 'prettier'; +import { EnvironmentModels } from '@kontent-ai/management-sdk'; export interface GenerateDeliveryModelsConfig { readonly environmentId: string; @@ -51,18 +51,21 @@ export async function generateDeliveryModelsAsync(config: GenerateDeliveryModels console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('delivery')}' models\n`); - const { contentTypeFiles, snippetFiles, taxonomyFiles, moduleResolution } = await getFilesAsync(config); + const { contentTypeFiles, snippetFiles, taxonomyFiles, moduleResolution, environmentInfo } = + await getFilesAsync(config); await createFilesAsync( { contentTypeFiles, snippetFiles, - taxonomyFiles + taxonomyFiles, + environmentInfo }, { formatOptions: config.formatOptions, moduleResolution: moduleResolution, - outputDir: config.outputDir + outputDir: config.outputDir, + addTimestamp: config.addTimestamp } ); @@ -74,6 +77,7 @@ async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ readonly snippetFiles: readonly GeneratedFile[]; readonly taxonomyFiles: readonly GeneratedFile[]; readonly moduleResolution: ModuleResolution; + readonly environmentInfo: Readonly; }> { const moduleResolution: ModuleResolution = getDefaultModuleResolution(config.moduleResolution); const kontentFetcher = _kontentFetcher({ @@ -82,7 +86,7 @@ async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ baseUrl: config.baseUrl }); - const environment = await kontentFetcher.getEnvironmentInfoAsync(); + const environmentInfo = await kontentFetcher.getEnvironmentInfoAsync(); const taxonomies = await kontentFetcher.getTaxonomiesAsync(); const { contentTypeFiles, snippetFiles } = deliveryContentTypeGenerator({ @@ -90,7 +94,7 @@ async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ addEnvironmentInfo: config.addEnvironmentInfo, moduleResolution: moduleResolution, environmentData: { - environment: environment, + environment: environmentInfo, types: await kontentFetcher.getTypesAsync(), snippets: await kontentFetcher.getSnippetsAsync(), taxonomies: taxonomies @@ -114,7 +118,8 @@ async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ contentTypeFiles, snippetFiles, taxonomyFiles, - moduleResolution + moduleResolution, + environmentInfo }; } @@ -123,69 +128,73 @@ async function createFilesAsync( readonly contentTypeFiles: readonly GeneratedFile[]; readonly snippetFiles: readonly GeneratedFile[]; readonly taxonomyFiles: readonly GeneratedFile[]; + readonly environmentInfo: Readonly; }, config: { + readonly addTimestamp: boolean; readonly outputDir: string | undefined; readonly moduleResolution: ModuleResolution; readonly formatOptions: Readonly | undefined; } ): Promise { - const fileManager = _fileManager(toOutputDirPath(config.outputDir)); + const fileManager = _fileManager({ + outputDir: config.outputDir, + addTimestamp: config.addTimestamp, + environmentInfo: data.environmentInfo, + formatOptions: config.formatOptions + }); - await fileManager.createFilesAsync( - [ - ...data.contentTypeFiles, - ...data.snippetFiles, - ...data.taxonomyFiles, - // barrel files - { - filename: `${deliveryConfig.contentTypesFolderName}/${coreConfig.barrelExportFilename}`, - text: getBarrelExportCode({ - moduleResolution: config.moduleResolution, - filenames: [ - ...data.contentTypeFiles.map((m) => { - const path = parse(m.filename); - return `./${path.name}`; - }) - ] - }) - }, - { - filename: `${deliveryConfig.contentTypeSnippetsFolderName}/${coreConfig.barrelExportFilename}`, - text: getBarrelExportCode({ - moduleResolution: config.moduleResolution, - filenames: [ - ...data.snippetFiles.map((m) => { - const path = parse(m.filename); - return `./${path.name}`; - }) - ] - }) - }, - { - filename: `${deliveryConfig.taxonomiesFolderName}/${coreConfig.barrelExportFilename}`, - text: getBarrelExportCode({ - moduleResolution: config.moduleResolution, - filenames: [ - ...data.taxonomyFiles.map((m) => { - const path = parse(m.filename); - return `./${path.name}`; - }) - ] - }) - }, - { - filename: coreConfig.barrelExportFilename, - text: getBarrelExportCode({ - moduleResolution: config.moduleResolution, - filenames: [ - `./${deliveryConfig.contentTypesFolderName}/index`, - `./${deliveryConfig.contentTypeSnippetsFolderName}/index`, - `./${deliveryConfig.taxonomiesFolderName}/index` - ] - }) - } - ], - config.formatOptions - ); + await fileManager.createFilesAsync([ + ...data.contentTypeFiles, + ...data.snippetFiles, + ...data.taxonomyFiles, + // barrel files + { + filename: `${deliveryConfig.contentTypesFolderName}/${coreConfig.barrelExportFilename}`, + text: getBarrelExportCode({ + moduleResolution: config.moduleResolution, + filenames: [ + ...data.contentTypeFiles.map((m) => { + const path = parse(m.filename); + return `./${path.name}`; + }) + ] + }) + }, + { + filename: `${deliveryConfig.contentTypeSnippetsFolderName}/${coreConfig.barrelExportFilename}`, + text: getBarrelExportCode({ + moduleResolution: config.moduleResolution, + filenames: [ + ...data.snippetFiles.map((m) => { + const path = parse(m.filename); + return `./${path.name}`; + }) + ] + }) + }, + { + filename: `${deliveryConfig.taxonomiesFolderName}/${coreConfig.barrelExportFilename}`, + text: getBarrelExportCode({ + moduleResolution: config.moduleResolution, + filenames: [ + ...data.taxonomyFiles.map((m) => { + const path = parse(m.filename); + return `./${path.name}`; + }) + ] + }) + }, + { + filename: coreConfig.barrelExportFilename, + text: getBarrelExportCode({ + moduleResolution: config.moduleResolution, + filenames: [ + `./${deliveryConfig.contentTypesFolderName}/index`, + `./${deliveryConfig.contentTypeSnippetsFolderName}/index`, + `./${deliveryConfig.taxonomiesFolderName}/index` + ] + }) + } + ]); } diff --git a/lib/generators/delivery/delivery-taxonomy.generator.ts b/lib/generators/delivery/delivery-taxonomy.generator.ts index 7ccdcc1..756b3dc 100644 --- a/lib/generators/delivery/delivery-taxonomy.generator.ts +++ b/lib/generators/delivery/delivery-taxonomy.generator.ts @@ -11,7 +11,6 @@ import { ModuleResolution, deliveryConfig } from '../../core/index.js'; -import { commentsManager as _commentsManager } from '../../comments/index.js'; export interface DeliveryTaxonomyGeneratorConfig { readonly addTimestamp: boolean; @@ -31,7 +30,6 @@ export interface DeliveryTaxonomyGeneratorConfig { } export function deliveryTaxonomyGenerator(config: DeliveryTaxonomyGeneratorConfig) { - const commentsManager = _commentsManager(config.addTimestamp); const taxonomyFileNameMap = mapFilename(config.fileResolvers?.taxonomy); const taxonomyNameMap = mapName(config.nameResolvers?.taxonomy, 'pascalCase'); @@ -50,8 +48,6 @@ export function deliveryTaxonomyGenerator(config: DeliveryTaxonomyGeneratorConfi const getModelCode = (taxonomy: Readonly): string => { return ` -${commentsManager.environmentInfo(config.environmentData.environment)} - /** * ${toSafeString(taxonomy.name)} * diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index c9fc7e3..eb6d6be 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -2,7 +2,6 @@ import chalk from 'chalk'; import { migrationConfig, coreConfig, - toOutputDirPath, getBarrelExportCode, ModuleResolution, GeneratedFile, @@ -13,6 +12,7 @@ import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; import { migrationGenerator as _migrationGenerator } from './migration.generator.js'; import { parse } from 'path'; import { Options } from 'prettier'; +import { EnvironmentModels } from '@kontent-ai/management-sdk'; export interface GenerateMigrationModelsConfig { readonly environmentId: string; @@ -29,14 +29,16 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('migration')}' models\n`); - const { migrationItemFiles, migrationTypeFile, moduleResolution } = await getFilesAsync(config); + const { migrationItemFiles, migrationTypeFile, moduleResolution, environmentInfo } = await getFilesAsync(config); await createFilesAsync({ migrationItemFiles, migrationTypeFile, moduleResolution, outputDir: config.outputDir, - formatOptions: config.formatOptions + formatOptions: config.formatOptions, + addTimestamp: config.addTimestamp, + environmentInfo }); console.log(chalk.green(`\nCompleted`)); @@ -46,6 +48,7 @@ async function getFilesAsync(config: GenerateMigrationModelsConfig): Promise<{ readonly migrationTypeFile: GeneratedFile; readonly migrationItemFiles: readonly GeneratedFile[]; readonly moduleResolution: ModuleResolution; + readonly environmentInfo: Readonly; }> { const moduleResolution: ModuleResolution = getDefaultModuleResolution(config.moduleResolution); const kontentFetcher = _kontentFetcher({ @@ -54,13 +57,13 @@ async function getFilesAsync(config: GenerateMigrationModelsConfig): Promise<{ baseUrl: config.baseUrl }); - const projectInformation = await kontentFetcher.getEnvironmentInfoAsync(); + const environmentInfo = await kontentFetcher.getEnvironmentInfoAsync(); const migrationGenerator = _migrationGenerator({ addTimestamp: config.addTimestamp, moduleResolution: config.moduleResolution, environmentData: { - environment: projectInformation, + environment: environmentInfo, taxonomies: await kontentFetcher.getTaxonomiesAsync(), languages: await kontentFetcher.getLanguagesAsync(), workflows: await kontentFetcher.getWorkflowsAsync(), @@ -73,7 +76,8 @@ async function getFilesAsync(config: GenerateMigrationModelsConfig): Promise<{ return { moduleResolution, migrationTypeFile: migrationGenerator.getMigrationTypesFile(), - migrationItemFiles: migrationGenerator.getMigrationItemFiles() + migrationItemFiles: migrationGenerator.getMigrationItemFiles(), + environmentInfo }; } @@ -83,37 +87,41 @@ async function createFilesAsync(data: { readonly moduleResolution: ModuleResolution; readonly outputDir: string; readonly formatOptions?: Readonly; + readonly environmentInfo: Readonly; + readonly addTimestamp: boolean; }): Promise { - const fileManager = _fileManager(toOutputDirPath(data.outputDir)); + const fileManager = _fileManager({ + outputDir: data.outputDir, + addTimestamp: data.addTimestamp, + environmentInfo: data.environmentInfo, + formatOptions: data.formatOptions + }); - await fileManager.createFilesAsync( - [ - data.migrationTypeFile, - ...data.migrationItemFiles, - // types barrel file - { - filename: `${migrationConfig.migrationItemsFolderName}/${coreConfig.barrelExportFilename}`, - text: getBarrelExportCode({ - moduleResolution: data.moduleResolution, - filenames: [ - ...data.migrationItemFiles.map((m) => { - return `./${parse(m.filename).name}`; - }) - ] - }) - }, - // main barrel file - { - filename: coreConfig.barrelExportFilename, - text: getBarrelExportCode({ - moduleResolution: data.moduleResolution, - filenames: [ - `./${migrationConfig.migrationItemsFolderName}/index`, - `./${data.migrationTypeFile.filename}` - ] - }) - } - ], - data.formatOptions - ); + await fileManager.createFilesAsync([ + data.migrationTypeFile, + ...data.migrationItemFiles, + // types barrel file + { + filename: `${migrationConfig.migrationItemsFolderName}/${coreConfig.barrelExportFilename}`, + text: getBarrelExportCode({ + moduleResolution: data.moduleResolution, + filenames: [ + ...data.migrationItemFiles.map((m) => { + return `./${parse(m.filename).name}`; + }) + ] + }) + }, + // main barrel file + { + filename: coreConfig.barrelExportFilename, + text: getBarrelExportCode({ + moduleResolution: data.moduleResolution, + filenames: [ + `./${migrationConfig.migrationItemsFolderName}/index`, + `./${data.migrationTypeFile.filename}` + ] + }) + } + ]); } diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index 893ae7d..9458b1a 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -53,7 +53,7 @@ const migrationTypeNames = { } as const; export function migrationGenerator(config: MigrationGeneratorConfig) { - const commentsManager = _commentsManager(config.addTimestamp); + const commentsManager = _commentsManager(); const getMigrationItemType = (type: Readonly): GeneratedFile => { return { @@ -113,8 +113,6 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { moduleResolution: config.moduleResolution })} - ${commentsManager.environmentInfo(config.environmentData.environment)} - ${commentsManager.wrapComment('Type representing all languages')} ${getLanguageCodenamesType(config.environmentData.languages)} diff --git a/lib/generators/project/project-func.ts b/lib/generators/project/project-func.ts index 637fee1..e5719a5 100644 --- a/lib/generators/project/project-func.ts +++ b/lib/generators/project/project-func.ts @@ -8,10 +8,10 @@ import { GeneratedFile, getBarrelExportCode, getDefaultModuleResolution, - ModuleResolution, - toOutputDirPath + ModuleResolution } from '../../core/index.js'; import { Options } from 'prettier'; +import { EnvironmentModels } from '@kontent-ai/management-sdk'; export interface GenerateProjectModelsConfig { readonly environmentId: string; @@ -29,21 +29,25 @@ export async function generateProjectModelsAsync(config: GenerateProjectModelsCo console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('project')}' models\n`); - const { moduleResolution, projectFiles } = await getModelsAsync(config); + const { moduleResolution, projectFiles, environmentInfo } = await getModelsAsync(config); await createFilesAsync({ moduleResolution, projectFiles, outputDir: config.outputDir, - formatOptions: config.formatOptions + formatOptions: config.formatOptions, + addTimestamp: config.addTimestamp, + environmentInfo }); console.log(chalk.green(`\nCompleted`)); } -async function getModelsAsync( - config: GenerateProjectModelsConfig -): Promise<{ projectFiles: readonly GeneratedFile[]; moduleResolution: ModuleResolution }> { +async function getModelsAsync(config: GenerateProjectModelsConfig): Promise<{ + projectFiles: readonly GeneratedFile[]; + moduleResolution: ModuleResolution; + readonly environmentInfo: Readonly; +}> { const moduleResolution: ModuleResolution = getDefaultModuleResolution(config.moduleResolution); const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, @@ -51,14 +55,15 @@ async function getModelsAsync( baseUrl: config.baseUrl }); - const projectInformation = await kontentFetcher.getEnvironmentInfoAsync(); + const environmentInfo = await kontentFetcher.getEnvironmentInfoAsync(); return { + environmentInfo, projectFiles: _projectGenerator({ addTimestamp: config.addTimestamp, formatOptions: config.formatOptions, environmentData: { - environmentInfo: projectInformation, + environmentInfo: environmentInfo, languages: await kontentFetcher.getLanguagesAsync(), taxonomies: await kontentFetcher.getTaxonomiesAsync(), types: await kontentFetcher.getTypesAsync(), @@ -78,27 +83,31 @@ async function createFilesAsync(data: { readonly projectFiles: readonly GeneratedFile[]; readonly moduleResolution: ModuleResolution; readonly outputDir?: string; - + readonly addTimestamp: boolean; + readonly environmentInfo: Readonly; readonly formatOptions?: Readonly; }): Promise { - const fileManager = _fileManager(toOutputDirPath(data.outputDir)); - await fileManager.createFilesAsync( - [ - ...data.projectFiles, - // barrel file - { - filename: coreConfig.barrelExportFilename, - text: getBarrelExportCode({ - moduleResolution: data.moduleResolution, - filenames: [ - ...data.projectFiles.map((m) => { - const path = parse(m.filename); - return `./${path.name}`; - }) - ] - }) - } - ], - data.formatOptions - ); + const fileManager = _fileManager({ + addTimestamp: data.addTimestamp, + environmentInfo: data.environmentInfo, + formatOptions: data.formatOptions, + outputDir: data.outputDir + }); + + await fileManager.createFilesAsync([ + ...data.projectFiles, + // barrel file + { + filename: coreConfig.barrelExportFilename, + text: getBarrelExportCode({ + moduleResolution: data.moduleResolution, + filenames: [ + ...data.projectFiles.map((m) => { + const path = parse(m.filename); + return `./${path.name}`; + }) + ] + }) + } + ]); } diff --git a/lib/generators/project/project.generator.ts b/lib/generators/project/project.generator.ts index 8bfb623..62505d0 100644 --- a/lib/generators/project/project.generator.ts +++ b/lib/generators/project/project.generator.ts @@ -13,7 +13,6 @@ import { WorkflowModels, ContentTypeElements } from '@kontent-ai/management-sdk'; -import { commentsManager as _commentsManager } from '../../comments/index.js'; import { FlattenedElement, GeneratedFile, @@ -55,19 +54,11 @@ export interface ProjectGeneratorConfig { } export function projectGenerator(config: ProjectGeneratorConfig) { - const commentsManager = _commentsManager(config.addTimestamp); - - const getHeaderComment = (): string => { - return `${commentsManager.environmentInfo(config.environmentData.environmentInfo, { addGeneratedBy: true })}`; - }; - const generateProjectModel = (): readonly GeneratedFile[] => { - const headerCode = getHeaderComment(); - return getProjectModelCode().map((projectCode) => { return { filename: `${projectCode.filename}`, - text: headerCode + '\n' + projectCode.code + text: projectCode.code }; }); }; diff --git a/sample/delivery/content-type-snippets/index.ts b/sample/delivery/content-type-snippets/index.ts index bc0c90e..6b2e0f1 100644 --- a/sample/delivery/content-type-snippets/index.ts +++ b/sample/delivery/content-type-snippets/index.ts @@ -1,2 +1,15 @@ +/** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- + * + * Environment: Production + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ + export * from './my_snippet.js'; export * from './taxonomy_snippet_test.js'; diff --git a/sample/delivery/content-type-snippets/my_snippet.ts b/sample/delivery/content-type-snippets/my_snippet.ts index 642b9b6..ca3e1d7 100644 --- a/sample/delivery/content-type-snippets/my_snippet.ts +++ b/sample/delivery/content-type-snippets/my_snippet.ts @@ -1,12 +1,17 @@ -import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; - /** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. * - * Migration Toolkit tests + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- * * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 - */ + * + * ------------------------------------------------------------------------------- + **/ + +import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; /** * My snippet diff --git a/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts b/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts index 29371a0..e3171a5 100644 --- a/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts +++ b/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts @@ -1,13 +1,18 @@ -import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; -import type { Category } from '../taxonomies/category.js'; - /** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. * - * Migration Toolkit tests + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- * * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 - */ + * + * ------------------------------------------------------------------------------- + **/ + +import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; +import type { Category } from '../taxonomies/category.js'; /** * Taxonomy snippet test diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index bb7881c..c0438c2 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -1,12 +1,17 @@ -import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; - /** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. * - * Migration Toolkit tests + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- * * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 - */ + * + * ------------------------------------------------------------------------------- + **/ + +import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; /** * Actor diff --git a/sample/delivery/content-types/index.ts b/sample/delivery/content-types/index.ts index e8c4f36..8fe5273 100644 --- a/sample/delivery/content-types/index.ts +++ b/sample/delivery/content-types/index.ts @@ -1,3 +1,16 @@ +/** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- + * + * Environment: Production + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ + export * from './actor.js'; export * from './movie.js'; export * from './test.js'; diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 2ddef1f..7bf1696 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -1,15 +1,20 @@ -import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; -import type { Category } from '../taxonomies/category.js'; -import type { ReleaseCategory } from '../taxonomies/release_category.js'; -import type { TaxonomySnippetTest } from '../content-type-snippets/taxonomy_snippet_test.js'; - /** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai * - * Migration Toolkit tests + * ------------------------------------------------------------------------------- * * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 - */ + * + * ------------------------------------------------------------------------------- + **/ + +import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; +import type { Category } from '../taxonomies/category.js'; +import type { ReleaseCategory } from '../taxonomies/release_category.js'; +import type { TaxonomySnippetTest } from '../content-type-snippets/taxonomy_snippet_test.js'; /** * Movie diff --git a/sample/delivery/content-types/test.ts b/sample/delivery/content-types/test.ts index 8780150..69a9956 100644 --- a/sample/delivery/content-types/test.ts +++ b/sample/delivery/content-types/test.ts @@ -1,13 +1,18 @@ -import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; -import type { MySnippet } from '../content-type-snippets/my_snippet.js'; - /** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. * - * Migration Toolkit tests + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- * * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 - */ + * + * ------------------------------------------------------------------------------- + **/ + +import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; +import type { MySnippet } from '../content-type-snippets/my_snippet.js'; /** * Test diff --git a/sample/delivery/index.ts b/sample/delivery/index.ts index 5e8dc5a..0ea0c5f 100644 --- a/sample/delivery/index.ts +++ b/sample/delivery/index.ts @@ -1,3 +1,16 @@ +/** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- + * + * Environment: Production + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ + export * from './content-types/index.js'; export * from './content-type-snippets/index.js'; export * from './taxonomies/index.js'; diff --git a/sample/delivery/taxonomies/category.ts b/sample/delivery/taxonomies/category.ts index 5bbcaa6..7f61d47 100644 --- a/sample/delivery/taxonomies/category.ts +++ b/sample/delivery/taxonomies/category.ts @@ -1,10 +1,15 @@ /** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. * - * Migration Toolkit tests + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- * * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 - */ + * + * ------------------------------------------------------------------------------- + **/ /** * Category diff --git a/sample/delivery/taxonomies/index.ts b/sample/delivery/taxonomies/index.ts index 116ed03..51facae 100644 --- a/sample/delivery/taxonomies/index.ts +++ b/sample/delivery/taxonomies/index.ts @@ -1,2 +1,15 @@ +/** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- + * + * Environment: Production + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ + export * from './category.js'; export * from './release_category.js'; diff --git a/sample/delivery/taxonomies/release_category.ts b/sample/delivery/taxonomies/release_category.ts index 714a6bd..66d58bc 100644 --- a/sample/delivery/taxonomies/release_category.ts +++ b/sample/delivery/taxonomies/release_category.ts @@ -1,10 +1,15 @@ /** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. * - * Migration Toolkit tests + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- * * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 - */ + * + * ------------------------------------------------------------------------------- + **/ /** * Release category diff --git a/sample/migration/content-types/actor.ts b/sample/migration/content-types/actor.ts index 543ce67..2100f90 100644 --- a/sample/migration/content-types/actor.ts +++ b/sample/migration/content-types/actor.ts @@ -1,3 +1,16 @@ +/** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- + * + * Environment: Production + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ + import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; import type { Item } from '../core.models.js'; diff --git a/sample/migration/content-types/index.ts b/sample/migration/content-types/index.ts index e8c4f36..8fe5273 100644 --- a/sample/migration/content-types/index.ts +++ b/sample/migration/content-types/index.ts @@ -1,3 +1,16 @@ +/** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- + * + * Environment: Production + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ + export * from './actor.js'; export * from './movie.js'; export * from './test.js'; diff --git a/sample/migration/content-types/movie.ts b/sample/migration/content-types/movie.ts index f9684b5..433a9dc 100644 --- a/sample/migration/content-types/movie.ts +++ b/sample/migration/content-types/movie.ts @@ -1,3 +1,16 @@ +/** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- + * + * Environment: Production + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ + import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; import type { Item } from '../core.models.js'; diff --git a/sample/migration/content-types/test.ts b/sample/migration/content-types/test.ts index 2a9f76e..87d0333 100644 --- a/sample/migration/content-types/test.ts +++ b/sample/migration/content-types/test.ts @@ -1,3 +1,16 @@ +/** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- + * + * Environment: Production + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ + import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; import type { Item } from '../core.models.js'; diff --git a/sample/migration/core.models.ts b/sample/migration/core.models.ts index bd9997d..f813b59 100644 --- a/sample/migration/core.models.ts +++ b/sample/migration/core.models.ts @@ -1,12 +1,17 @@ -import type { MigrationItemSystem, MigrationItem, MigrationElements } from '@kontent-ai/migration-toolkit'; - /** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. * - * Migration Toolkit tests + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- * * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 - */ + * + * ------------------------------------------------------------------------------- + **/ + +import type { MigrationItemSystem, MigrationItem, MigrationElements } from '@kontent-ai/migration-toolkit'; /** * Type representing all languages diff --git a/sample/migration/index.ts b/sample/migration/index.ts index 1e05f1f..c1f868e 100644 --- a/sample/migration/index.ts +++ b/sample/migration/index.ts @@ -1,2 +1,15 @@ +/** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- + * + * Environment: Production + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ + export * from './content-types/index.js'; export * from './core.models.js'; diff --git a/sample/project/assetFolders.ts b/sample/project/assetFolders.ts index 3c7f907..378af9a 100644 --- a/sample/project/assetFolders.ts +++ b/sample/project/assetFolders.ts @@ -1,63 +1,35 @@ /** - * Generated by '@kontent-ai/model-generator@7.4.0' - * Movie Database + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- * * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - */ + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ export const assetFolders = { /** - * my folder A + * my folder */ - myFolderA: { - codename: 'my_folder_a', - id: '6bb4814a-6a5c-4b8c-836e-7f83b008d5d1', + myFolder: { + codename: 'my_folder', + id: 'f1c6ba01-3b13-41ce-81e7-3125840b0b0e', externalId: undefined, - name: 'my folder A', - folders: { - /** - * my folder nested A - */ - myFolderNestedA: { - codename: 'my_folder_nested_a', - id: '555784e5-e92e-4a86-b40b-d642afbf7b4e', - externalId: undefined, - name: 'my folder nested A', - folders: { - /** - * even more nested A - */ - evenMoreNestedA: { - codename: 'even_more_nested_a', - id: 'd26940cc-6c8d-41e6-93a0-0748c854b100', - externalId: undefined, - name: 'even more nested A', - folders: {} - }, - - /** - * even more nested B - */ - evenMoreNestedB: { - codename: 'even_more_nested_b', - id: '97fc4b03-98d2-44b4-8e03-b223a013b0b6', - externalId: undefined, - name: 'even more nested B', - folders: {} - } - } - } - } + name: 'my folder', + folders: {} }, /** - * my folder B + * my folder2 */ - myFolderB: { - codename: 'my_folder_b', - id: '58d1c135-42cb-43c2-a2cd-c615e0a36e83', + myFolder2: { + codename: 'my_folder2', + id: '44a00189-9298-4cf9-b8fb-3f208c3f4f8f', externalId: undefined, - name: 'my folder B', + name: 'my folder2', folders: {} } } as const; diff --git a/sample/project/collections.ts b/sample/project/collections.ts index 417d017..2a6877f 100644 --- a/sample/project/collections.ts +++ b/sample/project/collections.ts @@ -1,10 +1,15 @@ /** - * Generated by '@kontent-ai/model-generator@7.4.0' - * Movie Database + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- * * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - */ + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ export const collections = { /** * Default diff --git a/sample/project/contentTypeSnippets.ts b/sample/project/contentTypeSnippets.ts index 81119c3..e09c5d5 100644 --- a/sample/project/contentTypeSnippets.ts +++ b/sample/project/contentTypeSnippets.ts @@ -1,8 +1,71 @@ /** - * Generated by '@kontent-ai/model-generator@7.4.0' - * Movie Database + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- * * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - */ -export const contentTypeSnippets = {} as const; + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ +export const contentTypeSnippets = { + /** + * My snippet + */ + mySnippet: { + codename: 'my_snippet', + id: '3274f9e7-ff1b-43f8-aa32-29b53939cd3e', + externalId: undefined, + name: 'My snippet', + elements: { + /** + * Snippet elem1 (text) + */ + mySnippetSnippetElem1: { + codename: 'my_snippet__snippet_elem1', + id: '3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d', + externalId: undefined, + name: 'Snippet elem1', + required: false, + type: 'text' + }, + + /** + * Snippet elem 2 (number) + */ + mySnippetSnippetElem2: { + codename: 'my_snippet__snippet_elem_2', + id: 'b2f65646-3310-4a64-af2a-0d9d025a91d0', + externalId: undefined, + name: 'Snippet elem 2', + required: false, + type: 'number' + } + } + }, + + /** + * Taxonomy snippet test + */ + taxonomySnippetTest: { + codename: 'taxonomy_snippet_test', + id: 'e8219115-e629-4552-b79b-d9f813272573', + externalId: undefined, + name: 'Taxonomy snippet test', + elements: { + /** + * Category (taxonomy) + */ + taxonomySnippetTestTestTaxonomy: { + codename: 'taxonomy_snippet_test__test_taxonomy', + id: 'c030e3ec-5031-4d7f-af88-5032365733c7', + externalId: undefined, + name: 'Category', + required: false, + type: 'taxonomy' + } + } + } +} as const; diff --git a/sample/project/contentTypes.ts b/sample/project/contentTypes.ts index 44df780..1fbb290 100644 --- a/sample/project/contentTypes.ts +++ b/sample/project/contentTypes.ts @@ -1,67 +1,71 @@ /** - * Generated by '@kontent-ai/model-generator@7.4.0' - * Movie Database + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- * * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - */ + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ export const contentTypes = { /** * Actor */ actor: { codename: 'actor', - id: '58099989-319f-495f-aa36-cb3710854e36', + id: 'd8900ee2-82f4-4189-a994-4e121582aadf', externalId: undefined, name: 'Actor', elements: { /** - * Url (url_slug) + * photo (asset) */ - url: { - codename: 'url', - id: 'c8658782-f209-a573-9c85-430fb4e3e9f0', + photo: { + codename: 'photo', + id: '069b38ee-385c-410f-b7fe-53ec59a5f139', externalId: undefined, - name: 'Url', + name: 'photo', required: false, - type: 'url_slug' + type: 'asset' }, /** - * First name (text) - * Guidelines: This is the first name of the actor + * url (url_slug) */ - firstName: { - codename: 'first_name', - id: '14dd70e5-c42d-f111-9640-c82b443edf1d', + url: { + codename: 'url', + id: 'c4b2d64f-af45-45a4-92d8-4829833563ff', externalId: undefined, - name: 'First name', - required: true, - type: 'text' + name: 'url', + required: false, + type: 'url_slug' }, /** - * Last name (text) + * last_name (text) */ lastName: { codename: 'last_name', - id: '9f7a0dd4-af3a-95ca-0358-400c14ce7075', + id: '0f00b26e-60f3-462d-8110-18180137c3a0', externalId: undefined, - name: 'Last name', - required: true, + name: 'last_name', + required: false, type: 'text' }, /** - * Photo (asset) + * first_name (text) */ - photo: { - codename: 'photo', - id: 'eaec9ba3-9624-6875-04ec-80d0b2e00781', + firstName: { + codename: 'first_name', + id: '4af5e7ce-88ef-4159-96ae-96a552992f91', externalId: undefined, - name: 'Photo', + name: 'first_name', required: false, - type: 'asset' + type: 'text' } } }, @@ -71,197 +75,175 @@ export const contentTypes = { */ movie: { codename: 'movie', - id: 'b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c', + id: 'db7356f6-1d82-42a0-9ebb-07865cffa995', externalId: undefined, name: 'Movie', elements: { /** - * Title (text) + * Category (taxonomy) */ - title: { - codename: 'title', - id: '3473187e-dc78-eff2-7099-f690f7042d4a', + taxonomySnippetTestTestTaxonomy: { + codename: 'taxonomy_snippet_test__test_taxonomy', + id: 'c030e3ec-5031-4d7f-af88-5032365733c7', externalId: undefined, - name: 'Title', - required: true, - type: 'text' + name: 'Category', + required: false, + type: 'taxonomy' }, /** - * Plot (rich_text) + * Release category (taxonomy) */ - plot: { - codename: 'plot', - id: 'f7ee4f27-27fd-a19b-3c5c-102aae1c50ce', + releasecategory: { + codename: 'releasecategory', + id: '5faa827f-f262-43c3-8f58-0f354b8d393f', externalId: undefined, - name: 'Plot', + name: 'Release category', required: false, - type: 'rich_text' + type: 'taxonomy' }, /** - * Released (date_time) + * Category (taxonomy) */ - released: { - codename: 'released', - id: '5ccf4644-0d65-5d96-9a32-f4ea21974d51', + category: { + codename: 'category', + id: '8c12be35-e3e7-447c-a185-7b5e101ebf12', externalId: undefined, - name: 'Released', + name: 'Category', required: false, - type: 'date_time' + type: 'taxonomy' }, /** - * Length (number) + * length (number) */ length: { codename: 'length', - id: '7e8ecfab-a419-27ee-d8ec-8adb76fd007c', + id: 'e3d07f3a-60c2-4072-846d-c23e51ec833e', externalId: undefined, - name: 'Length', + name: 'length', required: false, type: 'number' }, /** - * Poster (asset) + * stars (modular_content) + */ + stars: { + codename: 'stars', + id: '55596dd1-e808-415d-95aa-e2be34238d11', + externalId: undefined, + name: 'stars', + required: false, + type: 'modular_content' + }, + + /** + * seoname (url_slug) + */ + seoname: { + codename: 'seoname', + id: '734f94be-5930-4bdf-b05b-f59f5a291675', + externalId: undefined, + name: 'seoname', + required: false, + type: 'url_slug' + }, + + /** + * poster (asset) */ poster: { codename: 'poster', - id: 'a39a7237-9503-a1ae-8431-5b6cdb85ae9d', + id: '9b197f1e-0728-4d14-9814-97f7b8ef01fc', externalId: undefined, - name: 'Poster', + name: 'poster', required: false, type: 'asset' }, /** - * Category (multiple_choice) + * released (date_time) */ - category: { - codename: 'category', - id: '9821c252-6414-f549-c17f-cc171dd87713', + released: { + codename: 'released', + id: '656b9dc9-7bba-4f1f-a2b8-52f7f730a66f', externalId: undefined, - name: 'Category', + name: 'released', required: false, - type: 'multiple_choice', - options: { - /** - * Sci fi - */ - sciFi: { - name: 'Sci fi', - id: 'b087f774-1f57-9aa8-dab5-2ca88a646824', - codename: 'sci_fi', - externalId: undefined - }, - - /** - * Documentary - */ - documentary: { - name: 'Documentary', - id: '19c5e959-c24a-4863-0b4d-453cdef8fe9d', - codename: 'documentary', - externalId: undefined - }, - - /** - * Action - */ - action: { - name: 'Action', - id: '7d453309-8d74-9607-80c4-36dcc1bd005f', - codename: 'action', - externalId: undefined - }, - - /** - * Romance - */ - romance: { - name: 'Romance', - id: '60550cc7-c986-a59f-b069-7565862fe1c1', - codename: 'romance', - externalId: undefined - }, - - /** - * Animation - */ - animation: { - name: 'Animation', - id: '54c0590d-6a94-a69a-902d-fceea4fa62f8', - codename: 'animation', - externalId: undefined - }, - - /** - * Comedy - */ - comedy: { - name: 'Comedy', - id: 'd2fe357f-894e-9bc3-550c-c2c400d99c6b', - codename: 'comedy', - externalId: undefined - }, - - /** - * Adventure - */ - adventure: { - name: 'Adventure', - id: 'cd8389b0-7628-7739-7b14-3225a50212c1', - codename: 'adventure', - externalId: undefined - }, + type: 'date_time' + }, - /** - * Drama - */ - drama: { - name: 'Drama', - id: '051e74de-f2e0-f405-9ad5-5263221e46f2', - codename: 'drama', - externalId: undefined - } - } + /** + * plot (rich_text) + */ + plot: { + codename: 'plot', + id: 'ad2e5dc7-8d08-4f74-afeb-25b475f1e6fc', + externalId: undefined, + name: 'plot', + required: false, + type: 'rich_text' }, /** - * Stars (modular_content) + * title (text) */ - stars: { - codename: 'stars', - id: 'aa26a55d-19f8-7501-fea3-b0d9b1eeac71', + title: { + codename: 'title', + id: '660c851a-a9a1-4378-97a3-1348bc2a4d76', externalId: undefined, - name: 'Stars', + name: 'title', required: false, - type: 'modular_content' + type: 'text' + } + } + }, + + /** + * Test + */ + test: { + codename: 'test', + id: '81ab0b2c-dd14-41e7-a1ed-868b249ad8bc', + externalId: undefined, + name: 'Test', + elements: { + /** + * Text (text) + */ + text: { + codename: 'text', + id: '65f61f6a-b69c-47dc-bc38-19855507bf14', + externalId: undefined, + name: 'Text', + required: false, + type: 'text' }, /** - * SeoName (url_slug) + * Snippet elem1 (text) */ - seoname: { - codename: 'seoname', - id: '756cc91a-a090-60f9-a7f0-f505bfbe046c', + mySnippetSnippetElem1: { + codename: 'my_snippet__snippet_elem1', + id: '3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d', externalId: undefined, - name: 'SeoName', + name: 'Snippet elem1', required: false, - type: 'url_slug' + type: 'text' }, /** - * ReleaseCategory (taxonomy) + * Snippet elem 2 (number) */ - releasecategory: { - codename: 'releasecategory', - id: '65f2fd44-1856-bc2b-17c2-decb0635e3d2', + mySnippetSnippetElem2: { + codename: 'my_snippet__snippet_elem_2', + id: 'b2f65646-3310-4a64-af2a-0d9d025a91d0', externalId: undefined, - name: 'ReleaseCategory', + name: 'Snippet elem 2', required: false, - type: 'taxonomy' + type: 'number' } } } diff --git a/sample/project/index.ts b/sample/project/index.ts index 886cbf6..c9dafe7 100644 --- a/sample/project/index.ts +++ b/sample/project/index.ts @@ -1,3 +1,15 @@ +/** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- + * + * Environment: Production + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ export * from './languages.js'; export * from './collections.js'; export * from './contentTypes.js'; diff --git a/sample/project/languages.ts b/sample/project/languages.ts index 21577e9..b3aec88 100644 --- a/sample/project/languages.ts +++ b/sample/project/languages.ts @@ -1,31 +1,23 @@ /** - * Generated by '@kontent-ai/model-generator@7.4.0' - * Movie Database + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- * * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - */ + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ export const languages = { /** - * cz - */ - cz: { - codename: 'cz', - id: '41ccb26f-ceab-04d0-6ffa-9c7c5358aa8f', - name: 'cz', - isActive: true, - isDefault: false, - fallbackLanguageId: '00000000-0000-0000-0000-000000000000', - externalId: undefined - }, - - /** - * English + * Default project language */ en: { codename: 'en', id: '00000000-0000-0000-0000-000000000000', - name: 'English', + name: 'Default project language', isActive: true, isDefault: true, fallbackLanguageId: '00000000-0000-0000-0000-000000000000', @@ -33,13 +25,13 @@ export const languages = { }, /** - * German + * Spanish */ - german: { - codename: 'German', - id: '14f7bcc0-4fd6-4b77-8c22-70e5ccfdae1d', - name: 'German', - isActive: false, + es: { + codename: 'es', + id: '71cf90e5-8124-43e3-8ef4-bbb8bdcd22ae', + name: 'Spanish', + isActive: true, isDefault: false, fallbackLanguageId: '00000000-0000-0000-0000-000000000000', externalId: undefined diff --git a/sample/project/roles.ts b/sample/project/roles.ts index 8caaf5b..16683b8 100644 --- a/sample/project/roles.ts +++ b/sample/project/roles.ts @@ -1,44 +1,22 @@ /** - * Generated by '@kontent-ai/model-generator@7.4.0' - * Movie Database + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- * * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - */ + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ export const roles = { - /** - * Content contributor - */ - contentContributor: { - codename: undefined, - id: 'dca0ac85-274f-429e-b00e-6f74bf917051', - name: 'Content contributor' - }, - - /** - * Developer - */ - developer: { - codename: undefined, - id: 'b3994090-0818-4969-816b-f4c5d3e526f3', - name: 'Developer' - }, - /** * Project manager */ projectManager: { codename: 'project-manager', - id: 'af95ac37-4efa-4b92-aa26-db773cd172c6', + id: '5a8e7afd-3dcc-4adc-9f23-bf36a31d61bf', name: 'Project manager' - }, - - /** - * Reviewer - */ - reviewer: { - codename: undefined, - id: '94478afa-d898-45dd-8300-ba61b6e0eb4b', - name: 'Reviewer' } } as const; diff --git a/sample/project/taxonomies.ts b/sample/project/taxonomies.ts index d095aff..6c6c3b2 100644 --- a/sample/project/taxonomies.ts +++ b/sample/project/taxonomies.ts @@ -1,116 +1,121 @@ /** - * Generated by '@kontent-ai/model-generator@7.4.0' - * Movie Database + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- * * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - */ + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ export const taxonomies = { /** - * MovieType + * Category */ - movietype: { - codename: 'movietype', + category: { + codename: 'category', externalId: undefined, - id: '365a17e6-1929-27ab-9f67-a9273c846717', - name: 'MovieType', + id: 'c1b56389-f00a-4917-95c4-3b02ea3610ea', + name: 'Category', terms: { /** - * Film + * action + */ + action: { + codename: 'action', + id: 'e3410312-52d6-4c15-8e23-e5a4cc57a204', + externalId: undefined, + name: 'action', + terms: {} + }, + + /** + * animation + */ + animation: { + codename: 'animation', + id: '2d8a95a8-61c9-4add-94a1-1d7944098144', + externalId: undefined, + name: 'animation', + terms: {} + }, + + /** + * comedy */ - film: { - codename: 'film', - id: '5a2a1927-41a4-294f-5d89-cf0cc045e943', + comedy: { + codename: 'comedy', + id: 'eddaa24b-fb5c-4a44-8507-8dd7a45fdc39', externalId: undefined, - name: 'Film', - terms: { - /** - * Blockbuster - */ - blockbuster: { - codename: 'blockbuster', - id: '875a4657-1dcd-0415-cb3a-892078f5991a', - externalId: undefined, - name: 'Blockbuster', - terms: {} - }, + name: 'comedy', + terms: {} + }, - /** - * Cinema only - */ - cinemaOnly: { - codename: 'cinema_only', - id: 'e15c4e32-ab7c-57a2-1b66-d8e3566a1dd2', - externalId: undefined, - name: 'Cinema only', - terms: {} - }, + /** + * drama + */ + drama: { + codename: 'drama', + id: '7377ea7c-d928-408a-bfb8-a0bf7392c996', + externalId: undefined, + name: 'drama', + terms: {} + }, - /** - * TV - */ - tv: { - codename: 'tv', - id: '47511b09-6c39-fa04-ff59-7c47551e827f', - externalId: undefined, - name: 'TV', - terms: {} - } - } + /** + * romance + */ + romance: { + codename: 'romance', + id: 'fe8bdfdb-cc13-4890-ab45-a6669e94d1d0', + externalId: undefined, + name: 'romance', + terms: {} }, /** - * Student + * sci_fi */ - student: { - codename: 'student', - id: 'b107e12c-124d-705f-1029-c0dfdd0b2438', + sciFi: { + codename: 'sci_fi', + id: '1432c10c-096c-47c5-a045-dcd6dc4af366', externalId: undefined, - name: 'Student', + name: 'sci_fi', terms: {} } } }, /** - * ReleaseCategory + * Release category */ - releasecategory: { - codename: 'releasecategory', + releaseCategory: { + codename: 'release_category', externalId: undefined, - id: '09b6a348-0f86-7a68-4af3-7cab9a5c60b7', - name: 'ReleaseCategory', + id: '4dbfc78f-5ea2-4f33-880d-193c75e0b975', + name: 'Release category', terms: { /** - * Global release + * global_release */ globalRelease: { codename: 'global_release', - id: '4acaf439-9f3a-f34a-6211-d3fc6ec7152e', - externalId: undefined, - name: 'Global release', - terms: {} - }, - - /** - * Local release - */ - localRelease: { - codename: 'local_release', - id: '37e55484-f0dc-14eb-bf2a-b0293a0d1b1f', + id: 'afb51aba-cb5a-499a-973c-d5b44fdeafcf', externalId: undefined, - name: 'Local release', + name: 'global_release', terms: {} }, /** - * US only + * us_only */ usOnly: { codename: 'us_only', - id: 'b03d990a-55a9-601e-dd5c-aa2edc8698ca', + id: '3f8bddaf-c203-471b-af76-6539d3e72e89', externalId: undefined, - name: 'US only', + name: 'us_only', terms: {} } } diff --git a/sample/project/webhooks.ts b/sample/project/webhooks.ts index fc0272e..75b3159 100644 --- a/sample/project/webhooks.ts +++ b/sample/project/webhooks.ts @@ -1,8 +1,13 @@ /** - * Generated by '@kontent-ai/model-generator@7.4.0' - * Movie Database + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- * * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - */ + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ export const webhooks = {} as const; diff --git a/sample/project/workflows.ts b/sample/project/workflows.ts index a93b01b..2b1b016 100644 --- a/sample/project/workflows.ts +++ b/sample/project/workflows.ts @@ -1,10 +1,15 @@ /** - * Generated by '@kontent-ai/model-generator@7.4.0' - * Movie Database + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- * * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - */ + * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * + * ------------------------------------------------------------------------------- + **/ export const workflows = { /** * Default @@ -22,7 +27,7 @@ export const workflows = { published: { name: 'Published', codename: 'published', - id: 'f05b8a85-c6cc-429a-ac6d-21d5edd268fe' + id: 'c199950d-99f0-4983-b711-6c4c91624b22' }, scheduled: { name: 'Scheduled', @@ -32,17 +37,48 @@ export const workflows = { draft: { name: 'Draft', codename: 'draft', - id: 'e3ef0816-2203-4456-bfdc-a735b4f339ab' - }, - review: { - name: 'Review', - codename: 'review', - id: 'c5682935-f5a2-4514-8025-57d8bdf7558d' + id: 'eee6db3b-545a-4785-8e86-e3772c8756f9' }, readyToPublish: { - name: 'Ready to publish', + name: 'ready_to_publish', codename: 'ready_to_publish', - id: 'aaee1d73-f0cc-4185-9e49-844d161c3634' + id: 'f4afd295-cc0b-48e3-9431-176cc1e17e2c' + } + } + }, + + /** + * my_test_workflow + */ + myTestWorkflow: { + codename: 'my_test_workflow', + id: '51036ae0-1a0c-48c6-980e-bf73600ba462', + name: 'my_test_workflow', + steps: { + archived: { + name: 'Archived', + codename: 'archived', + id: '7a535a69-ad34-47f8-806a-def1fdf4d391' + }, + published: { + name: 'Published', + codename: 'published', + id: 'c199950d-99f0-4983-b711-6c4c91624b22' + }, + scheduled: { + name: 'Scheduled', + codename: 'scheduled', + id: '9d2b0228-4d0d-4c23-8b49-01a698857709' + }, + draft3171da5: { + name: 'Draft', + codename: 'draft_3171da5', + id: '3171da5f-679d-49af-a42c-617d83eac222' + }, + readyForReview: { + name: 'ready_for_review', + codename: 'ready_for_review', + id: '20f49208-5e57-4300-b6bd-0f668cbce00b' } } } From 2db379695b27f5423007cc587c343f134d06a22b Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 29 Aug 2024 11:25:16 +0200 Subject: [PATCH 037/183] Updates samples --- .../delivery/content-type-snippets/index.ts | 5 +- .../content-type-snippets/my_snippet.ts | 40 --- .../taxonomy_snippet_test.ts | 32 -- sample/delivery/content-types/actor.ts | 37 +-- sample/delivery/content-types/index.ts | 3 +- sample/delivery/content-types/movie.ts | 86 +++--- sample/delivery/content-types/test.ts | 33 -- sample/delivery/index.ts | 2 +- sample/delivery/taxonomies/index.ts | 6 +- .../{release_category.ts => movietype.ts} | 10 +- .../{category.ts => releasecategory.ts} | 10 +- sample/migration/content-types/actor.ts | 37 +-- sample/migration/content-types/index.ts | 3 +- sample/migration/content-types/movie.ts | 83 +++-- sample/migration/content-types/test.ts | 53 ---- sample/migration/core.models.ts | 17 +- sample/migration/index.ts | 2 +- sample/project/assetFolders.ts | 58 +++- sample/project/collections.ts | 3 +- sample/project/contentTypeSnippets.ts | 61 +--- sample/project/contentTypes.ts | 290 ++++++++++-------- sample/project/index.ts | 3 +- sample/project/languages.ts | 32 +- sample/project/roles.ts | 32 +- sample/project/taxonomies.ts | 141 ++++----- sample/project/webhooks.ts | 3 +- sample/project/workflows.ts | 52 +--- 27 files changed, 487 insertions(+), 647 deletions(-) delete mode 100644 sample/delivery/content-type-snippets/my_snippet.ts delete mode 100644 sample/delivery/content-type-snippets/taxonomy_snippet_test.ts delete mode 100644 sample/delivery/content-types/test.ts rename sample/delivery/taxonomies/{release_category.ts => movietype.ts} (60%) rename sample/delivery/taxonomies/{category.ts => releasecategory.ts} (60%) delete mode 100644 sample/migration/content-types/test.ts diff --git a/sample/delivery/content-type-snippets/index.ts b/sample/delivery/content-type-snippets/index.ts index 6b2e0f1..5ecc785 100644 --- a/sample/delivery/content-type-snippets/index.ts +++ b/sample/delivery/content-type-snippets/index.ts @@ -6,10 +6,9 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ -export * from './my_snippet.js'; -export * from './taxonomy_snippet_test.js'; +export {}; diff --git a/sample/delivery/content-type-snippets/my_snippet.ts b/sample/delivery/content-type-snippets/my_snippet.ts deleted file mode 100644 index ca3e1d7..0000000 --- a/sample/delivery/content-type-snippets/my_snippet.ts +++ /dev/null @@ -1,40 +0,0 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 - * - * ------------------------------------------------------------------------------- - **/ - -import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; - -/** - * My snippet - * - * Id: 3274f9e7-ff1b-43f8-aa32-29b53939cd3e - * Codename: my_snippet - */ -export type MySnippet = IContentItem<{ - /** - * Snippet elem1 (text) - * - * Required: false - * Codename: my_snippet__snippet_elem1 - * Id: 3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d - */ - mySnippetSnippetElem1: Elements.TextElement; - - /** - * Snippet elem 2 (number) - * - * Required: false - * Codename: my_snippet__snippet_elem_2 - * Id: b2f65646-3310-4a64-af2a-0d9d025a91d0 - */ - mySnippetSnippetElem2: Elements.NumberElement; -}>; diff --git a/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts b/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts deleted file mode 100644 index e3171a5..0000000 --- a/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 - * - * ------------------------------------------------------------------------------- - **/ - -import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; -import type { Category } from '../taxonomies/category.js'; - -/** - * Taxonomy snippet test - * - * Id: e8219115-e629-4552-b79b-d9f813272573 - * Codename: taxonomy_snippet_test - */ -export type TaxonomySnippetTest = IContentItem<{ - /** - * Category (taxonomy) - * - * Required: false - * Codename: taxonomy_snippet_test__test_taxonomy - * Id: c030e3ec-5031-4d7f-af88-5032365733c7 - */ - taxonomySnippetTestTestTaxonomy: Elements.TaxonomyElement; -}>; diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index c0438c2..9422f91 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -6,7 +6,7 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ @@ -16,43 +16,44 @@ import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; /** * Actor * - * Id: d8900ee2-82f4-4189-a994-4e121582aadf + * Id: 58099989-319f-495f-aa36-cb3710854e36 * Codename: actor */ export type Actor = IContentItem<{ /** - * photo (asset) + * Url (url_slug) * * Required: false - * Codename: photo - * Id: 069b38ee-385c-410f-b7fe-53ec59a5f139 + * Codename: url + * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 */ - photo: Elements.AssetsElement; + url: Elements.UrlSlugElement; /** - * url (url_slug) + * First name (text) * - * Required: false - * Codename: url - * Id: c4b2d64f-af45-45a4-92d8-4829833563ff + * Required: true + * Codename: first_name + * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d + * Guidelines: This is the first name of the actor */ - url: Elements.UrlSlugElement; + firstName: Elements.TextElement; /** - * last_name (text) + * Last name (text) * - * Required: false + * Required: true * Codename: last_name - * Id: 0f00b26e-60f3-462d-8110-18180137c3a0 + * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 */ lastName: Elements.TextElement; /** - * first_name (text) + * Photo (asset) * * Required: false - * Codename: first_name - * Id: 4af5e7ce-88ef-4159-96ae-96a552992f91 + * Codename: photo + * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 */ - firstName: Elements.TextElement; + photo: Elements.AssetsElement; }>; diff --git a/sample/delivery/content-types/index.ts b/sample/delivery/content-types/index.ts index 8fe5273..2d9351d 100644 --- a/sample/delivery/content-types/index.ts +++ b/sample/delivery/content-types/index.ts @@ -6,11 +6,10 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ export * from './actor.js'; export * from './movie.js'; -export * from './test.js'; diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 7bf1696..061b895 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -6,102 +6,100 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; -import type { Category } from '../taxonomies/category.js'; -import type { ReleaseCategory } from '../taxonomies/release_category.js'; -import type { TaxonomySnippetTest } from '../content-type-snippets/taxonomy_snippet_test.js'; +import type { Actor } from '../taxonomies/actor.js'; +import type { Releasecategory } from '../taxonomies/releasecategory.js'; /** * Movie * - * Id: db7356f6-1d82-42a0-9ebb-07865cffa995 + * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c * Codename: movie */ export type Movie = IContentItem<{ /** - * Release category (taxonomy) + * Title (text) * - * Required: false - * Codename: releasecategory - * Id: 5faa827f-f262-43c3-8f58-0f354b8d393f + * Required: true + * Codename: title + * Id: 3473187e-dc78-eff2-7099-f690f7042d4a */ - releasecategory: Elements.TaxonomyElement; + title: Elements.TextElement; /** - * Category (taxonomy) + * Plot (rich_text) * * Required: false - * Codename: category - * Id: 8c12be35-e3e7-447c-a185-7b5e101ebf12 + * Codename: plot + * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce */ - category: Elements.TaxonomyElement; + plot: Elements.RichTextElement; /** - * length (number) + * Released (date_time) * * Required: false - * Codename: length - * Id: e3d07f3a-60c2-4072-846d-c23e51ec833e + * Codename: released + * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 */ - length: Elements.NumberElement; + released: Elements.DateTimeElement; /** - * stars (modular_content) + * Length (number) * * Required: false - * Codename: stars - * Id: 55596dd1-e808-415d-95aa-e2be34238d11 + * Codename: length + * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c */ - stars: Elements.LinkedItemsElement; + length: Elements.NumberElement; /** - * seoname (url_slug) + * Poster (asset) * * Required: false - * Codename: seoname - * Id: 734f94be-5930-4bdf-b05b-f59f5a291675 + * Codename: poster + * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d */ - seoname: Elements.UrlSlugElement; + poster: Elements.AssetsElement; /** - * poster (asset) + * Category (multiple_choice) * * Required: false - * Codename: poster - * Id: 9b197f1e-0728-4d14-9814-97f7b8ef01fc + * Codename: category + * Id: 9821c252-6414-f549-c17f-cc171dd87713 */ - poster: Elements.AssetsElement; + category: Elements.MultipleChoiceElement; /** - * released (date_time) + * Stars (modular_content) * * Required: false - * Codename: released - * Id: 656b9dc9-7bba-4f1f-a2b8-52f7f730a66f + * Codename: stars + * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 */ - released: Elements.DateTimeElement; + stars: Elements.LinkedItemsElement; /** - * plot (rich_text) + * SeoName (url_slug) * * Required: false - * Codename: plot - * Id: ad2e5dc7-8d08-4f74-afeb-25b475f1e6fc + * Codename: seoname + * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c */ - plot: Elements.RichTextElement; + seoname: Elements.UrlSlugElement; /** - * title (text) + * ReleaseCategory (taxonomy) * * Required: false - * Codename: title - * Id: 660c851a-a9a1-4378-97a3-1348bc2a4d76 + * Codename: releasecategory + * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 */ - title: Elements.TextElement; -}> & - TaxonomySnippetTest; + releasecategory: Elements.TaxonomyElement; +}>; diff --git a/sample/delivery/content-types/test.ts b/sample/delivery/content-types/test.ts deleted file mode 100644 index 69a9956..0000000 --- a/sample/delivery/content-types/test.ts +++ /dev/null @@ -1,33 +0,0 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 - * - * ------------------------------------------------------------------------------- - **/ - -import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; -import type { MySnippet } from '../content-type-snippets/my_snippet.js'; - -/** - * Test - * - * Id: 81ab0b2c-dd14-41e7-a1ed-868b249ad8bc - * Codename: test - */ -export type Test = IContentItem<{ - /** - * Text (text) - * - * Required: false - * Codename: text - * Id: 65f61f6a-b69c-47dc-bc38-19855507bf14 - */ - text: Elements.TextElement; -}> & - MySnippet; diff --git a/sample/delivery/index.ts b/sample/delivery/index.ts index 0ea0c5f..c55b743 100644 --- a/sample/delivery/index.ts +++ b/sample/delivery/index.ts @@ -6,7 +6,7 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ diff --git a/sample/delivery/taxonomies/index.ts b/sample/delivery/taxonomies/index.ts index 51facae..70647d0 100644 --- a/sample/delivery/taxonomies/index.ts +++ b/sample/delivery/taxonomies/index.ts @@ -6,10 +6,10 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ -export * from './category.js'; -export * from './release_category.js'; +export * from './movietype.js'; +export * from './releasecategory.js'; diff --git a/sample/delivery/taxonomies/release_category.ts b/sample/delivery/taxonomies/movietype.ts similarity index 60% rename from sample/delivery/taxonomies/release_category.ts rename to sample/delivery/taxonomies/movietype.ts index 66d58bc..e28d3a7 100644 --- a/sample/delivery/taxonomies/release_category.ts +++ b/sample/delivery/taxonomies/movietype.ts @@ -6,15 +6,15 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ /** - * Release category + * MovieType * - * Codename: release_category - * Id: 4dbfc78f-5ea2-4f33-880d-193c75e0b975 + * Codename: movietype + * Id: 365a17e6-1929-27ab-9f67-a9273c846717 */ -export type ReleaseCategory = 'global_release' | 'us_only'; +export type Movietype = 'blockbuster' | 'cinema_only' | 'film' | 'student' | 'tv'; diff --git a/sample/delivery/taxonomies/category.ts b/sample/delivery/taxonomies/releasecategory.ts similarity index 60% rename from sample/delivery/taxonomies/category.ts rename to sample/delivery/taxonomies/releasecategory.ts index 7f61d47..4217bc2 100644 --- a/sample/delivery/taxonomies/category.ts +++ b/sample/delivery/taxonomies/releasecategory.ts @@ -6,15 +6,15 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ /** - * Category + * ReleaseCategory * - * Codename: category - * Id: c1b56389-f00a-4917-95c4-3b02ea3610ea + * Codename: releasecategory + * Id: 09b6a348-0f86-7a68-4af3-7cab9a5c60b7 */ -export type Category = 'action' | 'animation' | 'comedy' | 'drama' | 'romance' | 'sci_fi'; +export type Releasecategory = 'global_release' | 'local_release' | 'us_only'; diff --git a/sample/migration/content-types/actor.ts b/sample/migration/content-types/actor.ts index 2100f90..8e4d258 100644 --- a/sample/migration/content-types/actor.ts +++ b/sample/migration/content-types/actor.ts @@ -6,7 +6,7 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ @@ -18,45 +18,46 @@ import type { Item } from '../core.models.js'; * Actor * * Codename: actor - * Id: d8900ee2-82f4-4189-a994-4e121582aadf + * Id: 58099989-319f-495f-aa36-cb3710854e36 */ export type ActorItem = Item< 'actor', { /** - * photo (asset) + * Url (url_slug) * * Required: false - * Codename: photo - * Id: 069b38ee-385c-410f-b7fe-53ec59a5f139 + * Codename: url + * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 */ - photo: MigrationElementModels.AssetElement; + url: MigrationElementModels.UrlSlugElement; /** - * url (url_slug) + * First name (text) * - * Required: false - * Codename: url - * Id: c4b2d64f-af45-45a4-92d8-4829833563ff + * Required: true + * Codename: first_name + * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d + * Guidelines: This is the first name of the actor */ - url: MigrationElementModels.UrlSlugElement; + first_name: MigrationElementModels.TextElement; /** - * last_name (text) + * Last name (text) * - * Required: false + * Required: true * Codename: last_name - * Id: 0f00b26e-60f3-462d-8110-18180137c3a0 + * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 */ last_name: MigrationElementModels.TextElement; /** - * first_name (text) + * Photo (asset) * * Required: false - * Codename: first_name - * Id: 4af5e7ce-88ef-4159-96ae-96a552992f91 + * Codename: photo + * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 */ - first_name: MigrationElementModels.TextElement; + photo: MigrationElementModels.AssetElement; } >; diff --git a/sample/migration/content-types/index.ts b/sample/migration/content-types/index.ts index 8fe5273..2d9351d 100644 --- a/sample/migration/content-types/index.ts +++ b/sample/migration/content-types/index.ts @@ -6,11 +6,10 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ export * from './actor.js'; export * from './movie.js'; -export * from './test.js'; diff --git a/sample/migration/content-types/movie.ts b/sample/migration/content-types/movie.ts index 433a9dc..233c498 100644 --- a/sample/migration/content-types/movie.ts +++ b/sample/migration/content-types/movie.ts @@ -6,7 +6,7 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ @@ -18,99 +18,90 @@ import type { Item } from '../core.models.js'; * Movie * * Codename: movie - * Id: db7356f6-1d82-42a0-9ebb-07865cffa995 + * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c */ export type MovieItem = Item< 'movie', { /** - * Category (taxonomy) + * Title (text) * - * Required: false - * Codename: taxonomy_snippet_test__test_taxonomy - * Id: c030e3ec-5031-4d7f-af88-5032365733c7 + * Required: true + * Codename: title + * Id: 3473187e-dc78-eff2-7099-f690f7042d4a */ - taxonomy_snippet_test__test_taxonomy: MigrationElementModels.TaxonomyElement; + title: MigrationElementModels.TextElement; /** - * Release category (taxonomy) + * Plot (rich_text) * * Required: false - * Codename: releasecategory - * Id: 5faa827f-f262-43c3-8f58-0f354b8d393f + * Codename: plot + * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce */ - releasecategory: MigrationElementModels.TaxonomyElement; + plot: MigrationElementModels.RichTextElement; /** - * Category (taxonomy) + * Released (date_time) * * Required: false - * Codename: category - * Id: 8c12be35-e3e7-447c-a185-7b5e101ebf12 + * Codename: released + * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 */ - category: MigrationElementModels.TaxonomyElement; + released: MigrationElementModels.DateTimeElement; /** - * length (number) + * Length (number) * * Required: false * Codename: length - * Id: e3d07f3a-60c2-4072-846d-c23e51ec833e + * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c */ length: MigrationElementModels.NumberElement; /** - * stars (modular_content) + * Poster (asset) * * Required: false - * Codename: stars - * Id: 55596dd1-e808-415d-95aa-e2be34238d11 - */ - stars: MigrationElementModels.LinkedItemsElement; - - /** - * seoname (url_slug) - * - * Required: false - * Codename: seoname - * Id: 734f94be-5930-4bdf-b05b-f59f5a291675 + * Codename: poster + * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d */ - seoname: MigrationElementModels.UrlSlugElement; + poster: MigrationElementModels.AssetElement; /** - * poster (asset) + * Category (multiple_choice) * * Required: false - * Codename: poster - * Id: 9b197f1e-0728-4d14-9814-97f7b8ef01fc + * Codename: category + * Id: 9821c252-6414-f549-c17f-cc171dd87713 */ - poster: MigrationElementModels.AssetElement; + category: MigrationElementModels.MultipleChoiceElement; /** - * released (date_time) + * Stars (modular_content) * * Required: false - * Codename: released - * Id: 656b9dc9-7bba-4f1f-a2b8-52f7f730a66f + * Codename: stars + * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 */ - released: MigrationElementModels.DateTimeElement; + stars: MigrationElementModels.LinkedItemsElement; /** - * plot (rich_text) + * SeoName (url_slug) * * Required: false - * Codename: plot - * Id: ad2e5dc7-8d08-4f74-afeb-25b475f1e6fc + * Codename: seoname + * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c */ - plot: MigrationElementModels.RichTextElement; + seoname: MigrationElementModels.UrlSlugElement; /** - * title (text) + * ReleaseCategory (taxonomy) * * Required: false - * Codename: title - * Id: 660c851a-a9a1-4378-97a3-1348bc2a4d76 + * Codename: releasecategory + * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 */ - title: MigrationElementModels.TextElement; + releasecategory: MigrationElementModels.TaxonomyElement; } >; diff --git a/sample/migration/content-types/test.ts b/sample/migration/content-types/test.ts deleted file mode 100644 index 87d0333..0000000 --- a/sample/migration/content-types/test.ts +++ /dev/null @@ -1,53 +0,0 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 - * - * ------------------------------------------------------------------------------- - **/ - -import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; -import type { Item } from '../core.models.js'; - -/** - * Test - * - * Codename: test - * Id: 81ab0b2c-dd14-41e7-a1ed-868b249ad8bc - */ -export type TestItem = Item< - 'test', - { - /** - * Text (text) - * - * Required: false - * Codename: text - * Id: 65f61f6a-b69c-47dc-bc38-19855507bf14 - */ - text: MigrationElementModels.TextElement; - - /** - * Snippet elem1 (text) - * - * Required: false - * Codename: my_snippet__snippet_elem1 - * Id: 3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d - */ - my_snippet__snippet_elem1: MigrationElementModels.TextElement; - - /** - * Snippet elem 2 (number) - * - * Required: false - * Codename: my_snippet__snippet_elem_2 - * Id: b2f65646-3310-4a64-af2a-0d9d025a91d0 - */ - my_snippet__snippet_elem_2: MigrationElementModels.NumberElement; - } ->; diff --git a/sample/migration/core.models.ts b/sample/migration/core.models.ts index f813b59..dadc042 100644 --- a/sample/migration/core.models.ts +++ b/sample/migration/core.models.ts @@ -6,7 +6,7 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ @@ -16,12 +16,12 @@ import type { MigrationItemSystem, MigrationItem, MigrationElements } from '@kon /** * Type representing all languages */ -export type LanguageCodenames = 'en' | 'es'; +export type LanguageCodenames = 'cz' | 'en' | 'German'; /** * Type representing all content types */ -export type ContentTypeCodenames = 'actor' | 'movie' | 'test'; +export type ContentTypeCodenames = 'actor' | 'movie'; /** * Type representing all collections @@ -31,19 +31,12 @@ export type CollectionCodenames = 'default'; /** * Type representing all workflows */ -export type WorkflowCodenames = 'default' | 'my_test_workflow'; +export type WorkflowCodenames = 'default'; /** * Type representing all worksflow steps across all workflows */ -export type WorkflowStepCodenames = - | 'draft' - | 'ready_to_publish' - | 'published' - | 'archived' - | 'scheduled' - | 'draft_3171da5' - | 'ready_for_review'; +export type WorkflowStepCodenames = 'draft' | 'review' | 'ready_to_publish' | 'published' | 'archived' | 'scheduled'; /** * System object shared by all individual content type models diff --git a/sample/migration/index.ts b/sample/migration/index.ts index c1f868e..60b0911 100644 --- a/sample/migration/index.ts +++ b/sample/migration/index.ts @@ -6,7 +6,7 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ diff --git a/sample/project/assetFolders.ts b/sample/project/assetFolders.ts index 378af9a..698129f 100644 --- a/sample/project/assetFolders.ts +++ b/sample/project/assetFolders.ts @@ -6,30 +6,64 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ + export const assetFolders = { /** - * my folder + * my folder A */ - myFolder: { - codename: 'my_folder', - id: 'f1c6ba01-3b13-41ce-81e7-3125840b0b0e', + myFolderA: { + codename: 'my_folder_a', + id: '6bb4814a-6a5c-4b8c-836e-7f83b008d5d1', externalId: undefined, - name: 'my folder', - folders: {} + name: 'my folder A', + folders: { + /** + * my folder nested A + */ + myFolderNestedA: { + codename: 'my_folder_nested_a', + id: '555784e5-e92e-4a86-b40b-d642afbf7b4e', + externalId: undefined, + name: 'my folder nested A', + folders: { + /** + * even more nested A + */ + evenMoreNestedA: { + codename: 'even_more_nested_a', + id: 'd26940cc-6c8d-41e6-93a0-0748c854b100', + externalId: undefined, + name: 'even more nested A', + folders: {} + }, + + /** + * even more nested B + */ + evenMoreNestedB: { + codename: 'even_more_nested_b', + id: '97fc4b03-98d2-44b4-8e03-b223a013b0b6', + externalId: undefined, + name: 'even more nested B', + folders: {} + } + } + } + } }, /** - * my folder2 + * my folder B */ - myFolder2: { - codename: 'my_folder2', - id: '44a00189-9298-4cf9-b8fb-3f208c3f4f8f', + myFolderB: { + codename: 'my_folder_b', + id: '58d1c135-42cb-43c2-a2cd-c615e0a36e83', externalId: undefined, - name: 'my folder2', + name: 'my folder B', folders: {} } } as const; diff --git a/sample/project/collections.ts b/sample/project/collections.ts index 2a6877f..c547f52 100644 --- a/sample/project/collections.ts +++ b/sample/project/collections.ts @@ -6,10 +6,11 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ + export const collections = { /** * Default diff --git a/sample/project/contentTypeSnippets.ts b/sample/project/contentTypeSnippets.ts index e09c5d5..9e92896 100644 --- a/sample/project/contentTypeSnippets.ts +++ b/sample/project/contentTypeSnippets.ts @@ -6,66 +6,9 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ -export const contentTypeSnippets = { - /** - * My snippet - */ - mySnippet: { - codename: 'my_snippet', - id: '3274f9e7-ff1b-43f8-aa32-29b53939cd3e', - externalId: undefined, - name: 'My snippet', - elements: { - /** - * Snippet elem1 (text) - */ - mySnippetSnippetElem1: { - codename: 'my_snippet__snippet_elem1', - id: '3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d', - externalId: undefined, - name: 'Snippet elem1', - required: false, - type: 'text' - }, - /** - * Snippet elem 2 (number) - */ - mySnippetSnippetElem2: { - codename: 'my_snippet__snippet_elem_2', - id: 'b2f65646-3310-4a64-af2a-0d9d025a91d0', - externalId: undefined, - name: 'Snippet elem 2', - required: false, - type: 'number' - } - } - }, - - /** - * Taxonomy snippet test - */ - taxonomySnippetTest: { - codename: 'taxonomy_snippet_test', - id: 'e8219115-e629-4552-b79b-d9f813272573', - externalId: undefined, - name: 'Taxonomy snippet test', - elements: { - /** - * Category (taxonomy) - */ - taxonomySnippetTestTestTaxonomy: { - codename: 'taxonomy_snippet_test__test_taxonomy', - id: 'c030e3ec-5031-4d7f-af88-5032365733c7', - externalId: undefined, - name: 'Category', - required: false, - type: 'taxonomy' - } - } - } -} as const; +export const contentTypeSnippets = {} as const; diff --git a/sample/project/contentTypes.ts b/sample/project/contentTypes.ts index 1fbb290..3d0fd8f 100644 --- a/sample/project/contentTypes.ts +++ b/sample/project/contentTypes.ts @@ -6,66 +6,68 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ + export const contentTypes = { /** * Actor */ actor: { codename: 'actor', - id: 'd8900ee2-82f4-4189-a994-4e121582aadf', + id: '58099989-319f-495f-aa36-cb3710854e36', externalId: undefined, name: 'Actor', elements: { /** - * photo (asset) + * Url (url_slug) */ - photo: { - codename: 'photo', - id: '069b38ee-385c-410f-b7fe-53ec59a5f139', + url: { + codename: 'url', + id: 'c8658782-f209-a573-9c85-430fb4e3e9f0', externalId: undefined, - name: 'photo', + name: 'Url', required: false, - type: 'asset' + type: 'url_slug' }, /** - * url (url_slug) + * First name (text) + * Guidelines: This is the first name of the actor */ - url: { - codename: 'url', - id: 'c4b2d64f-af45-45a4-92d8-4829833563ff', + firstName: { + codename: 'first_name', + id: '14dd70e5-c42d-f111-9640-c82b443edf1d', externalId: undefined, - name: 'url', - required: false, - type: 'url_slug' + name: 'First name', + required: true, + type: 'text' }, /** - * last_name (text) + * Last name (text) */ lastName: { codename: 'last_name', - id: '0f00b26e-60f3-462d-8110-18180137c3a0', + id: '9f7a0dd4-af3a-95ca-0358-400c14ce7075', externalId: undefined, - name: 'last_name', - required: false, + name: 'Last name', + required: true, type: 'text' }, /** - * first_name (text) + * Photo (asset) */ - firstName: { - codename: 'first_name', - id: '4af5e7ce-88ef-4159-96ae-96a552992f91', + photo: { + codename: 'photo', + id: 'eaec9ba3-9624-6875-04ec-80d0b2e00781', externalId: undefined, - name: 'first_name', + name: 'Photo', required: false, - type: 'text' + type: 'asset' } } }, @@ -75,175 +77,197 @@ export const contentTypes = { */ movie: { codename: 'movie', - id: 'db7356f6-1d82-42a0-9ebb-07865cffa995', + id: 'b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c', externalId: undefined, name: 'Movie', elements: { /** - * Category (taxonomy) + * Title (text) */ - taxonomySnippetTestTestTaxonomy: { - codename: 'taxonomy_snippet_test__test_taxonomy', - id: 'c030e3ec-5031-4d7f-af88-5032365733c7', + title: { + codename: 'title', + id: '3473187e-dc78-eff2-7099-f690f7042d4a', externalId: undefined, - name: 'Category', - required: false, - type: 'taxonomy' + name: 'Title', + required: true, + type: 'text' }, /** - * Release category (taxonomy) + * Plot (rich_text) */ - releasecategory: { - codename: 'releasecategory', - id: '5faa827f-f262-43c3-8f58-0f354b8d393f', + plot: { + codename: 'plot', + id: 'f7ee4f27-27fd-a19b-3c5c-102aae1c50ce', externalId: undefined, - name: 'Release category', + name: 'Plot', required: false, - type: 'taxonomy' + type: 'rich_text' }, /** - * Category (taxonomy) + * Released (date_time) */ - category: { - codename: 'category', - id: '8c12be35-e3e7-447c-a185-7b5e101ebf12', + released: { + codename: 'released', + id: '5ccf4644-0d65-5d96-9a32-f4ea21974d51', externalId: undefined, - name: 'Category', + name: 'Released', required: false, - type: 'taxonomy' + type: 'date_time' }, /** - * length (number) + * Length (number) */ length: { codename: 'length', - id: 'e3d07f3a-60c2-4072-846d-c23e51ec833e', + id: '7e8ecfab-a419-27ee-d8ec-8adb76fd007c', externalId: undefined, - name: 'length', + name: 'Length', required: false, type: 'number' }, /** - * stars (modular_content) - */ - stars: { - codename: 'stars', - id: '55596dd1-e808-415d-95aa-e2be34238d11', - externalId: undefined, - name: 'stars', - required: false, - type: 'modular_content' - }, - - /** - * seoname (url_slug) - */ - seoname: { - codename: 'seoname', - id: '734f94be-5930-4bdf-b05b-f59f5a291675', - externalId: undefined, - name: 'seoname', - required: false, - type: 'url_slug' - }, - - /** - * poster (asset) + * Poster (asset) */ poster: { codename: 'poster', - id: '9b197f1e-0728-4d14-9814-97f7b8ef01fc', + id: 'a39a7237-9503-a1ae-8431-5b6cdb85ae9d', externalId: undefined, - name: 'poster', + name: 'Poster', required: false, type: 'asset' }, /** - * released (date_time) + * Category (multiple_choice) */ - released: { - codename: 'released', - id: '656b9dc9-7bba-4f1f-a2b8-52f7f730a66f', + category: { + codename: 'category', + id: '9821c252-6414-f549-c17f-cc171dd87713', externalId: undefined, - name: 'released', + name: 'Category', required: false, - type: 'date_time' - }, + type: 'multiple_choice', + options: { + /** + * Sci fi + */ + sciFi: { + name: 'Sci fi', + id: 'b087f774-1f57-9aa8-dab5-2ca88a646824', + codename: 'sci_fi', + externalId: undefined + }, - /** - * plot (rich_text) - */ - plot: { - codename: 'plot', - id: 'ad2e5dc7-8d08-4f74-afeb-25b475f1e6fc', - externalId: undefined, - name: 'plot', - required: false, - type: 'rich_text' - }, + /** + * Documentary + */ + documentary: { + name: 'Documentary', + id: '19c5e959-c24a-4863-0b4d-453cdef8fe9d', + codename: 'documentary', + externalId: undefined + }, - /** - * title (text) - */ - title: { - codename: 'title', - id: '660c851a-a9a1-4378-97a3-1348bc2a4d76', - externalId: undefined, - name: 'title', - required: false, - type: 'text' - } - } - }, + /** + * Action + */ + action: { + name: 'Action', + id: '7d453309-8d74-9607-80c4-36dcc1bd005f', + codename: 'action', + externalId: undefined + }, + + /** + * Romance + */ + romance: { + name: 'Romance', + id: '60550cc7-c986-a59f-b069-7565862fe1c1', + codename: 'romance', + externalId: undefined + }, + + /** + * Animation + */ + animation: { + name: 'Animation', + id: '54c0590d-6a94-a69a-902d-fceea4fa62f8', + codename: 'animation', + externalId: undefined + }, + + /** + * Comedy + */ + comedy: { + name: 'Comedy', + id: 'd2fe357f-894e-9bc3-550c-c2c400d99c6b', + codename: 'comedy', + externalId: undefined + }, + + /** + * Adventure + */ + adventure: { + name: 'Adventure', + id: 'cd8389b0-7628-7739-7b14-3225a50212c1', + codename: 'adventure', + externalId: undefined + }, + + /** + * Drama + */ + drama: { + name: 'Drama', + id: '051e74de-f2e0-f405-9ad5-5263221e46f2', + codename: 'drama', + externalId: undefined + } + } + }, - /** - * Test - */ - test: { - codename: 'test', - id: '81ab0b2c-dd14-41e7-a1ed-868b249ad8bc', - externalId: undefined, - name: 'Test', - elements: { /** - * Text (text) + * Stars (modular_content) */ - text: { - codename: 'text', - id: '65f61f6a-b69c-47dc-bc38-19855507bf14', + stars: { + codename: 'stars', + id: 'aa26a55d-19f8-7501-fea3-b0d9b1eeac71', externalId: undefined, - name: 'Text', + name: 'Stars', required: false, - type: 'text' + type: 'modular_content' }, /** - * Snippet elem1 (text) + * SeoName (url_slug) */ - mySnippetSnippetElem1: { - codename: 'my_snippet__snippet_elem1', - id: '3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d', + seoname: { + codename: 'seoname', + id: '756cc91a-a090-60f9-a7f0-f505bfbe046c', externalId: undefined, - name: 'Snippet elem1', + name: 'SeoName', required: false, - type: 'text' + type: 'url_slug' }, /** - * Snippet elem 2 (number) + * ReleaseCategory (taxonomy) */ - mySnippetSnippetElem2: { - codename: 'my_snippet__snippet_elem_2', - id: 'b2f65646-3310-4a64-af2a-0d9d025a91d0', + releasecategory: { + codename: 'releasecategory', + id: '65f2fd44-1856-bc2b-17c2-decb0635e3d2', externalId: undefined, - name: 'Snippet elem 2', + name: 'ReleaseCategory', required: false, - type: 'number' + type: 'taxonomy' } } } diff --git a/sample/project/index.ts b/sample/project/index.ts index c9dafe7..0ae5835 100644 --- a/sample/project/index.ts +++ b/sample/project/index.ts @@ -6,10 +6,11 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ + export * from './languages.js'; export * from './collections.js'; export * from './contentTypes.js'; diff --git a/sample/project/languages.ts b/sample/project/languages.ts index b3aec88..5cbd71a 100644 --- a/sample/project/languages.ts +++ b/sample/project/languages.ts @@ -6,18 +6,32 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ + export const languages = { /** - * Default project language + * cz + */ + cz: { + codename: 'cz', + id: '41ccb26f-ceab-04d0-6ffa-9c7c5358aa8f', + name: 'cz', + isActive: true, + isDefault: false, + fallbackLanguageId: '00000000-0000-0000-0000-000000000000', + externalId: undefined + }, + + /** + * English */ en: { codename: 'en', id: '00000000-0000-0000-0000-000000000000', - name: 'Default project language', + name: 'English', isActive: true, isDefault: true, fallbackLanguageId: '00000000-0000-0000-0000-000000000000', @@ -25,13 +39,13 @@ export const languages = { }, /** - * Spanish + * German */ - es: { - codename: 'es', - id: '71cf90e5-8124-43e3-8ef4-bbb8bdcd22ae', - name: 'Spanish', - isActive: true, + german: { + codename: 'German', + id: '14f7bcc0-4fd6-4b77-8c22-70e5ccfdae1d', + name: 'German', + isActive: false, isDefault: false, fallbackLanguageId: '00000000-0000-0000-0000-000000000000', externalId: undefined diff --git a/sample/project/roles.ts b/sample/project/roles.ts index 16683b8..49e4e63 100644 --- a/sample/project/roles.ts +++ b/sample/project/roles.ts @@ -6,17 +6,45 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ + export const roles = { + /** + * Content contributor + */ + contentContributor: { + codename: undefined, + id: 'dca0ac85-274f-429e-b00e-6f74bf917051', + name: 'Content contributor' + }, + + /** + * Developer + */ + developer: { + codename: undefined, + id: 'b3994090-0818-4969-816b-f4c5d3e526f3', + name: 'Developer' + }, + /** * Project manager */ projectManager: { codename: 'project-manager', - id: '5a8e7afd-3dcc-4adc-9f23-bf36a31d61bf', + id: 'af95ac37-4efa-4b92-aa26-db773cd172c6', name: 'Project manager' + }, + + /** + * Reviewer + */ + reviewer: { + codename: undefined, + id: '94478afa-d898-45dd-8300-ba61b6e0eb4b', + name: 'Reviewer' } } as const; diff --git a/sample/project/taxonomies.ts b/sample/project/taxonomies.ts index 6c6c3b2..b3c413d 100644 --- a/sample/project/taxonomies.ts +++ b/sample/project/taxonomies.ts @@ -6,116 +6,117 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ + export const taxonomies = { /** - * Category + * MovieType */ - category: { - codename: 'category', + movietype: { + codename: 'movietype', externalId: undefined, - id: 'c1b56389-f00a-4917-95c4-3b02ea3610ea', - name: 'Category', + id: '365a17e6-1929-27ab-9f67-a9273c846717', + name: 'MovieType', terms: { /** - * action - */ - action: { - codename: 'action', - id: 'e3410312-52d6-4c15-8e23-e5a4cc57a204', - externalId: undefined, - name: 'action', - terms: {} - }, - - /** - * animation + * Film */ - animation: { - codename: 'animation', - id: '2d8a95a8-61c9-4add-94a1-1d7944098144', + film: { + codename: 'film', + id: '5a2a1927-41a4-294f-5d89-cf0cc045e943', externalId: undefined, - name: 'animation', - terms: {} - }, - - /** - * comedy - */ - comedy: { - codename: 'comedy', - id: 'eddaa24b-fb5c-4a44-8507-8dd7a45fdc39', - externalId: undefined, - name: 'comedy', - terms: {} - }, + name: 'Film', + terms: { + /** + * Blockbuster + */ + blockbuster: { + codename: 'blockbuster', + id: '875a4657-1dcd-0415-cb3a-892078f5991a', + externalId: undefined, + name: 'Blockbuster', + terms: {} + }, - /** - * drama - */ - drama: { - codename: 'drama', - id: '7377ea7c-d928-408a-bfb8-a0bf7392c996', - externalId: undefined, - name: 'drama', - terms: {} - }, + /** + * Cinema only + */ + cinemaOnly: { + codename: 'cinema_only', + id: 'e15c4e32-ab7c-57a2-1b66-d8e3566a1dd2', + externalId: undefined, + name: 'Cinema only', + terms: {} + }, - /** - * romance - */ - romance: { - codename: 'romance', - id: 'fe8bdfdb-cc13-4890-ab45-a6669e94d1d0', - externalId: undefined, - name: 'romance', - terms: {} + /** + * TV + */ + tv: { + codename: 'tv', + id: '47511b09-6c39-fa04-ff59-7c47551e827f', + externalId: undefined, + name: 'TV', + terms: {} + } + } }, /** - * sci_fi + * Student */ - sciFi: { - codename: 'sci_fi', - id: '1432c10c-096c-47c5-a045-dcd6dc4af366', + student: { + codename: 'student', + id: 'b107e12c-124d-705f-1029-c0dfdd0b2438', externalId: undefined, - name: 'sci_fi', + name: 'Student', terms: {} } } }, /** - * Release category + * ReleaseCategory */ - releaseCategory: { - codename: 'release_category', + releasecategory: { + codename: 'releasecategory', externalId: undefined, - id: '4dbfc78f-5ea2-4f33-880d-193c75e0b975', - name: 'Release category', + id: '09b6a348-0f86-7a68-4af3-7cab9a5c60b7', + name: 'ReleaseCategory', terms: { /** - * global_release + * Global release */ globalRelease: { codename: 'global_release', - id: 'afb51aba-cb5a-499a-973c-d5b44fdeafcf', + id: '4acaf439-9f3a-f34a-6211-d3fc6ec7152e', + externalId: undefined, + name: 'Global release', + terms: {} + }, + + /** + * Local release + */ + localRelease: { + codename: 'local_release', + id: '37e55484-f0dc-14eb-bf2a-b0293a0d1b1f', externalId: undefined, - name: 'global_release', + name: 'Local release', terms: {} }, /** - * us_only + * US only */ usOnly: { codename: 'us_only', - id: '3f8bddaf-c203-471b-af76-6539d3e72e89', + id: 'b03d990a-55a9-601e-dd5c-aa2edc8698ca', externalId: undefined, - name: 'us_only', + name: 'US only', terms: {} } } diff --git a/sample/project/webhooks.ts b/sample/project/webhooks.ts index 75b3159..8a690b4 100644 --- a/sample/project/webhooks.ts +++ b/sample/project/webhooks.ts @@ -6,8 +6,9 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ + export const webhooks = {} as const; diff --git a/sample/project/workflows.ts b/sample/project/workflows.ts index 2b1b016..8454fec 100644 --- a/sample/project/workflows.ts +++ b/sample/project/workflows.ts @@ -6,10 +6,11 @@ * ------------------------------------------------------------------------------- * * Environment: Production - * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ + export const workflows = { /** * Default @@ -27,7 +28,7 @@ export const workflows = { published: { name: 'Published', codename: 'published', - id: 'c199950d-99f0-4983-b711-6c4c91624b22' + id: 'f05b8a85-c6cc-429a-ac6d-21d5edd268fe' }, scheduled: { name: 'Scheduled', @@ -37,48 +38,17 @@ export const workflows = { draft: { name: 'Draft', codename: 'draft', - id: 'eee6db3b-545a-4785-8e86-e3772c8756f9' + id: 'e3ef0816-2203-4456-bfdc-a735b4f339ab' + }, + review: { + name: 'Review', + codename: 'review', + id: 'c5682935-f5a2-4514-8025-57d8bdf7558d' }, readyToPublish: { - name: 'ready_to_publish', + name: 'Ready to publish', codename: 'ready_to_publish', - id: 'f4afd295-cc0b-48e3-9431-176cc1e17e2c' - } - } - }, - - /** - * my_test_workflow - */ - myTestWorkflow: { - codename: 'my_test_workflow', - id: '51036ae0-1a0c-48c6-980e-bf73600ba462', - name: 'my_test_workflow', - steps: { - archived: { - name: 'Archived', - codename: 'archived', - id: '7a535a69-ad34-47f8-806a-def1fdf4d391' - }, - published: { - name: 'Published', - codename: 'published', - id: 'c199950d-99f0-4983-b711-6c4c91624b22' - }, - scheduled: { - name: 'Scheduled', - codename: 'scheduled', - id: '9d2b0228-4d0d-4c23-8b49-01a698857709' - }, - draft3171da5: { - name: 'Draft', - codename: 'draft_3171da5', - id: '3171da5f-679d-49af-a42c-617d83eac222' - }, - readyForReview: { - name: 'ready_for_review', - codename: 'ready_for_review', - id: '20f49208-5e57-4300-b6bd-0f668cbce00b' + id: 'aaee1d73-f0cc-4185-9e49-844d161c3634' } } } From 964ae003f7694d69a2ca535c78871085143828ec Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 29 Aug 2024 11:26:37 +0200 Subject: [PATCH 038/183] fixes incorrect referenced types folder --- lib/generators/delivery/delivery-content-type.generator.ts | 2 +- sample/delivery/content-types/movie.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 75fdf66..3324a4b 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -143,7 +143,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato moduleResolution: config.moduleResolution, filePathOrPackage: typeOrSnippet instanceof ContentTypeModels.ContentType - ? `../${deliveryConfig.taxonomiesFolderName}/${referencedTypeFilename}.ts` + ? `../${deliveryConfig.contentTypesFolderName}/${referencedTypeFilename}.ts` : `./${referencedTypeFilename}.ts`, importValue: `${nameResolvers.contentType(allowedContentType)}` }); diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 061b895..ec62889 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -12,7 +12,7 @@ **/ import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; -import type { Actor } from '../taxonomies/actor.js'; +import type { Actor } from '../content-types/actor.js'; import type { Releasecategory } from '../taxonomies/releasecategory.js'; /** From 140d5d9ffd437f819e31529b6a2dfa27fd2c4741 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 29 Aug 2024 11:29:40 +0200 Subject: [PATCH 039/183] Adds project to environment info comment --- lib/comments/comments.manager.ts | 1 + sample/delivery/content-type-snippets/index.ts | 1 + sample/delivery/content-types/actor.ts | 1 + sample/delivery/content-types/index.ts | 1 + sample/delivery/content-types/movie.ts | 1 + sample/delivery/index.ts | 1 + sample/delivery/taxonomies/index.ts | 1 + sample/delivery/taxonomies/movietype.ts | 1 + sample/delivery/taxonomies/releasecategory.ts | 1 + sample/migration/content-types/actor.ts | 1 + sample/migration/content-types/index.ts | 1 + sample/migration/content-types/movie.ts | 1 + sample/migration/core.models.ts | 1 + sample/migration/index.ts | 1 + sample/project/assetFolders.ts | 1 + sample/project/collections.ts | 1 + sample/project/contentTypeSnippets.ts | 1 + sample/project/contentTypes.ts | 1 + sample/project/index.ts | 1 + sample/project/languages.ts | 1 + sample/project/roles.ts | 1 + sample/project/taxonomies.ts | 1 + sample/project/webhooks.ts | 1 + sample/project/workflows.ts | 1 + 24 files changed, 24 insertions(+) diff --git a/lib/comments/comments.manager.ts b/lib/comments/comments.manager.ts index e5c4bd7..9bc3dd8 100644 --- a/lib/comments/comments.manager.ts +++ b/lib/comments/comments.manager.ts @@ -19,6 +19,7 @@ export function commentsManager() { * * ------------------------------------------------------------------------------- * +* Project: ${toSafeString(data.environmentInfo.name)} * Environment: ${toSafeString(data.environmentInfo.environment)} * Id: ${data.environmentInfo.id}${data.addTimestamp ? `\n* Generated: ${new Date().toLocaleString()}` : ''} * diff --git a/sample/delivery/content-type-snippets/index.ts b/sample/delivery/content-type-snippets/index.ts index 5ecc785..0ae38c6 100644 --- a/sample/delivery/content-type-snippets/index.ts +++ b/sample/delivery/content-type-snippets/index.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index 9422f91..f0f3032 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/delivery/content-types/index.ts b/sample/delivery/content-types/index.ts index 2d9351d..f9d1d76 100644 --- a/sample/delivery/content-types/index.ts +++ b/sample/delivery/content-types/index.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index ec62889..2c5817d 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/delivery/index.ts b/sample/delivery/index.ts index c55b743..f4323f9 100644 --- a/sample/delivery/index.ts +++ b/sample/delivery/index.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/delivery/taxonomies/index.ts b/sample/delivery/taxonomies/index.ts index 70647d0..90da1b5 100644 --- a/sample/delivery/taxonomies/index.ts +++ b/sample/delivery/taxonomies/index.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/delivery/taxonomies/movietype.ts b/sample/delivery/taxonomies/movietype.ts index e28d3a7..519b904 100644 --- a/sample/delivery/taxonomies/movietype.ts +++ b/sample/delivery/taxonomies/movietype.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/delivery/taxonomies/releasecategory.ts b/sample/delivery/taxonomies/releasecategory.ts index 4217bc2..62d9662 100644 --- a/sample/delivery/taxonomies/releasecategory.ts +++ b/sample/delivery/taxonomies/releasecategory.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/migration/content-types/actor.ts b/sample/migration/content-types/actor.ts index 8e4d258..624dce9 100644 --- a/sample/migration/content-types/actor.ts +++ b/sample/migration/content-types/actor.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/migration/content-types/index.ts b/sample/migration/content-types/index.ts index 2d9351d..f9d1d76 100644 --- a/sample/migration/content-types/index.ts +++ b/sample/migration/content-types/index.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/migration/content-types/movie.ts b/sample/migration/content-types/movie.ts index 233c498..91a45db 100644 --- a/sample/migration/content-types/movie.ts +++ b/sample/migration/content-types/movie.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/migration/core.models.ts b/sample/migration/core.models.ts index dadc042..52f9b23 100644 --- a/sample/migration/core.models.ts +++ b/sample/migration/core.models.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/migration/index.ts b/sample/migration/index.ts index 60b0911..4d4b0a5 100644 --- a/sample/migration/index.ts +++ b/sample/migration/index.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/project/assetFolders.ts b/sample/project/assetFolders.ts index 698129f..b87987d 100644 --- a/sample/project/assetFolders.ts +++ b/sample/project/assetFolders.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/project/collections.ts b/sample/project/collections.ts index c547f52..0a6f9be 100644 --- a/sample/project/collections.ts +++ b/sample/project/collections.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/project/contentTypeSnippets.ts b/sample/project/contentTypeSnippets.ts index 9e92896..83010a7 100644 --- a/sample/project/contentTypeSnippets.ts +++ b/sample/project/contentTypeSnippets.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/project/contentTypes.ts b/sample/project/contentTypes.ts index 3d0fd8f..e91911d 100644 --- a/sample/project/contentTypes.ts +++ b/sample/project/contentTypes.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/project/index.ts b/sample/project/index.ts index 0ae5835..9c54cb9 100644 --- a/sample/project/index.ts +++ b/sample/project/index.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/project/languages.ts b/sample/project/languages.ts index 5cbd71a..2f8a176 100644 --- a/sample/project/languages.ts +++ b/sample/project/languages.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/project/roles.ts b/sample/project/roles.ts index 49e4e63..c8a386d 100644 --- a/sample/project/roles.ts +++ b/sample/project/roles.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/project/taxonomies.ts b/sample/project/taxonomies.ts index b3c413d..2a0ee98 100644 --- a/sample/project/taxonomies.ts +++ b/sample/project/taxonomies.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/project/webhooks.ts b/sample/project/webhooks.ts index 8a690b4..47dccbe 100644 --- a/sample/project/webhooks.ts +++ b/sample/project/webhooks.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * diff --git a/sample/project/workflows.ts b/sample/project/workflows.ts index 8454fec..1a53bdb 100644 --- a/sample/project/workflows.ts +++ b/sample/project/workflows.ts @@ -5,6 +5,7 @@ * * ------------------------------------------------------------------------------- * + * Project: Movie Database * Environment: Production * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * From f8c406b10777cfcf2a2b2a3321087bfe6d80a1bc Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 29 Aug 2024 11:47:56 +0200 Subject: [PATCH 040/183] increases print width --- .prettierrc | 20 ++++++++++---------- lib/core/resolvers.ts | 36 +++++++----------------------------- 2 files changed, 17 insertions(+), 39 deletions(-) diff --git a/.prettierrc b/.prettierrc index 71f3209..636cbd4 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,11 +1,11 @@ { - "singleQuote": true, - "printWidth": 120, - "proseWrap": "always", - "tabWidth": 4, - "requireConfig": false, - "useTabs": false, - "trailingComma": "none", - "bracketSpacing": true, - "semi": true -} \ No newline at end of file + "singleQuote": true, + "printWidth": 160, + "proseWrap": "always", + "tabWidth": 4, + "requireConfig": false, + "useTabs": false, + "trailingComma": "none", + "bracketSpacing": true, + "semi": true +} diff --git a/lib/core/resolvers.ts b/lib/core/resolvers.ts index d886bc0..120204b 100644 --- a/lib/core/resolvers.ts +++ b/lib/core/resolvers.ts @@ -1,10 +1,5 @@ import {} from '@kontent-ai/delivery-sdk'; -import { - ContentTypeModels, - ContentTypeSnippetModels, - ContentTypeElements, - TaxonomyModels -} from '@kontent-ai/management-sdk'; +import { ContentTypeModels, ContentTypeSnippetModels, ContentTypeElements, TaxonomyModels } from '@kontent-ai/management-sdk'; import { toCamelCase, toPascalCase, toSnakeCase } from './core.utils.js'; import { match } from 'ts-pattern'; import { CaseType, GeneratorElementResolver } from './core.models.js'; @@ -14,31 +9,20 @@ export type ObjectWithCodename = { }; /** File name resolvers */ -export type FilenameResolver> = - | undefined - | CaseType - | ((item: T & ObjectWithCodename) => string); +export type FilenameResolver> = undefined | CaseType | ((item: T & ObjectWithCodename) => string); -export type MapObjectToFileName = ObjectWithCodename> = ( - item: T, - addExtension: boolean -) => string; +export type MapObjectToFileName = ObjectWithCodename> = (item: T, addExtension: boolean) => string; export type ContentTypeFileNameResolver = FilenameResolver; export type ContentTypeSnippetFileNameResolver = FilenameResolver; export type TaxonomyTypeFileNameResolver = FilenameResolver; /** Name resolvers */ -export type NameResolver> = - | undefined - | CaseType - | ((item: T & ObjectWithCodename) => string); +export type NameResolver> = undefined | CaseType | ((item: T & ObjectWithCodename) => string); export type MapObjectToName = ObjectWithCodename> = (item: T) => string; -export type ElementNameResolver = ( - element: Readonly -) => string | undefined; +export type ElementNameResolver = (element: Readonly) => string | undefined; export type ContentTypeNameResolver = NameResolver; export type ContentTypeSnippetNameResolver = NameResolver; export type TaxonomyNameResolver = NameResolver; @@ -63,10 +47,7 @@ export function mapFilename(resolver: FilenameReso }; } -export function mapName( - resolver: NameResolver, - defaultCase: CaseType -): MapObjectToName { +export function mapName(resolver: NameResolver, defaultCase: CaseType): MapObjectToName { return (item) => { return match(resolver) .returnType() @@ -82,10 +63,7 @@ export function mapName( }; } -export function mapElementName( - resolver: GeneratorElementResolver | undefined, - defaultCase: CaseType -): ElementNameResolver { +export function mapElementName(resolver: GeneratorElementResolver | undefined, defaultCase: CaseType): ElementNameResolver { return (element) => { const codename = element.codename; From 40bf061bcdcbe60fbea89aad4ea70cda45359e2b Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 29 Aug 2024 11:48:11 +0200 Subject: [PATCH 041/183] Update resolvers.ts --- lib/core/resolvers.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/core/resolvers.ts b/lib/core/resolvers.ts index 120204b..73b325f 100644 --- a/lib/core/resolvers.ts +++ b/lib/core/resolvers.ts @@ -10,7 +10,6 @@ export type ObjectWithCodename = { /** File name resolvers */ export type FilenameResolver> = undefined | CaseType | ((item: T & ObjectWithCodename) => string); - export type MapObjectToFileName = ObjectWithCodename> = (item: T, addExtension: boolean) => string; export type ContentTypeFileNameResolver = FilenameResolver; @@ -19,7 +18,6 @@ export type TaxonomyTypeFileNameResolver = FilenameResolver> = undefined | CaseType | ((item: T & ObjectWithCodename) => string); - export type MapObjectToName = ObjectWithCodename> = (item: T) => string; export type ElementNameResolver = (element: Readonly) => string | undefined; From 7ea0eaea3cb08489e5fd4ac9674ab8e9f6831eea Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 29 Aug 2024 11:51:02 +0200 Subject: [PATCH 042/183] Adds missing readonly modifiers, updates printWidth --- .prettierrc | 2 +- lib/fetch/kontent-fetcher.ts | 59 +++++---------- .../delivery-content-type.generator.ts | 75 +++++++------------ lib/node/cli/cli.models.ts | 2 +- package.json | 2 +- 5 files changed, 49 insertions(+), 91 deletions(-) diff --git a/.prettierrc b/.prettierrc index 636cbd4..87f2c47 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,6 +1,6 @@ { "singleQuote": true, - "printWidth": 160, + "printWidth": 140, "proseWrap": "always", "tabWidth": 4, "requireConfig": false, diff --git a/lib/fetch/kontent-fetcher.ts b/lib/fetch/kontent-fetcher.ts index 9e19217..705933e 100644 --- a/lib/fetch/kontent-fetcher.ts +++ b/lib/fetch/kontent-fetcher.ts @@ -15,9 +15,9 @@ import { GeneratorManagementClient, sortAlphabetically, toSafeString } from '../ import chalk from 'chalk'; interface KontentFetcherConfig { - environmentId: string; - apiKey: string; - baseUrl?: string; + readonly environmentId: string; + readonly apiKey: string; + readonly baseUrl?: string; } export function kontentFetcher(config: KontentFetcherConfig) { @@ -34,69 +34,48 @@ export function kontentFetcher(config: KontentFetcherConfig) { console.log(`Environment '${chalk.yellow(toSafeString(projectInformation.project.environment))}'\n`); return projectInformation.project; }, - async getWorkflowsAsync(): Promise { + async getWorkflowsAsync(): Promise[]> { const items = sortAlphabetically((await client.listWorkflows().toPromise()).data, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' workflows`); return items; }, - async getRolesAsync(): Promise { + async getRolesAsync(): Promise[]> { const items = sortAlphabetically((await client.listRoles().toPromise()).data.roles, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' roles`); return items; }, - async getAssetFoldersAsync(): Promise { - const items = sortAlphabetically( - (await client.listAssetFolders().toPromise()).data.items, - (item) => item.name - ); + async getAssetFoldersAsync(): Promise[]> { + const items = sortAlphabetically((await client.listAssetFolders().toPromise()).data.items, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' asset folders`); return items; }, - async getCollectionsAsync(): Promise { - const items = sortAlphabetically( - (await client.listCollections().toPromise()).data.collections, - (item) => item.name - ); + async getCollectionsAsync(): Promise[]> { + const items = sortAlphabetically((await client.listCollections().toPromise()).data.collections, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' collections`); return items; }, - async getWebhooksAsync(): Promise { - const items = sortAlphabetically( - (await client.listWebhooks().toPromise()).data.webhooks, - (item) => item.name - ); + async getWebhooksAsync(): Promise[]> { + const items = sortAlphabetically((await client.listWebhooks().toPromise()).data.webhooks, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' webhooks`); return items; }, - async getLanguagesAsync(): Promise { - const items = sortAlphabetically( - (await client.listLanguages().toAllPromise()).data.items, - (item) => item.name - ); + async getLanguagesAsync(): Promise[]> { + const items = sortAlphabetically((await client.listLanguages().toAllPromise()).data.items, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' languages`); return items; }, - async getTypesAsync(): Promise { - const items = sortAlphabetically( - (await client.listContentTypes().toAllPromise()).data.items, - (item) => item.name - ); + async getTypesAsync(): Promise[]> { + const items = sortAlphabetically((await client.listContentTypes().toAllPromise()).data.items, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' types`); return items; }, - async getSnippetsAsync(): Promise { - const items = sortAlphabetically( - (await client.listContentTypeSnippets().toAllPromise()).data.items, - (item) => item.name - ); + async getSnippetsAsync(): Promise[]> { + const items = sortAlphabetically((await client.listContentTypeSnippets().toAllPromise()).data.items, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' snippets`); return items; }, - async getTaxonomiesAsync(): Promise { - const items = sortAlphabetically( - (await client.listTaxonomies().toAllPromise()).data.items, - (item) => item.name - ); + async getTaxonomiesAsync(): Promise[]> { + const items = sortAlphabetically((await client.listTaxonomies().toAllPromise()).data.items, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' taxonomies`); return items; } diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 3324a4b..a611293 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -1,11 +1,6 @@ import { match, P } from 'ts-pattern'; import { isNotUndefined } from '@kontent-ai/migration-toolkit'; -import { - ContentTypeModels, - ContentTypeSnippetModels, - EnvironmentModels, - TaxonomyModels -} from '@kontent-ai/management-sdk'; +import { ContentTypeModels, ContentTypeSnippetModels, EnvironmentModels, TaxonomyModels } from '@kontent-ai/management-sdk'; import { ContentTypeFileNameResolver, @@ -83,22 +78,15 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato } => { return { contentTypeFiles: config.environmentData.types.map((type) => createContentTypeModel(type)), - snippetFiles: config.environmentData.snippets.map((contentTypeSnippet) => - createContentTypeSnippetModel(contentTypeSnippet) - ) + snippetFiles: config.environmentData.snippets.map((contentTypeSnippet) => createContentTypeSnippetModel(contentTypeSnippet)) }; }; - const getSnippetImports = ( - snippets: readonly Readonly[] - ): readonly string[] => { + const getSnippetImports = (snippets: readonly Readonly[]): readonly string[] => { return snippets.map((snippet) => { return getImportStatement({ moduleResolution: config.moduleResolution, - filePathOrPackage: `../${deliveryConfig.contentTypeSnippetsFolderName}/${fileResolvers.snippet( - snippet, - false - )}.ts`, + filePathOrPackage: `../${deliveryConfig.contentTypeSnippetsFolderName}/${fileResolvers.snippet(snippet, false)}.ts`, importValue: nameResolvers.snippet(snippet) }); }); @@ -125,31 +113,28 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato importValue: nameResolvers.taxonomy(taxonomyElement.assignedTaxonomy) }); }) - .with( - P.union({ type: 'modular_content' }, { type: 'subpages' }), - (linkedItemsOrSubpagesElement) => { - return (linkedItemsOrSubpagesElement.allowedContentTypes ?? []) - .filter((allowedContentType) => { - // filter self-referencing types - if (allowedContentType.codename === typeOrSnippet.codename) { - return false; - } - return true; - }) - .map((allowedContentType) => { - const referencedTypeFilename: string = `${fileResolvers.contentType(allowedContentType, false)}`; + .with(P.union({ type: 'modular_content' }, { type: 'subpages' }), (linkedItemsOrSubpagesElement) => { + return (linkedItemsOrSubpagesElement.allowedContentTypes ?? []) + .filter((allowedContentType) => { + // filter self-referencing types + if (allowedContentType.codename === typeOrSnippet.codename) { + return false; + } + return true; + }) + .map((allowedContentType) => { + const referencedTypeFilename: string = `${fileResolvers.contentType(allowedContentType, false)}`; - return getImportStatement({ - moduleResolution: config.moduleResolution, - filePathOrPackage: - typeOrSnippet instanceof ContentTypeModels.ContentType - ? `../${deliveryConfig.contentTypesFolderName}/${referencedTypeFilename}.ts` - : `./${referencedTypeFilename}.ts`, - importValue: `${nameResolvers.contentType(allowedContentType)}` - }); + return getImportStatement({ + moduleResolution: config.moduleResolution, + filePathOrPackage: + typeOrSnippet instanceof ContentTypeModels.ContentType + ? `../${deliveryConfig.contentTypesFolderName}/${referencedTypeFilename}.ts` + : `./${referencedTypeFilename}.ts`, + importValue: `${nameResolvers.contentType(allowedContentType)}` }); - } - ) + }); + }) .otherwise(() => []) ) .flatMap((m) => m) @@ -159,9 +144,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato }; const getContentTypeImports = (data: { - readonly typeOrSnippet: - | Readonly - | Readonly; + readonly typeOrSnippet: Readonly | Readonly; readonly flattenedElements: readonly FlattenedElement[]; }): ExtractImportsResult => { const snippets = data.flattenedElements.map((m) => m.fromSnippet).filter(isNotUndefined); @@ -234,9 +217,7 @@ export type ${contentTypeImports.typeName} = IContentItem<{ }; }; - const createContentTypeSnippetModel = ( - snippet: Readonly - ): GeneratedFile => { + const createContentTypeSnippetModel = (snippet: Readonly): GeneratedFile => { return { filename: `${deliveryConfig.contentTypeSnippetsFolderName}/${fileResolvers.snippet(snippet, true)}`, text: getModelCode(snippet) @@ -294,9 +275,7 @@ export type ${contentTypeImports.typeName} = IContentItem<{ return element.assignedTaxonomy ? nameResolvers.taxonomy(element.assignedTaxonomy) : undefined; }; - const getLinkedItemsAllowedTypes = ( - types: readonly Readonly[] - ): readonly string[] => { + const getLinkedItemsAllowedTypes = (types: readonly Readonly[]): readonly string[] => { if (!types.length) { return ['IContentItem']; } diff --git a/lib/node/cli/cli.models.ts b/lib/node/cli/cli.models.ts index b9aca0a..c43d162 100644 --- a/lib/node/cli/cli.models.ts +++ b/lib/node/cli/cli.models.ts @@ -4,7 +4,7 @@ export interface Command { readonly name: string; readonly description: string; readonly options: readonly CommandOption[]; - readonly examples: string[]; + readonly examples: readonly string[]; } export interface CommandOption { diff --git a/package.json b/package.json index eb6b06a..ca2f6d3 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "test:delivery": "tsx scripts/tests/delivery-models", "test:project": "tsx scripts/tests/project-models", "test:migration": "tsx scripts/tests/migration-models", - "test:help:command": "tsx lib/node/cli/app delivery --help", + "test:help": "tsx lib/node/cli/app delivery --help", "lint": "npx eslint lib", "lint:fix": "npx eslint lib --fix", "clean": "tsx scripts/clean.ts", From 63c8e94ec0ca427ac9a9106556aa93df289ec070 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 2 Sep 2024 10:48:49 +0200 Subject: [PATCH 043/183] Further code refactorings --- README.md | 44 ++++----- lib/comments/comments.manager.ts | 4 +- lib/core/core.config.ts | 17 +++- lib/core/core.models.ts | 4 + lib/core/core.utils.ts | 70 ++++--------- lib/core/element.utils.ts | 14 +-- lib/core/error.utils.ts | 56 ++++++----- lib/core/importer.ts | 16 +++ lib/core/index.ts | 1 + lib/core/resolvers.ts | 40 ++------ lib/files/file-manager.ts | 46 ++++----- .../delivery-content-type.generator.ts | 32 +++--- lib/generators/delivery/delivery-func.ts | 7 +- .../delivery/delivery-taxonomy.generator.ts | 10 +- lib/generators/migration/migration-func.ts | 6 +- .../migration/migration.generator.ts | 99 +++++++------------ lib/generators/project/project-func.ts | 10 +- lib/generators/project/project.generator.ts | 34 ++----- lib/index.ts | 1 + lib/node/cli/actions/delivery-action.ts | 4 +- lib/node/cli/commands.ts | 9 +- .../delivery/content-type-snippets/index.ts | 27 ++--- sample/delivery/content-types/actor.ts | 30 +++--- sample/delivery/content-types/index.ts | 27 ++--- sample/delivery/content-types/movie.ts | 35 +++---- sample/delivery/index.ts | 27 ++--- sample/delivery/taxonomies/index.ts | 27 ++--- sample/delivery/taxonomies/movietype.ts | 27 ++--- sample/delivery/taxonomies/releasecategory.ts | 27 ++--- sample/migration/content-types/actor.ts | 27 ++--- sample/migration/content-types/index.ts | 27 ++--- sample/migration/content-types/movie.ts | 27 ++--- sample/migration/core.models.ts | 27 ++--- sample/migration/index.ts | 27 ++--- sample/project/assetFolders.ts | 27 ++--- sample/project/collections.ts | 27 ++--- sample/project/contentTypeSnippets.ts | 27 ++--- sample/project/contentTypes.ts | 27 ++--- sample/project/index.ts | 27 ++--- sample/project/languages.ts | 27 ++--- sample/project/roles.ts | 27 ++--- sample/project/taxonomies.ts | 27 ++--- sample/project/webhooks.ts | 27 ++--- sample/project/workflows.ts | 27 ++--- scripts/file-version-script.ts | 4 +- scripts/tests/delivery-models.ts | 1 - 46 files changed, 525 insertions(+), 636 deletions(-) create mode 100644 lib/core/importer.ts diff --git a/README.md b/README.md index 798ec58..e8ffeb1 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ # Kontent.ai Model Generator -The purpose of this project is to help you generate `Typescript models` based on [Kontent.ai](https://kontent.ai) item -types. These models can be used with the [Delivery SDK](https://www.npmjs.com/package/@kontent-ai/delivery-sdk) and -enhances your experience by providing strongly typed models. +The purpose of this project is to help you generate `Typescript models` based on [Kontent.ai](https://kontent.ai) item types. These models +can be used with the [Delivery SDK](https://www.npmjs.com/package/@kontent-ai/delivery-sdk) and enhances your experience by providing +strongly typed models. ## Installation @@ -26,8 +26,8 @@ You may specify other options like: ## Generate models in code -Apart from generating models via CLI, you may also generate models in code which also gives you some additional -configuration options (such as using custom name resolver). +Apart from generating models via CLI, you may also generate models in code which also gives you some additional configuration options (such +as using custom name resolver). ```typescript import { generateDeliveryModelsAsync } from '@kontent-ai/model-generator'; @@ -39,7 +39,6 @@ await generateDeliveryModelsAsync({ apiKey: 'yyy', addTimestamp: true, moduleResolution: 'nodeNext', - addEnvironmentInfo: true, elementResolver: 'camelCase', sortConfig: { sortTaxonomyTerms: true @@ -49,15 +48,14 @@ await generateDeliveryModelsAsync({ ### Customizing generated file names -You may customize the way filenames are stored on file system using the `contentTypeFileResolver` and / or -`taxonomyTypeFileResolver` configuration option: +You may customize the way filenames are stored on file system using the `contentTypeFileResolver` and / or `taxonomyTypeFileResolver` +configuration option: ```typescript await generateDeliveryModelsAsync({ sdkType: 'delivery', environmentId: 'da5abe9f-fdad-4168-97cd-b3464be2ccb9', isEnterpriseSubscription: true, - addEnvironmentInfo: true, apiKey: 'yyy', moduleResolution: 'nodeNext', addTimestamp: true, @@ -80,7 +78,6 @@ await generateDeliveryModelsAsync({ apiKey: 'yyy', moduleResolution: 'nodeNext', addTimestamp: true, - addEnvironmentInfo: true, elementResolver: 'camelCase', contentTypeResolver: (type) => `${textHelper.toPascalCase(type.codename)}Model`, taxonomyTypeResolver: (taxonomy) => `${textHelper.toPascalCase(taxonomy.codename)}Taxonomy` @@ -89,31 +86,25 @@ await generateDeliveryModelsAsync({ ## FAQ -- If you are getting the `The Subscription API is not supported in your plan` error, set the - `isEnterpriseSubscription` option to false +- If you are getting the `The Subscription API is not supported in your plan` error, set the `isEnterpriseSubscription` option to false ## CLI Configuration - `environmentId` - Id of the Kontent.ai environment - `apiKey`- Management API Key -- `outputDir`- Directory where files will be created. Defaults to current directory - `--outputDir=./`. Some other - examples: `--outputDir=./sample` +- `outputDir`- Directory where files will be created. Defaults to current directory - `--outputDir=./`. Some other examples: + `--outputDir=./sample` - `isEnterpriseSubscription` - Indicates if enterprise subscription endpoint can be used to export data. - `addTimestamp`- Indicates if timestamp is added to generated models -- `addEnvironmentInfo`- Indicates if environment info stamp is added to generated models - `elementResolver`- Name resolver for elements. Available options are: `camelCase`, `pascalCase`, `snakeCase` -- `contentTypeFileResolver`- Name resolver for content type filenames. Available options are: `camelCase`, - `pascalCase`, `snakeCase` -- `contentTypeSnippetFileResolver`- Name resolver for content type snippet filenames. Available options are: - `camelCase`, `pascalCase`, `snakeCase` -- `taxonomyTypeFileResolver`- Name resolver for taxonomy filenames. Available options are: `camelCase`, `pascalCase`, +- `contentTypeFileResolver`- Name resolver for content type filenames. Available options are: `camelCase`, `pascalCase`, `snakeCase` +- `contentTypeSnippetFileResolver`- Name resolver for content type snippet filenames. Available options are: `camelCase`, `pascalCase`, `snakeCase` -- `contentTypeResolver`- Name resolver for content type names. Available options are: `camelCase`, `pascalCase`, - `snakeCase` -- `contentTypeSnippetResolver`- Name resolver for content type snippet names. Available options are: `camelCase`, - `pascalCase`, `snakeCase` -- `taxonomyTypeResolver`- Name resolver for taxonomy type names. Available options are: `camelCase`, `pascalCase`, +- `taxonomyTypeFileResolver`- Name resolver for taxonomy filenames. Available options are: `camelCase`, `pascalCase`, `snakeCase` +- `contentTypeResolver`- Name resolver for content type names. Available options are: `camelCase`, `pascalCase`, `snakeCase` +- `contentTypeSnippetResolver`- Name resolver for content type snippet names. Available options are: `camelCase`, `pascalCase`, `snakeCase` +- `taxonomyTypeResolver`- Name resolver for taxonomy type names. Available options are: `camelCase`, `pascalCase`, `snakeCase` - `sdkType`- Type of sdk for which models are generated. Available options are: `delivery`, `migration` - `exportWebhooks` - Indicates if webhooks are exported - `exportWorkflows` - Indicates if workflows are exported @@ -230,8 +221,7 @@ export type Movie = IContentItem<{ export type MovieType = 'student' | 'film' | 'tv' | 'blockbuster' | 'cinema_only'; ``` -To learn the complete generator output, see the following folder: -https://github.com/kontent-ai/model-generator-js/tree/master/sample +To learn the complete generator output, see the following folder: https://github.com/kontent-ai/model-generator-js/tree/master/sample ## Contribution & Feedback diff --git a/lib/comments/comments.manager.ts b/lib/comments/comments.manager.ts index 9bc3dd8..b40ac31 100644 --- a/lib/comments/comments.manager.ts +++ b/lib/comments/comments.manager.ts @@ -8,8 +8,8 @@ export function commentsManager() { }; const getEnvironmentInfoComment = (data: { - addTimestamp?: boolean; - environmentInfo: Readonly; + readonly addTimestamp?: boolean; + readonly environmentInfo: Readonly; }): string => { return ` /** diff --git a/lib/core/core.config.ts b/lib/core/core.config.ts index 1348819..8f59643 100644 --- a/lib/core/core.config.ts +++ b/lib/core/core.config.ts @@ -5,7 +5,22 @@ export const coreConfig = { export const migrationConfig = { npmPackageName: '@kontent-ai/migration-toolkit', migrationItemsFolderName: `content-types`, - migrationTypesFilename: `core.models.ts` + migrationTypesFilename: `core.models.ts`, + + typeNames: { + languageCodenames: 'LanguageCodenames', + collectionCodenames: 'CollectionCodenames', + workflowCodenames: 'WorkflowCodenames', + workflowStepCodenames: 'WorkflowStepCodenames', + contentTypeCodenames: 'ContentTypeCodenames', + migrationItemSystem: 'MigrationItemSystem', + migrationElementModels: 'MigrationElementModels', + migrationItem: 'MigrationItem', + migrationElements: 'MigrationElements', + system: 'System', + item: 'Item', + codename: 'Codename' + } } as const; export const deliveryConfig = { diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index 1913bd7..790b4da 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -56,3 +56,7 @@ export interface GeneratedFile { readonly filename: string; readonly text: string; } + +export type ObjectWithCodename = { + readonly codename: string; +}; diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index a383824..bd60f2f 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -1,9 +1,4 @@ -import { - camelCasePropertyNameResolver, - pascalCasePropertyNameResolver, - snakeCasePropertyNameResolver -} from '@kontent-ai/delivery-sdk'; -import { LibraryType, LiteralUnion } from './index.js'; +import { camelCasePropertyNameResolver, pascalCasePropertyNameResolver, snakeCasePropertyNameResolver } from '@kontent-ai/delivery-sdk'; import { parse } from 'path'; import { ModuleResolution } from './core.models.js'; @@ -11,7 +6,7 @@ export function exitProgram(data: { readonly message: string }): never { throw Error(data.message); } -export function uniqueFilter(value: string, index: number, self: string[]) { +export function uniqueFilter(value: string, index: number, self: readonly string[]): boolean { return self.indexOf(value) === index; } @@ -24,31 +19,11 @@ export function replaceTsExtensionWithJs(filePath: string): string { } export function getFileNameWithoutExtension(filePath: string): string { - const lastDotIndex = filePath.lastIndexOf('.'); - if (lastDotIndex === -1) { - return filePath; - } - return filePath.substring(0, lastDotIndex); + return filePath.substring(0, filePath.lastIndexOf('.')); } export function sortAlphabetically(arrayToSort: readonly T[], propertySelector: (item: T) => string): readonly T[] { - return arrayToSort.toSorted((a, b) => - propertySelector(a).toLowerCase().localeCompare(propertySelector(b).toLowerCase()) - ); -} - -export function getImportStatement(data: { - filePathOrPackage: LiteralUnion; - importValue: string; - moduleResolution: ModuleResolution; -}): string { - const isExternalLib = !data.filePathOrPackage.endsWith('.js') && !data.filePathOrPackage.endsWith('.ts'); - const resolvedFilePath = - data.moduleResolution === 'nodeNext' && !isExternalLib - ? `${getFileNameWithoutExtension(data.filePathOrPackage)}.js` - : data.filePathOrPackage; - - return `import type { ${data.importValue} } from '${resolvedFilePath}';`; + return arrayToSort.toSorted((a, b) => propertySelector(a).toLowerCase().localeCompare(propertySelector(b).toLowerCase())); } export function toPascalCase(text: string): string { @@ -74,11 +49,12 @@ export function removeLineEndings(value: string): string { return value.replace(/(\r\n|\n|\r)/gm, ''); } +export function toGuidelinesComment(guidelines: string): string { + return toSafeString(removeLineEndings(guidelines)); +} + export function getStringOrUndefined(text?: string): string { - if (!text) { - return 'undefined'; - } - return `'${text}'`; + return text ? `'${text}'` : 'undefined'; } export function toSafeStringCode(text: string): string { @@ -95,24 +71,16 @@ export function toOutputDirPath(outputDir?: string): string { return outputDir ? `${outputDir}/`.replaceAll('//', '/') : `./`; } -export function getBarrelExportCode(data: { filenames: string[]; moduleResolution: ModuleResolution }): string { - let code = ''; - - if (data.filenames.length) { - for (let i = 0; i < data.filenames.length; i++) { - const isLast = i === data.filenames.length - 1; - const filename = data.filenames[i]; - const path = parse(filename); - const extension = data.moduleResolution === 'nodeNext' ? '.js' : ''; - code += `export * from '${path.dir}/${path.name}${extension}'`; +export function getExtensionForModuleResolution(moduleResolution: ModuleResolution): string { + return moduleResolution === 'nodeNext' ? '.js' : ''; +} - if (!isLast) { - code += `\n`; - } - } - } else { - code = `export {}`; +export function getBarrelExportCode(data: { readonly filenames: readonly string[]; readonly moduleResolution: ModuleResolution }): string { + if (!data.filenames.length) { + return 'export {}'; } - - return code; + return data.filenames.reduce((barrelCode, filename) => { + const path = parse(filename); + return (barrelCode += `export * from '${path.dir}/${path.name}${getExtensionForModuleResolution(data.moduleResolution)}';`); + }, ''); } diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts index 17377ef..c6b4b4c 100644 --- a/lib/core/element.utils.ts +++ b/lib/core/element.utils.ts @@ -1,9 +1,4 @@ -import { - ContentTypeElements, - ContentTypeModels, - ContentTypeSnippetModels, - TaxonomyModels -} from '@kontent-ai/management-sdk'; +import { ContentTypeElements, ContentTypeModels, ContentTypeSnippetModels, TaxonomyModels } from '@kontent-ai/management-sdk'; import { FlattenedElement } from './core.models.js'; import { isNotUndefined } from '@kontent-ai/migration-toolkit'; import { match } from 'ts-pattern'; @@ -101,12 +96,7 @@ function getElementTitle( } const taxonomy = taxonomies.find((m) => m.id === taxonomyGroupId); - - if (!taxonomy) { - return element.type; - } - - return taxonomy.name; + return taxonomy?.name ?? element.type; } return (<{ name?: string }>element).name ?? element.codename ?? 'n/a'; } diff --git a/lib/core/error.utils.ts b/lib/core/error.utils.ts index b13d126..cdc9ace 100644 --- a/lib/core/error.utils.ts +++ b/lib/core/error.utils.ts @@ -1,34 +1,40 @@ import { SharedModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { ErrorData, OriginalManagementError } from './core.models.js'; +import { match, P } from 'ts-pattern'; export function extractErrorData(error: unknown): ErrorData { - let isUnknownError: boolean = true; - let message: string = `Unknown error`; - let requestUrl: string | undefined = undefined; - let requestData: string | undefined = undefined; + return match(error) + .returnType() + .with(P.instanceOf(SharedModels.ContentManagementBaseKontentError), (error) => { + const originalError = error.originalError as OriginalManagementError | undefined; - if (error instanceof SharedModels.ContentManagementBaseKontentError) { - isUnknownError = false; - const originalError = error.originalError as OriginalManagementError | undefined; - - requestUrl = originalError?.response?.config?.url; - requestData = originalError?.response?.config?.data; - - message = `${error.message}: ${error.validationErrors.map((m) => m.message).join(', ')}`; - } else if (error instanceof Error) { - message = error.message; - } - - const errorData: ErrorData = { - message: message, - requestData: requestData, - requestUrl: requestUrl, - error: error, - isUnknownError: isUnknownError - }; - - return errorData; + return { + message: `${error.message}: ${error.validationErrors.map((m) => m.message).join(', ')}`, + requestData: originalError?.response?.config?.data, + requestUrl: originalError?.response?.config?.url, + error: error, + isUnknownError: false + }; + }) + .with(P.instanceOf(Error), (error) => { + return { + message: error.message, + requestData: undefined, + requestUrl: undefined, + error: error, + isUnknownError: true + }; + }) + .otherwise(() => { + return { + message: `Unknown error`, + requestData: undefined, + requestUrl: undefined, + error: error, + isUnknownError: true + }; + }); } export function is404Error(error: unknown): boolean { diff --git a/lib/core/importer.ts b/lib/core/importer.ts new file mode 100644 index 0000000..9af39cf --- /dev/null +++ b/lib/core/importer.ts @@ -0,0 +1,16 @@ +import { ModuleResolution, LibraryType, LiteralUnion } from './core.models.js'; +import { getFileNameWithoutExtension } from './core.utils.js'; + +export function importer(moduleResolution: ModuleResolution) { + return { + importType: (data: { readonly filePathOrPackage: LiteralUnion; readonly importValue: string }): string => { + const isExternalLib = !data.filePathOrPackage.endsWith('.js') && !data.filePathOrPackage.endsWith('.ts'); + const resolvedFilePath = + moduleResolution === 'nodeNext' && !isExternalLib + ? `${getFileNameWithoutExtension(data.filePathOrPackage)}.js` + : data.filePathOrPackage; + + return `import type { ${data.importValue} } from '${resolvedFilePath}';`; + } + }; +} diff --git a/lib/core/index.ts b/lib/core/index.ts index 98c063c..432a374 100644 --- a/lib/core/index.ts +++ b/lib/core/index.ts @@ -4,3 +4,4 @@ export * from './core.models.js'; export * from './element.utils.js'; export * from './core.config.js'; export * from './resolvers.js'; +export * from './importer.js'; diff --git a/lib/core/resolvers.ts b/lib/core/resolvers.ts index 73b325f..faa4b82 100644 --- a/lib/core/resolvers.ts +++ b/lib/core/resolvers.ts @@ -1,12 +1,7 @@ -import {} from '@kontent-ai/delivery-sdk'; import { ContentTypeModels, ContentTypeSnippetModels, ContentTypeElements, TaxonomyModels } from '@kontent-ai/management-sdk'; import { toCamelCase, toPascalCase, toSnakeCase } from './core.utils.js'; -import { match } from 'ts-pattern'; -import { CaseType, GeneratorElementResolver } from './core.models.js'; - -export type ObjectWithCodename = { - readonly codename: string; -}; +import { match, P } from 'ts-pattern'; +import { CaseType, GeneratorElementResolver, ObjectWithCodename } from './core.models.js'; /** File name resolvers */ export type FilenameResolver> = undefined | CaseType | ((item: T & ObjectWithCodename) => string); @@ -30,16 +25,9 @@ export function mapFilename(resolver: FilenameReso return addExtensionToFilename( match(resolver) .returnType() - .when( - (resolver) => resolver instanceof Function, - (resolver) => resolver(item) - ) - .when( - (resolver) => resolver === undefined, - () => item.codename - ) + .with(P.instanceOf(Function), (resolver) => resolver(item)) + .with(undefined, () => item.codename) .otherwise((resolverType) => resolveCase(item.codename, resolverType)), - addExtension ); }; @@ -49,14 +37,8 @@ export function mapName(resolver: NameResolver, return (item) => { return match(resolver) .returnType() - .when( - (resolver) => resolver instanceof Function, - (resolver) => resolver(item) - ) - .when( - (resolver) => resolver === undefined, - () => resolveCase(item.codename, defaultCase) - ) + .with(P.instanceOf(Function), (resolver) => resolver(item)) + .with(undefined, () => resolveCase(item.codename, defaultCase)) .otherwise((resolverType) => resolveCase(item.codename, resolverType)); }; } @@ -71,14 +53,8 @@ export function mapElementName(resolver: GeneratorElementResolver | undefined, d return match(resolver) .returnType() - .when( - (resolver) => resolver instanceof Function, - (resolver) => resolver('', codename) - ) - .when( - (resolver) => resolver === undefined, - () => resolveCase(codename, defaultCase) - ) + .with(P.instanceOf(Function), (resolver) => resolver('', codename)) + .with(undefined, () => resolveCase(codename, defaultCase)) .otherwise((resolverType) => resolveCase(codename, resolverType)); }; } diff --git a/lib/files/file-manager.ts b/lib/files/file-manager.ts index 01e80e3..6725255 100644 --- a/lib/files/file-manager.ts +++ b/lib/files/file-manager.ts @@ -8,40 +8,34 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import { commentsManager } from '../comments/index.js'; export function fileManager(config: { - outputDir: string | undefined; - formatOptions: Readonly | undefined; - environmentInfo: Readonly; - addTimestamp: boolean; + readonly outputDir: string | undefined; + readonly formatOptions: Readonly | undefined; + readonly environmentInfo: Readonly; + readonly addTimestamp: boolean; }) { const fixedOutputDir = toOutputDirPath(config.outputDir); - const createFileOnFsAsync = async ( - text: string, - filePath: string, - formatOptions: Readonly | undefined - ): Promise => { + const createFileOnFsAsync = async (text: string, filePath: string, formatOptions: Readonly | undefined): Promise => { const fullFilePath = `${fixedOutputDir.endsWith('/') ? fixedOutputDir : `${fixedOutputDir}/`}${filePath}`; + const fileContent = `${commentsManager().getEnvironmentInfoComment({ + environmentInfo: config.environmentInfo, + addTimestamp: config.addTimestamp + })}\n\n${await getFormattedCodeAsync(text, filePath, formatOptions)}`; - let fileContent = - `${commentsManager().getEnvironmentInfoComment({ - environmentInfo: config.environmentInfo, - addTimestamp: config.addTimestamp - })}\n\n` + text; + ensureDirectoryExistence(fullFilePath); + fs.writeFileSync('./' + fullFilePath, fileContent, {}); + console.log(`Created '${chalk.yellow(fullFilePath)}'`); + }; + + const getFormattedCodeAsync = async (code: string, filePath: string, formatOptions: Readonly | undefined): Promise => { try { - fileContent = await formatCodeAsync(fileContent, formatOptions); + return await formatCodeAsync(code, formatOptions); } catch { console.log(`Failed to format file '${chalk.red(filePath)}'. Skipping prettier for this file.`); - } finally { - ensureDirectoryExistence(fullFilePath); - fs.writeFileSync('./' + fullFilePath, fileContent, {}); - console.log(`Created '${chalk.yellow(fullFilePath)}'`); + return code; } }; - const createDir = (dirPath: string): void => { - fs.mkdirSync(dirPath, { recursive: true }); - }; - const ensureDirectoryExistence = (filePath: string): void => { const resolvedDirname = dirname(filePath); if (fs.existsSync(resolvedDirname)) { @@ -53,15 +47,13 @@ export function fileManager(config: { const createFilesAsync = async (files: readonly GeneratedFile[]): Promise => { await Promise.all( - files.map((file) => { - return createFileOnFsAsync(file.text, file.filename, config.formatOptions); + files.map(async (file) => { + return await createFileOnFsAsync(file.text, file.filename, config.formatOptions); }) ); }; return { - createDir, - createFileOnFsAsync, createFilesAsync }; } diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index a611293..f7094ea 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -11,18 +11,18 @@ import { FlattenedElement, GeneratedFile, getFlattenedElements, - getImportStatement, mapElementName, mapFilename, mapName, - removeLineEndings, sortAlphabetically, TaxonomyTypeFileNameResolver, TaxonomyNameResolver, toSafeString, uniqueFilter, ModuleResolution, - GeneratorElementResolver + GeneratorElementResolver, + importer as _importer, + toGuidelinesComment } from '../../core/index.js'; interface ExtractImportsResult { @@ -32,8 +32,6 @@ interface ExtractImportsResult { } export interface DeliveryContentTypeGeneratorConfig { - readonly addTimestamp: boolean; - readonly addEnvironmentInfo: boolean; readonly moduleResolution: ModuleResolution; readonly environmentData: { @@ -58,13 +56,14 @@ export interface DeliveryContentTypeGeneratorConfig { } export function deliveryContentTypeGenerator(config: DeliveryContentTypeGeneratorConfig) { - // prepare resolvers const fileResolvers = { snippet: mapFilename(config.fileResolvers?.snippet), contentType: mapFilename(config.fileResolvers?.contentType), taxonomy: mapFilename(config.fileResolvers?.taxonomy) }; + const importer = _importer(config.moduleResolution); + const nameResolvers = { snippet: mapName(config.nameResolvers?.snippet, 'pascalCase'), contentType: mapName(config.nameResolvers?.contentType, 'pascalCase'), @@ -84,8 +83,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato const getSnippetImports = (snippets: readonly Readonly[]): readonly string[] => { return snippets.map((snippet) => { - return getImportStatement({ - moduleResolution: config.moduleResolution, + return importer.importType({ filePathOrPackage: `../${deliveryConfig.contentTypeSnippetsFolderName}/${fileResolvers.snippet(snippet, false)}.ts`, importValue: nameResolvers.snippet(snippet) }); @@ -107,8 +105,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato if (!taxonomyElement.assignedTaxonomy) { throw Error(`Invalid taxonomy for element '${taxonomyElement.codename}'`); } - return getImportStatement({ - moduleResolution: config.moduleResolution, + return importer.importType({ filePathOrPackage: `../${deliveryConfig.taxonomiesFolderName}/${fileResolvers.taxonomy(taxonomyElement.assignedTaxonomy, false)}.ts`, importValue: nameResolvers.taxonomy(taxonomyElement.assignedTaxonomy) }); @@ -116,7 +113,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato .with(P.union({ type: 'modular_content' }, { type: 'subpages' }), (linkedItemsOrSubpagesElement) => { return (linkedItemsOrSubpagesElement.allowedContentTypes ?? []) .filter((allowedContentType) => { - // filter self-referencing types + // filter self-referencing types as they do not need to be importer if (allowedContentType.codename === typeOrSnippet.codename) { return false; } @@ -125,8 +122,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato .map((allowedContentType) => { const referencedTypeFilename: string = `${fileResolvers.contentType(allowedContentType, false)}`; - return getImportStatement({ - moduleResolution: config.moduleResolution, + return importer.importType({ filePathOrPackage: typeOrSnippet instanceof ContentTypeModels.ContentType ? `../${deliveryConfig.contentTypesFolderName}/${referencedTypeFilename}.ts` @@ -189,9 +185,8 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato flattenedElements: flattenedElements }); - const code = ` -${getImportStatement({ - moduleResolution: config.moduleResolution, + return ` +${importer.importType({ filePathOrPackage: deliveryConfig.npmPackageName, importValue: `${getDeliverySdkContentTypeImports(flattenedElements).join(', ')}` })} @@ -207,7 +202,6 @@ export type ${contentTypeImports.typeName} = IContentItem<{ ${getElementsCode(flattenedElements)} }>${contentTypeImports.contentTypeExtends ? ` ${contentTypeImports.contentTypeExtends}` : ''}; `; - return code; }; const createContentTypeModel = (type: Readonly): GeneratedFile => { @@ -237,13 +231,13 @@ export type ${contentTypeImports.typeName} = IContentItem<{ return code; } - return (code += `\n + return (code += ` /** * ${element.title} (${element.type}) * * Required: ${element.isRequired ? 'true' : 'false'} * Codename: ${element.codename} - * Id: ${element.id}${element.guidelines ? `\n* Guidelines: ${toSafeString(removeLineEndings(element.guidelines))}` : ''} + * Id: ${element.id}${element.guidelines ? `\n* Guidelines: ${toGuidelinesComment(element.guidelines)}` : ''} */ ${elementName}: Elements.${mappedType};`); }, '') diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index 3e2dbb5..64b67b0 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -25,7 +25,6 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; export interface GenerateDeliveryModelsConfig { readonly environmentId: string; readonly addTimestamp: boolean; - readonly addEnvironmentInfo: boolean; readonly apiKey: string; readonly moduleResolution?: ModuleResolution; @@ -51,8 +50,7 @@ export async function generateDeliveryModelsAsync(config: GenerateDeliveryModels console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('delivery')}' models\n`); - const { contentTypeFiles, snippetFiles, taxonomyFiles, moduleResolution, environmentInfo } = - await getFilesAsync(config); + const { contentTypeFiles, snippetFiles, taxonomyFiles, moduleResolution, environmentInfo } = await getFilesAsync(config); await createFilesAsync( { @@ -90,8 +88,6 @@ async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ const taxonomies = await kontentFetcher.getTaxonomiesAsync(); const { contentTypeFiles, snippetFiles } = deliveryContentTypeGenerator({ - addTimestamp: config.addTimestamp, - addEnvironmentInfo: config.addEnvironmentInfo, moduleResolution: moduleResolution, environmentData: { environment: environmentInfo, @@ -104,7 +100,6 @@ async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ }).generateModels(); const taxonomyFiles = deliveryTaxonomyGenerator({ - addTimestamp: config.addTimestamp, moduleResolution: moduleResolution, environmentData: { environment: await kontentFetcher.getEnvironmentInfoAsync(), diff --git a/lib/generators/delivery/delivery-taxonomy.generator.ts b/lib/generators/delivery/delivery-taxonomy.generator.ts index 756b3dc..e7b7ed9 100644 --- a/lib/generators/delivery/delivery-taxonomy.generator.ts +++ b/lib/generators/delivery/delivery-taxonomy.generator.ts @@ -13,7 +13,6 @@ import { } from '../../core/index.js'; export interface DeliveryTaxonomyGeneratorConfig { - readonly addTimestamp: boolean; readonly moduleResolution: ModuleResolution; readonly environmentData: { @@ -59,10 +58,7 @@ export type ${taxonomyNameMap(taxonomy)} = ${getTaxonomyTermsCode(taxonomy)}; }; const getTaxonomyTermsCode = (taxonomy: Readonly): string => { - const taxonomyTermCodenames = sortAlphabetically( - getTaxonomyTermCodenames(taxonomy.terms), - (codename) => codename - ); + const taxonomyTermCodenames = sortAlphabetically(getTaxonomyTermCodenames(taxonomy.terms), (codename) => codename); if (!taxonomyTermCodenames.length) { return `''`; @@ -74,9 +70,7 @@ export type ${taxonomyNameMap(taxonomy)} = ${getTaxonomyTermsCode(taxonomy)}; }, ''); }; - const getTaxonomyTermCodenames = ( - taxonomyTerms: readonly Readonly[] - ): readonly string[] => { + const getTaxonomyTermCodenames = (taxonomyTerms: readonly Readonly[]): readonly string[] => { return taxonomyTerms.reduce((codenames, taxonomyTerm) => { return codenames.concat(getTaxonomyTermCodenames(taxonomyTerm.terms), taxonomyTerm.codename); }, []); diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index eb6d6be..cc59b25 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -60,7 +60,6 @@ async function getFilesAsync(config: GenerateMigrationModelsConfig): Promise<{ const environmentInfo = await kontentFetcher.getEnvironmentInfoAsync(); const migrationGenerator = _migrationGenerator({ - addTimestamp: config.addTimestamp, moduleResolution: config.moduleResolution, environmentData: { environment: environmentInfo, @@ -117,10 +116,7 @@ async function createFilesAsync(data: { filename: coreConfig.barrelExportFilename, text: getBarrelExportCode({ moduleResolution: data.moduleResolution, - filenames: [ - `./${migrationConfig.migrationItemsFolderName}/index`, - `./${data.migrationTypeFile.filename}` - ] + filenames: [`./${migrationConfig.migrationItemsFolderName}/index`, `./${data.migrationTypeFile.filename}`] }) } ]); diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index 9458b1a..15287a1 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -10,20 +10,19 @@ import { import { match } from 'ts-pattern'; import { FlattenedElement, - getImportStatement, uniqueFilter, GeneratedFile, toSafeString, - removeLineEndings, toPascalCase, getFlattenedElements, migrationConfig, - ModuleResolution + ModuleResolution, + importer as _importer, + toGuidelinesComment } from '../../core/index.js'; import { commentsManager as _commentsManager } from '../../comments/index.js'; export interface MigrationGeneratorConfig { - readonly addTimestamp: boolean; readonly moduleResolution: ModuleResolution; readonly environmentData: { @@ -37,37 +36,21 @@ export interface MigrationGeneratorConfig { }; } -const migrationTypeNames = { - languageCodenames: 'LanguageCodenames', - collectionCodenames: 'CollectionCodenames', - workflowCodenames: 'WorkflowCodenames', - workflowStepCodenames: 'WorkflowStepCodenames', - contentTypeCodenames: 'ContentTypeCodenames', - migrationItemSystem: 'MigrationItemSystem', - migrationElementModels: 'MigrationElementModels', - migrationItem: 'MigrationItem', - migrationElements: 'MigrationElements', - system: 'System', - item: 'Item', - codename: 'Codename' -} as const; - export function migrationGenerator(config: MigrationGeneratorConfig) { const commentsManager = _commentsManager(); + const importer = _importer(config.moduleResolution); const getMigrationItemType = (type: Readonly): GeneratedFile => { return { filename: `${migrationConfig.migrationItemsFolderName}/${type.codename}.ts`, text: ` - ${getImportStatement({ + ${importer.importType({ filePathOrPackage: migrationConfig.npmPackageName, - importValue: migrationTypeNames.migrationElementModels, - moduleResolution: config.moduleResolution + importValue: migrationConfig.typeNames.migrationElementModels })} - ${getImportStatement({ + ${importer.importType({ filePathOrPackage: `../${migrationConfig.migrationTypesFilename}`, - importValue: migrationTypeNames.item, - moduleResolution: config.moduleResolution + importValue: migrationConfig.typeNames.item })} /** @@ -76,7 +59,7 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { * Codename: ${type.codename} * Id: ${type.id} */ - export type ${toPascalCase(type.name)}Item = ${migrationTypeNames.item}< + export type ${toPascalCase(type.name)}Item = ${migrationConfig.typeNames.item}< '${type.codename}', { ${getFlattenedElements( @@ -92,7 +75,7 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { * * Required: ${element.isRequired ? 'true' : 'false'} * Codename: ${element.codename} - * Id: ${element.id}${element.guidelines ? `\n* Guidelines: ${toSafeString(removeLineEndings(element.guidelines))}` : ''} + * Id: ${element.id}${element.guidelines ? `\n* Guidelines: ${toGuidelinesComment(element.guidelines)}` : ''} */ ${element.codename}: ${getElementPropType(element)}`; }) @@ -107,10 +90,9 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { return { filename: migrationConfig.migrationTypesFilename, text: ` - ${getImportStatement({ + ${importer.importType({ filePathOrPackage: migrationConfig.npmPackageName, - importValue: `${migrationTypeNames.migrationItemSystem}, ${migrationTypeNames.migrationItem}, ${migrationTypeNames.migrationElements}`, - moduleResolution: config.moduleResolution + importValue: `${migrationConfig.typeNames.migrationItemSystem}, ${migrationConfig.typeNames.migrationItem}, ${migrationConfig.typeNames.migrationElements}` })} ${commentsManager.wrapComment('Type representing all languages')} @@ -145,62 +127,57 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { function getElementPropType(element: Readonly): string { return match(element.type) .returnType() - .with('text', () => `${migrationTypeNames.migrationElementModels}.TextElement`) - .with('asset', () => `${migrationTypeNames.migrationElementModels}.AssetElement`) - .with('custom', () => `${migrationTypeNames.migrationElementModels}.CustomElement`) - .with('date_time', () => `${migrationTypeNames.migrationElementModels}.DateTimeElement`) - .with('rich_text', () => `${migrationTypeNames.migrationElementModels}.RichTextElement`) - .with('number', () => `${migrationTypeNames.migrationElementModels}.NumberElement`) - .with('multiple_choice', () => `${migrationTypeNames.migrationElementModels}.MultipleChoiceElement`) - .with('subpages', () => `${migrationTypeNames.migrationElementModels}.SubpagesElement`) - .with('taxonomy', () => `${migrationTypeNames.migrationElementModels}.TaxonomyElement`) - .with('url_slug', () => `${migrationTypeNames.migrationElementModels}.UrlSlugElement`) - .with('modular_content', () => `${migrationTypeNames.migrationElementModels}.LinkedItemsElement`) + .with('text', () => `${migrationConfig.typeNames.migrationElementModels}.TextElement`) + .with('asset', () => `${migrationConfig.typeNames.migrationElementModels}.AssetElement`) + .with('custom', () => `${migrationConfig.typeNames.migrationElementModels}.CustomElement`) + .with('date_time', () => `${migrationConfig.typeNames.migrationElementModels}.DateTimeElement`) + .with('rich_text', () => `${migrationConfig.typeNames.migrationElementModels}.RichTextElement`) + .with('number', () => `${migrationConfig.typeNames.migrationElementModels}.NumberElement`) + .with('multiple_choice', () => `${migrationConfig.typeNames.migrationElementModels}.MultipleChoiceElement`) + .with('subpages', () => `${migrationConfig.typeNames.migrationElementModels}.SubpagesElement`) + .with('taxonomy', () => `${migrationConfig.typeNames.migrationElementModels}.TaxonomyElement`) + .with('url_slug', () => `${migrationConfig.typeNames.migrationElementModels}.UrlSlugElement`) + .with('modular_content', () => `${migrationConfig.typeNames.migrationElementModels}.LinkedItemsElement`) .otherwise((type) => { throw Error(`Element type '${type}' is not supported.`); }); } function getItemType(): string { - return `export type ${migrationTypeNames.item}< - ${migrationTypeNames.codename} extends ${migrationTypeNames.contentTypeCodenames}, - TElements extends ${migrationTypeNames.migrationElements} = ${migrationTypeNames.migrationElements}, - > = ${migrationTypeNames.migrationItem}, ${migrationTypeNames.workflowStepCodenames}>;`; + return `export type ${migrationConfig.typeNames.item}< + ${migrationConfig.typeNames.codename} extends ${migrationConfig.typeNames.contentTypeCodenames}, + TElements extends ${migrationConfig.typeNames.migrationElements} = ${migrationConfig.typeNames.migrationElements}, + > = ${migrationConfig.typeNames.migrationItem}, ${migrationConfig.typeNames.workflowStepCodenames}>;`; } function getSystemType(): string { - return `export type ${migrationTypeNames.system}<${migrationTypeNames.codename} extends ${migrationTypeNames.contentTypeCodenames}> = ${migrationTypeNames.migrationItemSystem}< - ${migrationTypeNames.codename}, - ${migrationTypeNames.languageCodenames}, - ${migrationTypeNames.collectionCodenames}, - ${migrationTypeNames.workflowCodenames} + return `export type ${migrationConfig.typeNames.system}<${migrationConfig.typeNames.codename} extends ${migrationConfig.typeNames.contentTypeCodenames}> = ${migrationConfig.typeNames.migrationItemSystem}< + ${migrationConfig.typeNames.codename}, + ${migrationConfig.typeNames.languageCodenames}, + ${migrationConfig.typeNames.collectionCodenames}, + ${migrationConfig.typeNames.workflowCodenames} >;`; } function getLanguageCodenamesType(languages: readonly Readonly[]): string { - return `export type ${migrationTypeNames.languageCodenames} = ${languages.map((language) => `'${language.codename}'`).join(' | ')};`; + return `export type ${migrationConfig.typeNames.languageCodenames} = ${languages.map((language) => `'${language.codename}'`).join(' | ')};`; } function getContentTypeCodenamesType(types: readonly Readonly[]): string { - return `export type ${migrationTypeNames.contentTypeCodenames} = ${types.map((type) => `'${type.codename}'`).join(' | ')};`; + return `export type ${migrationConfig.typeNames.contentTypeCodenames} = ${types.map((type) => `'${type.codename}'`).join(' | ')};`; } function getWorkflowCodenamesType(workflows: readonly Readonly[]): string { - return `export type ${migrationTypeNames.workflowCodenames} = ${workflows.map((workflow) => `'${workflow.codename}'`).join(' | ')};`; + return `export type ${migrationConfig.typeNames.workflowCodenames} = ${workflows.map((workflow) => `'${workflow.codename}'`).join(' | ')};`; } function getCollectionCodenamesType(collections: readonly Readonly[]): string { - return `export type ${migrationTypeNames.collectionCodenames} = ${collections.map((collection) => `'${collection.codename}'`).join(' | ')};`; + return `export type ${migrationConfig.typeNames.collectionCodenames} = ${collections.map((collection) => `'${collection.codename}'`).join(' | ')};`; } function getWorkflowStepCodenamesType(workflows: readonly Readonly[]): string { - return `export type ${migrationTypeNames.workflowStepCodenames} = ${workflows - .flatMap((workflow) => [ - ...workflow.steps, - workflow.publishedStep, - workflow.archivedStep, - workflow.scheduledStep - ]) + return `export type ${migrationConfig.typeNames.workflowStepCodenames} = ${workflows + .flatMap((workflow) => [...workflow.steps, workflow.publishedStep, workflow.archivedStep, workflow.scheduledStep]) .map((workflowStep) => `'${workflowStep.codename}'`) .filter(uniqueFilter) .join(' | ')};`; diff --git a/lib/generators/project/project-func.ts b/lib/generators/project/project-func.ts index e5719a5..d49ffa8 100644 --- a/lib/generators/project/project-func.ts +++ b/lib/generators/project/project-func.ts @@ -3,13 +3,7 @@ import { projectGenerator as _projectGenerator } from './project.generator.js'; import { fileManager as _fileManager } from '../../files/index.js'; import { parse } from 'path'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; -import { - coreConfig, - GeneratedFile, - getBarrelExportCode, - getDefaultModuleResolution, - ModuleResolution -} from '../../core/index.js'; +import { coreConfig, GeneratedFile, getBarrelExportCode, getDefaultModuleResolution, ModuleResolution } from '../../core/index.js'; import { Options } from 'prettier'; import { EnvironmentModels } from '@kontent-ai/management-sdk'; @@ -60,8 +54,6 @@ async function getModelsAsync(config: GenerateProjectModelsConfig): Promise<{ return { environmentInfo, projectFiles: _projectGenerator({ - addTimestamp: config.addTimestamp, - formatOptions: config.formatOptions, environmentData: { environmentInfo: environmentInfo, languages: await kontentFetcher.getLanguagesAsync(), diff --git a/lib/generators/project/project.generator.ts b/lib/generators/project/project.generator.ts index 62505d0..b85eb0c 100644 --- a/lib/generators/project/project.generator.ts +++ b/lib/generators/project/project.generator.ts @@ -1,4 +1,3 @@ -import { Options } from 'prettier'; import { match } from 'ts-pattern'; import { AssetFolderModels, @@ -17,11 +16,11 @@ import { FlattenedElement, GeneratedFile, getFlattenedElements, - removeLineEndings, sortAlphabetically, toSafeString, toCamelCase, - getStringOrUndefined + getStringOrUndefined, + toGuidelinesComment } from '../../core/index.js'; interface ProjectCodeResult { @@ -36,9 +35,6 @@ interface WorkflowStep { } export interface ProjectGeneratorConfig { - readonly addTimestamp: boolean; - readonly formatOptions?: Options; - readonly environmentData: { readonly environmentInfo: Readonly; readonly types: readonly Readonly[]; @@ -64,7 +60,7 @@ export function projectGenerator(config: ProjectGeneratorConfig) { }; const getProjectModelCode = (): readonly ProjectCodeResult[] => { - const result: ProjectCodeResult[] = [ + return [ { code: `export const languages = { ${getProjectLanguages(config.environmentData.languages)} @@ -118,8 +114,6 @@ export function projectGenerator(config: ProjectGeneratorConfig) { filename: 'webhooks.ts' } ]; - - return result; }; const getProjectLanguages = (languages: readonly Readonly[]): string => { @@ -178,9 +172,7 @@ export function projectGenerator(config: ProjectGeneratorConfig) { ); }; - const getProjectContentTypeSnippets = ( - snippets: readonly Readonly[] - ): string => { + const getProjectContentTypeSnippets = (snippets: readonly Readonly[]): string => { return snippets.reduce((code, snippet, index) => { const isLast = index === snippets.length - 1; @@ -216,9 +208,7 @@ export function projectGenerator(config: ProjectGeneratorConfig) { }, ''); }; - const getContentTypeElements = ( - elements: readonly Readonly[] - ): string => { + const getContentTypeElements = (elements: readonly Readonly[]): string => { const flattenedElements = getFlattenedElements( elements, config.environmentData.snippets, @@ -232,7 +222,7 @@ export function projectGenerator(config: ProjectGeneratorConfig) { return `${code}\n /** - * ${toSafeString(element.title)} (${element.type})${element.guidelines ? `\n* Guidelines: ${removeLineEndings(element.guidelines)}` : ''} + * ${toSafeString(element.title)} (${element.type})${element.guidelines ? `\n* Guidelines: ${toGuidelinesComment(element.guidelines)}` : ''} */ ${toCamelCase(element.codename)}: { codename: '${element.codename}', @@ -253,7 +243,6 @@ export function projectGenerator(config: ProjectGeneratorConfig) { return ( element.options.reduce((code, option, index) => { const isLast = index === element.options.length - 1; - return `${code}\n /** * ${toSafeString(option.name)} @@ -359,14 +348,9 @@ export function projectGenerator(config: ProjectGeneratorConfig) { }; const getProjectWorkflowSteps = (workflow: Readonly): string => { - const steps: WorkflowStep[] = [ - workflow.archivedStep, - workflow.publishedStep, - workflow.scheduledStep, - ...workflow.steps - ]; + const steps: readonly WorkflowStep[] = [workflow.archivedStep, workflow.publishedStep, workflow.scheduledStep, ...workflow.steps]; - const code = `{${steps.reduce((code, step) => { + return `{${steps.reduce((code, step) => { return ( code + ` @@ -377,8 +361,6 @@ export function projectGenerator(config: ProjectGeneratorConfig) { },` ); }, ``)}}`; - - return code; }; return { diff --git a/lib/index.ts b/lib/index.ts index 91a18ed..eddfbdf 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,5 +1,6 @@ export * from './core/index.js'; export * from './files/index.js'; export * from './format/index.js'; +export * from './fetch/index.js'; export * from './comments/index.js'; export * from './generators/index.js'; diff --git a/lib/node/cli/actions/delivery-action.ts b/lib/node/cli/actions/delivery-action.ts index 2b96f08..fd5fc5a 100644 --- a/lib/node/cli/actions/delivery-action.ts +++ b/lib/node/cli/actions/delivery-action.ts @@ -9,8 +9,6 @@ export async function deliveryActionAsync(cliFetcher: CliArgumentsFetcher): Prom apiKey: cliFetcher.getRequiredArgumentValue('apiKey'), outputDir: cliFetcher.getRequiredArgumentValue('outputDir'), addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), - addEnvironmentInfo: cliFetcher.getBooleanArgumentValue('addEnvironmentInfo', false), - moduleResolution: - cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' + moduleResolution: cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' }); } diff --git a/lib/node/cli/commands.ts b/lib/node/cli/commands.ts index aac8969..3163927 100644 --- a/lib/node/cli/commands.ts +++ b/lib/node/cli/commands.ts @@ -3,8 +3,7 @@ import { argumentsSetter } from './args/args-setter.js'; export const cliArgs = argumentsSetter() .withCommand({ name: 'delivery', - description: - 'Generates Delivery & project models based on the content types and content items in your Kontent.ai project', + description: 'Generates Delivery & project models based on the content types and content items in your Kontent.ai project', examples: [`kontent-generate delivery --environmentId=x --apiKey=x`], options: [ { @@ -31,12 +30,6 @@ export const cliArgs = argumentsSetter() type: 'string', isRequired: false }, - { - name: `addEnvironmentInfo`, - description: `Indicates if environment info stamp should be generated`, - type: 'string', - isRequired: false - }, { name: `moduleResolution`, description: `Module resolution for imports. Available options are: node, nodeNext`, diff --git a/sample/delivery/content-type-snippets/index.ts b/sample/delivery/content-type-snippets/index.ts index 0ae38c6..f13c990 100644 --- a/sample/delivery/content-type-snippets/index.ts +++ b/sample/delivery/content-type-snippets/index.ts @@ -1,15 +1,16 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ export {}; diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index f0f3032..b9122cf 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; @@ -29,7 +30,6 @@ export type Actor = IContentItem<{ * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 */ url: Elements.UrlSlugElement; - /** * First name (text) * @@ -39,7 +39,6 @@ export type Actor = IContentItem<{ * Guidelines: This is the first name of the actor */ firstName: Elements.TextElement; - /** * Last name (text) * @@ -48,7 +47,6 @@ export type Actor = IContentItem<{ * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 */ lastName: Elements.TextElement; - /** * Photo (asset) * diff --git a/sample/delivery/content-types/index.ts b/sample/delivery/content-types/index.ts index f9d1d76..3116ea2 100644 --- a/sample/delivery/content-types/index.ts +++ b/sample/delivery/content-types/index.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ export * from './actor.js'; export * from './movie.js'; diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 2c5817d..0c39afa 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; import type { Actor } from '../content-types/actor.js'; @@ -31,7 +32,6 @@ export type Movie = IContentItem<{ * Id: 3473187e-dc78-eff2-7099-f690f7042d4a */ title: Elements.TextElement; - /** * Plot (rich_text) * @@ -40,7 +40,6 @@ export type Movie = IContentItem<{ * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce */ plot: Elements.RichTextElement; - /** * Released (date_time) * @@ -49,7 +48,6 @@ export type Movie = IContentItem<{ * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 */ released: Elements.DateTimeElement; - /** * Length (number) * @@ -58,7 +56,6 @@ export type Movie = IContentItem<{ * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c */ length: Elements.NumberElement; - /** * Poster (asset) * @@ -67,7 +64,6 @@ export type Movie = IContentItem<{ * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d */ poster: Elements.AssetsElement; - /** * Category (multiple_choice) * @@ -76,7 +72,6 @@ export type Movie = IContentItem<{ * Id: 9821c252-6414-f549-c17f-cc171dd87713 */ category: Elements.MultipleChoiceElement; - /** * Stars (modular_content) * @@ -85,7 +80,6 @@ export type Movie = IContentItem<{ * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 */ stars: Elements.LinkedItemsElement; - /** * SeoName (url_slug) * @@ -94,7 +88,6 @@ export type Movie = IContentItem<{ * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c */ seoname: Elements.UrlSlugElement; - /** * ReleaseCategory (taxonomy) * diff --git a/sample/delivery/index.ts b/sample/delivery/index.ts index f4323f9..bb6a87e 100644 --- a/sample/delivery/index.ts +++ b/sample/delivery/index.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ export * from './content-types/index.js'; export * from './content-type-snippets/index.js'; diff --git a/sample/delivery/taxonomies/index.ts b/sample/delivery/taxonomies/index.ts index 90da1b5..4948198 100644 --- a/sample/delivery/taxonomies/index.ts +++ b/sample/delivery/taxonomies/index.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ export * from './movietype.js'; export * from './releasecategory.js'; diff --git a/sample/delivery/taxonomies/movietype.ts b/sample/delivery/taxonomies/movietype.ts index 519b904..58aa2f7 100644 --- a/sample/delivery/taxonomies/movietype.ts +++ b/sample/delivery/taxonomies/movietype.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ /** * MovieType diff --git a/sample/delivery/taxonomies/releasecategory.ts b/sample/delivery/taxonomies/releasecategory.ts index 62d9662..72d8a43 100644 --- a/sample/delivery/taxonomies/releasecategory.ts +++ b/sample/delivery/taxonomies/releasecategory.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ /** * ReleaseCategory diff --git a/sample/migration/content-types/actor.ts b/sample/migration/content-types/actor.ts index 624dce9..783e6a1 100644 --- a/sample/migration/content-types/actor.ts +++ b/sample/migration/content-types/actor.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; import type { Item } from '../core.models.js'; diff --git a/sample/migration/content-types/index.ts b/sample/migration/content-types/index.ts index f9d1d76..3116ea2 100644 --- a/sample/migration/content-types/index.ts +++ b/sample/migration/content-types/index.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ export * from './actor.js'; export * from './movie.js'; diff --git a/sample/migration/content-types/movie.ts b/sample/migration/content-types/movie.ts index 91a45db..b1ee7e2 100644 --- a/sample/migration/content-types/movie.ts +++ b/sample/migration/content-types/movie.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; import type { Item } from '../core.models.js'; diff --git a/sample/migration/core.models.ts b/sample/migration/core.models.ts index 52f9b23..cffe50d 100644 --- a/sample/migration/core.models.ts +++ b/sample/migration/core.models.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ import type { MigrationItemSystem, MigrationItem, MigrationElements } from '@kontent-ai/migration-toolkit'; diff --git a/sample/migration/index.ts b/sample/migration/index.ts index 4d4b0a5..e81b559 100644 --- a/sample/migration/index.ts +++ b/sample/migration/index.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ export * from './content-types/index.js'; export * from './core.models.js'; diff --git a/sample/project/assetFolders.ts b/sample/project/assetFolders.ts index b87987d..22db46c 100644 --- a/sample/project/assetFolders.ts +++ b/sample/project/assetFolders.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ export const assetFolders = { /** diff --git a/sample/project/collections.ts b/sample/project/collections.ts index 0a6f9be..7e50501 100644 --- a/sample/project/collections.ts +++ b/sample/project/collections.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ export const collections = { /** diff --git a/sample/project/contentTypeSnippets.ts b/sample/project/contentTypeSnippets.ts index 83010a7..34f7746 100644 --- a/sample/project/contentTypeSnippets.ts +++ b/sample/project/contentTypeSnippets.ts @@ -1,15 +1,16 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ export const contentTypeSnippets = {} as const; diff --git a/sample/project/contentTypes.ts b/sample/project/contentTypes.ts index e91911d..1954cb9 100644 --- a/sample/project/contentTypes.ts +++ b/sample/project/contentTypes.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ export const contentTypes = { /** diff --git a/sample/project/index.ts b/sample/project/index.ts index 9c54cb9..5122dd6 100644 --- a/sample/project/index.ts +++ b/sample/project/index.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ export * from './languages.js'; export * from './collections.js'; diff --git a/sample/project/languages.ts b/sample/project/languages.ts index 2f8a176..90b3dc4 100644 --- a/sample/project/languages.ts +++ b/sample/project/languages.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ export const languages = { /** diff --git a/sample/project/roles.ts b/sample/project/roles.ts index c8a386d..1fc72b8 100644 --- a/sample/project/roles.ts +++ b/sample/project/roles.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ export const roles = { /** diff --git a/sample/project/taxonomies.ts b/sample/project/taxonomies.ts index 2a0ee98..585c912 100644 --- a/sample/project/taxonomies.ts +++ b/sample/project/taxonomies.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ export const taxonomies = { /** diff --git a/sample/project/webhooks.ts b/sample/project/webhooks.ts index 47dccbe..7d33dc3 100644 --- a/sample/project/webhooks.ts +++ b/sample/project/webhooks.ts @@ -1,15 +1,16 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ export const webhooks = {} as const; diff --git a/sample/project/workflows.ts b/sample/project/workflows.ts index 1a53bdb..11abd1d 100644 --- a/sample/project/workflows.ts +++ b/sample/project/workflows.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ export const workflows = { /** diff --git a/scripts/file-version-script.ts b/scripts/file-version-script.ts index db66247..d0bf13d 100644 --- a/scripts/file-version-script.ts +++ b/scripts/file-version-script.ts @@ -8,12 +8,10 @@ export const createVersionFile = (date: Date, versionPath: string, propertyName: }; function createFile(date: Date, filePath: string, propName: string) { - const timestamp = date.toUTCString(); - const src = ` export const ${propName} = { name: '${PackageJson.name}', - timestamp: '${timestamp}', + timestamp: date.toUTCString(), version: '${PackageJson.version}' }; `; diff --git a/scripts/tests/delivery-models.ts b/scripts/tests/delivery-models.ts index 254d4b4..ede19f6 100644 --- a/scripts/tests/delivery-models.ts +++ b/scripts/tests/delivery-models.ts @@ -30,7 +30,6 @@ const run = async () => { environmentId: environmentId, apiKey: apiKey, moduleResolution: moduleResolution?.toLowerCase() === 'node' ? 'node' : 'nodeNext', - addEnvironmentInfo: true, outputDir: outputDir }); }; From 14edc88190fdfa681e97a3e9db05333d8f864491 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 2 Sep 2024 12:41:41 +0200 Subject: [PATCH 044/183] Separates migration - environment types into own file / folder --- lib/core/core.config.ts | 22 +++-- lib/generators/migration/migration-func.ts | 43 +++++++-- .../migration/migration.generator.ts | 92 +++++++++++-------- sample/migration/content-types/actor.ts | 2 +- sample/migration/content-types/movie.ts | 2 +- .../environment.ts} | 20 ---- sample/migration/environment/index.ts | 16 ++++ sample/migration/index.ts | 3 +- sample/migration/migration.ts | 41 +++++++++ 9 files changed, 163 insertions(+), 78 deletions(-) rename sample/migration/{core.models.ts => environment/environment.ts} (60%) create mode 100644 sample/migration/environment/index.ts create mode 100644 sample/migration/migration.ts diff --git a/lib/core/core.config.ts b/lib/core/core.config.ts index 8f59643..6464862 100644 --- a/lib/core/core.config.ts +++ b/lib/core/core.config.ts @@ -5,21 +5,27 @@ export const coreConfig = { export const migrationConfig = { npmPackageName: '@kontent-ai/migration-toolkit', migrationItemsFolderName: `content-types`, - migrationTypesFilename: `core.models.ts`, + environmentFolderName: `environment`, + migrationTypesFilename: `migration`, + environmentFilename: `environment`, - typeNames: { + sdkTypeNames: { + system: 'MigrationItemSystem', + item: 'MigrationItem', + elements: 'MigrationElements', + elementModels: 'MigrationElementModels' + }, + + localTypeNames: { languageCodenames: 'LanguageCodenames', collectionCodenames: 'CollectionCodenames', workflowCodenames: 'WorkflowCodenames', workflowStepCodenames: 'WorkflowStepCodenames', contentTypeCodenames: 'ContentTypeCodenames', - migrationItemSystem: 'MigrationItemSystem', - migrationElementModels: 'MigrationElementModels', - migrationItem: 'MigrationItem', - migrationElements: 'MigrationElements', - system: 'System', + system: 'ItemSystem', item: 'Item', - codename: 'Codename' + codename: 'TCodename', + elements: 'TElements' } } as const; diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index cc59b25..f7cf6b4 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -29,11 +29,18 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('migration')}' models\n`); - const { migrationItemFiles, migrationTypeFile, moduleResolution, environmentInfo } = await getFilesAsync(config); + const { + migrationItemFiles, + migrationTypeFiles: migrationTypeFiles, + moduleResolution, + environmentInfo, + environmentFiles + } = await getFilesAsync(config); await createFilesAsync({ migrationItemFiles, - migrationTypeFile, + environmentFiles, + migrationTypeFiles, moduleResolution, outputDir: config.outputDir, formatOptions: config.formatOptions, @@ -45,8 +52,9 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode } async function getFilesAsync(config: GenerateMigrationModelsConfig): Promise<{ - readonly migrationTypeFile: GeneratedFile; + readonly migrationTypeFiles: readonly GeneratedFile[]; readonly migrationItemFiles: readonly GeneratedFile[]; + readonly environmentFiles: readonly GeneratedFile[]; readonly moduleResolution: ModuleResolution; readonly environmentInfo: Readonly; }> { @@ -74,14 +82,16 @@ async function getFilesAsync(config: GenerateMigrationModelsConfig): Promise<{ return { moduleResolution, - migrationTypeFile: migrationGenerator.getMigrationTypesFile(), + migrationTypeFiles: migrationGenerator.getMigrationTypeFiles(), migrationItemFiles: migrationGenerator.getMigrationItemFiles(), + environmentFiles: migrationGenerator.getEnvironmentFiles(), environmentInfo }; } async function createFilesAsync(data: { - readonly migrationTypeFile: GeneratedFile; + readonly migrationTypeFiles: readonly GeneratedFile[]; + readonly environmentFiles: readonly GeneratedFile[]; readonly migrationItemFiles: readonly GeneratedFile[]; readonly moduleResolution: ModuleResolution; readonly outputDir: string; @@ -97,9 +107,10 @@ async function createFilesAsync(data: { }); await fileManager.createFilesAsync([ - data.migrationTypeFile, + ...data.migrationTypeFiles, + ...data.environmentFiles, ...data.migrationItemFiles, - // types barrel file + // items barrel file { filename: `${migrationConfig.migrationItemsFolderName}/${coreConfig.barrelExportFilename}`, text: getBarrelExportCode({ @@ -111,12 +122,28 @@ async function createFilesAsync(data: { ] }) }, + // environment barrel file + { + filename: `${migrationConfig.environmentFolderName}/${coreConfig.barrelExportFilename}`, + text: getBarrelExportCode({ + moduleResolution: data.moduleResolution, + filenames: [ + ...data.environmentFiles.map((m) => { + return `./${parse(m.filename).name}`; + }) + ] + }) + }, // main barrel file { filename: coreConfig.barrelExportFilename, text: getBarrelExportCode({ moduleResolution: data.moduleResolution, - filenames: [`./${migrationConfig.migrationItemsFolderName}/index`, `./${data.migrationTypeFile.filename}`] + filenames: [ + `./${migrationConfig.migrationItemsFolderName}/index`, + `./${migrationConfig.environmentFolderName}/index`, + ...data.migrationTypeFiles.map((file) => `./${file.filename}`) + ] }) } ]); diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index 15287a1..bc65308 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -46,11 +46,11 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { text: ` ${importer.importType({ filePathOrPackage: migrationConfig.npmPackageName, - importValue: migrationConfig.typeNames.migrationElementModels + importValue: migrationConfig.sdkTypeNames.elementModels })} ${importer.importType({ - filePathOrPackage: `../${migrationConfig.migrationTypesFilename}`, - importValue: migrationConfig.typeNames.item + filePathOrPackage: `../${migrationConfig.migrationTypesFilename}.ts`, + importValue: migrationConfig.localTypeNames.item })} /** @@ -59,7 +59,7 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { * Codename: ${type.codename} * Id: ${type.id} */ - export type ${toPascalCase(type.name)}Item = ${migrationConfig.typeNames.item}< + export type ${toPascalCase(type.name)}Item = ${migrationConfig.localTypeNames.item}< '${type.codename}', { ${getFlattenedElements( @@ -86,15 +86,11 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { }; return { - getMigrationTypesFile(): GeneratedFile { - return { - filename: migrationConfig.migrationTypesFilename, - text: ` - ${importer.importType({ - filePathOrPackage: migrationConfig.npmPackageName, - importValue: `${migrationConfig.typeNames.migrationItemSystem}, ${migrationConfig.typeNames.migrationItem}, ${migrationConfig.typeNames.migrationElements}` - })} - + getEnvironmentFiles(): readonly GeneratedFile[] { + return [ + { + filename: `${migrationConfig.environmentFolderName}/${migrationConfig.environmentFilename}.ts`, + text: ` ${commentsManager.wrapComment('Type representing all languages')} ${getLanguageCodenamesType(config.environmentData.languages)} @@ -109,6 +105,23 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { ${commentsManager.wrapComment('Type representing all worksflow steps across all workflows')} ${getWorkflowStepCodenamesType(config.environmentData.workflows)} + ` + } + ]; + }, + getMigrationTypeFiles(): readonly GeneratedFile[] { + return [ + { + filename: `${migrationConfig.migrationTypesFilename}.ts`, + text: ` + ${importer.importType({ + filePathOrPackage: migrationConfig.npmPackageName, + importValue: `${migrationConfig.sdkTypeNames.item}, ${migrationConfig.sdkTypeNames.system}, ${migrationConfig.sdkTypeNames.elements}` + })} + ${importer.importType({ + filePathOrPackage: `./${migrationConfig.environmentFolderName}/${migrationConfig.environmentFilename}.ts`, + importValue: `${migrationConfig.localTypeNames.collectionCodenames}, ${migrationConfig.localTypeNames.contentTypeCodenames}, ${migrationConfig.localTypeNames.languageCodenames}, ${migrationConfig.localTypeNames.workflowCodenames}, ${migrationConfig.localTypeNames.workflowStepCodenames}` + })} ${commentsManager.wrapComment('System object shared by all individual content type models')} ${getSystemType()} @@ -116,7 +129,8 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { ${commentsManager.wrapComment('Item object shared by all individual content type models')} ${getItemType()} ` - }; + } + ]; }, getMigrationItemFiles(): readonly GeneratedFile[] { return config.environmentData.types.map((type) => getMigrationItemType(type)); @@ -127,56 +141,56 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { function getElementPropType(element: Readonly): string { return match(element.type) .returnType() - .with('text', () => `${migrationConfig.typeNames.migrationElementModels}.TextElement`) - .with('asset', () => `${migrationConfig.typeNames.migrationElementModels}.AssetElement`) - .with('custom', () => `${migrationConfig.typeNames.migrationElementModels}.CustomElement`) - .with('date_time', () => `${migrationConfig.typeNames.migrationElementModels}.DateTimeElement`) - .with('rich_text', () => `${migrationConfig.typeNames.migrationElementModels}.RichTextElement`) - .with('number', () => `${migrationConfig.typeNames.migrationElementModels}.NumberElement`) - .with('multiple_choice', () => `${migrationConfig.typeNames.migrationElementModels}.MultipleChoiceElement`) - .with('subpages', () => `${migrationConfig.typeNames.migrationElementModels}.SubpagesElement`) - .with('taxonomy', () => `${migrationConfig.typeNames.migrationElementModels}.TaxonomyElement`) - .with('url_slug', () => `${migrationConfig.typeNames.migrationElementModels}.UrlSlugElement`) - .with('modular_content', () => `${migrationConfig.typeNames.migrationElementModels}.LinkedItemsElement`) + .with('text', () => `${migrationConfig.sdkTypeNames.elementModels}.TextElement`) + .with('asset', () => `${migrationConfig.sdkTypeNames.elementModels}.AssetElement`) + .with('custom', () => `${migrationConfig.sdkTypeNames.elementModels}.CustomElement`) + .with('date_time', () => `${migrationConfig.sdkTypeNames.elementModels}.DateTimeElement`) + .with('rich_text', () => `${migrationConfig.sdkTypeNames.elementModels}.RichTextElement`) + .with('number', () => `${migrationConfig.sdkTypeNames.elementModels}.NumberElement`) + .with('multiple_choice', () => `${migrationConfig.sdkTypeNames.elementModels}.MultipleChoiceElement`) + .with('subpages', () => `${migrationConfig.sdkTypeNames.elementModels}.SubpagesElement`) + .with('taxonomy', () => `${migrationConfig.sdkTypeNames.elementModels}.TaxonomyElement`) + .with('url_slug', () => `${migrationConfig.sdkTypeNames.elementModels}.UrlSlugElement`) + .with('modular_content', () => `${migrationConfig.sdkTypeNames.elementModels}.LinkedItemsElement`) .otherwise((type) => { throw Error(`Element type '${type}' is not supported.`); }); } function getItemType(): string { - return `export type ${migrationConfig.typeNames.item}< - ${migrationConfig.typeNames.codename} extends ${migrationConfig.typeNames.contentTypeCodenames}, - TElements extends ${migrationConfig.typeNames.migrationElements} = ${migrationConfig.typeNames.migrationElements}, - > = ${migrationConfig.typeNames.migrationItem}, ${migrationConfig.typeNames.workflowStepCodenames}>;`; + return `export type ${migrationConfig.localTypeNames.item}< + ${migrationConfig.localTypeNames.codename} extends ${migrationConfig.localTypeNames.contentTypeCodenames}, + ${migrationConfig.localTypeNames.elements} extends ${migrationConfig.sdkTypeNames.elements} = ${migrationConfig.sdkTypeNames.elements}, + > = ${migrationConfig.sdkTypeNames.item}<${migrationConfig.localTypeNames.elements}, ${migrationConfig.localTypeNames.system}<${migrationConfig.localTypeNames.codename}>, ${migrationConfig.localTypeNames.workflowStepCodenames}>;`; } function getSystemType(): string { - return `export type ${migrationConfig.typeNames.system}<${migrationConfig.typeNames.codename} extends ${migrationConfig.typeNames.contentTypeCodenames}> = ${migrationConfig.typeNames.migrationItemSystem}< - ${migrationConfig.typeNames.codename}, - ${migrationConfig.typeNames.languageCodenames}, - ${migrationConfig.typeNames.collectionCodenames}, - ${migrationConfig.typeNames.workflowCodenames} + return `export type ${migrationConfig.localTypeNames.system}<${migrationConfig.localTypeNames.codename} extends ${migrationConfig.localTypeNames.contentTypeCodenames}> = ${migrationConfig.sdkTypeNames.system}< + ${migrationConfig.localTypeNames.codename}, + ${migrationConfig.localTypeNames.languageCodenames}, + ${migrationConfig.localTypeNames.collectionCodenames}, + ${migrationConfig.localTypeNames.workflowCodenames} >;`; } function getLanguageCodenamesType(languages: readonly Readonly[]): string { - return `export type ${migrationConfig.typeNames.languageCodenames} = ${languages.map((language) => `'${language.codename}'`).join(' | ')};`; + return `export type ${migrationConfig.localTypeNames.languageCodenames} = ${languages.map((language) => `'${language.codename}'`).join(' | ')};`; } function getContentTypeCodenamesType(types: readonly Readonly[]): string { - return `export type ${migrationConfig.typeNames.contentTypeCodenames} = ${types.map((type) => `'${type.codename}'`).join(' | ')};`; + return `export type ${migrationConfig.localTypeNames.contentTypeCodenames} = ${types.map((type) => `'${type.codename}'`).join(' | ')};`; } function getWorkflowCodenamesType(workflows: readonly Readonly[]): string { - return `export type ${migrationConfig.typeNames.workflowCodenames} = ${workflows.map((workflow) => `'${workflow.codename}'`).join(' | ')};`; + return `export type ${migrationConfig.localTypeNames.workflowCodenames} = ${workflows.map((workflow) => `'${workflow.codename}'`).join(' | ')};`; } function getCollectionCodenamesType(collections: readonly Readonly[]): string { - return `export type ${migrationConfig.typeNames.collectionCodenames} = ${collections.map((collection) => `'${collection.codename}'`).join(' | ')};`; + return `export type ${migrationConfig.localTypeNames.collectionCodenames} = ${collections.map((collection) => `'${collection.codename}'`).join(' | ')};`; } function getWorkflowStepCodenamesType(workflows: readonly Readonly[]): string { - return `export type ${migrationConfig.typeNames.workflowStepCodenames} = ${workflows + return `export type ${migrationConfig.localTypeNames.workflowStepCodenames} = ${workflows .flatMap((workflow) => [...workflow.steps, workflow.publishedStep, workflow.archivedStep, workflow.scheduledStep]) .map((workflowStep) => `'${workflowStep.codename}'`) .filter(uniqueFilter) diff --git a/sample/migration/content-types/actor.ts b/sample/migration/content-types/actor.ts index 783e6a1..299c4f5 100644 --- a/sample/migration/content-types/actor.ts +++ b/sample/migration/content-types/actor.ts @@ -14,7 +14,7 @@ **/ import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; -import type { Item } from '../core.models.js'; +import type { Item } from '../migration.js'; /** * Actor diff --git a/sample/migration/content-types/movie.ts b/sample/migration/content-types/movie.ts index b1ee7e2..f345d38 100644 --- a/sample/migration/content-types/movie.ts +++ b/sample/migration/content-types/movie.ts @@ -14,7 +14,7 @@ **/ import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; -import type { Item } from '../core.models.js'; +import type { Item } from '../migration.js'; /** * Movie diff --git a/sample/migration/core.models.ts b/sample/migration/environment/environment.ts similarity index 60% rename from sample/migration/core.models.ts rename to sample/migration/environment/environment.ts index cffe50d..1675709 100644 --- a/sample/migration/core.models.ts +++ b/sample/migration/environment/environment.ts @@ -13,8 +13,6 @@ * ------------------------------------------------------------------------------- **/ -import type { MigrationItemSystem, MigrationItem, MigrationElements } from '@kontent-ai/migration-toolkit'; - /** * Type representing all languages */ @@ -39,21 +37,3 @@ export type WorkflowCodenames = 'default'; * Type representing all worksflow steps across all workflows */ export type WorkflowStepCodenames = 'draft' | 'review' | 'ready_to_publish' | 'published' | 'archived' | 'scheduled'; - -/** - * System object shared by all individual content type models - */ -export type System = MigrationItemSystem< - Codename, - LanguageCodenames, - CollectionCodenames, - WorkflowCodenames ->; - -/** - * Item object shared by all individual content type models - */ -export type Item< - Codename extends ContentTypeCodenames, - TElements extends MigrationElements = MigrationElements -> = MigrationItem, WorkflowStepCodenames>; diff --git a/sample/migration/environment/index.ts b/sample/migration/environment/index.ts new file mode 100644 index 0000000..2bfdee9 --- /dev/null +++ b/sample/migration/environment/index.ts @@ -0,0 +1,16 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +export * from './environment.js'; diff --git a/sample/migration/index.ts b/sample/migration/index.ts index e81b559..aedabaf 100644 --- a/sample/migration/index.ts +++ b/sample/migration/index.ts @@ -14,4 +14,5 @@ **/ export * from './content-types/index.js'; -export * from './core.models.js'; +export * from './environment/index.js'; +export * from './migration.js'; diff --git a/sample/migration/migration.ts b/sample/migration/migration.ts new file mode 100644 index 0000000..b9c4c9a --- /dev/null +++ b/sample/migration/migration.ts @@ -0,0 +1,41 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +import type { MigrationItem, MigrationItemSystem, MigrationElements } from '@kontent-ai/migration-toolkit'; +import type { + CollectionCodenames, + ContentTypeCodenames, + LanguageCodenames, + WorkflowCodenames, + WorkflowStepCodenames +} from './environment/environment.js'; + +/** + * System object shared by all individual content type models + */ +export type ItemSystem = MigrationItemSystem< + TCodename, + LanguageCodenames, + CollectionCodenames, + WorkflowCodenames +>; + +/** + * Item object shared by all individual content type models + */ +export type Item< + TCodename extends ContentTypeCodenames, + TElements extends MigrationElements = MigrationElements +> = MigrationItem, WorkflowStepCodenames>; From c6ee50ce518fbf26ad0c950b6b514bd4e09ae79d Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 2 Sep 2024 12:46:22 +0200 Subject: [PATCH 045/183] Extends delivery config --- lib/core/core.config.ts | 7 ++++++- .../delivery/delivery-content-type.generator.ts | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/core/core.config.ts b/lib/core/core.config.ts index 6464862..9dcfcf5 100644 --- a/lib/core/core.config.ts +++ b/lib/core/core.config.ts @@ -33,5 +33,10 @@ export const deliveryConfig = { npmPackageName: '@kontent-ai/delivery-sdk', contentTypesFolderName: `content-types`, contentTypeSnippetsFolderName: `content-type-snippets`, - taxonomiesFolderName: `taxonomies` + taxonomiesFolderName: `taxonomies`, + + sdkTypes: { + contentItem: 'IContentItem', + elements: 'Elements' + } } as const; diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index f7094ea..faff536 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -167,7 +167,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato }; const getDeliverySdkContentTypeImports = (flattenedElements: readonly FlattenedElement[]): readonly string[] => { - return ['IContentItem', ...(flattenedElements.length ? ['Elements'] : [])]; + return [deliveryConfig.sdkTypes.contentItem, ...(flattenedElements.length ? [deliveryConfig.sdkTypes.elements] : [])]; }; const getModelCode = ( @@ -198,7 +198,7 @@ ${contentTypeImports.imports.join('\n')} * Id: ${typeOrSnippet.id} * Codename: ${typeOrSnippet.codename} */ -export type ${contentTypeImports.typeName} = IContentItem<{ +export type ${contentTypeImports.typeName} = ${deliveryConfig.sdkTypes.contentItem}<{ ${getElementsCode(flattenedElements)} }>${contentTypeImports.contentTypeExtends ? ` ${contentTypeImports.contentTypeExtends}` : ''}; `; @@ -239,7 +239,7 @@ export type ${contentTypeImports.typeName} = IContentItem<{ * Codename: ${element.codename} * Id: ${element.id}${element.guidelines ? `\n* Guidelines: ${toGuidelinesComment(element.guidelines)}` : ''} */ - ${elementName}: Elements.${mappedType};`); + ${elementName}: ${deliveryConfig.sdkTypes.elements}.${mappedType};`); }, '') ); }; @@ -271,7 +271,7 @@ export type ${contentTypeImports.typeName} = IContentItem<{ const getLinkedItemsAllowedTypes = (types: readonly Readonly[]): readonly string[] => { if (!types.length) { - return ['IContentItem']; + return [deliveryConfig.sdkTypes.contentItem]; } return types.map((type) => nameResolvers.contentType(type)); From cfa66d59fa39ef9d366b31a31cf9d7340b74408d Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 2 Sep 2024 12:52:44 +0200 Subject: [PATCH 046/183] Unifies filename extraction --- lib/core/core.utils.ts | 4 ++++ lib/generators/delivery/delivery-func.ts | 13 +++++-------- lib/generators/migration/migration-func.ts | 8 ++++---- lib/generators/project/project-func.ts | 13 +++++++++---- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index bd60f2f..08a304a 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -22,6 +22,10 @@ export function getFileNameWithoutExtension(filePath: string): string { return filePath.substring(0, filePath.lastIndexOf('.')); } +export function getFilenameFromPath(filePath: string): string { + return parse(filePath).name; +} + export function sortAlphabetically(arrayToSort: readonly T[], propertySelector: (item: T) => string): readonly T[] { return arrayToSort.toSorted((a, b) => propertySelector(a).toLowerCase().localeCompare(propertySelector(b).toLowerCase())); } diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index 64b67b0..9541526 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -2,7 +2,6 @@ import chalk from 'chalk'; import { deliveryContentTypeGenerator } from './delivery-content-type.generator.js'; import { deliveryTaxonomyGenerator } from './delivery-taxonomy.generator.js'; import { fileManager as _fileManager } from '../../files/index.js'; -import { parse } from 'path'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; import { ContentTypeFileNameResolver, @@ -17,7 +16,8 @@ import { ModuleResolution, TaxonomyNameResolver, TaxonomyTypeFileNameResolver, - getDefaultModuleResolution + getDefaultModuleResolution, + getFilenameFromPath } from '../../core/index.js'; import { Options } from 'prettier'; import { EnvironmentModels } from '@kontent-ai/management-sdk'; @@ -150,8 +150,7 @@ async function createFilesAsync( moduleResolution: config.moduleResolution, filenames: [ ...data.contentTypeFiles.map((m) => { - const path = parse(m.filename); - return `./${path.name}`; + return `./${getFilenameFromPath(m.filename)}`; }) ] }) @@ -162,8 +161,7 @@ async function createFilesAsync( moduleResolution: config.moduleResolution, filenames: [ ...data.snippetFiles.map((m) => { - const path = parse(m.filename); - return `./${path.name}`; + return `./${getFilenameFromPath(m.filename)}`; }) ] }) @@ -174,8 +172,7 @@ async function createFilesAsync( moduleResolution: config.moduleResolution, filenames: [ ...data.taxonomyFiles.map((m) => { - const path = parse(m.filename); - return `./${path.name}`; + return `./${getFilenameFromPath(m.filename)}`; }) ] }) diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index f7cf6b4..f7dc154 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -5,12 +5,12 @@ import { getBarrelExportCode, ModuleResolution, GeneratedFile, - getDefaultModuleResolution + getDefaultModuleResolution, + getFilenameFromPath } from '../../core/index.js'; import { fileManager as _fileManager } from '../../files/index.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; import { migrationGenerator as _migrationGenerator } from './migration.generator.js'; -import { parse } from 'path'; import { Options } from 'prettier'; import { EnvironmentModels } from '@kontent-ai/management-sdk'; @@ -117,7 +117,7 @@ async function createFilesAsync(data: { moduleResolution: data.moduleResolution, filenames: [ ...data.migrationItemFiles.map((m) => { - return `./${parse(m.filename).name}`; + return `./${getFilenameFromPath(m.filename)}`; }) ] }) @@ -129,7 +129,7 @@ async function createFilesAsync(data: { moduleResolution: data.moduleResolution, filenames: [ ...data.environmentFiles.map((m) => { - return `./${parse(m.filename).name}`; + return `./${getFilenameFromPath(m.filename)}`; }) ] }) diff --git a/lib/generators/project/project-func.ts b/lib/generators/project/project-func.ts index d49ffa8..d767d18 100644 --- a/lib/generators/project/project-func.ts +++ b/lib/generators/project/project-func.ts @@ -1,9 +1,15 @@ import chalk from 'chalk'; import { projectGenerator as _projectGenerator } from './project.generator.js'; import { fileManager as _fileManager } from '../../files/index.js'; -import { parse } from 'path'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; -import { coreConfig, GeneratedFile, getBarrelExportCode, getDefaultModuleResolution, ModuleResolution } from '../../core/index.js'; +import { + coreConfig, + GeneratedFile, + getBarrelExportCode, + getDefaultModuleResolution, + getFilenameFromPath, + ModuleResolution +} from '../../core/index.js'; import { Options } from 'prettier'; import { EnvironmentModels } from '@kontent-ai/management-sdk'; @@ -95,8 +101,7 @@ async function createFilesAsync(data: { moduleResolution: data.moduleResolution, filenames: [ ...data.projectFiles.map((m) => { - const path = parse(m.filename); - return `./${path.name}`; + return `./${getFilenameFromPath(m.filename)}`; }) ] }) From 1e2af7d57535bdb0ac7c4974a0e359d39c420f78 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 2 Sep 2024 13:08:14 +0200 Subject: [PATCH 047/183] Removes unused code, minor improvements --- lib/core/core.utils.ts | 8 ----- lib/core/element.utils.ts | 11 ++----- lib/core/error.utils.ts | 5 +-- lib/fetch/kontent-fetcher.ts | 14 +++++--- lib/format/formatter.ts | 27 ++++++++-------- .../delivery-content-type.generator.ts | 1 - lib/generators/project/project.generator.ts | 32 ++++++------------- 7 files changed, 34 insertions(+), 64 deletions(-) diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 08a304a..84aa651 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -14,10 +14,6 @@ export function getDefaultModuleResolution(moduleResolution: ModuleResolution | return moduleResolution ?? 'node'; } -export function replaceTsExtensionWithJs(filePath: string): string { - return filePath.replace('.ts', '.js'); -} - export function getFileNameWithoutExtension(filePath: string): string { return filePath.substring(0, filePath.lastIndexOf('.')); } @@ -45,10 +41,6 @@ export function toSnakeCase(text: string): string { return toSafeStringCode(snakeCasePropertyNameResolver('', text)); } -export function toAlphanumeric(value: string): string { - return value.replace(/\W/g, ''); -} - export function removeLineEndings(value: string): string { return value.replace(/(\r\n|\n|\r)/gm, ''); } diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts index c6b4b4c..f1f9ed2 100644 --- a/lib/core/element.utils.ts +++ b/lib/core/element.utils.ts @@ -16,11 +16,7 @@ export function getFlattenedElements( ): readonly FlattenedElement[] { return elements .filter((element) => { - if (element.type === 'guidelines') { - return false; - } - - return true; + return element.type !== 'guidelines'; }) .flatMap((element) => { if (element.type === 'snippet') { @@ -54,10 +50,7 @@ export function getFlattenedElement( taxonomies: readonly Readonly[], types: readonly Readonly[] ): Readonly | undefined { - if (!wrapper.element.codename) { - return undefined; - } - if (!wrapper.element.id) { + if (!wrapper.element.codename || !wrapper.element.id) { return undefined; } diff --git a/lib/core/error.utils.ts b/lib/core/error.utils.ts index cdc9ace..ba84ff8 100644 --- a/lib/core/error.utils.ts +++ b/lib/core/error.utils.ts @@ -40,10 +40,7 @@ export function extractErrorData(error: unknown): ErrorData { export function is404Error(error: unknown): boolean { if (error instanceof SharedModels.ContentManagementBaseKontentError) { const originalError = error.originalError as OriginalManagementError | undefined; - - if (originalError?.response?.status === 404) { - return true; - } + return originalError?.response?.status === 404; } return false; diff --git a/lib/fetch/kontent-fetcher.ts b/lib/fetch/kontent-fetcher.ts index 705933e..8557cba 100644 --- a/lib/fetch/kontent-fetcher.ts +++ b/lib/fetch/kontent-fetcher.ts @@ -21,11 +21,15 @@ interface KontentFetcherConfig { } export function kontentFetcher(config: KontentFetcherConfig) { - const client: GeneratorManagementClient = createManagementClient({ - environmentId: config.environmentId, - apiKey: config.apiKey, - baseUrl: config.baseUrl - }); + const getManagementClient = (): GeneratorManagementClient => { + return createManagementClient({ + environmentId: config.environmentId, + apiKey: config.apiKey, + baseUrl: config.baseUrl + }); + }; + + const client = getManagementClient(); return { async getEnvironmentInfoAsync(): Promise> { diff --git a/lib/format/formatter.ts b/lib/format/formatter.ts index 3032582..7346faa 100644 --- a/lib/format/formatter.ts +++ b/lib/format/formatter.ts @@ -1,18 +1,17 @@ import { Options, format } from 'prettier'; export async function formatCodeAsync(code: string, options?: Readonly): Promise { - const formatOptions: Options = options - ? options - : { - parser: 'typescript', - singleQuote: true, - printWidth: 120, - tabWidth: 4, - useTabs: false, - trailingComma: 'none', - bracketSpacing: true, - semi: true - }; - - return await format(code, formatOptions); + return await format( + code, + options ?? { + parser: 'typescript', + singleQuote: true, + printWidth: 140, + tabWidth: 4, + useTabs: false, + trailingComma: 'none', + bracketSpacing: true, + semi: true + } + ); } diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index faff536..9b50c52 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -1,7 +1,6 @@ import { match, P } from 'ts-pattern'; import { isNotUndefined } from '@kontent-ai/migration-toolkit'; import { ContentTypeModels, ContentTypeSnippetModels, EnvironmentModels, TaxonomyModels } from '@kontent-ai/management-sdk'; - import { ContentTypeFileNameResolver, ContentTypeNameResolver, diff --git a/lib/generators/project/project.generator.ts b/lib/generators/project/project.generator.ts index b85eb0c..aebc60d 100644 --- a/lib/generators/project/project.generator.ts +++ b/lib/generators/project/project.generator.ts @@ -23,11 +23,6 @@ import { toGuidelinesComment } from '../../core/index.js'; -interface ProjectCodeResult { - readonly filename: string; - readonly code: string; -} - interface WorkflowStep { readonly name: string; readonly codename: string; @@ -51,64 +46,55 @@ export interface ProjectGeneratorConfig { export function projectGenerator(config: ProjectGeneratorConfig) { const generateProjectModel = (): readonly GeneratedFile[] => { - return getProjectModelCode().map((projectCode) => { - return { - filename: `${projectCode.filename}`, - text: projectCode.code - }; - }); - }; - - const getProjectModelCode = (): readonly ProjectCodeResult[] => { return [ { - code: `export const languages = { + text: `export const languages = { ${getProjectLanguages(config.environmentData.languages)} } as const;`, filename: 'languages.ts' }, { - code: `export const collections = { + text: `export const collections = { ${getCollections(config.environmentData.collections)} } as const;`, filename: 'collections.ts' }, { - code: `export const contentTypes = { + text: `export const contentTypes = { ${getProjectContentTypes(config.environmentData.types)} } as const;`, filename: 'contentTypes.ts' }, { - code: `export const contentTypeSnippets = { + text: `export const contentTypeSnippets = { ${getProjectContentTypeSnippets(config.environmentData.snippets)} } as const;`, filename: 'contentTypeSnippets.ts' }, { - code: `export const taxonomies = { + text: `export const taxonomies = { ${getProjectTaxonomies(config.environmentData.taxonomies)} } as const;`, filename: 'taxonomies.ts' }, { - code: `export const workflows = { + text: `export const workflows = { ${getProjectWorkflows(config.environmentData.workflows)} } as const;`, filename: 'workflows.ts' }, { - code: `export const roles = { + text: `export const roles = { ${getRoles(config.environmentData.roles)} } as const;`, filename: 'roles.ts' }, { - code: `export const assetFolders = ${getAssetFolders(config.environmentData.assetFolders)} as const;`, + text: `export const assetFolders = ${getAssetFolders(config.environmentData.assetFolders)} as const;`, filename: 'assetFolders.ts' }, { - code: `export const webhooks = { + text: `export const webhooks = { ${getWebhooks(config.environmentData.webhooks)} } as const;`, filename: 'webhooks.ts' From 087e6cfa2ead12c86c7404dd06495227cd97aae7 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 2 Sep 2024 13:09:04 +0200 Subject: [PATCH 048/183] updates deps --- package-lock.json | 209 +++++++++++++++++----------------------------- package.json | 12 +-- 2 files changed, 81 insertions(+), 140 deletions(-) diff --git a/package-lock.json b/package-lock.json index c13f338..a472905 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,16 +22,16 @@ }, "devDependencies": { "@types/eslint__js": "8.42.3", - "@types/node": "22.4.1", + "@types/node": "22.5.2", "@types/yargs": "17.0.33", - "@typescript-eslint/eslint-plugin": "8.1.0", - "@typescript-eslint/parser": "8.1.0", + "@typescript-eslint/eslint-plugin": "8.3.0", + "@typescript-eslint/parser": "8.3.0", "dotenv-cli": "7.4.2", - "eslint": "9.9.0", + "eslint": "9.9.1", "standard-version": "9.5.0", - "tsx": "4.17.0", + "tsx": "4.19.0", "typescript": "5.5.4", - "typescript-eslint": "8.1.0" + "typescript-eslint": "8.3.0" }, "engines": { "node": ">= 20" @@ -554,9 +554,9 @@ } }, "node_modules/@eslint/config-array": { - "version": "0.17.1", - "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.17.1.tgz", - "integrity": "sha512-BlYOpej8AQ8Ev9xVqroV7a02JK3SkBAaN9GfMMH9W6Ch8FlQlkjGw4Ir7+FgYwfirivAf4t+GtzuAxqfukmISA==", + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/@eslint/config-array/-/config-array-0.18.0.tgz", + "integrity": "sha512-fTxvnS1sRMu3+JjXwJG0j/i4RT9u4qJ+lqS/yCGap4lH4zZGzQ7tu+xZqQmcMZq5OBZDL4QRxQzRjkWcGt8IVw==", "dev": true, "dependencies": { "@eslint/object-schema": "^2.1.4", @@ -635,9 +635,9 @@ } }, "node_modules/@eslint/js": { - "version": "9.9.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.9.0.tgz", - "integrity": "sha512-hhetes6ZHP3BlXLxmd8K2SNgkhNSi+UcecbnwWKwpP7kyi/uC75DJ1lOOBO3xrC4jyojtGE3YxKZPHfk4yrgug==", + "version": "9.9.1", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.9.1.tgz", + "integrity": "sha512-xIDQRsfg5hNBqHz04H1R3scSVwmI+KUbqjsQKHKQ1DAUSaUjYPReZZmS/5PNiKu1fUvzDd6H7DEDKACSEhu+TQ==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -849,9 +849,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.4.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.4.1.tgz", - "integrity": "sha512-1tbpb9325+gPnKK0dMm+/LMriX0vKxf6RnB0SZUqfyVkQ4fMgUSySqhxE/y8Jvs4NyF1yHzTfG9KlnkIODxPKg==", + "version": "22.5.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.2.tgz", + "integrity": "sha512-acJsPTEqYqulZS/Yp/S3GgeE6GZ0qYODUR8aVr/DkhHQ8l9nd4j5x1/ZJy9/gHrRlFMqkO6i0I3E27Alu4jjPg==", "dev": true, "dependencies": { "undici-types": "~6.19.2" @@ -879,16 +879,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.1.0.tgz", - "integrity": "sha512-LlNBaHFCEBPHyD4pZXb35mzjGkuGKXU5eeCA1SxvHfiRES0E82dOounfVpL4DCqYvJEKab0bZIA0gCRpdLKkCw==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.3.0.tgz", + "integrity": "sha512-FLAIn63G5KH+adZosDYiutqkOkYEx0nvcwNNfJAf+c7Ae/H35qWwTYvPZUKFj5AS+WfHG/WJJfWnDnyNUlp8UA==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "8.1.0", - "@typescript-eslint/type-utils": "8.1.0", - "@typescript-eslint/utils": "8.1.0", - "@typescript-eslint/visitor-keys": "8.1.0", + "@typescript-eslint/scope-manager": "8.3.0", + "@typescript-eslint/type-utils": "8.3.0", + "@typescript-eslint/utils": "8.3.0", + "@typescript-eslint/visitor-keys": "8.3.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", @@ -912,15 +912,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.1.0.tgz", - "integrity": "sha512-U7iTAtGgJk6DPX9wIWPPOlt1gO57097G06gIcl0N0EEnNw8RGD62c+2/DiP/zL7KrkqnnqF7gtFGR7YgzPllTA==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.3.0.tgz", + "integrity": "sha512-h53RhVyLu6AtpUzVCYLPhZGL5jzTD9fZL+SYf/+hYOx2bDkyQXztXSc4tbvKYHzfMXExMLiL9CWqJmVz6+78IQ==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "8.1.0", - "@typescript-eslint/types": "8.1.0", - "@typescript-eslint/typescript-estree": "8.1.0", - "@typescript-eslint/visitor-keys": "8.1.0", + "@typescript-eslint/scope-manager": "8.3.0", + "@typescript-eslint/types": "8.3.0", + "@typescript-eslint/typescript-estree": "8.3.0", + "@typescript-eslint/visitor-keys": "8.3.0", "debug": "^4.3.4" }, "engines": { @@ -940,13 +940,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.1.0.tgz", - "integrity": "sha512-DsuOZQji687sQUjm4N6c9xABJa7fjvfIdjqpSIIVOgaENf2jFXiM9hIBZOL3hb6DHK9Nvd2d7zZnoMLf9e0OtQ==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.3.0.tgz", + "integrity": "sha512-mz2X8WcN2nVu5Hodku+IR8GgCOl4C0G/Z1ruaWN4dgec64kDBabuXyPAr+/RgJtumv8EEkqIzf3X2U5DUKB2eg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.1.0", - "@typescript-eslint/visitor-keys": "8.1.0" + "@typescript-eslint/types": "8.3.0", + "@typescript-eslint/visitor-keys": "8.3.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -957,13 +957,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.1.0.tgz", - "integrity": "sha512-oLYvTxljVvsMnldfl6jIKxTaU7ok7km0KDrwOt1RHYu6nxlhN3TIx8k5Q52L6wR33nOwDgM7VwW1fT1qMNfFIA==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.3.0.tgz", + "integrity": "sha512-wrV6qh//nLbfXZQoj32EXKmwHf4b7L+xXLrP3FZ0GOUU72gSvLjeWUl5J5Ue5IwRxIV1TfF73j/eaBapxx99Lg==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "8.1.0", - "@typescript-eslint/utils": "8.1.0", + "@typescript-eslint/typescript-estree": "8.3.0", + "@typescript-eslint/utils": "8.3.0", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -981,9 +981,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.1.0.tgz", - "integrity": "sha512-q2/Bxa0gMOu/2/AKALI0tCKbG2zppccnRIRCW6BaaTlRVaPKft4oVYPp7WOPpcnsgbr0qROAVCVKCvIQ0tbWog==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.3.0.tgz", + "integrity": "sha512-y6sSEeK+facMaAyixM36dQ5NVXTnKWunfD1Ft4xraYqxP0lC0POJmIaL/mw72CUMqjY9qfyVfXafMeaUj0noWw==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -994,15 +994,15 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.1.0.tgz", - "integrity": "sha512-NTHhmufocEkMiAord/g++gWKb0Fr34e9AExBRdqgWdVBaKoei2dIyYKD9Q0jBnvfbEA5zaf8plUFMUH6kQ0vGg==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.3.0.tgz", + "integrity": "sha512-Mq7FTHl0R36EmWlCJWojIC1qn/ZWo2YiWYc1XVtasJ7FIgjo0MVv9rZWXEE7IK2CGrtwe1dVOxWwqXUdNgfRCA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.1.0", - "@typescript-eslint/visitor-keys": "8.1.0", + "@typescript-eslint/types": "8.3.0", + "@typescript-eslint/visitor-keys": "8.3.0", "debug": "^4.3.4", - "globby": "^11.1.0", + "fast-glob": "^3.3.2", "is-glob": "^4.0.3", "minimatch": "^9.0.4", "semver": "^7.6.0", @@ -1022,15 +1022,15 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.1.0.tgz", - "integrity": "sha512-ypRueFNKTIFwqPeJBfeIpxZ895PQhNyH4YID6js0UoBImWYoSjBsahUn9KMiJXh94uOjVBgHD9AmkyPsPnFwJA==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.3.0.tgz", + "integrity": "sha512-F77WwqxIi/qGkIGOGXNBLV7nykwfjLsdauRB/DOFPdv6LTF3BHHkBpq81/b5iMPSF055oO2BiivDJV4ChvNtXA==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "8.1.0", - "@typescript-eslint/types": "8.1.0", - "@typescript-eslint/typescript-estree": "8.1.0" + "@typescript-eslint/scope-manager": "8.3.0", + "@typescript-eslint/types": "8.3.0", + "@typescript-eslint/typescript-estree": "8.3.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1044,12 +1044,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.1.0.tgz", - "integrity": "sha512-ba0lNI19awqZ5ZNKh6wCModMwoZs457StTebQ0q1NP58zSi2F6MOZRXwfKZy+jB78JNJ/WH8GSh2IQNzXX8Nag==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.3.0.tgz", + "integrity": "sha512-RmZwrTbQ9QveF15m/Cl28n0LXD6ea2CjkhH5rQ55ewz3H24w+AMCJHPVYaZ8/0HoG8Z3cLLFFycRXxeO2tz9FA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.1.0", + "@typescript-eslint/types": "8.3.0", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -1152,15 +1152,6 @@ "integrity": "sha512-c5AMf34bKdvPhQ7tBGhqkgKNUzMr4WUs+WDtC2ZUGOUncbxKMTvqxYctiseW3+L4bA8ec+GcZ6/A/FW4m8ukng==", "dev": true }, - "node_modules/array-union": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", - "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/arrify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", @@ -1881,18 +1872,6 @@ "node": ">=8" } }, - "node_modules/dir-glob": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", - "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", - "dev": true, - "dependencies": { - "path-type": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/dot-prop": { "version": "5.3.0", "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-5.3.0.tgz", @@ -2148,16 +2127,16 @@ } }, "node_modules/eslint": { - "version": "9.9.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.9.0.tgz", - "integrity": "sha512-JfiKJrbx0506OEerjK2Y1QlldtBxkAlLxT5OEcRF8uaQ86noDe2k31Vw9rnSWv+MXZHj7OOUV/dA0AhdLFcyvA==", + "version": "9.9.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.9.1.tgz", + "integrity": "sha512-dHvhrbfr4xFQ9/dq+jcVneZMyRYLjggWjk6RVsIiHsP8Rz6yZ8LvZ//iU4TrZF+SXWG+JkNF2OyiZRvzgRDqMg==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.11.0", - "@eslint/config-array": "^0.17.1", + "@eslint/config-array": "^0.18.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.9.0", + "@eslint/js": "9.9.1", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.3.0", "@nodelib/fs.walk": "^1.2.8", @@ -2779,26 +2758,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/globby": { - "version": "11.1.0", - "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", - "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", - "dev": true, - "dependencies": { - "array-union": "^2.1.0", - "dir-glob": "^3.0.1", - "fast-glob": "^3.2.9", - "ignore": "^5.2.0", - "merge2": "^1.4.1", - "slash": "^3.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/gopd": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", @@ -3774,9 +3733,9 @@ } }, "node_modules/micromatch": { - "version": "4.0.7", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.7.tgz", - "integrity": "sha512-LPP/3KorzCwBxfeUuZmaR6bG2kdeHSbe0P2tY3FLRU4vYrjYz5hI4QZwV0njUx3jeuKe67YukQ1LSPZBKDqO/Q==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dev": true, "dependencies": { "braces": "^3.0.3", @@ -4161,15 +4120,6 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, - "node_modules/path-type": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", - "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/picocolors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.1.tgz", @@ -4691,15 +4641,6 @@ "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==" }, - "node_modules/slash": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", - "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -5153,9 +5094,9 @@ "integrity": "sha512-1RUMKa8jYQdNfmnK4jyzBK3/PS/tnjcZ1CW0v1vWDeYe5RBklc/nquw03MEoB66hVBm4BnlCfmOqDVxHyT1DpA==" }, "node_modules/tsx": { - "version": "4.17.0", - "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.17.0.tgz", - "integrity": "sha512-eN4mnDA5UMKDt4YZixo9tBioibaMBpoxBkD+rIPAjVmYERSG0/dWEY1CEFuV89CgASlKL499q8AhmkMnnjtOJg==", + "version": "4.19.0", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.19.0.tgz", + "integrity": "sha512-bV30kM7bsLZKZIOCHeMNVMJ32/LuJzLVajkQI/qf92J2Qr08ueLQvW00PUZGiuLPP760UINwupgUj8qrSCPUKg==", "dev": true, "dependencies": { "esbuild": "~0.23.0", @@ -5215,14 +5156,14 @@ } }, "node_modules/typescript-eslint": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.1.0.tgz", - "integrity": "sha512-prB2U3jXPJLpo1iVLN338Lvolh6OrcCZO+9Yv6AR+tvegPPptYCDBIHiEEUdqRi8gAv2bXNKfMUrgAd2ejn/ow==", + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.3.0.tgz", + "integrity": "sha512-EvWjwWLwwKDIJuBjk2I6UkV8KEQcwZ0VM10nR1rIunRDIP67QJTZAHBXTX0HW/oI1H10YESF8yWie8fRQxjvFA==", "dev": true, "dependencies": { - "@typescript-eslint/eslint-plugin": "8.1.0", - "@typescript-eslint/parser": "8.1.0", - "@typescript-eslint/utils": "8.1.0" + "@typescript-eslint/eslint-plugin": "8.3.0", + "@typescript-eslint/parser": "8.3.0", + "@typescript-eslint/utils": "8.3.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" diff --git a/package.json b/package.json index ca2f6d3..e27b705 100644 --- a/package.json +++ b/package.json @@ -61,13 +61,13 @@ "@types/yargs": "17.0.33", "standard-version": "9.5.0", "typescript": "5.5.4", - "@types/node": "22.4.1", + "@types/node": "22.5.2", "@types/eslint__js": "8.42.3", - "@typescript-eslint/eslint-plugin": "8.1.0", - "typescript-eslint": "8.1.0", - "@typescript-eslint/parser": "8.1.0", - "eslint": "9.9.0", - "tsx": "4.17.0", + "@typescript-eslint/eslint-plugin": "8.3.0", + "typescript-eslint": "8.3.0", + "@typescript-eslint/parser": "8.3.0", + "eslint": "9.9.1", + "tsx": "4.19.0", "dotenv-cli": "7.4.2" } } From ee9480cfdbaf743d7ffdb8c4cd0d8a6ad1b235ca Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 3 Sep 2024 09:05:37 +0200 Subject: [PATCH 049/183] Organizes imports --- eslint.config.mjs | 4 ++++ lib/comments/comments.manager.ts | 2 +- lib/core/core.models.ts | 2 +- lib/core/element.utils.ts | 2 +- lib/core/error.utils.ts | 2 +- lib/core/importer.ts | 2 +- lib/core/index.ts | 8 ++++---- lib/core/resolvers.ts | 4 ++-- lib/fetch/kontent-fetcher.ts | 2 +- lib/files/file-manager.ts | 8 ++++---- .../delivery-content-type.generator.ts | 16 +++++++-------- lib/generators/delivery/delivery-func.ts | 20 +++++++++---------- .../delivery/delivery-taxonomy.generator.ts | 8 ++++---- lib/generators/index.ts | 6 +++--- lib/generators/migration/migration-func.ts | 14 ++++++------- .../migration/migration.generator.ts | 12 +++++------ lib/generators/project/project-func.ts | 10 +++++----- lib/generators/project/project.generator.ts | 14 ++++++------- lib/index.ts | 4 ++-- lib/meta/index.ts | 2 +- lib/node/cli/actions/migrate-action.ts | 3 +-- lib/node/cli/actions/project-action.ts | 3 +-- lib/node/cli/app.ts | 2 +- lib/node/cli/args/args-fetcher.ts | 4 ++-- scripts/clean.ts | 2 +- scripts/file-version-script.ts | 2 +- scripts/tests/delivery-models.ts | 2 +- scripts/tests/migration-models.ts | 2 +- scripts/tests/project-models.ts | 2 +- 29 files changed, 83 insertions(+), 81 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 21e7940..63708c3 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -10,6 +10,10 @@ export default tseslint.config(eslint.configs.recommended, ...tseslint.configs.r }, rules: { '@typescript-eslint/no-namespace': 'off', + 'import/no-duplicatees': 'error', + 'import/newline-after-import': 'error', + 'simple-import-sort/imports': 'error', + 'sipmle-export-sort/exports': 'error', '@typescript-eslint/naming-convention': [ 'warn', { diff --git a/lib/comments/comments.manager.ts b/lib/comments/comments.manager.ts index b40ac31..b630e08 100644 --- a/lib/comments/comments.manager.ts +++ b/lib/comments/comments.manager.ts @@ -1,6 +1,6 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; -import { libMetadata } from '../meta/index.js'; import { toSafeString } from '../core/index.js'; +import { libMetadata } from '../meta/index.js'; export function commentsManager() { const wrapComment = (comment: string): string => { diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index 790b4da..5443f4a 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -1,3 +1,4 @@ +import { PropertyNameResolver } from '@kontent-ai/delivery-sdk'; import { ContentTypeElements, ContentTypeModels, @@ -6,7 +7,6 @@ import { IManagementClient, TaxonomyModels } from '@kontent-ai/management-sdk'; -import { PropertyNameResolver } from '@kontent-ai/delivery-sdk'; export type CliAction = 'delivery' | 'migration'; export type LibraryType = '@kontent-ai/migration-toolkit' | '@kontent-ai/delivery-sdk'; diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts index f1f9ed2..f4698a4 100644 --- a/lib/core/element.utils.ts +++ b/lib/core/element.utils.ts @@ -1,7 +1,7 @@ import { ContentTypeElements, ContentTypeModels, ContentTypeSnippetModels, TaxonomyModels } from '@kontent-ai/management-sdk'; -import { FlattenedElement } from './core.models.js'; import { isNotUndefined } from '@kontent-ai/migration-toolkit'; import { match } from 'ts-pattern'; +import { FlattenedElement } from './core.models.js'; interface ElementWrapper { readonly element: Readonly; diff --git a/lib/core/error.utils.ts b/lib/core/error.utils.ts index ba84ff8..86695ea 100644 --- a/lib/core/error.utils.ts +++ b/lib/core/error.utils.ts @@ -1,7 +1,7 @@ import { SharedModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; -import { ErrorData, OriginalManagementError } from './core.models.js'; import { match, P } from 'ts-pattern'; +import { ErrorData, OriginalManagementError } from './core.models.js'; export function extractErrorData(error: unknown): ErrorData { return match(error) diff --git a/lib/core/importer.ts b/lib/core/importer.ts index 9af39cf..fe0b361 100644 --- a/lib/core/importer.ts +++ b/lib/core/importer.ts @@ -1,4 +1,4 @@ -import { ModuleResolution, LibraryType, LiteralUnion } from './core.models.js'; +import { LibraryType, LiteralUnion, ModuleResolution } from './core.models.js'; import { getFileNameWithoutExtension } from './core.utils.js'; export function importer(moduleResolution: ModuleResolution) { diff --git a/lib/core/index.ts b/lib/core/index.ts index 432a374..17514e7 100644 --- a/lib/core/index.ts +++ b/lib/core/index.ts @@ -1,7 +1,7 @@ -export * from './core.utils.js'; -export * from './error.utils.js'; +export * from './core.config.js'; export * from './core.models.js'; +export * from './core.utils.js'; export * from './element.utils.js'; -export * from './core.config.js'; -export * from './resolvers.js'; +export * from './error.utils.js'; export * from './importer.js'; +export * from './resolvers.js'; diff --git a/lib/core/resolvers.ts b/lib/core/resolvers.ts index faa4b82..0d05a5c 100644 --- a/lib/core/resolvers.ts +++ b/lib/core/resolvers.ts @@ -1,7 +1,7 @@ -import { ContentTypeModels, ContentTypeSnippetModels, ContentTypeElements, TaxonomyModels } from '@kontent-ai/management-sdk'; -import { toCamelCase, toPascalCase, toSnakeCase } from './core.utils.js'; +import { ContentTypeElements, ContentTypeModels, ContentTypeSnippetModels, TaxonomyModels } from '@kontent-ai/management-sdk'; import { match, P } from 'ts-pattern'; import { CaseType, GeneratorElementResolver, ObjectWithCodename } from './core.models.js'; +import { toCamelCase, toPascalCase, toSnakeCase } from './core.utils.js'; /** File name resolvers */ export type FilenameResolver> = undefined | CaseType | ((item: T & ObjectWithCodename) => string); diff --git a/lib/fetch/kontent-fetcher.ts b/lib/fetch/kontent-fetcher.ts index 8557cba..b9f9bb3 100644 --- a/lib/fetch/kontent-fetcher.ts +++ b/lib/fetch/kontent-fetcher.ts @@ -11,8 +11,8 @@ import { WebhookModels, WorkflowModels } from '@kontent-ai/management-sdk'; -import { GeneratorManagementClient, sortAlphabetically, toSafeString } from '../core/index.js'; import chalk from 'chalk'; +import { GeneratorManagementClient, sortAlphabetically, toSafeString } from '../core/index.js'; interface KontentFetcherConfig { readonly environmentId: string; diff --git a/lib/files/file-manager.ts b/lib/files/file-manager.ts index 6725255..2521324 100644 --- a/lib/files/file-manager.ts +++ b/lib/files/file-manager.ts @@ -1,11 +1,11 @@ +import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; -import { Options } from 'prettier'; -import { formatCodeAsync } from '../format/formatter.js'; import * as fs from 'fs'; import { dirname } from 'path'; -import { GeneratedFile, toOutputDirPath } from '../core/index.js'; -import { EnvironmentModels } from '@kontent-ai/management-sdk'; +import { Options } from 'prettier'; import { commentsManager } from '../comments/index.js'; +import { GeneratedFile, toOutputDirPath } from '../core/index.js'; +import { formatCodeAsync } from '../format/formatter.js'; export function fileManager(config: { readonly outputDir: string | undefined; diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 9b50c52..03584e4 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -1,7 +1,8 @@ -import { match, P } from 'ts-pattern'; -import { isNotUndefined } from '@kontent-ai/migration-toolkit'; import { ContentTypeModels, ContentTypeSnippetModels, EnvironmentModels, TaxonomyModels } from '@kontent-ai/management-sdk'; +import { isNotUndefined } from '@kontent-ai/migration-toolkit'; +import { match, P } from 'ts-pattern'; import { + importer as _importer, ContentTypeFileNameResolver, ContentTypeNameResolver, ContentTypeSnippetFileNameResolver, @@ -9,19 +10,18 @@ import { deliveryConfig, FlattenedElement, GeneratedFile, + GeneratorElementResolver, getFlattenedElements, mapElementName, mapFilename, mapName, + ModuleResolution, sortAlphabetically, - TaxonomyTypeFileNameResolver, TaxonomyNameResolver, + TaxonomyTypeFileNameResolver, + toGuidelinesComment, toSafeString, - uniqueFilter, - ModuleResolution, - GeneratorElementResolver, - importer as _importer, - toGuidelinesComment + uniqueFilter } from '../../core/index.js'; interface ExtractImportsResult { diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index 9541526..4999f26 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -1,8 +1,6 @@ +import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; -import { deliveryContentTypeGenerator } from './delivery-content-type.generator.js'; -import { deliveryTaxonomyGenerator } from './delivery-taxonomy.generator.js'; -import { fileManager as _fileManager } from '../../files/index.js'; -import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; +import { Options } from 'prettier'; import { ContentTypeFileNameResolver, ContentTypeNameResolver, @@ -10,17 +8,19 @@ import { ContentTypeSnippetNameResolver, coreConfig, deliveryConfig, - GeneratorElementResolver, GeneratedFile, + GeneratorElementResolver, getBarrelExportCode, + getDefaultModuleResolution, + getFilenameFromPath, ModuleResolution, TaxonomyNameResolver, - TaxonomyTypeFileNameResolver, - getDefaultModuleResolution, - getFilenameFromPath + TaxonomyTypeFileNameResolver } from '../../core/index.js'; -import { Options } from 'prettier'; -import { EnvironmentModels } from '@kontent-ai/management-sdk'; +import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; +import { fileManager as _fileManager } from '../../files/index.js'; +import { deliveryContentTypeGenerator } from './delivery-content-type.generator.js'; +import { deliveryTaxonomyGenerator } from './delivery-taxonomy.generator.js'; export interface GenerateDeliveryModelsConfig { readonly environmentId: string; diff --git a/lib/generators/delivery/delivery-taxonomy.generator.ts b/lib/generators/delivery/delivery-taxonomy.generator.ts index e7b7ed9..bf5d38e 100644 --- a/lib/generators/delivery/delivery-taxonomy.generator.ts +++ b/lib/generators/delivery/delivery-taxonomy.generator.ts @@ -1,15 +1,15 @@ import { EnvironmentModels, TaxonomyModels } from '@kontent-ai/management-sdk'; import { + deliveryConfig, GeneratedFile, mapFilename, mapName, + ModuleResolution, sortAlphabetically, - TaxonomyTypeFileNameResolver, TaxonomyNameResolver, - toSafeString, - ModuleResolution, - deliveryConfig + TaxonomyTypeFileNameResolver, + toSafeString } from '../../core/index.js'; export interface DeliveryTaxonomyGeneratorConfig { diff --git a/lib/generators/index.ts b/lib/generators/index.ts index d6e29d3..8c995e4 100644 --- a/lib/generators/index.ts +++ b/lib/generators/index.ts @@ -1,12 +1,12 @@ // delivery export * from './delivery/delivery-content-type.generator.js'; -export * from './delivery/delivery-taxonomy.generator.js'; export * from './delivery/delivery-func.js'; +export * from './delivery/delivery-taxonomy.generator.js'; // project -export * from './project/project.generator.js'; export * from './project/project-func.js'; +export * from './project/project.generator.js'; // migration -export * from './migration/migration.generator.js'; export * from './migration/migration-func.js'; +export * from './migration/migration.generator.js'; diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index f7dc154..e6a7266 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -1,18 +1,18 @@ +import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; +import { Options } from 'prettier'; import { - migrationConfig, coreConfig, - getBarrelExportCode, - ModuleResolution, GeneratedFile, + getBarrelExportCode, getDefaultModuleResolution, - getFilenameFromPath + getFilenameFromPath, + migrationConfig, + ModuleResolution } from '../../core/index.js'; -import { fileManager as _fileManager } from '../../files/index.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; +import { fileManager as _fileManager } from '../../files/index.js'; import { migrationGenerator as _migrationGenerator } from './migration.generator.js'; -import { Options } from 'prettier'; -import { EnvironmentModels } from '@kontent-ai/management-sdk'; export interface GenerateMigrationModelsConfig { readonly environmentId: string; diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index bc65308..2c18008 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -8,19 +8,19 @@ import { WorkflowModels } from '@kontent-ai/management-sdk'; import { match } from 'ts-pattern'; +import { commentsManager as _commentsManager } from '../../comments/index.js'; import { + importer as _importer, FlattenedElement, - uniqueFilter, GeneratedFile, - toSafeString, - toPascalCase, getFlattenedElements, migrationConfig, ModuleResolution, - importer as _importer, - toGuidelinesComment + toGuidelinesComment, + toPascalCase, + toSafeString, + uniqueFilter } from '../../core/index.js'; -import { commentsManager as _commentsManager } from '../../comments/index.js'; export interface MigrationGeneratorConfig { readonly moduleResolution: ModuleResolution; diff --git a/lib/generators/project/project-func.ts b/lib/generators/project/project-func.ts index d767d18..27b27bc 100644 --- a/lib/generators/project/project-func.ts +++ b/lib/generators/project/project-func.ts @@ -1,7 +1,6 @@ +import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; -import { projectGenerator as _projectGenerator } from './project.generator.js'; -import { fileManager as _fileManager } from '../../files/index.js'; -import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; +import { Options } from 'prettier'; import { coreConfig, GeneratedFile, @@ -10,8 +9,9 @@ import { getFilenameFromPath, ModuleResolution } from '../../core/index.js'; -import { Options } from 'prettier'; -import { EnvironmentModels } from '@kontent-ai/management-sdk'; +import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; +import { fileManager as _fileManager } from '../../files/index.js'; +import { projectGenerator as _projectGenerator } from './project.generator.js'; export interface GenerateProjectModelsConfig { readonly environmentId: string; diff --git a/lib/generators/project/project.generator.ts b/lib/generators/project/project.generator.ts index aebc60d..53156b4 100644 --- a/lib/generators/project/project.generator.ts +++ b/lib/generators/project/project.generator.ts @@ -1,26 +1,26 @@ -import { match } from 'ts-pattern'; import { AssetFolderModels, CollectionModels, + ContentTypeElements, ContentTypeModels, ContentTypeSnippetModels, - LanguageModels, EnvironmentModels, + LanguageModels, RoleModels, TaxonomyModels, WebhookModels, - WorkflowModels, - ContentTypeElements + WorkflowModels } from '@kontent-ai/management-sdk'; +import { match } from 'ts-pattern'; import { FlattenedElement, GeneratedFile, getFlattenedElements, + getStringOrUndefined, sortAlphabetically, - toSafeString, toCamelCase, - getStringOrUndefined, - toGuidelinesComment + toGuidelinesComment, + toSafeString } from '../../core/index.js'; interface WorkflowStep { diff --git a/lib/index.ts b/lib/index.ts index eddfbdf..d1b9a08 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,6 +1,6 @@ +export * from './comments/index.js'; export * from './core/index.js'; +export * from './fetch/index.js'; export * from './files/index.js'; export * from './format/index.js'; -export * from './fetch/index.js'; -export * from './comments/index.js'; export * from './generators/index.js'; diff --git a/lib/meta/index.ts b/lib/meta/index.ts index 09e6464..fc7693b 100644 --- a/lib/meta/index.ts +++ b/lib/meta/index.ts @@ -1 +1 @@ -export * from './metadata.js'; \ No newline at end of file +export * from './metadata.js'; diff --git a/lib/node/cli/actions/migrate-action.ts b/lib/node/cli/actions/migrate-action.ts index a8c2924..7313322 100644 --- a/lib/node/cli/actions/migrate-action.ts +++ b/lib/node/cli/actions/migrate-action.ts @@ -10,7 +10,6 @@ export async function migrateActionAsync(cliFetcher: CliArgumentsFetcher): Promi outputDir: cliFetcher.getRequiredArgumentValue('outputDir'), addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), formatOptions: undefined, - moduleResolution: - cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' + moduleResolution: cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' }); } diff --git a/lib/node/cli/actions/project-action.ts b/lib/node/cli/actions/project-action.ts index 3b5306d..c421629 100644 --- a/lib/node/cli/actions/project-action.ts +++ b/lib/node/cli/actions/project-action.ts @@ -10,7 +10,6 @@ export async function projectActionAsync(cliFetcher: CliArgumentsFetcher): Promi outputDir: cliFetcher.getRequiredArgumentValue('outputDir'), isEnterpriseSubscription: cliFetcher.getBooleanArgumentValue('isEnterpriseSubscription', false), addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), - moduleResolution: - cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' + moduleResolution: cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' }); } diff --git a/lib/node/cli/app.ts b/lib/node/cli/app.ts index 92ea738..c2378cf 100644 --- a/lib/node/cli/app.ts +++ b/lib/node/cli/app.ts @@ -1,7 +1,7 @@ #!/usr/bin/env node import chalk from 'chalk'; -import { handleError, exitProgram } from '../../core/index.js'; +import { exitProgram, handleError } from '../../core/index.js'; import { deliveryActionAsync } from './actions/delivery-action.js'; import { migrateActionAsync } from './actions/migrate-action.js'; import { argumentsFetcherAsync } from './args/args-fetcher.js'; diff --git a/lib/node/cli/args/args-fetcher.ts b/lib/node/cli/args/args-fetcher.ts index ad7c404..e8b9363 100644 --- a/lib/node/cli/args/args-fetcher.ts +++ b/lib/node/cli/args/args-fetcher.ts @@ -1,9 +1,9 @@ +import chalk from 'chalk'; import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; -import chalk from 'chalk'; -import { CliArgumentsFetcher } from '../cli.models.js'; import { CliAction } from '../../../core/core.models.js'; import { exitProgram } from '../../../core/index.js'; +import { CliArgumentsFetcher } from '../cli.models.js'; type ArgvResult = { [x: string]: unknown; diff --git a/scripts/clean.ts b/scripts/clean.ts index b7bd4b7..5be2f45 100644 --- a/scripts/clean.ts +++ b/scripts/clean.ts @@ -1,5 +1,5 @@ -import fs from 'fs'; import chalk from 'chalk'; +import fs from 'fs'; const paths = ['dist']; for (const path of paths) { diff --git a/scripts/file-version-script.ts b/scripts/file-version-script.ts index d0bf13d..59fdb58 100644 --- a/scripts/file-version-script.ts +++ b/scripts/file-version-script.ts @@ -1,5 +1,5 @@ -import fs from 'fs'; import chalk from 'chalk'; +import fs from 'fs'; import PackageJson from '../package.json' assert { type: 'json' }; export const createVersionFile = (date: Date, versionPath: string, propertyName: string) => { diff --git a/scripts/tests/delivery-models.ts b/scripts/tests/delivery-models.ts index ede19f6..0616377 100644 --- a/scripts/tests/delivery-models.ts +++ b/scripts/tests/delivery-models.ts @@ -1,7 +1,7 @@ +import chalk from 'chalk'; import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; import { ModuleResolution, generateDeliveryModelsAsync, handleError } from '../../lib/index.js'; -import chalk from 'chalk'; import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; const outputDir: string = './sample/delivery'; diff --git a/scripts/tests/migration-models.ts b/scripts/tests/migration-models.ts index 32894ea..7339a8e 100644 --- a/scripts/tests/migration-models.ts +++ b/scripts/tests/migration-models.ts @@ -1,7 +1,7 @@ +import chalk from 'chalk'; import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; import { ModuleResolution, generateMigrationModelsAsync, handleError } from '../../lib/index.js'; -import chalk from 'chalk'; import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; const outputDir: string = './sample/migration'; diff --git a/scripts/tests/project-models.ts b/scripts/tests/project-models.ts index ca601f0..95e25bd 100644 --- a/scripts/tests/project-models.ts +++ b/scripts/tests/project-models.ts @@ -1,7 +1,7 @@ +import chalk from 'chalk'; import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; import { ModuleResolution, generateProjectModelsAsync, handleError } from '../../lib/index.js'; -import chalk from 'chalk'; import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; const outputDir: string = './sample/project'; From 7fc9a71c361810c104471f9c4d0aa7d4e2b68742 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 3 Sep 2024 09:24:15 +0200 Subject: [PATCH 050/183] removes exitProgram func --- lib/core/core.utils.ts | 4 ---- lib/node/cli/actions/migrate-action.ts | 1 - lib/node/cli/app.ts | 6 ++---- lib/node/cli/args/args-fetcher.ts | 5 +---- 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 84aa651..0888ed0 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -2,10 +2,6 @@ import { camelCasePropertyNameResolver, pascalCasePropertyNameResolver, snakeCas import { parse } from 'path'; import { ModuleResolution } from './core.models.js'; -export function exitProgram(data: { readonly message: string }): never { - throw Error(data.message); -} - export function uniqueFilter(value: string, index: number, self: readonly string[]): boolean { return self.indexOf(value) === index; } diff --git a/lib/node/cli/actions/migrate-action.ts b/lib/node/cli/actions/migrate-action.ts index 7313322..1c39ab8 100644 --- a/lib/node/cli/actions/migrate-action.ts +++ b/lib/node/cli/actions/migrate-action.ts @@ -9,7 +9,6 @@ export async function migrateActionAsync(cliFetcher: CliArgumentsFetcher): Promi apiKey: cliFetcher.getRequiredArgumentValue('apiKey'), outputDir: cliFetcher.getRequiredArgumentValue('outputDir'), addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), - formatOptions: undefined, moduleResolution: cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' }); } diff --git a/lib/node/cli/app.ts b/lib/node/cli/app.ts index c2378cf..31a5562 100644 --- a/lib/node/cli/app.ts +++ b/lib/node/cli/app.ts @@ -1,7 +1,7 @@ #!/usr/bin/env node import chalk from 'chalk'; -import { exitProgram, handleError } from '../../core/index.js'; +import { handleError } from '../../core/index.js'; import { deliveryActionAsync } from './actions/delivery-action.js'; import { migrateActionAsync } from './actions/migrate-action.js'; import { argumentsFetcherAsync } from './args/args-fetcher.js'; @@ -22,9 +22,7 @@ const run = async () => { return await migrateActionAsync(argsFetcher); } - exitProgram({ - message: `Invalid action '${chalk.red(action)}'` - }); + throw Error(`Invalid action '${chalk.red(action)}'`); }; run().catch((err) => { diff --git a/lib/node/cli/args/args-fetcher.ts b/lib/node/cli/args/args-fetcher.ts index e8b9363..05502ca 100644 --- a/lib/node/cli/args/args-fetcher.ts +++ b/lib/node/cli/args/args-fetcher.ts @@ -2,7 +2,6 @@ import chalk from 'chalk'; import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; import { CliAction } from '../../../core/core.models.js'; -import { exitProgram } from '../../../core/index.js'; import { CliArgumentsFetcher } from '../cli.models.js'; type ArgvResult = { @@ -39,9 +38,7 @@ export async function argumentsFetcherAsync(): Promise { const value = getOptionalArgumentValue(argName); if (!value) { - exitProgram({ - message: `Missing '${chalk.yellow(argName)}' argument value` - }); + throw Error(`Missing '${chalk.yellow(argName)}' argument value`); } return value; From 45fea6e53183bb5de8c27ad901f0b53601626219 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 3 Sep 2024 10:40:51 +0200 Subject: [PATCH 051/183] Adds sorting to fetched items / elements --- eslint.config.mjs | 4 - lib/core/core.utils.ts | 2 +- lib/core/element.utils.ts | 58 ++--- lib/fetch/kontent-fetcher.ts | 18 +- .../delivery/delivery-taxonomy.generator.ts | 5 +- .../migration/migration.generator.ts | 13 +- lib/generators/project/project.generator.ts | 11 +- sample/delivery/content-types/actor.ts | 16 +- sample/delivery/content-types/movie.ts | 64 ++--- sample/migration/content-types/actor.ts | 18 +- sample/migration/content-types/movie.ts | 66 ++--- sample/migration/migration.ts | 9 +- sample/project/contentTypes.ts | 228 +++++++++--------- sample/project/index.ts | 8 +- 14 files changed, 265 insertions(+), 255 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 63708c3..21e7940 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -10,10 +10,6 @@ export default tseslint.config(eslint.configs.recommended, ...tseslint.configs.r }, rules: { '@typescript-eslint/no-namespace': 'off', - 'import/no-duplicatees': 'error', - 'import/newline-after-import': 'error', - 'simple-import-sort/imports': 'error', - 'sipmle-export-sort/exports': 'error', '@typescript-eslint/naming-convention': [ 'warn', { diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 0888ed0..2e43a38 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -71,7 +71,7 @@ export function getBarrelExportCode(data: { readonly filenames: readonly string[ if (!data.filenames.length) { return 'export {}'; } - return data.filenames.reduce((barrelCode, filename) => { + return sortAlphabetically(data.filenames, (filename) => filename).reduce((barrelCode, filename) => { const path = parse(filename); return (barrelCode += `export * from '${path.dir}/${path.name}${getExtensionForModuleResolution(data.moduleResolution)}';`); }, ''); diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts index f4698a4..756cf65 100644 --- a/lib/core/element.utils.ts +++ b/lib/core/element.utils.ts @@ -2,6 +2,7 @@ import { ContentTypeElements, ContentTypeModels, ContentTypeSnippetModels, Taxon import { isNotUndefined } from '@kontent-ai/migration-toolkit'; import { match } from 'ts-pattern'; import { FlattenedElement } from './core.models.js'; +import { sortAlphabetically } from './core.utils.js'; interface ElementWrapper { readonly element: Readonly; @@ -14,35 +15,38 @@ export function getFlattenedElements( taxonomies: readonly Readonly[], types: readonly Readonly[] ): readonly FlattenedElement[] { - return elements - .filter((element) => { - return element.type !== 'guidelines'; - }) - .flatMap((element) => { - if (element.type === 'snippet') { - const snippet = snippets.find((snippet) => snippet.id === element.snippet.id); + return sortAlphabetically( + elements + .filter((element) => { + return element.type !== 'guidelines'; + }) + .flatMap((element) => { + if (element.type === 'snippet') { + const snippet = snippets.find((snippet) => snippet.id === element.snippet.id); - if (!snippet) { - throw Error(`Could not find snippet with id '${element.snippet.id}'`); - } + if (!snippet) { + throw Error(`Could not find snippet with id '${element.snippet.id}'`); + } - return snippet.elements.map((snippetElement) => { - return { - element: snippetElement, - fromSnippet: snippet - }; - }); - } + return snippet.elements.map((snippetElement) => { + return { + element: snippetElement, + fromSnippet: snippet + }; + }); + } - return { - element: element, - fromSnippet: undefined - }; - }) - .map((element) => { - return getFlattenedElement(element, taxonomies, types); - }) - .filter(isNotUndefined); + return { + element: element, + fromSnippet: undefined + }; + }) + .map((element) => { + return getFlattenedElement(element, taxonomies, types); + }) + .filter(isNotUndefined), + (element) => element.codename + ); } export function getFlattenedElement( @@ -108,7 +112,7 @@ function extractLinkedItemsAllowedTypes( }) .otherwise(() => []); - return allowedTypeIds.map((id) => types.find((m) => m.id === id)).filter(isNotUndefined); + return sortAlphabetically(allowedTypeIds.map((id) => types.find((m) => m.id === id)).filter(isNotUndefined), (type) => type.codename); } function extractTaxonomy( diff --git a/lib/fetch/kontent-fetcher.ts b/lib/fetch/kontent-fetcher.ts index b9f9bb3..a165d8b 100644 --- a/lib/fetch/kontent-fetcher.ts +++ b/lib/fetch/kontent-fetcher.ts @@ -41,47 +41,47 @@ export function kontentFetcher(config: KontentFetcherConfig) { async getWorkflowsAsync(): Promise[]> { const items = sortAlphabetically((await client.listWorkflows().toPromise()).data, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' workflows`); - return items; + return sortAlphabetically(items, (item) => item.codename); }, async getRolesAsync(): Promise[]> { const items = sortAlphabetically((await client.listRoles().toPromise()).data.roles, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' roles`); - return items; + return sortAlphabetically(items, (item) => item.codename ?? item.name); }, async getAssetFoldersAsync(): Promise[]> { const items = sortAlphabetically((await client.listAssetFolders().toPromise()).data.items, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' asset folders`); - return items; + return sortAlphabetically(items, (item) => item.codename); }, async getCollectionsAsync(): Promise[]> { const items = sortAlphabetically((await client.listCollections().toPromise()).data.collections, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' collections`); - return items; + return sortAlphabetically(items, (item) => item.codename); }, async getWebhooksAsync(): Promise[]> { const items = sortAlphabetically((await client.listWebhooks().toPromise()).data.webhooks, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' webhooks`); - return items; + return sortAlphabetically(items, (item) => item.name); }, async getLanguagesAsync(): Promise[]> { const items = sortAlphabetically((await client.listLanguages().toAllPromise()).data.items, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' languages`); - return items; + return sortAlphabetically(items, (item) => item.codename); }, async getTypesAsync(): Promise[]> { const items = sortAlphabetically((await client.listContentTypes().toAllPromise()).data.items, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' types`); - return items; + return sortAlphabetically(items, (item) => item.codename); }, async getSnippetsAsync(): Promise[]> { const items = sortAlphabetically((await client.listContentTypeSnippets().toAllPromise()).data.items, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' snippets`); - return items; + return sortAlphabetically(items, (item) => item.codename); }, async getTaxonomiesAsync(): Promise[]> { const items = sortAlphabetically((await client.listTaxonomies().toAllPromise()).data.items, (item) => item.name); console.log(`Fetched '${chalk.yellow(items.length.toString())}' taxonomies`); - return items; + return sortAlphabetically(items, (item) => item.codename); } }; } diff --git a/lib/generators/delivery/delivery-taxonomy.generator.ts b/lib/generators/delivery/delivery-taxonomy.generator.ts index bf5d38e..c92b63d 100644 --- a/lib/generators/delivery/delivery-taxonomy.generator.ts +++ b/lib/generators/delivery/delivery-taxonomy.generator.ts @@ -72,7 +72,10 @@ export type ${taxonomyNameMap(taxonomy)} = ${getTaxonomyTermsCode(taxonomy)}; const getTaxonomyTermCodenames = (taxonomyTerms: readonly Readonly[]): readonly string[] => { return taxonomyTerms.reduce((codenames, taxonomyTerm) => { - return codenames.concat(getTaxonomyTermCodenames(taxonomyTerm.terms), taxonomyTerm.codename); + return sortAlphabetically( + codenames.concat(getTaxonomyTermCodenames(taxonomyTerm.terms), taxonomyTerm.codename), + (codename) => codename + ); }, []); }; diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index 2c18008..095ea3e 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -16,6 +16,7 @@ import { getFlattenedElements, migrationConfig, ModuleResolution, + sortAlphabetically, toGuidelinesComment, toPascalCase, toSafeString, @@ -190,9 +191,11 @@ function getCollectionCodenamesType(collections: readonly Readonly[]): string { - return `export type ${migrationConfig.localTypeNames.workflowStepCodenames} = ${workflows - .flatMap((workflow) => [...workflow.steps, workflow.publishedStep, workflow.archivedStep, workflow.scheduledStep]) - .map((workflowStep) => `'${workflowStep.codename}'`) - .filter(uniqueFilter) - .join(' | ')};`; + return `export type ${migrationConfig.localTypeNames.workflowStepCodenames} = ${sortAlphabetically( + workflows + .flatMap((workflow) => [...workflow.steps, workflow.publishedStep, workflow.archivedStep, workflow.scheduledStep]) + .map((workflowStep) => `'${workflowStep.codename}'`) + .filter(uniqueFilter), + (codename) => codename + ).join(' | ')};`; } diff --git a/lib/generators/project/project.generator.ts b/lib/generators/project/project.generator.ts index 53156b4..1f9275b 100644 --- a/lib/generators/project/project.generator.ts +++ b/lib/generators/project/project.generator.ts @@ -227,9 +227,10 @@ export function projectGenerator(config: ProjectGeneratorConfig) { .returnType() .with({ type: 'multiple_choice' }, (element) => { return ( - element.options.reduce((code, option, index) => { - const isLast = index === element.options.length - 1; - return `${code}\n + sortAlphabetically(element.options, (option) => option.codename ?? option.name).reduce( + (code, option, index) => { + const isLast = index === element.options.length - 1; + return `${code}\n /** * ${toSafeString(option.name)} */ @@ -239,7 +240,9 @@ export function projectGenerator(config: ProjectGeneratorConfig) { codename: ${getStringOrUndefined(option.codename)}, externalId: ${getStringOrUndefined(option.external_id)} }${!isLast ? ',\n' : ''}`; - }, '{') + '}' + }, + '{' + ) + '}' ); }) .otherwise(() => undefined); diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index b9122cf..e20f960 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -22,14 +22,6 @@ import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; * Codename: actor */ export type Actor = IContentItem<{ - /** - * Url (url_slug) - * - * Required: false - * Codename: url - * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 - */ - url: Elements.UrlSlugElement; /** * First name (text) * @@ -55,4 +47,12 @@ export type Actor = IContentItem<{ * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 */ photo: Elements.AssetsElement; + /** + * Url (url_slug) + * + * Required: false + * Codename: url + * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 + */ + url: Elements.UrlSlugElement; }>; diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 0c39afa..a2a2461 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -25,29 +25,13 @@ import type { Releasecategory } from '../taxonomies/releasecategory.js'; */ export type Movie = IContentItem<{ /** - * Title (text) - * - * Required: true - * Codename: title - * Id: 3473187e-dc78-eff2-7099-f690f7042d4a - */ - title: Elements.TextElement; - /** - * Plot (rich_text) - * - * Required: false - * Codename: plot - * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce - */ - plot: Elements.RichTextElement; - /** - * Released (date_time) + * Category (multiple_choice) * * Required: false - * Codename: released - * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 + * Codename: category + * Id: 9821c252-6414-f549-c17f-cc171dd87713 */ - released: Elements.DateTimeElement; + category: Elements.MultipleChoiceElement; /** * Length (number) * @@ -56,6 +40,14 @@ export type Movie = IContentItem<{ * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c */ length: Elements.NumberElement; + /** + * Plot (rich_text) + * + * Required: false + * Codename: plot + * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce + */ + plot: Elements.RichTextElement; /** * Poster (asset) * @@ -65,21 +57,21 @@ export type Movie = IContentItem<{ */ poster: Elements.AssetsElement; /** - * Category (multiple_choice) + * ReleaseCategory (taxonomy) * * Required: false - * Codename: category - * Id: 9821c252-6414-f549-c17f-cc171dd87713 + * Codename: releasecategory + * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 */ - category: Elements.MultipleChoiceElement; + releasecategory: Elements.TaxonomyElement; /** - * Stars (modular_content) + * Released (date_time) * * Required: false - * Codename: stars - * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 + * Codename: released + * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 */ - stars: Elements.LinkedItemsElement; + released: Elements.DateTimeElement; /** * SeoName (url_slug) * @@ -89,11 +81,19 @@ export type Movie = IContentItem<{ */ seoname: Elements.UrlSlugElement; /** - * ReleaseCategory (taxonomy) + * Stars (modular_content) * * Required: false - * Codename: releasecategory - * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 + * Codename: stars + * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 */ - releasecategory: Elements.TaxonomyElement; + stars: Elements.LinkedItemsElement; + /** + * Title (text) + * + * Required: true + * Codename: title + * Id: 3473187e-dc78-eff2-7099-f690f7042d4a + */ + title: Elements.TextElement; }>; diff --git a/sample/migration/content-types/actor.ts b/sample/migration/content-types/actor.ts index 299c4f5..4229a92 100644 --- a/sample/migration/content-types/actor.ts +++ b/sample/migration/content-types/actor.ts @@ -25,15 +25,6 @@ import type { Item } from '../migration.js'; export type ActorItem = Item< 'actor', { - /** - * Url (url_slug) - * - * Required: false - * Codename: url - * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 - */ - url: MigrationElementModels.UrlSlugElement; - /** * First name (text) * @@ -61,5 +52,14 @@ export type ActorItem = Item< * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 */ photo: MigrationElementModels.AssetElement; + + /** + * Url (url_slug) + * + * Required: false + * Codename: url + * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 + */ + url: MigrationElementModels.UrlSlugElement; } >; diff --git a/sample/migration/content-types/movie.ts b/sample/migration/content-types/movie.ts index f345d38..eaa1679 100644 --- a/sample/migration/content-types/movie.ts +++ b/sample/migration/content-types/movie.ts @@ -26,40 +26,31 @@ export type MovieItem = Item< 'movie', { /** - * Title (text) - * - * Required: true - * Codename: title - * Id: 3473187e-dc78-eff2-7099-f690f7042d4a - */ - title: MigrationElementModels.TextElement; - - /** - * Plot (rich_text) + * Category (multiple_choice) * * Required: false - * Codename: plot - * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce + * Codename: category + * Id: 9821c252-6414-f549-c17f-cc171dd87713 */ - plot: MigrationElementModels.RichTextElement; + category: MigrationElementModels.MultipleChoiceElement; /** - * Released (date_time) + * Length (number) * * Required: false - * Codename: released - * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 + * Codename: length + * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c */ - released: MigrationElementModels.DateTimeElement; + length: MigrationElementModels.NumberElement; /** - * Length (number) + * Plot (rich_text) * * Required: false - * Codename: length - * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c + * Codename: plot + * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce */ - length: MigrationElementModels.NumberElement; + plot: MigrationElementModels.RichTextElement; /** * Poster (asset) @@ -71,22 +62,22 @@ export type MovieItem = Item< poster: MigrationElementModels.AssetElement; /** - * Category (multiple_choice) + * ReleaseCategory (taxonomy) * * Required: false - * Codename: category - * Id: 9821c252-6414-f549-c17f-cc171dd87713 + * Codename: releasecategory + * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 */ - category: MigrationElementModels.MultipleChoiceElement; + releasecategory: MigrationElementModels.TaxonomyElement; /** - * Stars (modular_content) + * Released (date_time) * * Required: false - * Codename: stars - * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 + * Codename: released + * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 */ - stars: MigrationElementModels.LinkedItemsElement; + released: MigrationElementModels.DateTimeElement; /** * SeoName (url_slug) @@ -98,12 +89,21 @@ export type MovieItem = Item< seoname: MigrationElementModels.UrlSlugElement; /** - * ReleaseCategory (taxonomy) + * Stars (modular_content) * * Required: false - * Codename: releasecategory - * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 + * Codename: stars + * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 */ - releasecategory: MigrationElementModels.TaxonomyElement; + stars: MigrationElementModels.LinkedItemsElement; + + /** + * Title (text) + * + * Required: true + * Codename: title + * Id: 3473187e-dc78-eff2-7099-f690f7042d4a + */ + title: MigrationElementModels.TextElement; } >; diff --git a/sample/migration/migration.ts b/sample/migration/migration.ts index b9c4c9a..9d3f02b 100644 --- a/sample/migration/migration.ts +++ b/sample/migration/migration.ts @@ -35,7 +35,8 @@ export type ItemSystem = MigrationItemSy /** * Item object shared by all individual content type models */ -export type Item< - TCodename extends ContentTypeCodenames, - TElements extends MigrationElements = MigrationElements -> = MigrationItem, WorkflowStepCodenames>; +export type Item = MigrationItem< + TElements, + ItemSystem, + WorkflowStepCodenames +>; diff --git a/sample/project/contentTypes.ts b/sample/project/contentTypes.ts index 1954cb9..dcd3d55 100644 --- a/sample/project/contentTypes.ts +++ b/sample/project/contentTypes.ts @@ -23,18 +23,6 @@ export const contentTypes = { externalId: undefined, name: 'Actor', elements: { - /** - * Url (url_slug) - */ - url: { - codename: 'url', - id: 'c8658782-f209-a573-9c85-430fb4e3e9f0', - externalId: undefined, - name: 'Url', - required: false, - type: 'url_slug' - }, - /** * First name (text) * Guidelines: This is the first name of the actor @@ -70,6 +58,18 @@ export const contentTypes = { name: 'Photo', required: false, type: 'asset' + }, + + /** + * Url (url_slug) + */ + url: { + codename: 'url', + id: 'c8658782-f209-a573-9c85-430fb4e3e9f0', + externalId: undefined, + name: 'Url', + required: false, + type: 'url_slug' } } }, @@ -83,66 +83,6 @@ export const contentTypes = { externalId: undefined, name: 'Movie', elements: { - /** - * Title (text) - */ - title: { - codename: 'title', - id: '3473187e-dc78-eff2-7099-f690f7042d4a', - externalId: undefined, - name: 'Title', - required: true, - type: 'text' - }, - - /** - * Plot (rich_text) - */ - plot: { - codename: 'plot', - id: 'f7ee4f27-27fd-a19b-3c5c-102aae1c50ce', - externalId: undefined, - name: 'Plot', - required: false, - type: 'rich_text' - }, - - /** - * Released (date_time) - */ - released: { - codename: 'released', - id: '5ccf4644-0d65-5d96-9a32-f4ea21974d51', - externalId: undefined, - name: 'Released', - required: false, - type: 'date_time' - }, - - /** - * Length (number) - */ - length: { - codename: 'length', - id: '7e8ecfab-a419-27ee-d8ec-8adb76fd007c', - externalId: undefined, - name: 'Length', - required: false, - type: 'number' - }, - - /** - * Poster (asset) - */ - poster: { - codename: 'poster', - id: 'a39a7237-9503-a1ae-8431-5b6cdb85ae9d', - externalId: undefined, - name: 'Poster', - required: false, - type: 'asset' - }, - /** * Category (multiple_choice) */ @@ -154,26 +94,6 @@ export const contentTypes = { required: false, type: 'multiple_choice', options: { - /** - * Sci fi - */ - sciFi: { - name: 'Sci fi', - id: 'b087f774-1f57-9aa8-dab5-2ca88a646824', - codename: 'sci_fi', - externalId: undefined - }, - - /** - * Documentary - */ - documentary: { - name: 'Documentary', - id: '19c5e959-c24a-4863-0b4d-453cdef8fe9d', - codename: 'documentary', - externalId: undefined - }, - /** * Action */ @@ -185,12 +105,12 @@ export const contentTypes = { }, /** - * Romance + * Adventure */ - romance: { - name: 'Romance', - id: '60550cc7-c986-a59f-b069-7565862fe1c1', - codename: 'romance', + adventure: { + name: 'Adventure', + id: 'cd8389b0-7628-7739-7b14-3225a50212c1', + codename: 'adventure', externalId: undefined }, @@ -215,12 +135,12 @@ export const contentTypes = { }, /** - * Adventure + * Documentary */ - adventure: { - name: 'Adventure', - id: 'cd8389b0-7628-7739-7b14-3225a50212c1', - codename: 'adventure', + documentary: { + name: 'Documentary', + id: '19c5e959-c24a-4863-0b4d-453cdef8fe9d', + codename: 'documentary', externalId: undefined }, @@ -232,32 +152,64 @@ export const contentTypes = { id: '051e74de-f2e0-f405-9ad5-5263221e46f2', codename: 'drama', externalId: undefined + }, + + /** + * Romance + */ + romance: { + name: 'Romance', + id: '60550cc7-c986-a59f-b069-7565862fe1c1', + codename: 'romance', + externalId: undefined + }, + + /** + * Sci fi + */ + sciFi: { + name: 'Sci fi', + id: 'b087f774-1f57-9aa8-dab5-2ca88a646824', + codename: 'sci_fi', + externalId: undefined } } }, /** - * Stars (modular_content) + * Length (number) */ - stars: { - codename: 'stars', - id: 'aa26a55d-19f8-7501-fea3-b0d9b1eeac71', + length: { + codename: 'length', + id: '7e8ecfab-a419-27ee-d8ec-8adb76fd007c', externalId: undefined, - name: 'Stars', + name: 'Length', required: false, - type: 'modular_content' + type: 'number' }, /** - * SeoName (url_slug) + * Plot (rich_text) */ - seoname: { - codename: 'seoname', - id: '756cc91a-a090-60f9-a7f0-f505bfbe046c', + plot: { + codename: 'plot', + id: 'f7ee4f27-27fd-a19b-3c5c-102aae1c50ce', externalId: undefined, - name: 'SeoName', + name: 'Plot', required: false, - type: 'url_slug' + type: 'rich_text' + }, + + /** + * Poster (asset) + */ + poster: { + codename: 'poster', + id: 'a39a7237-9503-a1ae-8431-5b6cdb85ae9d', + externalId: undefined, + name: 'Poster', + required: false, + type: 'asset' }, /** @@ -270,6 +222,54 @@ export const contentTypes = { name: 'ReleaseCategory', required: false, type: 'taxonomy' + }, + + /** + * Released (date_time) + */ + released: { + codename: 'released', + id: '5ccf4644-0d65-5d96-9a32-f4ea21974d51', + externalId: undefined, + name: 'Released', + required: false, + type: 'date_time' + }, + + /** + * SeoName (url_slug) + */ + seoname: { + codename: 'seoname', + id: '756cc91a-a090-60f9-a7f0-f505bfbe046c', + externalId: undefined, + name: 'SeoName', + required: false, + type: 'url_slug' + }, + + /** + * Stars (modular_content) + */ + stars: { + codename: 'stars', + id: 'aa26a55d-19f8-7501-fea3-b0d9b1eeac71', + externalId: undefined, + name: 'Stars', + required: false, + type: 'modular_content' + }, + + /** + * Title (text) + */ + title: { + codename: 'title', + id: '3473187e-dc78-eff2-7099-f690f7042d4a', + externalId: undefined, + name: 'Title', + required: true, + type: 'text' } } } diff --git a/sample/project/index.ts b/sample/project/index.ts index 5122dd6..91a4ee3 100644 --- a/sample/project/index.ts +++ b/sample/project/index.ts @@ -13,12 +13,12 @@ * ------------------------------------------------------------------------------- **/ -export * from './languages.js'; +export * from './assetFolders.js'; export * from './collections.js'; export * from './contentTypes.js'; export * from './contentTypeSnippets.js'; -export * from './taxonomies.js'; -export * from './workflows.js'; +export * from './languages.js'; export * from './roles.js'; -export * from './assetFolders.js'; +export * from './taxonomies.js'; export * from './webhooks.js'; +export * from './workflows.js'; From 0b4a5c92b3c932ce39dc542b5a84e35bcddd9ed3 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 3 Sep 2024 11:05:13 +0200 Subject: [PATCH 052/183] removes comments manager --- lib/comments/index.ts | 1 - lib/config.ts | 42 +++++++++++++++++++ .../comment.utils.ts} | 25 ++++------- lib/core/core.config.ts | 41 ------------------ lib/core/index.ts | 1 + lib/files/file-manager.ts | 5 +-- .../delivery-content-type.generator.ts | 2 +- lib/generators/delivery/delivery-func.ts | 3 +- .../delivery/delivery-taxonomy.generator.ts | 2 +- lib/generators/migration/migration-func.ts | 11 +---- .../migration/migration.generator.ts | 21 +++++----- lib/generators/project/project-func.ts | 10 +---- lib/index.ts | 1 - 13 files changed, 71 insertions(+), 94 deletions(-) delete mode 100644 lib/comments/index.ts create mode 100644 lib/config.ts rename lib/{comments/comments.manager.ts => core/comment.utils.ts} (56%) diff --git a/lib/comments/index.ts b/lib/comments/index.ts deleted file mode 100644 index 63ec63f..0000000 --- a/lib/comments/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './comments.manager.js'; diff --git a/lib/config.ts b/lib/config.ts new file mode 100644 index 0000000..9dcfcf5 --- /dev/null +++ b/lib/config.ts @@ -0,0 +1,42 @@ +export const coreConfig = { + barrelExportFilename: 'index.ts' +} as const; + +export const migrationConfig = { + npmPackageName: '@kontent-ai/migration-toolkit', + migrationItemsFolderName: `content-types`, + environmentFolderName: `environment`, + migrationTypesFilename: `migration`, + environmentFilename: `environment`, + + sdkTypeNames: { + system: 'MigrationItemSystem', + item: 'MigrationItem', + elements: 'MigrationElements', + elementModels: 'MigrationElementModels' + }, + + localTypeNames: { + languageCodenames: 'LanguageCodenames', + collectionCodenames: 'CollectionCodenames', + workflowCodenames: 'WorkflowCodenames', + workflowStepCodenames: 'WorkflowStepCodenames', + contentTypeCodenames: 'ContentTypeCodenames', + system: 'ItemSystem', + item: 'Item', + codename: 'TCodename', + elements: 'TElements' + } +} as const; + +export const deliveryConfig = { + npmPackageName: '@kontent-ai/delivery-sdk', + contentTypesFolderName: `content-types`, + contentTypeSnippetsFolderName: `content-type-snippets`, + taxonomiesFolderName: `taxonomies`, + + sdkTypes: { + contentItem: 'IContentItem', + elements: 'Elements' + } +} as const; diff --git a/lib/comments/comments.manager.ts b/lib/core/comment.utils.ts similarity index 56% rename from lib/comments/comments.manager.ts rename to lib/core/comment.utils.ts index b630e08..bdeb781 100644 --- a/lib/comments/comments.manager.ts +++ b/lib/core/comment.utils.ts @@ -1,17 +1,16 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; -import { toSafeString } from '../core/index.js'; import { libMetadata } from '../meta/index.js'; +import { toSafeString } from './core.utils.js'; -export function commentsManager() { - const wrapComment = (comment: string): string => { - return `/** \n * ${comment} \n*/`; - }; +export function wrapComment(comment: string): string { + return `/** \n * ${comment} \n*/`; +} - const getEnvironmentInfoComment = (data: { - readonly addTimestamp?: boolean; - readonly environmentInfo: Readonly; - }): string => { - return ` +export function getEnvironmentInfoComment(data: { + readonly addTimestamp?: boolean; + readonly environmentInfo: Readonly; +}): string { + return ` /** * This file has been auto-generated by '${libMetadata.name}@${libMetadata.version}'. * @@ -25,10 +24,4 @@ export function commentsManager() { * * ------------------------------------------------------------------------------- **/`; - }; - - return { - wrapComment, - getEnvironmentInfoComment - }; } diff --git a/lib/core/core.config.ts b/lib/core/core.config.ts index 9dcfcf5..8b13789 100644 --- a/lib/core/core.config.ts +++ b/lib/core/core.config.ts @@ -1,42 +1 @@ -export const coreConfig = { - barrelExportFilename: 'index.ts' -} as const; -export const migrationConfig = { - npmPackageName: '@kontent-ai/migration-toolkit', - migrationItemsFolderName: `content-types`, - environmentFolderName: `environment`, - migrationTypesFilename: `migration`, - environmentFilename: `environment`, - - sdkTypeNames: { - system: 'MigrationItemSystem', - item: 'MigrationItem', - elements: 'MigrationElements', - elementModels: 'MigrationElementModels' - }, - - localTypeNames: { - languageCodenames: 'LanguageCodenames', - collectionCodenames: 'CollectionCodenames', - workflowCodenames: 'WorkflowCodenames', - workflowStepCodenames: 'WorkflowStepCodenames', - contentTypeCodenames: 'ContentTypeCodenames', - system: 'ItemSystem', - item: 'Item', - codename: 'TCodename', - elements: 'TElements' - } -} as const; - -export const deliveryConfig = { - npmPackageName: '@kontent-ai/delivery-sdk', - contentTypesFolderName: `content-types`, - contentTypeSnippetsFolderName: `content-type-snippets`, - taxonomiesFolderName: `taxonomies`, - - sdkTypes: { - contentItem: 'IContentItem', - elements: 'Elements' - } -} as const; diff --git a/lib/core/index.ts b/lib/core/index.ts index 17514e7..1e6d0e7 100644 --- a/lib/core/index.ts +++ b/lib/core/index.ts @@ -1,3 +1,4 @@ +export * from './comment.utils.js'; export * from './core.config.js'; export * from './core.models.js'; export * from './core.utils.js'; diff --git a/lib/files/file-manager.ts b/lib/files/file-manager.ts index 2521324..65364dc 100644 --- a/lib/files/file-manager.ts +++ b/lib/files/file-manager.ts @@ -3,8 +3,7 @@ import chalk from 'chalk'; import * as fs from 'fs'; import { dirname } from 'path'; import { Options } from 'prettier'; -import { commentsManager } from '../comments/index.js'; -import { GeneratedFile, toOutputDirPath } from '../core/index.js'; +import { GeneratedFile, getEnvironmentInfoComment, toOutputDirPath } from '../core/index.js'; import { formatCodeAsync } from '../format/formatter.js'; export function fileManager(config: { @@ -17,7 +16,7 @@ export function fileManager(config: { const createFileOnFsAsync = async (text: string, filePath: string, formatOptions: Readonly | undefined): Promise => { const fullFilePath = `${fixedOutputDir.endsWith('/') ? fixedOutputDir : `${fixedOutputDir}/`}${filePath}`; - const fileContent = `${commentsManager().getEnvironmentInfoComment({ + const fileContent = `${getEnvironmentInfoComment({ environmentInfo: config.environmentInfo, addTimestamp: config.addTimestamp })}\n\n${await getFormattedCodeAsync(text, filePath, formatOptions)}`; diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 03584e4..9fc314a 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -1,13 +1,13 @@ import { ContentTypeModels, ContentTypeSnippetModels, EnvironmentModels, TaxonomyModels } from '@kontent-ai/management-sdk'; import { isNotUndefined } from '@kontent-ai/migration-toolkit'; import { match, P } from 'ts-pattern'; +import { deliveryConfig } from '../../config.js'; import { importer as _importer, ContentTypeFileNameResolver, ContentTypeNameResolver, ContentTypeSnippetFileNameResolver, ContentTypeSnippetNameResolver, - deliveryConfig, FlattenedElement, GeneratedFile, GeneratorElementResolver, diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index 4999f26..4171452 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -1,13 +1,12 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; +import { coreConfig, deliveryConfig } from '../../config.js'; import { ContentTypeFileNameResolver, ContentTypeNameResolver, ContentTypeSnippetFileNameResolver, ContentTypeSnippetNameResolver, - coreConfig, - deliveryConfig, GeneratedFile, GeneratorElementResolver, getBarrelExportCode, diff --git a/lib/generators/delivery/delivery-taxonomy.generator.ts b/lib/generators/delivery/delivery-taxonomy.generator.ts index c92b63d..a3fd943 100644 --- a/lib/generators/delivery/delivery-taxonomy.generator.ts +++ b/lib/generators/delivery/delivery-taxonomy.generator.ts @@ -1,7 +1,7 @@ import { EnvironmentModels, TaxonomyModels } from '@kontent-ai/management-sdk'; +import { deliveryConfig } from '../../config.js'; import { - deliveryConfig, GeneratedFile, mapFilename, mapName, diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index e6a7266..2ee06c6 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -1,15 +1,8 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; -import { - coreConfig, - GeneratedFile, - getBarrelExportCode, - getDefaultModuleResolution, - getFilenameFromPath, - migrationConfig, - ModuleResolution -} from '../../core/index.js'; +import { coreConfig, migrationConfig } from '../../config.js'; +import { GeneratedFile, getBarrelExportCode, getDefaultModuleResolution, getFilenameFromPath, ModuleResolution } from '../../core/index.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; import { fileManager as _fileManager } from '../../files/index.js'; import { migrationGenerator as _migrationGenerator } from './migration.generator.js'; diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index 095ea3e..edf4b8c 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -8,19 +8,19 @@ import { WorkflowModels } from '@kontent-ai/management-sdk'; import { match } from 'ts-pattern'; -import { commentsManager as _commentsManager } from '../../comments/index.js'; +import { migrationConfig } from '../../config.js'; import { importer as _importer, FlattenedElement, GeneratedFile, getFlattenedElements, - migrationConfig, ModuleResolution, sortAlphabetically, toGuidelinesComment, toPascalCase, toSafeString, - uniqueFilter + uniqueFilter, + wrapComment } from '../../core/index.js'; export interface MigrationGeneratorConfig { @@ -38,7 +38,6 @@ export interface MigrationGeneratorConfig { } export function migrationGenerator(config: MigrationGeneratorConfig) { - const commentsManager = _commentsManager(); const importer = _importer(config.moduleResolution); const getMigrationItemType = (type: Readonly): GeneratedFile => { @@ -92,19 +91,19 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { { filename: `${migrationConfig.environmentFolderName}/${migrationConfig.environmentFilename}.ts`, text: ` - ${commentsManager.wrapComment('Type representing all languages')} + ${wrapComment('Type representing all languages')} ${getLanguageCodenamesType(config.environmentData.languages)} - ${commentsManager.wrapComment('Type representing all content types')} + ${wrapComment('Type representing all content types')} ${getContentTypeCodenamesType(config.environmentData.types)} - ${commentsManager.wrapComment('Type representing all collections')} + ${wrapComment('Type representing all collections')} ${getCollectionCodenamesType(config.environmentData.collections)} - ${commentsManager.wrapComment('Type representing all workflows')} + ${wrapComment('Type representing all workflows')} ${getWorkflowCodenamesType(config.environmentData.workflows)} - ${commentsManager.wrapComment('Type representing all worksflow steps across all workflows')} + ${wrapComment('Type representing all worksflow steps across all workflows')} ${getWorkflowStepCodenamesType(config.environmentData.workflows)} ` } @@ -124,10 +123,10 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { importValue: `${migrationConfig.localTypeNames.collectionCodenames}, ${migrationConfig.localTypeNames.contentTypeCodenames}, ${migrationConfig.localTypeNames.languageCodenames}, ${migrationConfig.localTypeNames.workflowCodenames}, ${migrationConfig.localTypeNames.workflowStepCodenames}` })} - ${commentsManager.wrapComment('System object shared by all individual content type models')} + ${wrapComment('System object shared by all individual content type models')} ${getSystemType()} - ${commentsManager.wrapComment('Item object shared by all individual content type models')} + ${wrapComment('Item object shared by all individual content type models')} ${getItemType()} ` } diff --git a/lib/generators/project/project-func.ts b/lib/generators/project/project-func.ts index 27b27bc..f7f8ad6 100644 --- a/lib/generators/project/project-func.ts +++ b/lib/generators/project/project-func.ts @@ -1,14 +1,8 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; -import { - coreConfig, - GeneratedFile, - getBarrelExportCode, - getDefaultModuleResolution, - getFilenameFromPath, - ModuleResolution -} from '../../core/index.js'; +import { coreConfig } from '../../config.js'; +import { GeneratedFile, getBarrelExportCode, getDefaultModuleResolution, getFilenameFromPath, ModuleResolution } from '../../core/index.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; import { fileManager as _fileManager } from '../../files/index.js'; import { projectGenerator as _projectGenerator } from './project.generator.js'; diff --git a/lib/index.ts b/lib/index.ts index d1b9a08..cf601bb 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -1,4 +1,3 @@ -export * from './comments/index.js'; export * from './core/index.js'; export * from './fetch/index.js'; export * from './files/index.js'; From 34ef29cf26690354cbc44194c39763da7a3f882d Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 3 Sep 2024 11:40:25 +0200 Subject: [PATCH 053/183] Loads kontent.ai items in paralel --- lib/core/core.config.ts | 1 - lib/core/core.utils.ts | 16 +++++------ lib/core/element.utils.ts | 2 +- lib/core/error.utils.ts | 9 ------- lib/core/index.ts | 1 - lib/fetch/kontent-fetcher.ts | 4 ++- lib/generators/delivery/delivery-func.ts | 13 ++++++--- lib/generators/migration/migration-func.ts | 21 ++++++++++----- lib/generators/project/project-func.ts | 30 ++++++++++++++------- sample/delivery/index.ts | 2 +- sample/migration/environment/environment.ts | 2 +- 11 files changed, 59 insertions(+), 42 deletions(-) delete mode 100644 lib/core/core.config.ts diff --git a/lib/core/core.config.ts b/lib/core/core.config.ts deleted file mode 100644 index 8b13789..0000000 --- a/lib/core/core.config.ts +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 2e43a38..585ab32 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -37,10 +37,6 @@ export function toSnakeCase(text: string): string { return toSafeStringCode(snakeCasePropertyNameResolver('', text)); } -export function removeLineEndings(value: string): string { - return value.replace(/(\r\n|\n|\r)/gm, ''); -} - export function toGuidelinesComment(guidelines: string): string { return toSafeString(removeLineEndings(guidelines)); } @@ -63,10 +59,6 @@ export function toOutputDirPath(outputDir?: string): string { return outputDir ? `${outputDir}/`.replaceAll('//', '/') : `./`; } -export function getExtensionForModuleResolution(moduleResolution: ModuleResolution): string { - return moduleResolution === 'nodeNext' ? '.js' : ''; -} - export function getBarrelExportCode(data: { readonly filenames: readonly string[]; readonly moduleResolution: ModuleResolution }): string { if (!data.filenames.length) { return 'export {}'; @@ -76,3 +68,11 @@ export function getBarrelExportCode(data: { readonly filenames: readonly string[ return (barrelCode += `export * from '${path.dir}/${path.name}${getExtensionForModuleResolution(data.moduleResolution)}';`); }, ''); } + +function getExtensionForModuleResolution(moduleResolution: ModuleResolution): string { + return moduleResolution === 'nodeNext' ? '.js' : ''; +} + +function removeLineEndings(value: string): string { + return value.replace(/(\r\n|\n|\r)/gm, ''); +} diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts index 756cf65..f2f40a4 100644 --- a/lib/core/element.utils.ts +++ b/lib/core/element.utils.ts @@ -49,7 +49,7 @@ export function getFlattenedElements( ); } -export function getFlattenedElement( +function getFlattenedElement( wrapper: ElementWrapper, taxonomies: readonly Readonly[], types: readonly Readonly[] diff --git a/lib/core/error.utils.ts b/lib/core/error.utils.ts index 86695ea..1b182da 100644 --- a/lib/core/error.utils.ts +++ b/lib/core/error.utils.ts @@ -37,15 +37,6 @@ export function extractErrorData(error: unknown): ErrorData { }); } -export function is404Error(error: unknown): boolean { - if (error instanceof SharedModels.ContentManagementBaseKontentError) { - const originalError = error.originalError as OriginalManagementError | undefined; - return originalError?.response?.status === 404; - } - - return false; -} - export function handleError(error: unknown): void { const errorData = extractErrorData(error); diff --git a/lib/core/index.ts b/lib/core/index.ts index 1e6d0e7..b32e185 100644 --- a/lib/core/index.ts +++ b/lib/core/index.ts @@ -1,5 +1,4 @@ export * from './comment.utils.js'; -export * from './core.config.js'; export * from './core.models.js'; export * from './core.utils.js'; export * from './element.utils.js'; diff --git a/lib/fetch/kontent-fetcher.ts b/lib/fetch/kontent-fetcher.ts index a165d8b..4c2b5f4 100644 --- a/lib/fetch/kontent-fetcher.ts +++ b/lib/fetch/kontent-fetcher.ts @@ -1,3 +1,4 @@ +import { HttpService } from '@kontent-ai/core-sdk'; import { AssetFolderModels, CollectionModels, @@ -25,7 +26,8 @@ export function kontentFetcher(config: KontentFetcherConfig) { return createManagementClient({ environmentId: config.environmentId, apiKey: config.apiKey, - baseUrl: config.baseUrl + baseUrl: config.baseUrl, + httpService: new HttpService({ logErrorsToConsole: false }) }); }; diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index 4171452..cd29980 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -84,14 +84,19 @@ async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ }); const environmentInfo = await kontentFetcher.getEnvironmentInfoAsync(); - const taxonomies = await kontentFetcher.getTaxonomiesAsync(); + + const [taxonomies, types, snippets] = await Promise.all([ + kontentFetcher.getTaxonomiesAsync(), + kontentFetcher.getTypesAsync(), + kontentFetcher.getSnippetsAsync() + ]); const { contentTypeFiles, snippetFiles } = deliveryContentTypeGenerator({ moduleResolution: moduleResolution, environmentData: { environment: environmentInfo, - types: await kontentFetcher.getTypesAsync(), - snippets: await kontentFetcher.getSnippetsAsync(), + types: types, + snippets: snippets, taxonomies: taxonomies }, fileResolvers: config.fileResolvers, @@ -101,7 +106,7 @@ async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ const taxonomyFiles = deliveryTaxonomyGenerator({ moduleResolution: moduleResolution, environmentData: { - environment: await kontentFetcher.getEnvironmentInfoAsync(), + environment: environmentInfo, taxonomies: taxonomies }, fileResolvers: config.fileResolvers, diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index 2ee06c6..29edef3 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -60,16 +60,25 @@ async function getFilesAsync(config: GenerateMigrationModelsConfig): Promise<{ 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 migrationGenerator = _migrationGenerator({ moduleResolution: config.moduleResolution, environmentData: { environment: environmentInfo, - taxonomies: await kontentFetcher.getTaxonomiesAsync(), - languages: await kontentFetcher.getLanguagesAsync(), - workflows: await kontentFetcher.getWorkflowsAsync(), - types: await kontentFetcher.getTypesAsync(), - snippets: await kontentFetcher.getSnippetsAsync(), - collections: await kontentFetcher.getCollectionsAsync() + taxonomies: taxonomies, + languages: languages, + workflows: workflows, + types: types, + snippets: snippets, + collections: collections } }); diff --git a/lib/generators/project/project-func.ts b/lib/generators/project/project-func.ts index f7f8ad6..ea13b1a 100644 --- a/lib/generators/project/project-func.ts +++ b/lib/generators/project/project-func.ts @@ -51,20 +51,32 @@ async function getModelsAsync(config: GenerateProjectModelsConfig): Promise<{ const environmentInfo = await kontentFetcher.getEnvironmentInfoAsync(); + const [languages, taxonomies, types, snippets, collections, workflows, webooks, assetFolders, roles] = await Promise.all([ + kontentFetcher.getLanguagesAsync(), + kontentFetcher.getTaxonomiesAsync(), + kontentFetcher.getTypesAsync(), + kontentFetcher.getSnippetsAsync(), + kontentFetcher.getCollectionsAsync(), + kontentFetcher.getWorkflowsAsync(), + kontentFetcher.getWebhooksAsync(), + kontentFetcher.getAssetFoldersAsync(), + config.isEnterpriseSubscription ? await kontentFetcher.getRolesAsync() : Promise.resolve([]) + ]); + return { environmentInfo, projectFiles: _projectGenerator({ environmentData: { environmentInfo: environmentInfo, - languages: await kontentFetcher.getLanguagesAsync(), - taxonomies: await kontentFetcher.getTaxonomiesAsync(), - types: await kontentFetcher.getTypesAsync(), - workflows: await kontentFetcher.getWorkflowsAsync(), - assetFolders: await kontentFetcher.getAssetFoldersAsync(), - collections: await kontentFetcher.getCollectionsAsync(), - roles: config.isEnterpriseSubscription ? await kontentFetcher.getRolesAsync() : [], - snippets: await kontentFetcher.getSnippetsAsync(), - webhooks: await kontentFetcher.getWebhooksAsync() + languages: languages, + taxonomies: taxonomies, + types: types, + workflows: workflows, + assetFolders: assetFolders, + collections: collections, + roles: roles, + snippets: snippets, + webhooks: webooks } }).generateProjectModel(), moduleResolution: moduleResolution diff --git a/sample/delivery/index.ts b/sample/delivery/index.ts index bb6a87e..45e59b5 100644 --- a/sample/delivery/index.ts +++ b/sample/delivery/index.ts @@ -13,6 +13,6 @@ * ------------------------------------------------------------------------------- **/ -export * from './content-types/index.js'; export * from './content-type-snippets/index.js'; +export * from './content-types/index.js'; export * from './taxonomies/index.js'; diff --git a/sample/migration/environment/environment.ts b/sample/migration/environment/environment.ts index 1675709..901b7eb 100644 --- a/sample/migration/environment/environment.ts +++ b/sample/migration/environment/environment.ts @@ -36,4 +36,4 @@ export type WorkflowCodenames = 'default'; /** * Type representing all worksflow steps across all workflows */ -export type WorkflowStepCodenames = 'draft' | 'review' | 'ready_to_publish' | 'published' | 'archived' | 'scheduled'; +export type WorkflowStepCodenames = 'archived' | 'draft' | 'published' | 'ready_to_publish' | 'review' | 'scheduled'; From fc9ec586e92094d372089e5bae7595c94c707c06 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 3 Sep 2024 11:40:44 +0200 Subject: [PATCH 054/183] Update project-func.ts --- lib/generators/project/project-func.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/project/project-func.ts b/lib/generators/project/project-func.ts index ea13b1a..c0ff9c3 100644 --- a/lib/generators/project/project-func.ts +++ b/lib/generators/project/project-func.ts @@ -60,7 +60,7 @@ async function getModelsAsync(config: GenerateProjectModelsConfig): Promise<{ kontentFetcher.getWorkflowsAsync(), kontentFetcher.getWebhooksAsync(), kontentFetcher.getAssetFoldersAsync(), - config.isEnterpriseSubscription ? await kontentFetcher.getRolesAsync() : Promise.resolve([]) + config.isEnterpriseSubscription ? kontentFetcher.getRolesAsync() : Promise.resolve([]) ]); return { From 7013249a15ec98e9869ad9f34d9864b32b3e8f96 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 3 Sep 2024 11:41:34 +0200 Subject: [PATCH 055/183] Update migration-func.ts --- lib/generators/migration/migration-func.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index 29edef3..644182c 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -22,13 +22,7 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('migration')}' models\n`); - const { - migrationItemFiles, - migrationTypeFiles: migrationTypeFiles, - moduleResolution, - environmentInfo, - environmentFiles - } = await getFilesAsync(config); + const { migrationItemFiles, migrationTypeFiles, moduleResolution, environmentInfo, environmentFiles } = await getFilesAsync(config); await createFilesAsync({ migrationItemFiles, From 4aa21ed17464ecc9035ce660691bc49639997008 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 3 Sep 2024 11:50:37 +0200 Subject: [PATCH 056/183] Adds sort --- .../delivery-content-type.generator.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 9fc314a..5404a61 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -153,10 +153,10 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato ), contentTypeExtends: data.typeOrSnippet instanceof ContentTypeModels.ContentType && snippets.length - ? `& ${snippets - .map((snippet) => nameResolvers.snippet(snippet)) - .filter(uniqueFilter) - .join(' & ')}` + ? `& ${sortAlphabetically( + snippets.map((snippet) => nameResolvers.snippet(snippet)).filter(uniqueFilter), + (snippetName) => snippetName + ).join(' & ')}` : undefined, typeName: data.typeOrSnippet instanceof ContentTypeModels.ContentType @@ -166,7 +166,10 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato }; const getDeliverySdkContentTypeImports = (flattenedElements: readonly FlattenedElement[]): readonly string[] => { - return [deliveryConfig.sdkTypes.contentItem, ...(flattenedElements.length ? [deliveryConfig.sdkTypes.elements] : [])]; + return sortAlphabetically( + [deliveryConfig.sdkTypes.contentItem, ...(flattenedElements.length ? [deliveryConfig.sdkTypes.elements] : [])], + (m) => m + ); }; const getModelCode = ( @@ -273,7 +276,10 @@ export type ${contentTypeImports.typeName} = ${deliveryConfig.sdkTypes.contentIt return [deliveryConfig.sdkTypes.contentItem]; } - return types.map((type) => nameResolvers.contentType(type)); + return sortAlphabetically( + types.map((type) => nameResolvers.contentType(type)), + (type) => type + ); }; return { From 2ebb7954b735e2b48e34247f7e2a9a879d4f61ca Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 3 Sep 2024 11:55:40 +0200 Subject: [PATCH 057/183] Updates CLI actions, uses pattern match for action input --- lib/core/core.models.ts | 3 +-- lib/node/cli/args/args-fetcher.ts | 27 +++++++++++++-------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index 5443f4a..ea99fd4 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -8,11 +8,10 @@ import { TaxonomyModels } from '@kontent-ai/management-sdk'; -export type CliAction = 'delivery' | 'migration'; +export type CliAction = 'delivery-sdk' | 'migration-toolkit' | 'environment'; export type LibraryType = '@kontent-ai/migration-toolkit' | '@kontent-ai/delivery-sdk'; export type ModuleResolution = 'nodeNext' | 'node'; export type CaseType = 'camelCase' | 'pascalCase' | 'snakeCase'; -export type ModelType = 'delivery' | 'migration'; export type GeneratorElementResolver = CaseType | PropertyNameResolver; export type GeneratorManagementClient = Readonly>; export type LiteralUnion = T | (string & NonNullable); diff --git a/lib/node/cli/args/args-fetcher.ts b/lib/node/cli/args/args-fetcher.ts index 05502ca..352650f 100644 --- a/lib/node/cli/args/args-fetcher.ts +++ b/lib/node/cli/args/args-fetcher.ts @@ -1,7 +1,8 @@ import chalk from 'chalk'; +import { match } from 'ts-pattern'; import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; -import { CliAction } from '../../../core/core.models.js'; +import { CliAction, LiteralUnion } from '../../../core/core.models.js'; import { CliArgumentsFetcher } from '../cli.models.js'; type ArgvResult = { @@ -20,20 +21,18 @@ export async function argumentsFetcherAsync(): Promise { return { getCliAction(): CliAction { - const command = resolvedArgv._?.[0]?.toString()?.toLowerCase(); - - if (command === 'delivery') { - return 'delivery'; - } - if (command === 'migration') { - return 'migration'; - } - - throw Error(`Unsupported command '${chalk.yellow(command)}'`); - }, - getOptionalArgumentValue(argName: string): string | undefined { - return resolvedArgv[argName]?.toString(); + const command = resolvedArgv._?.[0]?.toString()?.toLowerCase() as LiteralUnion; + + return match(command) + .returnType() + .with('delivery-sdk', () => 'delivery-sdk') + .with('migration-toolkit', () => 'migration-toolkit') + .with('environment', () => 'environment') + .otherwise(() => { + throw Error(`Unsupported command '${chalk.red(command)}'`); + }); }, + getOptionalArgumentValue, getRequiredArgumentValue(argName: string): string { const value = getOptionalArgumentValue(argName); From b80ea249378b5c63c868cf1e9a1cc4a395f35133 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 3 Sep 2024 12:00:22 +0200 Subject: [PATCH 058/183] Uses pattern match for cli app --- lib/node/cli/app.ts | 20 ++++++++++---------- sample/delivery/content-types/actor.ts | 2 +- sample/delivery/content-types/movie.ts | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/node/cli/app.ts b/lib/node/cli/app.ts index 31a5562..b3e8051 100644 --- a/lib/node/cli/app.ts +++ b/lib/node/cli/app.ts @@ -1,9 +1,11 @@ #!/usr/bin/env node import chalk from 'chalk'; +import { match } from 'ts-pattern'; import { handleError } from '../../core/index.js'; import { deliveryActionAsync } from './actions/delivery-action.js'; import { migrateActionAsync } from './actions/migrate-action.js'; +import { projectActionAsync } from './actions/project-action.js'; import { argumentsFetcherAsync } from './args/args-fetcher.js'; import { cliArgs } from './commands.js'; @@ -12,17 +14,15 @@ cliArgs.registerCommands(); const run = async () => { const argsFetcher = await argumentsFetcherAsync(); - const action = argsFetcher.getCliAction(); - if (action === 'delivery') { - return await deliveryActionAsync(argsFetcher); - } - - if (action === 'migration') { - return await migrateActionAsync(argsFetcher); - } - - throw Error(`Invalid action '${chalk.red(action)}'`); + return match(argsFetcher.getCliAction()) + .returnType>() + .with('delivery-sdk', async () => await deliveryActionAsync(argsFetcher)) + .with('migration-toolkit', async () => await migrateActionAsync(argsFetcher)) + .with('environment', async () => await projectActionAsync(argsFetcher)) + .otherwise((action) => { + throw Error(`Invalid action '${chalk.red(action)}'`); + }); }; run().catch((err) => { diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index e20f960..c23a5b2 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -13,7 +13,7 @@ * ------------------------------------------------------------------------------- **/ -import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; +import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; /** * Actor diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index a2a2461..085ea5c 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -13,7 +13,7 @@ * ------------------------------------------------------------------------------- **/ -import type { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; +import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; import type { Actor } from '../content-types/actor.js'; import type { Releasecategory } from '../taxonomies/releasecategory.js'; From df8b8fedde315e5f489b29e212488fa07706123e Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 3 Sep 2024 12:02:40 +0200 Subject: [PATCH 059/183] Renames project action to environment --- .../environment-func.ts} | 16 ++++++++-------- .../environment.generator.ts} | 6 +++--- lib/generators/index.ts | 4 ++-- .../{project-action.ts => environment-action.ts} | 6 +++--- lib/node/cli/app.ts | 4 ++-- scripts/tests/project-models.ts | 4 ++-- 6 files changed, 20 insertions(+), 20 deletions(-) rename lib/generators/{project/project-func.ts => environment/environment-func.ts} (86%) rename lib/generators/{project/project.generator.ts => environment/environment.generator.ts} (98%) rename lib/node/cli/actions/{project-action.ts => environment-action.ts} (77%) diff --git a/lib/generators/project/project-func.ts b/lib/generators/environment/environment-func.ts similarity index 86% rename from lib/generators/project/project-func.ts rename to lib/generators/environment/environment-func.ts index c0ff9c3..44ce35a 100644 --- a/lib/generators/project/project-func.ts +++ b/lib/generators/environment/environment-func.ts @@ -5,9 +5,9 @@ import { coreConfig } from '../../config.js'; import { GeneratedFile, getBarrelExportCode, getDefaultModuleResolution, getFilenameFromPath, ModuleResolution } from '../../core/index.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; import { fileManager as _fileManager } from '../../files/index.js'; -import { projectGenerator as _projectGenerator } from './project.generator.js'; +import { environmentGenerator as _environmentGenerator } from './environment.generator.js'; -export interface GenerateProjectModelsConfig { +export interface GenerateEnvironmentModelsConfig { readonly environmentId: string; readonly addTimestamp: boolean; readonly isEnterpriseSubscription: boolean; @@ -19,11 +19,11 @@ export interface GenerateProjectModelsConfig { readonly formatOptions?: Readonly; } -export async function generateProjectModelsAsync(config: GenerateProjectModelsConfig): Promise { +export async function generateEnvironmentModelsAsync(config: GenerateEnvironmentModelsConfig): Promise { console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('project')}' models\n`); - const { moduleResolution, projectFiles, environmentInfo } = await getModelsAsync(config); + const { moduleResolution, environmentFiles: projectFiles, environmentInfo } = await getModelsAsync(config); await createFilesAsync({ moduleResolution, @@ -37,8 +37,8 @@ export async function generateProjectModelsAsync(config: GenerateProjectModelsCo console.log(chalk.green(`\nCompleted`)); } -async function getModelsAsync(config: GenerateProjectModelsConfig): Promise<{ - projectFiles: readonly GeneratedFile[]; +async function getModelsAsync(config: GenerateEnvironmentModelsConfig): Promise<{ + environmentFiles: readonly GeneratedFile[]; moduleResolution: ModuleResolution; readonly environmentInfo: Readonly; }> { @@ -65,7 +65,7 @@ async function getModelsAsync(config: GenerateProjectModelsConfig): Promise<{ return { environmentInfo, - projectFiles: _projectGenerator({ + environmentFiles: _environmentGenerator({ environmentData: { environmentInfo: environmentInfo, languages: languages, @@ -78,7 +78,7 @@ async function getModelsAsync(config: GenerateProjectModelsConfig): Promise<{ snippets: snippets, webhooks: webooks } - }).generateProjectModel(), + }).generateEnvironmentModels(), moduleResolution: moduleResolution }; } diff --git a/lib/generators/project/project.generator.ts b/lib/generators/environment/environment.generator.ts similarity index 98% rename from lib/generators/project/project.generator.ts rename to lib/generators/environment/environment.generator.ts index 1f9275b..409ae21 100644 --- a/lib/generators/project/project.generator.ts +++ b/lib/generators/environment/environment.generator.ts @@ -44,8 +44,8 @@ export interface ProjectGeneratorConfig { }; } -export function projectGenerator(config: ProjectGeneratorConfig) { - const generateProjectModel = (): readonly GeneratedFile[] => { +export function environmentGenerator(config: ProjectGeneratorConfig) { + const generateEnvironmentModels = (): readonly GeneratedFile[] => { return [ { text: `export const languages = { @@ -353,6 +353,6 @@ export function projectGenerator(config: ProjectGeneratorConfig) { }; return { - generateProjectModel + generateEnvironmentModels }; } diff --git a/lib/generators/index.ts b/lib/generators/index.ts index 8c995e4..ff63b09 100644 --- a/lib/generators/index.ts +++ b/lib/generators/index.ts @@ -4,8 +4,8 @@ export * from './delivery/delivery-func.js'; export * from './delivery/delivery-taxonomy.generator.js'; // project -export * from './project/project-func.js'; -export * from './project/project.generator.js'; +export * from './environment/environment-func.js'; +export * from './environment/environment.generator.js'; // migration export * from './migration/migration-func.js'; diff --git a/lib/node/cli/actions/project-action.ts b/lib/node/cli/actions/environment-action.ts similarity index 77% rename from lib/node/cli/actions/project-action.ts rename to lib/node/cli/actions/environment-action.ts index c421629..6edd54f 100644 --- a/lib/node/cli/actions/project-action.ts +++ b/lib/node/cli/actions/environment-action.ts @@ -1,9 +1,9 @@ import { ModuleResolution } from '../../../core/index.js'; -import { generateProjectModelsAsync } from '../../../generators/index.js'; +import { generateEnvironmentModelsAsync } from '../../../generators/index.js'; import { CliArgumentsFetcher } from '../cli.models.js'; -export async function projectActionAsync(cliFetcher: CliArgumentsFetcher): Promise { - await generateProjectModelsAsync({ +export async function environmentActionAsync(cliFetcher: CliArgumentsFetcher): Promise { + await generateEnvironmentModelsAsync({ environmentId: cliFetcher.getRequiredArgumentValue('environmentId'), baseUrl: cliFetcher.getRequiredArgumentValue('managementApiUrl'), apiKey: cliFetcher.getRequiredArgumentValue('apiKey'), diff --git a/lib/node/cli/app.ts b/lib/node/cli/app.ts index b3e8051..413d315 100644 --- a/lib/node/cli/app.ts +++ b/lib/node/cli/app.ts @@ -4,8 +4,8 @@ import chalk from 'chalk'; import { match } from 'ts-pattern'; import { handleError } from '../../core/index.js'; import { deliveryActionAsync } from './actions/delivery-action.js'; +import { environmentActionAsync } from './actions/environment-action.js'; import { migrateActionAsync } from './actions/migrate-action.js'; -import { projectActionAsync } from './actions/project-action.js'; import { argumentsFetcherAsync } from './args/args-fetcher.js'; import { cliArgs } from './commands.js'; @@ -19,7 +19,7 @@ const run = async () => { .returnType>() .with('delivery-sdk', async () => await deliveryActionAsync(argsFetcher)) .with('migration-toolkit', async () => await migrateActionAsync(argsFetcher)) - .with('environment', async () => await projectActionAsync(argsFetcher)) + .with('environment', async () => await environmentActionAsync(argsFetcher)) .otherwise((action) => { throw Error(`Invalid action '${chalk.red(action)}'`); }); diff --git a/scripts/tests/project-models.ts b/scripts/tests/project-models.ts index 95e25bd..ec9adda 100644 --- a/scripts/tests/project-models.ts +++ b/scripts/tests/project-models.ts @@ -1,7 +1,7 @@ import chalk from 'chalk'; import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; -import { ModuleResolution, generateProjectModelsAsync, handleError } from '../../lib/index.js'; +import { ModuleResolution, generateEnvironmentModelsAsync, handleError } from '../../lib/index.js'; import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; const outputDir: string = './sample/project'; @@ -25,7 +25,7 @@ const run = async () => { const apiKey = getEnvironmentRequiredValue('API_KEY'); const moduleResolution = getEnvironmentRequiredValue('MODULE_RESOLUTION'); - await generateProjectModelsAsync({ + await generateEnvironmentModelsAsync({ addTimestamp: false, environmentId: environmentId, apiKey: apiKey, From 2442fe635faf7e5d2db0dd97358dc27d44b0da59 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 3 Sep 2024 12:35:23 +0200 Subject: [PATCH 060/183] Sets up commands & options --- lib/core/core.utils.ts | 14 ++- lib/generators/migration/migration-func.ts | 4 +- lib/node/cli/actions/delivery-action.ts | 6 +- lib/node/cli/actions/environment-action.ts | 10 +- lib/node/cli/actions/migrate-action.ts | 6 +- lib/node/cli/commands.ts | 113 +++++++++++---------- package.json | 3 +- 7 files changed, 91 insertions(+), 65 deletions(-) diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 585ab32..13cd1eb 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -1,11 +1,23 @@ import { camelCasePropertyNameResolver, pascalCasePropertyNameResolver, snakeCasePropertyNameResolver } from '@kontent-ai/delivery-sdk'; import { parse } from 'path'; -import { ModuleResolution } from './core.models.js'; +import { CliAction, LibraryType, ModuleResolution } from './core.models.js'; export function uniqueFilter(value: string, index: number, self: readonly string[]): boolean { return self.indexOf(value) === index; } +export function getCliAction(cliAction: CliAction): CliAction { + return cliAction; +} + +export function getLibrary(library: LibraryType): LibraryType { + return library; +} + +export function getModuleResolution(module: ModuleResolution): ModuleResolution { + return module; +} + export function getDefaultModuleResolution(moduleResolution: ModuleResolution | undefined): ModuleResolution { return moduleResolution ?? 'node'; } diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index 644182c..7eba8a3 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -12,8 +12,8 @@ export interface GenerateMigrationModelsConfig { readonly addTimestamp: boolean; readonly apiKey: string; readonly moduleResolution: ModuleResolution; - readonly outputDir: string; + readonly outputDir?: string; readonly baseUrl?: string; readonly formatOptions?: Readonly; } @@ -90,7 +90,7 @@ async function createFilesAsync(data: { readonly environmentFiles: readonly GeneratedFile[]; readonly migrationItemFiles: readonly GeneratedFile[]; readonly moduleResolution: ModuleResolution; - readonly outputDir: string; + readonly outputDir?: string; readonly formatOptions?: Readonly; readonly environmentInfo: Readonly; readonly addTimestamp: boolean; diff --git a/lib/node/cli/actions/delivery-action.ts b/lib/node/cli/actions/delivery-action.ts index fd5fc5a..40520d4 100644 --- a/lib/node/cli/actions/delivery-action.ts +++ b/lib/node/cli/actions/delivery-action.ts @@ -4,10 +4,12 @@ import { CliArgumentsFetcher } from '../cli.models.js'; export async function deliveryActionAsync(cliFetcher: CliArgumentsFetcher): Promise { await generateDeliveryModelsAsync({ + // required environmentId: cliFetcher.getRequiredArgumentValue('environmentId'), - baseUrl: cliFetcher.getRequiredArgumentValue('managementApiUrl'), apiKey: cliFetcher.getRequiredArgumentValue('apiKey'), - outputDir: cliFetcher.getRequiredArgumentValue('outputDir'), + // optional + baseUrl: cliFetcher.getOptionalArgumentValue('baseUrl'), + outputDir: cliFetcher.getOptionalArgumentValue('outputDir'), addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), moduleResolution: cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' }); diff --git a/lib/node/cli/actions/environment-action.ts b/lib/node/cli/actions/environment-action.ts index 6edd54f..ddca2be 100644 --- a/lib/node/cli/actions/environment-action.ts +++ b/lib/node/cli/actions/environment-action.ts @@ -4,12 +4,14 @@ import { CliArgumentsFetcher } from '../cli.models.js'; export async function environmentActionAsync(cliFetcher: CliArgumentsFetcher): Promise { await generateEnvironmentModelsAsync({ + // required environmentId: cliFetcher.getRequiredArgumentValue('environmentId'), - baseUrl: cliFetcher.getRequiredArgumentValue('managementApiUrl'), apiKey: cliFetcher.getRequiredArgumentValue('apiKey'), - outputDir: cliFetcher.getRequiredArgumentValue('outputDir'), - isEnterpriseSubscription: cliFetcher.getBooleanArgumentValue('isEnterpriseSubscription', false), + // optional + baseUrl: cliFetcher.getOptionalArgumentValue('baseUrl'), + outputDir: cliFetcher.getOptionalArgumentValue('outputDir'), addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), - moduleResolution: cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' + moduleResolution: cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext', + isEnterpriseSubscription: cliFetcher.getBooleanArgumentValue('isEnterpriseSubscription', false) }); } diff --git a/lib/node/cli/actions/migrate-action.ts b/lib/node/cli/actions/migrate-action.ts index 1c39ab8..0b596c1 100644 --- a/lib/node/cli/actions/migrate-action.ts +++ b/lib/node/cli/actions/migrate-action.ts @@ -4,10 +4,12 @@ import { CliArgumentsFetcher } from '../cli.models.js'; export async function migrateActionAsync(cliFetcher: CliArgumentsFetcher): Promise { await generateMigrationModelsAsync({ + // required environmentId: cliFetcher.getRequiredArgumentValue('environmentId'), - baseUrl: cliFetcher.getRequiredArgumentValue('managementApiUrl'), apiKey: cliFetcher.getRequiredArgumentValue('apiKey'), - outputDir: cliFetcher.getRequiredArgumentValue('outputDir'), + // optional + baseUrl: cliFetcher.getOptionalArgumentValue('baseUrl'), + outputDir: cliFetcher.getOptionalArgumentValue('outputDir'), addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), moduleResolution: cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' }); diff --git a/lib/node/cli/commands.ts b/lib/node/cli/commands.ts index 3163927..eb07275 100644 --- a/lib/node/cli/commands.ts +++ b/lib/node/cli/commands.ts @@ -1,60 +1,67 @@ +import { getCliAction, getLibrary, getModuleResolution } from '../../core/index.js'; import { argumentsSetter } from './args/args-setter.js'; +import { CommandOption } from './cli.models.js'; + +const environmentIdOption: CommandOption = { + name: `environmentId`, + description: `Id of the environment`, + type: 'string', + isRequired: true +}; + +const apiKeyOption: CommandOption = { + name: `apiKey`, + description: `Management API key`, + type: 'string', + isRequired: true +}; + +const outputDirOption: CommandOption = { + name: `outputDir`, + description: `Relative directory path where directory will be created`, + type: 'string', + isRequired: false +}; + +const addTimestampOption: CommandOption = { + name: `outputDir`, + description: `Indicates whether timestamp should be generated for every file`, + type: 'boolean', + isRequired: false +}; + +const moduleResolutionOption: CommandOption = { + name: `moduleResolution`, + description: `Module resolution for imports. Available options are: '${getModuleResolution('node')}', '${getModuleResolution('nodeNext')}'`, + type: 'string', + isRequired: false +}; + +const baseUrl: CommandOption = { + name: `baseUrl`, + description: `Base URL for Management API`, + type: 'string', + isRequired: false +}; export const cliArgs = argumentsSetter() .withCommand({ - name: 'delivery', - description: 'Generates Delivery & project models based on the content types and content items in your Kontent.ai project', - examples: [`kontent-generate delivery --environmentId=x --apiKey=x`], - options: [ - { - name: `environmentId`, - description: `Id of the environment`, - type: 'string', - isRequired: true - }, - { - name: `apiKey`, - description: `Management API key`, - type: 'string', - isRequired: true - }, - { - name: `outputDir`, - description: `Directory where generated files will be created`, - type: 'string', - isRequired: false - }, - { - name: `addTimestamp`, - description: `Indicates if timestamp should be generated`, - type: 'string', - isRequired: false - }, - { - name: `moduleResolution`, - description: `Module resolution for imports. Available options are: node, nodeNext`, - type: 'string', - isRequired: false - }, - { - name: `isEnterpriseSubscription`, - description: `Indicates if enterprise subscription endpoint can be used to export data`, - type: 'string', - isRequired: false - }, - { - name: `sortTaxonomyTerms`, - description: `Indicates if taxonomy terms are sorted alphabetically`, - type: 'string', - isRequired: false - }, - { - name: `managementApiUrl`, - description: `Sets the url of Management API`, - type: 'string', - isRequired: false - } - ] + name: getCliAction('delivery-sdk'), + description: `Generates models for '${getLibrary('@kontent-ai/delivery-sdk')}' library`, + examples: [`kontent-generate ${getCliAction('delivery-sdk')} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], + options: [environmentIdOption, apiKeyOption, addTimestampOption, moduleResolutionOption, outputDirOption, baseUrl] + }) + .withCommand({ + name: getCliAction('environment'), + description: `Generates strongly typed models representing all objects in the environment. This is useful for creating custom tools or scripts where you need to reference objects within your environment`, + examples: [`kontent-generate ${getCliAction('environment')} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], + options: [environmentIdOption, apiKeyOption, addTimestampOption, moduleResolutionOption, outputDirOption, baseUrl] + }) + .withCommand({ + name: getCliAction('migration-toolkit'), + description: `Generates models for '${getLibrary('@kontent-ai/migration-toolkit')}' library`, + examples: [`kontent-generate ${getCliAction('migration-toolkit')} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], + options: [environmentIdOption, apiKeyOption, addTimestampOption, moduleResolutionOption, outputDirOption, baseUrl] }) .withOption({ alias: `h`, diff --git a/package.json b/package.json index e27b705..4d651d1 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,8 @@ "test:delivery": "tsx scripts/tests/delivery-models", "test:project": "tsx scripts/tests/project-models", "test:migration": "tsx scripts/tests/migration-models", - "test:help": "tsx lib/node/cli/app delivery --help", + "test:help": "tsx lib/node/cli/app --help", + "test:help:delivery-sdk": "tsx lib/node/cli/app delivery-sdk --help", "lint": "npx eslint lib", "lint:fix": "npx eslint lib --fix", "clean": "tsx scripts/clean.ts", From 6839f0edf74518b80fd5087fb84ed88f6bf636fb Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 3 Sep 2024 12:51:31 +0200 Subject: [PATCH 061/183] typo --- lib/node/cli/app.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node/cli/app.ts b/lib/node/cli/app.ts index 413d315..e2973bc 100644 --- a/lib/node/cli/app.ts +++ b/lib/node/cli/app.ts @@ -9,7 +9,7 @@ import { migrateActionAsync } from './actions/migrate-action.js'; import { argumentsFetcherAsync } from './args/args-fetcher.js'; import { cliArgs } from './commands.js'; -// This enabled --help with all commands, options & samples +// This enables --help with all commands, options & samples cliArgs.registerCommands(); const run = async () => { From 8bc87a137abea1c77f12d31ea2c304343204d9af Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 3 Sep 2024 12:54:38 +0200 Subject: [PATCH 062/183] Use top level await --- lib/node/cli/app.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/node/cli/app.ts b/lib/node/cli/app.ts index e2973bc..8aa27e3 100644 --- a/lib/node/cli/app.ts +++ b/lib/node/cli/app.ts @@ -12,10 +12,10 @@ import { cliArgs } from './commands.js'; // This enables --help with all commands, options & samples cliArgs.registerCommands(); -const run = async () => { +try { const argsFetcher = await argumentsFetcherAsync(); - return match(argsFetcher.getCliAction()) + await match(argsFetcher.getCliAction()) .returnType>() .with('delivery-sdk', async () => await deliveryActionAsync(argsFetcher)) .with('migration-toolkit', async () => await migrateActionAsync(argsFetcher)) @@ -23,8 +23,6 @@ const run = async () => { .otherwise((action) => { throw Error(`Invalid action '${chalk.red(action)}'`); }); -}; - -run().catch((err) => { - handleError(err); -}); +} catch (error) { + handleError(error); +} From 6af41cd300139b232fce374a6383ca8dd7881fa7 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 3 Sep 2024 13:22:35 +0200 Subject: [PATCH 063/183] Updates readme --- README.md | 231 +++++++++--------------------------------------------- 1 file changed, 39 insertions(+), 192 deletions(-) diff --git a/README.md b/README.md index e8ffeb1..6f6e0fd 100644 --- a/README.md +++ b/README.md @@ -4,224 +4,71 @@ # Kontent.ai Model Generator -The purpose of this project is to help you generate `Typescript models` based on [Kontent.ai](https://kontent.ai) item types. These models -can be used with the [Delivery SDK](https://www.npmjs.com/package/@kontent-ai/delivery-sdk) and enhances your experience by providing -strongly typed models. +The purpose of this library is to help you write better code by using strongly typed objects or Typescript models. There are 3 types of +models you can generate: + +1. `delivery-sdk` - Typescript models for [JS Delivery SDK](https://www.npmjs.com/package/@kontent-ai/delivery-sdk) representing Content + types / taxonomies +2. `migration-toolkit` - Typescript models [Migration Toolkit](https://www.npmjs.com/package/@kontent-ai/migration-toolkit) helping you + write migration scripts easier +3. `environment` - Strongly typed objects representing all structural objects within an environment (i.e. content types, workflows, + taxonomies ...). These models help you write scripts because they provide you a straightforward access to objects properties. ## Installation Install package globally so you can use it anywhere: -`npm i @kontent-ai/model-generator -g` +```bash +npm i @kontent-ai/model-generator -g +``` -## Generate models with CLI +## Use with CLI Go to folder where you want to create models and run: -`kontent-generate --environmentId=xxx --apiKey=yyy` +```bash +kontent-generate delivery-sdk --environmentId=x --apiKey=y +kontent-generate migration-toolkit --environmentId=x --apiKey=y +kontent-generate environment --environmentId=x --apiKey=y +``` -You may specify other options like: +To learn what options are available use the `help` command: -`kontent-generate --environmentId=xxx --apiKey=yyy --addTimestamp=false --elementResolver=camelCase` +```bash +kontent-generate --help -## Generate models in code +# or get help for specific command +kontent-generate delivery-sdk --help +``` -Apart from generating models via CLI, you may also generate models in code which also gives you some additional configuration options (such -as using custom name resolver). +## Use in code ```typescript -import { generateDeliveryModelsAsync } from '@kontent-ai/model-generator'; +import { generateDeliveryModelsAsync, generateEnvironmentModelsAsync, generateMigrationModelsAsync } from '@kontent-ai/model-generator'; +// delivery-sdk models await generateDeliveryModelsAsync({ - sdkType: 'delivery', - environmentId: 'da5abe9f-fdad-4168-97cd-b3464be2ccb9', - isEnterpriseSubscription: true, - apiKey: 'yyy', - addTimestamp: true, - moduleResolution: 'nodeNext', - elementResolver: 'camelCase', - sortConfig: { - sortTaxonomyTerms: true - } + ... }); -``` -### Customizing generated file names - -You may customize the way filenames are stored on file system using the `contentTypeFileResolver` and / or `taxonomyTypeFileResolver` -configuration option: - -```typescript -await generateDeliveryModelsAsync({ - sdkType: 'delivery', - environmentId: 'da5abe9f-fdad-4168-97cd-b3464be2ccb9', - isEnterpriseSubscription: true, - apiKey: 'yyy', - moduleResolution: 'nodeNext', - addTimestamp: true, - elementResolver: 'camelCase', - contentTypeFileResolver: (type) => `content_type_${type.codename}`, - taxonomyTypeFileResolver: (taxonomy) => `taxonomy_${taxonomy.codename}` +// migration-toolkit models +await generateMigrationModelsAsync({ + ... }); -``` -### Customizing generated content type names - -You may customize name of content types using the `contentTypeResolver` configuration option and taxonomy types with the -`taxonomyTypeResolver` option: - -```typescript -await generateDeliveryModelsAsync({ - sdkType: 'delivery', - environmentId: 'da5abe9f-fdad-4168-97cd-b3464be2ccb9', - isEnterpriseSubscription: true, - apiKey: 'yyy', - moduleResolution: 'nodeNext', - addTimestamp: true, - elementResolver: 'camelCase', - contentTypeResolver: (type) => `${textHelper.toPascalCase(type.codename)}Model`, - taxonomyTypeResolver: (taxonomy) => `${textHelper.toPascalCase(taxonomy.codename)}Taxonomy` +// environment models +await generateEnvironmentModelsAsync({ + ... }); ``` -## FAQ - -- If you are getting the `The Subscription API is not supported in your plan` error, set the `isEnterpriseSubscription` option to false - -## CLI Configuration - -- `environmentId` - Id of the Kontent.ai environment -- `apiKey`- Management API Key -- `outputDir`- Directory where files will be created. Defaults to current directory - `--outputDir=./`. Some other examples: - `--outputDir=./sample` -- `isEnterpriseSubscription` - Indicates if enterprise subscription endpoint can be used to export data. -- `addTimestamp`- Indicates if timestamp is added to generated models -- `elementResolver`- Name resolver for elements. Available options are: `camelCase`, `pascalCase`, `snakeCase` -- `contentTypeFileResolver`- Name resolver for content type filenames. Available options are: `camelCase`, `pascalCase`, `snakeCase` -- `contentTypeSnippetFileResolver`- Name resolver for content type snippet filenames. Available options are: `camelCase`, `pascalCase`, - `snakeCase` -- `taxonomyTypeFileResolver`- Name resolver for taxonomy filenames. Available options are: `camelCase`, `pascalCase`, `snakeCase` -- `contentTypeResolver`- Name resolver for content type names. Available options are: `camelCase`, `pascalCase`, `snakeCase` -- `contentTypeSnippetResolver`- Name resolver for content type snippet names. Available options are: `camelCase`, `pascalCase`, - `snakeCase` -- `taxonomyTypeResolver`- Name resolver for taxonomy type names. Available options are: `camelCase`, `pascalCase`, `snakeCase` -- `sdkType`- Type of sdk for which models are generated. Available options are: `delivery`, `migration` -- `exportWebhooks` - Indicates if webhooks are exported -- `exportWorkflows` - Indicates if workflows are exported -- `exportAssetFolders` - Indicates if asset folders are exported -- `exportCollections` - Indicates if collections are exported -- `exportLanguages` - Indicates if languages are exported -- `exportRoles` - Indicates if roles are exported. \* Only available for Enterprise subscription plans -- `managementApiUrl` - Sets the url of Management API. -- `moduleResolution` - Module resolution for imports. Available options are: `node`, `nodeNext` - -## Example models - -Generator creates file for each content type in your project. For example: - -`movie.ts` - -```typescript -import { IContentItem, Elements } from '@kontent-ai/delivery-sdk'; -import { Actor } from './actor'; -import { ReleaseCategory } from '../taxonomies/releasecategory'; - -/** - * Generated by '@kontent-ai/model-generator@5.0.0-3' at 'Thu, 14 Jul 2022 13:58:53 GMT' - * - * Movie - * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c - * Codename: movie - */ -export type Movie = IContentItem<{ - /** - * Title (text) - * Required: true - * Id: 3473187e-dc78-eff2-7099-f690f7042d4a - * Codename: title - */ - title: Elements.TextElement; - - /** - * Plot (rich_text) - * Required: false - * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce - * Codename: plot - */ - plot: Elements.RichTextElement; - - /** - * Released (date_time) - * Required: false - * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 - * Codename: released - */ - released: Elements.DateTimeElement; - - /** - * Length (number) - * Required: false - * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c - * Codename: length - */ - length: Elements.NumberElement; - - /** - * Poster (asset) - * Required: false - * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d - * Codename: poster - */ - poster: Elements.AssetsElement; - - /** - * Category (multiple_choice) - * Required: false - * Id: 9821c252-6414-f549-c17f-cc171dd87713 - * Codename: category - */ - category: Elements.MultipleChoiceElement; - - /** - * Stars (modular_content) - * Required: false - * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 - * Codename: stars - */ - stars: Elements.LinkedItemsElement; - - /** - * SeoName (url_slug) - * Required: false - * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c - * Codename: seoname - */ - seoname: Elements.UrlSlugElement; - - /** - * ReleaseCategory (taxonomy) - * Required: false - * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 - * Codename: releasecategory - */ - releasecategory: Elements.TaxonomyElement; -}>; -``` - -`movietype.ts` +## Sample models -```typescript -/** - * Generated by '@kontent-ai/model-generator@5.0.0' at 'Mon, 28 Mar 2022 14:36:32 GMT' - * - * MovieType - * Id: 365a17e6-1929-27ab-9f67-a9273c846717 - * Codename: movietype - */ -export type MovieType = 'student' | 'film' | 'tv' | 'blockbuster' | 'cinema_only'; -``` +To see how models are generated have a look at following sample generated models: -To learn the complete generator output, see the following folder: https://github.com/kontent-ai/model-generator-js/tree/master/sample +1. `delivery-sdk` -> https://github.com/kontent-ai/model-generator-js/tree/master/sample/delivery +2. `migration-toolkit` -> https://github.com/kontent-ai/model-generator-js/tree/master/sample/migration +3. `environment` -> https://github.com/kontent-ai/model-generator-js/tree/master/sample/environment ## Contribution & Feedback From dbf06938a2dbd4d4a839ca6337cd7b7a0e5f3e6b Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 3 Sep 2024 13:22:42 +0200 Subject: [PATCH 064/183] Updates project -> environment sample --- package.json | 2 +- sample/{project => environment}/assetFolders.ts | 0 sample/{project => environment}/collections.ts | 0 sample/{project => environment}/contentTypeSnippets.ts | 0 sample/{project => environment}/contentTypes.ts | 0 sample/{project => environment}/index.ts | 0 sample/{project => environment}/languages.ts | 0 sample/{project => environment}/roles.ts | 0 sample/{project => environment}/taxonomies.ts | 0 sample/{project => environment}/webhooks.ts | 0 sample/{project => environment}/workflows.ts | 0 scripts/tests/{project-models.ts => environment-models.ts} | 2 +- 12 files changed, 2 insertions(+), 2 deletions(-) rename sample/{project => environment}/assetFolders.ts (100%) rename sample/{project => environment}/collections.ts (100%) rename sample/{project => environment}/contentTypeSnippets.ts (100%) rename sample/{project => environment}/contentTypes.ts (100%) rename sample/{project => environment}/index.ts (100%) rename sample/{project => environment}/languages.ts (100%) rename sample/{project => environment}/roles.ts (100%) rename sample/{project => environment}/taxonomies.ts (100%) rename sample/{project => environment}/webhooks.ts (100%) rename sample/{project => environment}/workflows.ts (100%) rename scripts/tests/{project-models.ts => environment-models.ts} (96%) diff --git a/package.json b/package.json index 4d651d1..41a8cea 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "build": "npm run lint && npm run clean && npm run build:es2022", "test:all": "npm run build && npm run test:delivery-models", "test:delivery": "tsx scripts/tests/delivery-models", - "test:project": "tsx scripts/tests/project-models", + "test:environment": "tsx scripts/tests/environment-models", "test:migration": "tsx scripts/tests/migration-models", "test:help": "tsx lib/node/cli/app --help", "test:help:delivery-sdk": "tsx lib/node/cli/app delivery-sdk --help", diff --git a/sample/project/assetFolders.ts b/sample/environment/assetFolders.ts similarity index 100% rename from sample/project/assetFolders.ts rename to sample/environment/assetFolders.ts diff --git a/sample/project/collections.ts b/sample/environment/collections.ts similarity index 100% rename from sample/project/collections.ts rename to sample/environment/collections.ts diff --git a/sample/project/contentTypeSnippets.ts b/sample/environment/contentTypeSnippets.ts similarity index 100% rename from sample/project/contentTypeSnippets.ts rename to sample/environment/contentTypeSnippets.ts diff --git a/sample/project/contentTypes.ts b/sample/environment/contentTypes.ts similarity index 100% rename from sample/project/contentTypes.ts rename to sample/environment/contentTypes.ts diff --git a/sample/project/index.ts b/sample/environment/index.ts similarity index 100% rename from sample/project/index.ts rename to sample/environment/index.ts diff --git a/sample/project/languages.ts b/sample/environment/languages.ts similarity index 100% rename from sample/project/languages.ts rename to sample/environment/languages.ts diff --git a/sample/project/roles.ts b/sample/environment/roles.ts similarity index 100% rename from sample/project/roles.ts rename to sample/environment/roles.ts diff --git a/sample/project/taxonomies.ts b/sample/environment/taxonomies.ts similarity index 100% rename from sample/project/taxonomies.ts rename to sample/environment/taxonomies.ts diff --git a/sample/project/webhooks.ts b/sample/environment/webhooks.ts similarity index 100% rename from sample/project/webhooks.ts rename to sample/environment/webhooks.ts diff --git a/sample/project/workflows.ts b/sample/environment/workflows.ts similarity index 100% rename from sample/project/workflows.ts rename to sample/environment/workflows.ts diff --git a/scripts/tests/project-models.ts b/scripts/tests/environment-models.ts similarity index 96% rename from scripts/tests/project-models.ts rename to scripts/tests/environment-models.ts index ec9adda..ea2cb83 100644 --- a/scripts/tests/project-models.ts +++ b/scripts/tests/environment-models.ts @@ -4,7 +4,7 @@ import { rmSync } from 'fs'; import { ModuleResolution, generateEnvironmentModelsAsync, handleError } from '../../lib/index.js'; import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; -const outputDir: string = './sample/project'; +const outputDir: string = './sample/environment'; const run = async () => { // needed to load .env environment to current process when run via package.json script From 217b735626b449807a3f2973df84b1c4bd0298db Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 3 Sep 2024 13:24:22 +0200 Subject: [PATCH 065/183] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 6f6e0fd..8c317f9 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,13 @@ npm i @kontent-ai/model-generator -g Go to folder where you want to create models and run: ```bash +# Models for Delivery SDK kontent-generate delivery-sdk --environmentId=x --apiKey=y + +# Models for Migration Toolkit kontent-generate migration-toolkit --environmentId=x --apiKey=y + +# Environment models used for scripting and strongly typed access to environment objects kontent-generate environment --environmentId=x --apiKey=y ``` From 1c9d2ca063cb29e0d4cb44c754bd6ece97203ce0 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 3 Sep 2024 13:25:39 +0200 Subject: [PATCH 066/183] Update LICENSE.md --- LICENSE.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 4b1c689..a2d4b36 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,9 +1,15 @@ MIT License -Copyright (c) 2022 Kontent s.r.o. +Copyright (c) 2024 Kontent.ai -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the +following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. From 2e8c08d407554401114c1d06f390cbc06e829f88 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 4 Sep 2024 08:32:19 +0200 Subject: [PATCH 067/183] updates deps --- package-lock.json | 110 +++++++++++++++++++++++----------------------- package.json | 8 ++-- 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/package-lock.json b/package-lock.json index a472905..97138d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,16 +22,16 @@ }, "devDependencies": { "@types/eslint__js": "8.42.3", - "@types/node": "22.5.2", + "@types/node": "22.5.3", "@types/yargs": "17.0.33", - "@typescript-eslint/eslint-plugin": "8.3.0", - "@typescript-eslint/parser": "8.3.0", + "@typescript-eslint/eslint-plugin": "8.4.0", + "@typescript-eslint/parser": "8.4.0", "dotenv-cli": "7.4.2", "eslint": "9.9.1", "standard-version": "9.5.0", "tsx": "4.19.0", "typescript": "5.5.4", - "typescript-eslint": "8.3.0" + "typescript-eslint": "8.4.0" }, "engines": { "node": ">= 20" @@ -849,9 +849,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.5.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.2.tgz", - "integrity": "sha512-acJsPTEqYqulZS/Yp/S3GgeE6GZ0qYODUR8aVr/DkhHQ8l9nd4j5x1/ZJy9/gHrRlFMqkO6i0I3E27Alu4jjPg==", + "version": "22.5.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.3.tgz", + "integrity": "sha512-njripolh85IA9SQGTAqbmnNZTdxv7X/4OYGPz8tgy5JDr8MP+uDBa921GpYEoDDnwm0Hmn5ZPeJgiiSTPoOzkQ==", "dev": true, "dependencies": { "undici-types": "~6.19.2" @@ -879,16 +879,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.3.0.tgz", - "integrity": "sha512-FLAIn63G5KH+adZosDYiutqkOkYEx0nvcwNNfJAf+c7Ae/H35qWwTYvPZUKFj5AS+WfHG/WJJfWnDnyNUlp8UA==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.4.0.tgz", + "integrity": "sha512-rg8LGdv7ri3oAlenMACk9e+AR4wUV0yrrG+XKsGKOK0EVgeEDqurkXMPILG2836fW4ibokTB5v4b6Z9+GYQDEw==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "8.3.0", - "@typescript-eslint/type-utils": "8.3.0", - "@typescript-eslint/utils": "8.3.0", - "@typescript-eslint/visitor-keys": "8.3.0", + "@typescript-eslint/scope-manager": "8.4.0", + "@typescript-eslint/type-utils": "8.4.0", + "@typescript-eslint/utils": "8.4.0", + "@typescript-eslint/visitor-keys": "8.4.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", @@ -912,15 +912,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.3.0.tgz", - "integrity": "sha512-h53RhVyLu6AtpUzVCYLPhZGL5jzTD9fZL+SYf/+hYOx2bDkyQXztXSc4tbvKYHzfMXExMLiL9CWqJmVz6+78IQ==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.4.0.tgz", + "integrity": "sha512-NHgWmKSgJk5K9N16GIhQ4jSobBoJwrmURaLErad0qlLjrpP5bECYg+wxVTGlGZmJbU03jj/dfnb6V9bw+5icsA==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "8.3.0", - "@typescript-eslint/types": "8.3.0", - "@typescript-eslint/typescript-estree": "8.3.0", - "@typescript-eslint/visitor-keys": "8.3.0", + "@typescript-eslint/scope-manager": "8.4.0", + "@typescript-eslint/types": "8.4.0", + "@typescript-eslint/typescript-estree": "8.4.0", + "@typescript-eslint/visitor-keys": "8.4.0", "debug": "^4.3.4" }, "engines": { @@ -940,13 +940,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.3.0.tgz", - "integrity": "sha512-mz2X8WcN2nVu5Hodku+IR8GgCOl4C0G/Z1ruaWN4dgec64kDBabuXyPAr+/RgJtumv8EEkqIzf3X2U5DUKB2eg==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.4.0.tgz", + "integrity": "sha512-n2jFxLeY0JmKfUqy3P70rs6vdoPjHK8P/w+zJcV3fk0b0BwRXC/zxRTEnAsgYT7MwdQDt/ZEbtdzdVC+hcpF0A==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.3.0", - "@typescript-eslint/visitor-keys": "8.3.0" + "@typescript-eslint/types": "8.4.0", + "@typescript-eslint/visitor-keys": "8.4.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -957,13 +957,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.3.0.tgz", - "integrity": "sha512-wrV6qh//nLbfXZQoj32EXKmwHf4b7L+xXLrP3FZ0GOUU72gSvLjeWUl5J5Ue5IwRxIV1TfF73j/eaBapxx99Lg==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.4.0.tgz", + "integrity": "sha512-pu2PAmNrl9KX6TtirVOrbLPLwDmASpZhK/XU7WvoKoCUkdtq9zF7qQ7gna0GBZFN0hci0vHaSusiL2WpsQk37A==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "8.3.0", - "@typescript-eslint/utils": "8.3.0", + "@typescript-eslint/typescript-estree": "8.4.0", + "@typescript-eslint/utils": "8.4.0", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -981,9 +981,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.3.0.tgz", - "integrity": "sha512-y6sSEeK+facMaAyixM36dQ5NVXTnKWunfD1Ft4xraYqxP0lC0POJmIaL/mw72CUMqjY9qfyVfXafMeaUj0noWw==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.4.0.tgz", + "integrity": "sha512-T1RB3KQdskh9t3v/qv7niK6P8yvn7ja1mS7QK7XfRVL6wtZ8/mFs/FHf4fKvTA0rKnqnYxl/uHFNbnEt0phgbw==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -994,13 +994,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.3.0.tgz", - "integrity": "sha512-Mq7FTHl0R36EmWlCJWojIC1qn/ZWo2YiWYc1XVtasJ7FIgjo0MVv9rZWXEE7IK2CGrtwe1dVOxWwqXUdNgfRCA==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.4.0.tgz", + "integrity": "sha512-kJ2OIP4dQw5gdI4uXsaxUZHRwWAGpREJ9Zq6D5L0BweyOrWsL6Sz0YcAZGWhvKnH7fm1J5YFE1JrQL0c9dd53A==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.3.0", - "@typescript-eslint/visitor-keys": "8.3.0", + "@typescript-eslint/types": "8.4.0", + "@typescript-eslint/visitor-keys": "8.4.0", "debug": "^4.3.4", "fast-glob": "^3.3.2", "is-glob": "^4.0.3", @@ -1022,15 +1022,15 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.3.0.tgz", - "integrity": "sha512-F77WwqxIi/qGkIGOGXNBLV7nykwfjLsdauRB/DOFPdv6LTF3BHHkBpq81/b5iMPSF055oO2BiivDJV4ChvNtXA==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.4.0.tgz", + "integrity": "sha512-swULW8n1IKLjRAgciCkTCafyTHHfwVQFt8DovmaF69sKbOxTSFMmIZaSHjqO9i/RV0wIblaawhzvtva8Nmm7lQ==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "8.3.0", - "@typescript-eslint/types": "8.3.0", - "@typescript-eslint/typescript-estree": "8.3.0" + "@typescript-eslint/scope-manager": "8.4.0", + "@typescript-eslint/types": "8.4.0", + "@typescript-eslint/typescript-estree": "8.4.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1044,12 +1044,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.3.0.tgz", - "integrity": "sha512-RmZwrTbQ9QveF15m/Cl28n0LXD6ea2CjkhH5rQ55ewz3H24w+AMCJHPVYaZ8/0HoG8Z3cLLFFycRXxeO2tz9FA==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.4.0.tgz", + "integrity": "sha512-zTQD6WLNTre1hj5wp09nBIDiOc2U5r/qmzo7wxPn4ZgAjHql09EofqhF9WF+fZHzL5aCyaIpPcT2hyxl73kr9A==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.3.0", + "@typescript-eslint/types": "8.4.0", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -5156,14 +5156,14 @@ } }, "node_modules/typescript-eslint": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.3.0.tgz", - "integrity": "sha512-EvWjwWLwwKDIJuBjk2I6UkV8KEQcwZ0VM10nR1rIunRDIP67QJTZAHBXTX0HW/oI1H10YESF8yWie8fRQxjvFA==", + "version": "8.4.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.4.0.tgz", + "integrity": "sha512-67qoc3zQZe3CAkO0ua17+7aCLI0dU+sSQd1eKPGq06QE4rfQjstVXR6woHO5qQvGUa550NfGckT4tzh3b3c8Pw==", "dev": true, "dependencies": { - "@typescript-eslint/eslint-plugin": "8.3.0", - "@typescript-eslint/parser": "8.3.0", - "@typescript-eslint/utils": "8.3.0" + "@typescript-eslint/eslint-plugin": "8.4.0", + "@typescript-eslint/parser": "8.4.0", + "@typescript-eslint/utils": "8.4.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" diff --git a/package.json b/package.json index 41a8cea..1778218 100644 --- a/package.json +++ b/package.json @@ -62,11 +62,11 @@ "@types/yargs": "17.0.33", "standard-version": "9.5.0", "typescript": "5.5.4", - "@types/node": "22.5.2", + "@types/node": "22.5.3", "@types/eslint__js": "8.42.3", - "@typescript-eslint/eslint-plugin": "8.3.0", - "typescript-eslint": "8.3.0", - "@typescript-eslint/parser": "8.3.0", + "@typescript-eslint/eslint-plugin": "8.4.0", + "typescript-eslint": "8.4.0", + "@typescript-eslint/parser": "8.4.0", "eslint": "9.9.1", "tsx": "4.19.0", "dotenv-cli": "7.4.2" From 20ae2429ed352ea1d6d1524dfcbb5485d6558264 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 4 Sep 2024 08:40:28 +0200 Subject: [PATCH 068/183] Simplifies version script, uses top-level await for sample codes --- .../delivery/content-type-snippets/index.ts | 16 --- sample/delivery/content-types/actor.ts | 58 ----------- sample/delivery/content-types/index.ts | 17 ---- sample/delivery/content-types/movie.ts | 99 ------------------- sample/delivery/index.ts | 18 ---- sample/delivery/taxonomies/index.ts | 17 ---- sample/delivery/taxonomies/movietype.ts | 22 ----- sample/delivery/taxonomies/releasecategory.ts | 22 ----- scripts/file-version-script.ts | 27 ----- scripts/tests/delivery-models.ts | 10 +- scripts/tests/environment-models.ts | 10 +- scripts/tests/migration-models.ts | 10 +- scripts/update-version.ts | 21 +++- scripts/utils/test.utils.ts | 9 +- 14 files changed, 32 insertions(+), 324 deletions(-) delete mode 100644 sample/delivery/content-type-snippets/index.ts delete mode 100644 sample/delivery/content-types/actor.ts delete mode 100644 sample/delivery/content-types/index.ts delete mode 100644 sample/delivery/content-types/movie.ts delete mode 100644 sample/delivery/index.ts delete mode 100644 sample/delivery/taxonomies/index.ts delete mode 100644 sample/delivery/taxonomies/movietype.ts delete mode 100644 sample/delivery/taxonomies/releasecategory.ts delete mode 100644 scripts/file-version-script.ts diff --git a/sample/delivery/content-type-snippets/index.ts b/sample/delivery/content-type-snippets/index.ts deleted file mode 100644 index f13c990..0000000 --- a/sample/delivery/content-type-snippets/index.ts +++ /dev/null @@ -1,16 +0,0 @@ - -/** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Movie Database -* Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 -* -* ------------------------------------------------------------------------------- -**/ - -export {}; diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts deleted file mode 100644 index c23a5b2..0000000 --- a/sample/delivery/content-types/actor.ts +++ /dev/null @@ -1,58 +0,0 @@ - -/** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Movie Database -* Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 -* -* ------------------------------------------------------------------------------- -**/ - -import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; - -/** - * Actor - * - * Id: 58099989-319f-495f-aa36-cb3710854e36 - * Codename: actor - */ -export type Actor = IContentItem<{ - /** - * First name (text) - * - * Required: true - * Codename: first_name - * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d - * Guidelines: This is the first name of the actor - */ - firstName: Elements.TextElement; - /** - * Last name (text) - * - * Required: true - * Codename: last_name - * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 - */ - lastName: Elements.TextElement; - /** - * Photo (asset) - * - * Required: false - * Codename: photo - * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 - */ - photo: Elements.AssetsElement; - /** - * Url (url_slug) - * - * Required: false - * Codename: url - * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 - */ - url: Elements.UrlSlugElement; -}>; diff --git a/sample/delivery/content-types/index.ts b/sample/delivery/content-types/index.ts deleted file mode 100644 index 3116ea2..0000000 --- a/sample/delivery/content-types/index.ts +++ /dev/null @@ -1,17 +0,0 @@ - -/** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Movie Database -* Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 -* -* ------------------------------------------------------------------------------- -**/ - -export * from './actor.js'; -export * from './movie.js'; diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts deleted file mode 100644 index 085ea5c..0000000 --- a/sample/delivery/content-types/movie.ts +++ /dev/null @@ -1,99 +0,0 @@ - -/** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Movie Database -* Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 -* -* ------------------------------------------------------------------------------- -**/ - -import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; -import type { Actor } from '../content-types/actor.js'; -import type { Releasecategory } from '../taxonomies/releasecategory.js'; - -/** - * Movie - * - * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c - * Codename: movie - */ -export type Movie = IContentItem<{ - /** - * Category (multiple_choice) - * - * Required: false - * Codename: category - * Id: 9821c252-6414-f549-c17f-cc171dd87713 - */ - category: Elements.MultipleChoiceElement; - /** - * Length (number) - * - * Required: false - * Codename: length - * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c - */ - length: Elements.NumberElement; - /** - * Plot (rich_text) - * - * Required: false - * Codename: plot - * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce - */ - plot: Elements.RichTextElement; - /** - * Poster (asset) - * - * Required: false - * Codename: poster - * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d - */ - poster: Elements.AssetsElement; - /** - * ReleaseCategory (taxonomy) - * - * Required: false - * Codename: releasecategory - * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 - */ - releasecategory: Elements.TaxonomyElement; - /** - * Released (date_time) - * - * Required: false - * Codename: released - * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 - */ - released: Elements.DateTimeElement; - /** - * SeoName (url_slug) - * - * Required: false - * Codename: seoname - * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c - */ - seoname: Elements.UrlSlugElement; - /** - * Stars (modular_content) - * - * Required: false - * Codename: stars - * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 - */ - stars: Elements.LinkedItemsElement; - /** - * Title (text) - * - * Required: true - * Codename: title - * Id: 3473187e-dc78-eff2-7099-f690f7042d4a - */ - title: Elements.TextElement; -}>; diff --git a/sample/delivery/index.ts b/sample/delivery/index.ts deleted file mode 100644 index 45e59b5..0000000 --- a/sample/delivery/index.ts +++ /dev/null @@ -1,18 +0,0 @@ - -/** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Movie Database -* Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 -* -* ------------------------------------------------------------------------------- -**/ - -export * from './content-type-snippets/index.js'; -export * from './content-types/index.js'; -export * from './taxonomies/index.js'; diff --git a/sample/delivery/taxonomies/index.ts b/sample/delivery/taxonomies/index.ts deleted file mode 100644 index 4948198..0000000 --- a/sample/delivery/taxonomies/index.ts +++ /dev/null @@ -1,17 +0,0 @@ - -/** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Movie Database -* Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 -* -* ------------------------------------------------------------------------------- -**/ - -export * from './movietype.js'; -export * from './releasecategory.js'; diff --git a/sample/delivery/taxonomies/movietype.ts b/sample/delivery/taxonomies/movietype.ts deleted file mode 100644 index 58aa2f7..0000000 --- a/sample/delivery/taxonomies/movietype.ts +++ /dev/null @@ -1,22 +0,0 @@ - -/** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Movie Database -* Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 -* -* ------------------------------------------------------------------------------- -**/ - -/** - * MovieType - * - * Codename: movietype - * Id: 365a17e6-1929-27ab-9f67-a9273c846717 - */ -export type Movietype = 'blockbuster' | 'cinema_only' | 'film' | 'student' | 'tv'; diff --git a/sample/delivery/taxonomies/releasecategory.ts b/sample/delivery/taxonomies/releasecategory.ts deleted file mode 100644 index 72d8a43..0000000 --- a/sample/delivery/taxonomies/releasecategory.ts +++ /dev/null @@ -1,22 +0,0 @@ - -/** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Movie Database -* Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 -* -* ------------------------------------------------------------------------------- -**/ - -/** - * ReleaseCategory - * - * Codename: releasecategory - * Id: 09b6a348-0f86-7a68-4af3-7cab9a5c60b7 - */ -export type Releasecategory = 'global_release' | 'local_release' | 'us_only'; diff --git a/scripts/file-version-script.ts b/scripts/file-version-script.ts deleted file mode 100644 index 59fdb58..0000000 --- a/scripts/file-version-script.ts +++ /dev/null @@ -1,27 +0,0 @@ -import chalk from 'chalk'; -import fs from 'fs'; -import PackageJson from '../package.json' assert { type: 'json' }; - -export const createVersionFile = (date: Date, versionPath: string, propertyName: string) => { - console.log(chalk.cyan(`\nCreating version file at '${versionPath}' with prop '${propertyName}'`)); - createFile(date, versionPath, propertyName); -}; - -function createFile(date: Date, filePath: string, propName: string) { - const src = ` -export const ${propName} = { - name: '${PackageJson.name}', - timestamp: date.toUTCString(), - version: '${PackageJson.version}' -}; -`; - - fs.writeFile(filePath, src, { flag: 'w' }, (err) => { - if (err) { - return console.log(chalk.red(err.message)); - } - - console.log(chalk.green(`Updating version ${chalk.yellow(PackageJson.version)}`)); - console.log(`${chalk.green('Writing version to ')}${chalk.yellow(filePath)}\n`); - }); -} diff --git a/scripts/tests/delivery-models.ts b/scripts/tests/delivery-models.ts index 0616377..149b161 100644 --- a/scripts/tests/delivery-models.ts +++ b/scripts/tests/delivery-models.ts @@ -6,7 +6,7 @@ import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; const outputDir: string = './sample/delivery'; -const run = async () => { +try { // needed to load .env environment to current process when run via package.json script dotenv.config({ path: './.env' @@ -32,8 +32,6 @@ const run = async () => { moduleResolution: moduleResolution?.toLowerCase() === 'node' ? 'node' : 'nodeNext', outputDir: outputDir }); -}; - -run().catch((err) => { - handleError(err); -}); +} catch (error) { + handleError(error); +} diff --git a/scripts/tests/environment-models.ts b/scripts/tests/environment-models.ts index ea2cb83..83716d3 100644 --- a/scripts/tests/environment-models.ts +++ b/scripts/tests/environment-models.ts @@ -6,7 +6,7 @@ import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; const outputDir: string = './sample/environment'; -const run = async () => { +try { // needed to load .env environment to current process when run via package.json script dotenv.config({ path: './.env' @@ -33,8 +33,6 @@ const run = async () => { isEnterpriseSubscription: true, outputDir: outputDir }); -}; - -run().catch((err) => { - handleError(err); -}); +} catch (error) { + handleError(error); +} diff --git a/scripts/tests/migration-models.ts b/scripts/tests/migration-models.ts index 7339a8e..e4dda87 100644 --- a/scripts/tests/migration-models.ts +++ b/scripts/tests/migration-models.ts @@ -6,7 +6,7 @@ import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; const outputDir: string = './sample/migration'; -const run = async () => { +try { // needed to load .env environment to current process when run via package.json script dotenv.config({ path: './.env' @@ -32,8 +32,6 @@ const run = async () => { moduleResolution: moduleResolution?.toLowerCase() === 'node' ? 'node' : 'nodeNext', outputDir: outputDir }); -}; - -run().catch((err) => { - handleError(err); -}); +} catch (error) { + handleError(error); +} diff --git a/scripts/update-version.ts b/scripts/update-version.ts index e1ecbff..148afe2 100644 --- a/scripts/update-version.ts +++ b/scripts/update-version.ts @@ -1,8 +1,25 @@ -import { createVersionFile } from './file-version-script.js'; +import chalk from 'chalk'; +import fs from 'fs'; +import PackageJson from '../package.json' assert { type: 'json' }; const date = new Date(); - const versionFilePath = './lib/meta/metadata.ts'; const versionProp = 'libMetadata'; createVersionFile(date, versionFilePath, versionProp); + +function createVersionFile(date: Date, filePath: string, propertyName: string): void { + console.log(chalk.cyan(`\nCreating version file at '${filePath}' with prop '${propertyName}'`)); + console.log(chalk.green(`Updating version ${chalk.yellow(PackageJson.version)}`)); + + const src = ` +export const ${propertyName} = { + name: '${PackageJson.name}', + timestamp: ${date.toUTCString()}, + version: '${PackageJson.version}' +}; +`; + + console.log(`${chalk.green('Writing version to ')}${chalk.yellow(filePath)}\n`); + fs.writeFileSync(filePath, src, { flag: 'w' }); +} diff --git a/scripts/utils/test.utils.ts b/scripts/utils/test.utils.ts index 7173677..cabd358 100644 --- a/scripts/utils/test.utils.ts +++ b/scripts/utils/test.utils.ts @@ -11,12 +11,5 @@ export function getEnvironmentRequiredValue(variableName: string): string { } export function getEnvironmentOptionalValue(variableName: string): string | undefined { - // get value from environment variables first - const value = process.env[variableName]; - - if (!value) { - return undefined; - } - - return value; + return process.env?.[variableName]; } From 437f6aec923e5255388e95e8eae4f6e29ecefbed Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 4 Sep 2024 08:40:44 +0200 Subject: [PATCH 069/183] Sample codes --- .../delivery/content-type-snippets/index.ts | 16 +++ sample/delivery/content-types/actor.ts | 58 +++++++++++ sample/delivery/content-types/index.ts | 17 ++++ sample/delivery/content-types/movie.ts | 99 +++++++++++++++++++ sample/delivery/index.ts | 18 ++++ sample/delivery/taxonomies/index.ts | 17 ++++ sample/delivery/taxonomies/movietype.ts | 22 +++++ sample/delivery/taxonomies/releasecategory.ts | 22 +++++ 8 files changed, 269 insertions(+) create mode 100644 sample/delivery/content-type-snippets/index.ts create mode 100644 sample/delivery/content-types/actor.ts create mode 100644 sample/delivery/content-types/index.ts create mode 100644 sample/delivery/content-types/movie.ts create mode 100644 sample/delivery/index.ts create mode 100644 sample/delivery/taxonomies/index.ts create mode 100644 sample/delivery/taxonomies/movietype.ts create mode 100644 sample/delivery/taxonomies/releasecategory.ts diff --git a/sample/delivery/content-type-snippets/index.ts b/sample/delivery/content-type-snippets/index.ts new file mode 100644 index 0000000..f13c990 --- /dev/null +++ b/sample/delivery/content-type-snippets/index.ts @@ -0,0 +1,16 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +export {}; diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts new file mode 100644 index 0000000..c23a5b2 --- /dev/null +++ b/sample/delivery/content-types/actor.ts @@ -0,0 +1,58 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; + +/** + * Actor + * + * Id: 58099989-319f-495f-aa36-cb3710854e36 + * Codename: actor + */ +export type Actor = IContentItem<{ + /** + * First name (text) + * + * Required: true + * Codename: first_name + * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d + * Guidelines: This is the first name of the actor + */ + firstName: Elements.TextElement; + /** + * Last name (text) + * + * Required: true + * Codename: last_name + * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 + */ + lastName: Elements.TextElement; + /** + * Photo (asset) + * + * Required: false + * Codename: photo + * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 + */ + photo: Elements.AssetsElement; + /** + * Url (url_slug) + * + * Required: false + * Codename: url + * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 + */ + url: Elements.UrlSlugElement; +}>; diff --git a/sample/delivery/content-types/index.ts b/sample/delivery/content-types/index.ts new file mode 100644 index 0000000..3116ea2 --- /dev/null +++ b/sample/delivery/content-types/index.ts @@ -0,0 +1,17 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +export * from './actor.js'; +export * from './movie.js'; diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts new file mode 100644 index 0000000..085ea5c --- /dev/null +++ b/sample/delivery/content-types/movie.ts @@ -0,0 +1,99 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; +import type { Actor } from '../content-types/actor.js'; +import type { Releasecategory } from '../taxonomies/releasecategory.js'; + +/** + * Movie + * + * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c + * Codename: movie + */ +export type Movie = IContentItem<{ + /** + * Category (multiple_choice) + * + * Required: false + * Codename: category + * Id: 9821c252-6414-f549-c17f-cc171dd87713 + */ + category: Elements.MultipleChoiceElement; + /** + * Length (number) + * + * Required: false + * Codename: length + * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c + */ + length: Elements.NumberElement; + /** + * Plot (rich_text) + * + * Required: false + * Codename: plot + * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce + */ + plot: Elements.RichTextElement; + /** + * Poster (asset) + * + * Required: false + * Codename: poster + * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d + */ + poster: Elements.AssetsElement; + /** + * ReleaseCategory (taxonomy) + * + * Required: false + * Codename: releasecategory + * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 + */ + releasecategory: Elements.TaxonomyElement; + /** + * Released (date_time) + * + * Required: false + * Codename: released + * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 + */ + released: Elements.DateTimeElement; + /** + * SeoName (url_slug) + * + * Required: false + * Codename: seoname + * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c + */ + seoname: Elements.UrlSlugElement; + /** + * Stars (modular_content) + * + * Required: false + * Codename: stars + * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 + */ + stars: Elements.LinkedItemsElement; + /** + * Title (text) + * + * Required: true + * Codename: title + * Id: 3473187e-dc78-eff2-7099-f690f7042d4a + */ + title: Elements.TextElement; +}>; diff --git a/sample/delivery/index.ts b/sample/delivery/index.ts new file mode 100644 index 0000000..45e59b5 --- /dev/null +++ b/sample/delivery/index.ts @@ -0,0 +1,18 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +export * from './content-type-snippets/index.js'; +export * from './content-types/index.js'; +export * from './taxonomies/index.js'; diff --git a/sample/delivery/taxonomies/index.ts b/sample/delivery/taxonomies/index.ts new file mode 100644 index 0000000..4948198 --- /dev/null +++ b/sample/delivery/taxonomies/index.ts @@ -0,0 +1,17 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +export * from './movietype.js'; +export * from './releasecategory.js'; diff --git a/sample/delivery/taxonomies/movietype.ts b/sample/delivery/taxonomies/movietype.ts new file mode 100644 index 0000000..58aa2f7 --- /dev/null +++ b/sample/delivery/taxonomies/movietype.ts @@ -0,0 +1,22 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +/** + * MovieType + * + * Codename: movietype + * Id: 365a17e6-1929-27ab-9f67-a9273c846717 + */ +export type Movietype = 'blockbuster' | 'cinema_only' | 'film' | 'student' | 'tv'; diff --git a/sample/delivery/taxonomies/releasecategory.ts b/sample/delivery/taxonomies/releasecategory.ts new file mode 100644 index 0000000..72d8a43 --- /dev/null +++ b/sample/delivery/taxonomies/releasecategory.ts @@ -0,0 +1,22 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +/** + * ReleaseCategory + * + * Codename: releasecategory + * Id: 09b6a348-0f86-7a68-4af3-7cab9a5c60b7 + */ +export type Releasecategory = 'global_release' | 'local_release' | 'us_only'; From d526138df32888db470348d1af61471e4f088ae2 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 4 Sep 2024 09:16:09 +0200 Subject: [PATCH 070/183] Update main.yml --- .github/workflows/main.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b61b17d..8d4ef0e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,16 +1,16 @@ name: Test on: [pull_request] jobs: - build: - runs-on: windows-latest - strategy: - matrix: - node-version: [18.x] - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - run: npm i - - run: npm run test:all + build: + runs-on: windows-latest + strategy: + matrix: + node-version: [20.x] + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm i + - run: npm run test:all From 2e711094eb26581390b54a1f5253a6c12b413d3f Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 4 Sep 2024 09:16:13 +0200 Subject: [PATCH 071/183] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1778218..db146d7 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "publish:beta": "npm publish --tag=next", "build:es2022": "tsc --p tsconfig.es2022.json", "build": "npm run lint && npm run clean && npm run build:es2022", - "test:all": "npm run build && npm run test:delivery-models", + "test:all": "npm run build", "test:delivery": "tsx scripts/tests/delivery-models", "test:environment": "tsx scripts/tests/environment-models", "test:migration": "tsx scripts/tests/migration-models", From 971d077a8124fd2d2acf781b6583e036dbd9c697 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 4 Sep 2024 09:16:28 +0200 Subject: [PATCH 072/183] Use name prop for resolving names instead of codename --- lib/core/core.models.ts | 4 ++++ lib/core/resolvers.ts | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index ea99fd4..932b319 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -59,3 +59,7 @@ export interface GeneratedFile { export type ObjectWithCodename = { readonly codename: string; }; + +export type ObjectWithName = { + readonly name: string; +}; diff --git a/lib/core/resolvers.ts b/lib/core/resolvers.ts index 0d05a5c..86518a7 100644 --- a/lib/core/resolvers.ts +++ b/lib/core/resolvers.ts @@ -1,6 +1,6 @@ import { ContentTypeElements, ContentTypeModels, ContentTypeSnippetModels, TaxonomyModels } from '@kontent-ai/management-sdk'; import { match, P } from 'ts-pattern'; -import { CaseType, GeneratorElementResolver, ObjectWithCodename } from './core.models.js'; +import { CaseType, GeneratorElementResolver, ObjectWithCodename, ObjectWithName } from './core.models.js'; import { toCamelCase, toPascalCase, toSnakeCase } from './core.utils.js'; /** File name resolvers */ @@ -12,8 +12,8 @@ export type ContentTypeSnippetFileNameResolver = FilenameResolver; /** Name resolvers */ -export type NameResolver> = undefined | CaseType | ((item: T & ObjectWithCodename) => string); -export type MapObjectToName = ObjectWithCodename> = (item: T) => string; +export type NameResolver> = undefined | CaseType | ((item: T & ObjectWithName) => string); +export type MapObjectToName = ObjectWithName> = (item: T) => string; export type ElementNameResolver = (element: Readonly) => string | undefined; export type ContentTypeNameResolver = NameResolver; @@ -33,13 +33,13 @@ export function mapFilename(resolver: FilenameReso }; } -export function mapName(resolver: NameResolver, defaultCase: CaseType): MapObjectToName { +export function mapName(resolver: NameResolver, defaultCase: CaseType): MapObjectToName { return (item) => { return match(resolver) .returnType() .with(P.instanceOf(Function), (resolver) => resolver(item)) - .with(undefined, () => resolveCase(item.codename, defaultCase)) - .otherwise((resolverType) => resolveCase(item.codename, resolverType)); + .with(undefined, () => resolveCase(item.name, defaultCase)) + .otherwise((resolverType) => resolveCase(item.name, resolverType)); }; } From 9706c25d8a9ae0ca2c777039deb3cfb1205ecd19 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 4 Sep 2024 09:43:16 +0200 Subject: [PATCH 073/183] Moves barrel export function to importer --- lib/core/core.utils.ts | 14 - lib/core/importer.ts | 16 +- lib/generators/delivery/delivery-func.ts | 56 ++-- .../environment/environment-func.ts | 23 +- lib/generators/migration/migration-func.ts | 49 ++-- .../delivery/content-type-snippets/index.ts | 7 +- .../content-type-snippets/my_snippet.ts | 41 +++ .../taxonomy_snippet_test.ts | 34 +++ sample/delivery/content-types/actor.ts | 27 +- sample/delivery/content-types/index.ts | 6 +- sample/delivery/content-types/movie.ts | 58 ++-- sample/delivery/content-types/special_type.ts | 33 +++ sample/delivery/content-types/test.ts | 35 +++ sample/delivery/index.ts | 4 +- .../{releasecategory.ts => category.ts} | 12 +- sample/delivery/taxonomies/index.ts | 8 +- .../{movietype.ts => release_category.ts} | 12 +- sample/environment/assetFolders.ts | 59 +--- sample/environment/collections.ts | 4 +- sample/environment/contentTypeSnippets.ts | 64 ++++- sample/environment/contentTypes.ts | 256 +++++++++--------- sample/environment/index.ts | 4 +- sample/environment/languages.ts | 33 +-- sample/environment/roles.ts | 33 +-- sample/environment/taxonomies.ts | 142 +++++----- sample/environment/webhooks.ts | 4 +- sample/environment/workflows.ts | 53 +++- sample/migration/content-types/actor.ts | 27 +- sample/migration/content-types/index.ts | 6 +- sample/migration/content-types/movie.ts | 55 ++-- .../migration/content-types/special_type.ts | 37 +++ sample/migration/content-types/test.ts | 55 ++++ sample/migration/environment/environment.ts | 19 +- sample/migration/environment/index.ts | 4 +- sample/migration/index.ts | 4 +- sample/migration/migration.ts | 4 +- 36 files changed, 782 insertions(+), 516 deletions(-) create mode 100644 sample/delivery/content-type-snippets/my_snippet.ts create mode 100644 sample/delivery/content-type-snippets/taxonomy_snippet_test.ts create mode 100644 sample/delivery/content-types/special_type.ts create mode 100644 sample/delivery/content-types/test.ts rename sample/delivery/taxonomies/{releasecategory.ts => category.ts} (56%) rename sample/delivery/taxonomies/{movietype.ts => release_category.ts} (57%) create mode 100644 sample/migration/content-types/special_type.ts create mode 100644 sample/migration/content-types/test.ts diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 13cd1eb..52ae448 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -71,20 +71,6 @@ export function toOutputDirPath(outputDir?: string): string { return outputDir ? `${outputDir}/`.replaceAll('//', '/') : `./`; } -export function getBarrelExportCode(data: { readonly filenames: readonly string[]; readonly moduleResolution: ModuleResolution }): string { - if (!data.filenames.length) { - return 'export {}'; - } - return sortAlphabetically(data.filenames, (filename) => filename).reduce((barrelCode, filename) => { - const path = parse(filename); - return (barrelCode += `export * from '${path.dir}/${path.name}${getExtensionForModuleResolution(data.moduleResolution)}';`); - }, ''); -} - -function getExtensionForModuleResolution(moduleResolution: ModuleResolution): string { - return moduleResolution === 'nodeNext' ? '.js' : ''; -} - function removeLineEndings(value: string): string { return value.replace(/(\r\n|\n|\r)/gm, ''); } diff --git a/lib/core/importer.ts b/lib/core/importer.ts index fe0b361..879256b 100644 --- a/lib/core/importer.ts +++ b/lib/core/importer.ts @@ -1,7 +1,12 @@ +import { parse } from 'path'; import { LibraryType, LiteralUnion, ModuleResolution } from './core.models.js'; -import { getFileNameWithoutExtension } from './core.utils.js'; +import { getFileNameWithoutExtension, sortAlphabetically } from './core.utils.js'; export function importer(moduleResolution: ModuleResolution) { + const getExtensionForModuleResolution = (moduleResolution: ModuleResolution): string => { + return moduleResolution === 'nodeNext' ? '.js' : ''; + }; + return { importType: (data: { readonly filePathOrPackage: LiteralUnion; readonly importValue: string }): string => { const isExternalLib = !data.filePathOrPackage.endsWith('.js') && !data.filePathOrPackage.endsWith('.ts'); @@ -11,6 +16,15 @@ export function importer(moduleResolution: ModuleResolution) { : data.filePathOrPackage; return `import type { ${data.importValue} } from '${resolvedFilePath}';`; + }, + getBarrelExportCode(filenames: readonly string[]): string { + if (!filenames.length) { + return 'export {}'; + } + return sortAlphabetically(filenames, (filename) => filename).reduce((barrelCode, filename) => { + const path = parse(filename); + return (barrelCode += `export * from '${path.dir}/${path.name}${getExtensionForModuleResolution(moduleResolution)}';`); + }, ''); } }; } diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index cd29980..6a09dfb 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -3,13 +3,13 @@ import chalk from 'chalk'; import { Options } from 'prettier'; import { coreConfig, deliveryConfig } from '../../config.js'; import { + importer as _importer, ContentTypeFileNameResolver, ContentTypeNameResolver, ContentTypeSnippetFileNameResolver, ContentTypeSnippetNameResolver, GeneratedFile, GeneratorElementResolver, - getBarrelExportCode, getDefaultModuleResolution, getFilenameFromPath, ModuleResolution, @@ -143,6 +143,8 @@ async function createFilesAsync( formatOptions: config.formatOptions }); + const importer = _importer(config.moduleResolution); + await fileManager.createFilesAsync([ ...data.contentTypeFiles, ...data.snippetFiles, @@ -150,47 +152,35 @@ async function createFilesAsync( // barrel files { filename: `${deliveryConfig.contentTypesFolderName}/${coreConfig.barrelExportFilename}`, - text: getBarrelExportCode({ - moduleResolution: config.moduleResolution, - filenames: [ - ...data.contentTypeFiles.map((m) => { - return `./${getFilenameFromPath(m.filename)}`; - }) - ] - }) + text: importer.getBarrelExportCode([ + ...data.contentTypeFiles.map((m) => { + return `./${getFilenameFromPath(m.filename)}`; + }) + ]) }, { filename: `${deliveryConfig.contentTypeSnippetsFolderName}/${coreConfig.barrelExportFilename}`, - text: getBarrelExportCode({ - moduleResolution: config.moduleResolution, - filenames: [ - ...data.snippetFiles.map((m) => { - return `./${getFilenameFromPath(m.filename)}`; - }) - ] - }) + text: importer.getBarrelExportCode([ + ...data.snippetFiles.map((m) => { + return `./${getFilenameFromPath(m.filename)}`; + }) + ]) }, { filename: `${deliveryConfig.taxonomiesFolderName}/${coreConfig.barrelExportFilename}`, - text: getBarrelExportCode({ - moduleResolution: config.moduleResolution, - filenames: [ - ...data.taxonomyFiles.map((m) => { - return `./${getFilenameFromPath(m.filename)}`; - }) - ] - }) + text: importer.getBarrelExportCode([ + ...data.taxonomyFiles.map((m) => { + return `./${getFilenameFromPath(m.filename)}`; + }) + ]) }, { filename: coreConfig.barrelExportFilename, - text: getBarrelExportCode({ - moduleResolution: config.moduleResolution, - filenames: [ - `./${deliveryConfig.contentTypesFolderName}/index`, - `./${deliveryConfig.contentTypeSnippetsFolderName}/index`, - `./${deliveryConfig.taxonomiesFolderName}/index` - ] - }) + text: importer.getBarrelExportCode([ + `./${deliveryConfig.contentTypesFolderName}/index`, + `./${deliveryConfig.contentTypeSnippetsFolderName}/index`, + `./${deliveryConfig.taxonomiesFolderName}/index` + ]) } ]); } diff --git a/lib/generators/environment/environment-func.ts b/lib/generators/environment/environment-func.ts index 44ce35a..4d78b87 100644 --- a/lib/generators/environment/environment-func.ts +++ b/lib/generators/environment/environment-func.ts @@ -2,7 +2,13 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; import { coreConfig } from '../../config.js'; -import { GeneratedFile, getBarrelExportCode, getDefaultModuleResolution, getFilenameFromPath, ModuleResolution } from '../../core/index.js'; +import { + importer as _importer, + GeneratedFile, + getDefaultModuleResolution, + getFilenameFromPath, + ModuleResolution +} from '../../core/index.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; import { fileManager as _fileManager } from '../../files/index.js'; import { environmentGenerator as _environmentGenerator } from './environment.generator.js'; @@ -98,19 +104,18 @@ async function createFilesAsync(data: { outputDir: data.outputDir }); + const importer = _importer(data.moduleResolution); + await fileManager.createFilesAsync([ ...data.projectFiles, // barrel file { filename: coreConfig.barrelExportFilename, - text: getBarrelExportCode({ - moduleResolution: data.moduleResolution, - filenames: [ - ...data.projectFiles.map((m) => { - return `./${getFilenameFromPath(m.filename)}`; - }) - ] - }) + text: importer.getBarrelExportCode([ + ...data.projectFiles.map((m) => { + return `./${getFilenameFromPath(m.filename)}`; + }) + ]) } ]); } diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index 7eba8a3..00928f9 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -2,7 +2,13 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; import { coreConfig, migrationConfig } from '../../config.js'; -import { GeneratedFile, getBarrelExportCode, getDefaultModuleResolution, getFilenameFromPath, ModuleResolution } from '../../core/index.js'; +import { + importer as _importer, + GeneratedFile, + getDefaultModuleResolution, + getFilenameFromPath, + ModuleResolution +} from '../../core/index.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; import { fileManager as _fileManager } from '../../files/index.js'; import { migrationGenerator as _migrationGenerator } from './migration.generator.js'; @@ -102,6 +108,8 @@ async function createFilesAsync(data: { formatOptions: data.formatOptions }); + const importer = _importer(data.moduleResolution); + await fileManager.createFilesAsync([ ...data.migrationTypeFiles, ...data.environmentFiles, @@ -109,38 +117,29 @@ async function createFilesAsync(data: { // items barrel file { filename: `${migrationConfig.migrationItemsFolderName}/${coreConfig.barrelExportFilename}`, - text: getBarrelExportCode({ - moduleResolution: data.moduleResolution, - filenames: [ - ...data.migrationItemFiles.map((m) => { - return `./${getFilenameFromPath(m.filename)}`; - }) - ] - }) + text: importer.getBarrelExportCode([ + ...data.migrationItemFiles.map((m) => { + return `./${getFilenameFromPath(m.filename)}`; + }) + ]) }, // environment barrel file { filename: `${migrationConfig.environmentFolderName}/${coreConfig.barrelExportFilename}`, - text: getBarrelExportCode({ - moduleResolution: data.moduleResolution, - filenames: [ - ...data.environmentFiles.map((m) => { - return `./${getFilenameFromPath(m.filename)}`; - }) - ] - }) + text: importer.getBarrelExportCode([ + ...data.environmentFiles.map((m) => { + return `./${getFilenameFromPath(m.filename)}`; + }) + ]) }, // main barrel file { filename: coreConfig.barrelExportFilename, - text: getBarrelExportCode({ - moduleResolution: data.moduleResolution, - filenames: [ - `./${migrationConfig.migrationItemsFolderName}/index`, - `./${migrationConfig.environmentFolderName}/index`, - ...data.migrationTypeFiles.map((file) => `./${file.filename}`) - ] - }) + text: importer.getBarrelExportCode([ + `./${migrationConfig.migrationItemsFolderName}/index`, + `./${migrationConfig.environmentFolderName}/index`, + ...data.migrationTypeFiles.map((file) => `./${file.filename}`) + ]) } ]); } diff --git a/sample/delivery/content-type-snippets/index.ts b/sample/delivery/content-type-snippets/index.ts index f13c990..275c315 100644 --- a/sample/delivery/content-type-snippets/index.ts +++ b/sample/delivery/content-type-snippets/index.ts @@ -6,11 +6,12 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ -export {}; +export * from './my_snippet.js'; +export * from './taxonomy_snippet_test.js'; diff --git a/sample/delivery/content-type-snippets/my_snippet.ts b/sample/delivery/content-type-snippets/my_snippet.ts new file mode 100644 index 0000000..8566027 --- /dev/null +++ b/sample/delivery/content-type-snippets/my_snippet.ts @@ -0,0 +1,41 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Migration Toolkit tests +* Environment: Production +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* +* ------------------------------------------------------------------------------- +**/ + +import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; + +/** + * My snippet + * + * Id: 3274f9e7-ff1b-43f8-aa32-29b53939cd3e + * Codename: my_snippet + */ +export type MySnippet = IContentItem<{ + /** + * Snippet elem 2 (number) + * + * Required: false + * Codename: my_snippet__snippet_elem_2 + * Id: b2f65646-3310-4a64-af2a-0d9d025a91d0 + */ + mySnippetSnippetElem2: Elements.NumberElement; + /** + * Snippet elem1 (text) + * + * Required: false + * Codename: my_snippet__snippet_elem1 + * Id: 3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d + */ + mySnippetSnippetElem1: Elements.TextElement; +}>; diff --git a/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts b/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts new file mode 100644 index 0000000..8269f84 --- /dev/null +++ b/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts @@ -0,0 +1,34 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Migration Toolkit tests +* Environment: Production +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* +* ------------------------------------------------------------------------------- +**/ + +import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; +import type { Category } from '../taxonomies/category.js'; + +/** + * Taxonomy snippet test + * + * Id: e8219115-e629-4552-b79b-d9f813272573 + * Codename: taxonomy_snippet_test + */ +export type TaxonomySnippetTest = IContentItem<{ + /** + * Category (taxonomy) + * + * Required: false + * Codename: taxonomy_snippet_test__test_taxonomy + * Id: c030e3ec-5031-4d7f-af88-5032365733c7 + */ + taxonomySnippetTestTestTaxonomy: Elements.TaxonomyElement; +}>; diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index c23a5b2..28a2574 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ @@ -18,41 +18,40 @@ import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; /** * Actor * - * Id: 58099989-319f-495f-aa36-cb3710854e36 + * Id: d8900ee2-82f4-4189-a994-4e121582aadf * Codename: actor */ export type Actor = IContentItem<{ /** - * First name (text) + * first_name (text) * - * Required: true + * Required: false * Codename: first_name - * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d - * Guidelines: This is the first name of the actor + * Id: 4af5e7ce-88ef-4159-96ae-96a552992f91 */ firstName: Elements.TextElement; /** - * Last name (text) + * last_name (text) * - * Required: true + * Required: false * Codename: last_name - * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 + * Id: 0f00b26e-60f3-462d-8110-18180137c3a0 */ lastName: Elements.TextElement; /** - * Photo (asset) + * photo (asset) * * Required: false * Codename: photo - * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 + * Id: 069b38ee-385c-410f-b7fe-53ec59a5f139 */ photo: Elements.AssetsElement; /** - * Url (url_slug) + * url (url_slug) * * Required: false * Codename: url - * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 + * Id: c4b2d64f-af45-45a4-92d8-4829833563ff */ url: Elements.UrlSlugElement; }>; diff --git a/sample/delivery/content-types/index.ts b/sample/delivery/content-types/index.ts index 3116ea2..83a1c03 100644 --- a/sample/delivery/content-types/index.ts +++ b/sample/delivery/content-types/index.ts @@ -6,12 +6,14 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ export * from './actor.js'; export * from './movie.js'; +export * from './special_type.js'; +export * from './test.js'; diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 085ea5c..db57cab 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -6,94 +6,96 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; -import type { Actor } from '../content-types/actor.js'; -import type { Releasecategory } from '../taxonomies/releasecategory.js'; +import type { Category } from '../taxonomies/category.js'; +import type { ReleaseCategory } from '../taxonomies/release_category.js'; +import type { TaxonomySnippetTest } from '../content-type-snippets/taxonomy_snippet_test.js'; /** * Movie * - * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c + * Id: db7356f6-1d82-42a0-9ebb-07865cffa995 * Codename: movie */ export type Movie = IContentItem<{ /** - * Category (multiple_choice) + * Category (taxonomy) * * Required: false * Codename: category - * Id: 9821c252-6414-f549-c17f-cc171dd87713 + * Id: 8c12be35-e3e7-447c-a185-7b5e101ebf12 */ - category: Elements.MultipleChoiceElement; + category: Elements.TaxonomyElement; /** - * Length (number) + * length (number) * * Required: false * Codename: length - * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c + * Id: e3d07f3a-60c2-4072-846d-c23e51ec833e */ length: Elements.NumberElement; /** - * Plot (rich_text) + * plot (rich_text) * * Required: false * Codename: plot - * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce + * Id: ad2e5dc7-8d08-4f74-afeb-25b475f1e6fc */ plot: Elements.RichTextElement; /** - * Poster (asset) + * poster (asset) * * Required: false * Codename: poster - * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d + * Id: 9b197f1e-0728-4d14-9814-97f7b8ef01fc */ poster: Elements.AssetsElement; /** - * ReleaseCategory (taxonomy) + * Release category (taxonomy) * * Required: false * Codename: releasecategory - * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 + * Id: 5faa827f-f262-43c3-8f58-0f354b8d393f */ - releasecategory: Elements.TaxonomyElement; + releasecategory: Elements.TaxonomyElement; /** - * Released (date_time) + * released (date_time) * * Required: false * Codename: released - * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 + * Id: 656b9dc9-7bba-4f1f-a2b8-52f7f730a66f */ released: Elements.DateTimeElement; /** - * SeoName (url_slug) + * seoname (url_slug) * * Required: false * Codename: seoname - * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c + * Id: 734f94be-5930-4bdf-b05b-f59f5a291675 */ seoname: Elements.UrlSlugElement; /** - * Stars (modular_content) + * stars (modular_content) * * Required: false * Codename: stars - * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 + * Id: 55596dd1-e808-415d-95aa-e2be34238d11 */ - stars: Elements.LinkedItemsElement; + stars: Elements.LinkedItemsElement; /** - * Title (text) + * title (text) * - * Required: true + * Required: false * Codename: title - * Id: 3473187e-dc78-eff2-7099-f690f7042d4a + * Id: 660c851a-a9a1-4378-97a3-1348bc2a4d76 */ title: Elements.TextElement; -}>; +}> & + TaxonomySnippetTest; diff --git a/sample/delivery/content-types/special_type.ts b/sample/delivery/content-types/special_type.ts new file mode 100644 index 0000000..c00b61e --- /dev/null +++ b/sample/delivery/content-types/special_type.ts @@ -0,0 +1,33 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Migration Toolkit tests +* Environment: Production +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* +* ------------------------------------------------------------------------------- +**/ + +import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; + +/** + * My Special type hello + * + * Id: 410fb007-42e3-442d-8cdf-fba4cf50f850 + * Codename: special_type + */ +export type MySpecialTypehello = IContentItem<{ + /** + * Hello (text) + * + * Required: false + * Codename: hello + * Id: 41d50fe3-0858-494c-9f33-85960821b5d6 + */ + hello: Elements.TextElement; +}>; diff --git a/sample/delivery/content-types/test.ts b/sample/delivery/content-types/test.ts new file mode 100644 index 0000000..1a21eec --- /dev/null +++ b/sample/delivery/content-types/test.ts @@ -0,0 +1,35 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Migration Toolkit tests +* Environment: Production +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* +* ------------------------------------------------------------------------------- +**/ + +import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; +import type { MySnippet } from '../content-type-snippets/my_snippet.js'; + +/** + * Test + * + * Id: 81ab0b2c-dd14-41e7-a1ed-868b249ad8bc + * Codename: test + */ +export type Test = IContentItem<{ + /** + * Text (text) + * + * Required: false + * Codename: text + * Id: 65f61f6a-b69c-47dc-bc38-19855507bf14 + */ + text: Elements.TextElement; +}> & + MySnippet; diff --git a/sample/delivery/index.ts b/sample/delivery/index.ts index 45e59b5..aa463c5 100644 --- a/sample/delivery/index.ts +++ b/sample/delivery/index.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ diff --git a/sample/delivery/taxonomies/releasecategory.ts b/sample/delivery/taxonomies/category.ts similarity index 56% rename from sample/delivery/taxonomies/releasecategory.ts rename to sample/delivery/taxonomies/category.ts index 72d8a43..8873263 100644 --- a/sample/delivery/taxonomies/releasecategory.ts +++ b/sample/delivery/taxonomies/category.ts @@ -6,17 +6,17 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ /** - * ReleaseCategory + * Category * - * Codename: releasecategory - * Id: 09b6a348-0f86-7a68-4af3-7cab9a5c60b7 + * Codename: category + * Id: c1b56389-f00a-4917-95c4-3b02ea3610ea */ -export type Releasecategory = 'global_release' | 'local_release' | 'us_only'; +export type Category = 'action' | 'animation' | 'comedy' | 'drama' | 'romance' | 'sci_fi'; diff --git a/sample/delivery/taxonomies/index.ts b/sample/delivery/taxonomies/index.ts index 4948198..acfdbc4 100644 --- a/sample/delivery/taxonomies/index.ts +++ b/sample/delivery/taxonomies/index.ts @@ -6,12 +6,12 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ -export * from './movietype.js'; -export * from './releasecategory.js'; +export * from './category.js'; +export * from './release_category.js'; diff --git a/sample/delivery/taxonomies/movietype.ts b/sample/delivery/taxonomies/release_category.ts similarity index 57% rename from sample/delivery/taxonomies/movietype.ts rename to sample/delivery/taxonomies/release_category.ts index 58aa2f7..bfaade8 100644 --- a/sample/delivery/taxonomies/movietype.ts +++ b/sample/delivery/taxonomies/release_category.ts @@ -6,17 +6,17 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ /** - * MovieType + * Release category * - * Codename: movietype - * Id: 365a17e6-1929-27ab-9f67-a9273c846717 + * Codename: release_category + * Id: 4dbfc78f-5ea2-4f33-880d-193c75e0b975 */ -export type Movietype = 'blockbuster' | 'cinema_only' | 'film' | 'student' | 'tv'; +export type ReleaseCategory = 'global_release' | 'us_only'; diff --git a/sample/environment/assetFolders.ts b/sample/environment/assetFolders.ts index 22db46c..4dd2f59 100644 --- a/sample/environment/assetFolders.ts +++ b/sample/environment/assetFolders.ts @@ -6,66 +6,33 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ export const assetFolders = { /** - * my folder A + * my folder */ - myFolderA: { - codename: 'my_folder_a', - id: '6bb4814a-6a5c-4b8c-836e-7f83b008d5d1', + myFolder: { + codename: 'my_folder', + id: 'f1c6ba01-3b13-41ce-81e7-3125840b0b0e', externalId: undefined, - name: 'my folder A', - folders: { - /** - * my folder nested A - */ - myFolderNestedA: { - codename: 'my_folder_nested_a', - id: '555784e5-e92e-4a86-b40b-d642afbf7b4e', - externalId: undefined, - name: 'my folder nested A', - folders: { - /** - * even more nested A - */ - evenMoreNestedA: { - codename: 'even_more_nested_a', - id: 'd26940cc-6c8d-41e6-93a0-0748c854b100', - externalId: undefined, - name: 'even more nested A', - folders: {} - }, - - /** - * even more nested B - */ - evenMoreNestedB: { - codename: 'even_more_nested_b', - id: '97fc4b03-98d2-44b4-8e03-b223a013b0b6', - externalId: undefined, - name: 'even more nested B', - folders: {} - } - } - } - } + name: 'my folder', + folders: {} }, /** - * my folder B + * my folder2 */ - myFolderB: { - codename: 'my_folder_b', - id: '58d1c135-42cb-43c2-a2cd-c615e0a36e83', + myFolder2: { + codename: 'my_folder2', + id: '44a00189-9298-4cf9-b8fb-3f208c3f4f8f', externalId: undefined, - name: 'my folder B', + name: 'my folder2', folders: {} } } as const; diff --git a/sample/environment/collections.ts b/sample/environment/collections.ts index 7e50501..39f1c0d 100644 --- a/sample/environment/collections.ts +++ b/sample/environment/collections.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ diff --git a/sample/environment/contentTypeSnippets.ts b/sample/environment/contentTypeSnippets.ts index 34f7746..5aad5f3 100644 --- a/sample/environment/contentTypeSnippets.ts +++ b/sample/environment/contentTypeSnippets.ts @@ -6,11 +6,69 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ -export const contentTypeSnippets = {} as const; +export const contentTypeSnippets = { + /** + * My snippet + */ + mySnippet: { + codename: 'my_snippet', + id: '3274f9e7-ff1b-43f8-aa32-29b53939cd3e', + externalId: undefined, + name: 'My snippet', + elements: { + /** + * Snippet elem 2 (number) + */ + mySnippetSnippetElem2: { + codename: 'my_snippet__snippet_elem_2', + id: 'b2f65646-3310-4a64-af2a-0d9d025a91d0', + externalId: undefined, + name: 'Snippet elem 2', + required: false, + type: 'number' + }, + + /** + * Snippet elem1 (text) + */ + mySnippetSnippetElem1: { + codename: 'my_snippet__snippet_elem1', + id: '3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d', + externalId: undefined, + name: 'Snippet elem1', + required: false, + type: 'text' + } + } + }, + + /** + * Taxonomy snippet test + */ + taxonomySnippetTest: { + codename: 'taxonomy_snippet_test', + id: 'e8219115-e629-4552-b79b-d9f813272573', + externalId: undefined, + name: 'Taxonomy snippet test', + elements: { + /** + * Category (taxonomy) + */ + taxonomySnippetTestTestTaxonomy: { + codename: 'taxonomy_snippet_test__test_taxonomy', + id: 'c030e3ec-5031-4d7f-af88-5032365733c7', + externalId: undefined, + name: 'Category', + required: false, + type: 'taxonomy' + } + } + } +} as const; diff --git a/sample/environment/contentTypes.ts b/sample/environment/contentTypes.ts index dcd3d55..a922ff0 100644 --- a/sample/environment/contentTypes.ts +++ b/sample/environment/contentTypes.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ @@ -19,55 +19,54 @@ export const contentTypes = { */ actor: { codename: 'actor', - id: '58099989-319f-495f-aa36-cb3710854e36', + id: 'd8900ee2-82f4-4189-a994-4e121582aadf', externalId: undefined, name: 'Actor', elements: { /** - * First name (text) - * Guidelines: This is the first name of the actor + * first_name (text) */ firstName: { codename: 'first_name', - id: '14dd70e5-c42d-f111-9640-c82b443edf1d', + id: '4af5e7ce-88ef-4159-96ae-96a552992f91', externalId: undefined, - name: 'First name', - required: true, + name: 'first_name', + required: false, type: 'text' }, /** - * Last name (text) + * last_name (text) */ lastName: { codename: 'last_name', - id: '9f7a0dd4-af3a-95ca-0358-400c14ce7075', + id: '0f00b26e-60f3-462d-8110-18180137c3a0', externalId: undefined, - name: 'Last name', - required: true, + name: 'last_name', + required: false, type: 'text' }, /** - * Photo (asset) + * photo (asset) */ photo: { codename: 'photo', - id: 'eaec9ba3-9624-6875-04ec-80d0b2e00781', + id: '069b38ee-385c-410f-b7fe-53ec59a5f139', externalId: undefined, - name: 'Photo', + name: 'photo', required: false, type: 'asset' }, /** - * Url (url_slug) + * url (url_slug) */ url: { codename: 'url', - id: 'c8658782-f209-a573-9c85-430fb4e3e9f0', + id: 'c4b2d64f-af45-45a4-92d8-4829833563ff', externalId: undefined, - name: 'Url', + name: 'url', required: false, type: 'url_slug' } @@ -79,196 +78,197 @@ export const contentTypes = { */ movie: { codename: 'movie', - id: 'b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c', + id: 'db7356f6-1d82-42a0-9ebb-07865cffa995', externalId: undefined, name: 'Movie', elements: { /** - * Category (multiple_choice) + * Category (taxonomy) */ category: { codename: 'category', - id: '9821c252-6414-f549-c17f-cc171dd87713', + id: '8c12be35-e3e7-447c-a185-7b5e101ebf12', externalId: undefined, name: 'Category', required: false, - type: 'multiple_choice', - options: { - /** - * Action - */ - action: { - name: 'Action', - id: '7d453309-8d74-9607-80c4-36dcc1bd005f', - codename: 'action', - externalId: undefined - }, - - /** - * Adventure - */ - adventure: { - name: 'Adventure', - id: 'cd8389b0-7628-7739-7b14-3225a50212c1', - codename: 'adventure', - externalId: undefined - }, - - /** - * Animation - */ - animation: { - name: 'Animation', - id: '54c0590d-6a94-a69a-902d-fceea4fa62f8', - codename: 'animation', - externalId: undefined - }, - - /** - * Comedy - */ - comedy: { - name: 'Comedy', - id: 'd2fe357f-894e-9bc3-550c-c2c400d99c6b', - codename: 'comedy', - externalId: undefined - }, - - /** - * Documentary - */ - documentary: { - name: 'Documentary', - id: '19c5e959-c24a-4863-0b4d-453cdef8fe9d', - codename: 'documentary', - externalId: undefined - }, - - /** - * Drama - */ - drama: { - name: 'Drama', - id: '051e74de-f2e0-f405-9ad5-5263221e46f2', - codename: 'drama', - externalId: undefined - }, - - /** - * Romance - */ - romance: { - name: 'Romance', - id: '60550cc7-c986-a59f-b069-7565862fe1c1', - codename: 'romance', - externalId: undefined - }, - - /** - * Sci fi - */ - sciFi: { - name: 'Sci fi', - id: 'b087f774-1f57-9aa8-dab5-2ca88a646824', - codename: 'sci_fi', - externalId: undefined - } - } + type: 'taxonomy' }, /** - * Length (number) + * length (number) */ length: { codename: 'length', - id: '7e8ecfab-a419-27ee-d8ec-8adb76fd007c', + id: 'e3d07f3a-60c2-4072-846d-c23e51ec833e', externalId: undefined, - name: 'Length', + name: 'length', required: false, type: 'number' }, /** - * Plot (rich_text) + * plot (rich_text) */ plot: { codename: 'plot', - id: 'f7ee4f27-27fd-a19b-3c5c-102aae1c50ce', + id: 'ad2e5dc7-8d08-4f74-afeb-25b475f1e6fc', externalId: undefined, - name: 'Plot', + name: 'plot', required: false, type: 'rich_text' }, /** - * Poster (asset) + * poster (asset) */ poster: { codename: 'poster', - id: 'a39a7237-9503-a1ae-8431-5b6cdb85ae9d', + id: '9b197f1e-0728-4d14-9814-97f7b8ef01fc', externalId: undefined, - name: 'Poster', + name: 'poster', required: false, type: 'asset' }, /** - * ReleaseCategory (taxonomy) + * Release category (taxonomy) */ releasecategory: { codename: 'releasecategory', - id: '65f2fd44-1856-bc2b-17c2-decb0635e3d2', + id: '5faa827f-f262-43c3-8f58-0f354b8d393f', externalId: undefined, - name: 'ReleaseCategory', + name: 'Release category', required: false, type: 'taxonomy' }, /** - * Released (date_time) + * released (date_time) */ released: { codename: 'released', - id: '5ccf4644-0d65-5d96-9a32-f4ea21974d51', + id: '656b9dc9-7bba-4f1f-a2b8-52f7f730a66f', externalId: undefined, - name: 'Released', + name: 'released', required: false, type: 'date_time' }, /** - * SeoName (url_slug) + * seoname (url_slug) */ seoname: { codename: 'seoname', - id: '756cc91a-a090-60f9-a7f0-f505bfbe046c', + id: '734f94be-5930-4bdf-b05b-f59f5a291675', externalId: undefined, - name: 'SeoName', + name: 'seoname', required: false, type: 'url_slug' }, /** - * Stars (modular_content) + * stars (modular_content) */ stars: { codename: 'stars', - id: 'aa26a55d-19f8-7501-fea3-b0d9b1eeac71', + id: '55596dd1-e808-415d-95aa-e2be34238d11', externalId: undefined, - name: 'Stars', + name: 'stars', required: false, type: 'modular_content' }, /** - * Title (text) + * Category (taxonomy) + */ + taxonomySnippetTestTestTaxonomy: { + codename: 'taxonomy_snippet_test__test_taxonomy', + id: 'c030e3ec-5031-4d7f-af88-5032365733c7', + externalId: undefined, + name: 'Category', + required: false, + type: 'taxonomy' + }, + + /** + * title (text) */ title: { codename: 'title', - id: '3473187e-dc78-eff2-7099-f690f7042d4a', + id: '660c851a-a9a1-4378-97a3-1348bc2a4d76', externalId: undefined, - name: 'Title', - required: true, + name: 'title', + required: false, + type: 'text' + } + } + }, + + /** + * My Special type hello + */ + specialType: { + codename: 'special_type', + id: '410fb007-42e3-442d-8cdf-fba4cf50f850', + externalId: undefined, + name: ' My Special type hello ', + elements: { + /** + * Hello (text) + */ + hello: { + codename: 'hello', + id: '41d50fe3-0858-494c-9f33-85960821b5d6', + externalId: undefined, + name: 'Hello', + required: false, + type: 'text' + } + } + }, + + /** + * Test + */ + test: { + codename: 'test', + id: '81ab0b2c-dd14-41e7-a1ed-868b249ad8bc', + externalId: undefined, + name: 'Test', + elements: { + /** + * Snippet elem 2 (number) + */ + mySnippetSnippetElem2: { + codename: 'my_snippet__snippet_elem_2', + id: 'b2f65646-3310-4a64-af2a-0d9d025a91d0', + externalId: undefined, + name: 'Snippet elem 2', + required: false, + type: 'number' + }, + + /** + * Snippet elem1 (text) + */ + mySnippetSnippetElem1: { + codename: 'my_snippet__snippet_elem1', + id: '3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d', + externalId: undefined, + name: 'Snippet elem1', + required: false, + type: 'text' + }, + + /** + * Text (text) + */ + text: { + codename: 'text', + id: '65f61f6a-b69c-47dc-bc38-19855507bf14', + externalId: undefined, + name: 'Text', + required: false, type: 'text' } } diff --git a/sample/environment/index.ts b/sample/environment/index.ts index 91a4ee3..a01d79b 100644 --- a/sample/environment/index.ts +++ b/sample/environment/index.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ diff --git a/sample/environment/languages.ts b/sample/environment/languages.ts index 90b3dc4..d0840b0 100644 --- a/sample/environment/languages.ts +++ b/sample/environment/languages.ts @@ -6,34 +6,21 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ export const languages = { /** - * cz - */ - cz: { - codename: 'cz', - id: '41ccb26f-ceab-04d0-6ffa-9c7c5358aa8f', - name: 'cz', - isActive: true, - isDefault: false, - fallbackLanguageId: '00000000-0000-0000-0000-000000000000', - externalId: undefined - }, - - /** - * English + * Default project language */ en: { codename: 'en', id: '00000000-0000-0000-0000-000000000000', - name: 'English', + name: 'Default project language', isActive: true, isDefault: true, fallbackLanguageId: '00000000-0000-0000-0000-000000000000', @@ -41,13 +28,13 @@ export const languages = { }, /** - * German + * Spanish */ - german: { - codename: 'German', - id: '14f7bcc0-4fd6-4b77-8c22-70e5ccfdae1d', - name: 'German', - isActive: false, + es: { + codename: 'es', + id: '71cf90e5-8124-43e3-8ef4-bbb8bdcd22ae', + name: 'Spanish', + isActive: true, isDefault: false, fallbackLanguageId: '00000000-0000-0000-0000-000000000000', externalId: undefined diff --git a/sample/environment/roles.ts b/sample/environment/roles.ts index 1fc72b8..00d4ec0 100644 --- a/sample/environment/roles.ts +++ b/sample/environment/roles.ts @@ -6,47 +6,20 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ export const roles = { - /** - * Content contributor - */ - contentContributor: { - codename: undefined, - id: 'dca0ac85-274f-429e-b00e-6f74bf917051', - name: 'Content contributor' - }, - - /** - * Developer - */ - developer: { - codename: undefined, - id: 'b3994090-0818-4969-816b-f4c5d3e526f3', - name: 'Developer' - }, - /** * Project manager */ projectManager: { codename: 'project-manager', - id: 'af95ac37-4efa-4b92-aa26-db773cd172c6', + id: '5a8e7afd-3dcc-4adc-9f23-bf36a31d61bf', name: 'Project manager' - }, - - /** - * Reviewer - */ - reviewer: { - codename: undefined, - id: '94478afa-d898-45dd-8300-ba61b6e0eb4b', - name: 'Reviewer' } } as const; diff --git a/sample/environment/taxonomies.ts b/sample/environment/taxonomies.ts index 585c912..fc6348b 100644 --- a/sample/environment/taxonomies.ts +++ b/sample/environment/taxonomies.ts @@ -6,119 +6,119 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ export const taxonomies = { /** - * MovieType + * Category */ - movietype: { - codename: 'movietype', + category: { + codename: 'category', externalId: undefined, - id: '365a17e6-1929-27ab-9f67-a9273c846717', - name: 'MovieType', + id: 'c1b56389-f00a-4917-95c4-3b02ea3610ea', + name: 'Category', terms: { /** - * Film + * action */ - film: { - codename: 'film', - id: '5a2a1927-41a4-294f-5d89-cf0cc045e943', + action: { + codename: 'action', + id: 'e3410312-52d6-4c15-8e23-e5a4cc57a204', externalId: undefined, - name: 'Film', - terms: { - /** - * Blockbuster - */ - blockbuster: { - codename: 'blockbuster', - id: '875a4657-1dcd-0415-cb3a-892078f5991a', - externalId: undefined, - name: 'Blockbuster', - terms: {} - }, + name: 'action', + terms: {} + }, - /** - * Cinema only - */ - cinemaOnly: { - codename: 'cinema_only', - id: 'e15c4e32-ab7c-57a2-1b66-d8e3566a1dd2', - externalId: undefined, - name: 'Cinema only', - terms: {} - }, + /** + * animation + */ + animation: { + codename: 'animation', + id: '2d8a95a8-61c9-4add-94a1-1d7944098144', + externalId: undefined, + name: 'animation', + terms: {} + }, - /** - * TV - */ - tv: { - codename: 'tv', - id: '47511b09-6c39-fa04-ff59-7c47551e827f', - externalId: undefined, - name: 'TV', - terms: {} - } - } + /** + * comedy + */ + comedy: { + codename: 'comedy', + id: 'eddaa24b-fb5c-4a44-8507-8dd7a45fdc39', + externalId: undefined, + name: 'comedy', + terms: {} }, /** - * Student + * drama */ - student: { - codename: 'student', - id: 'b107e12c-124d-705f-1029-c0dfdd0b2438', + drama: { + codename: 'drama', + id: '7377ea7c-d928-408a-bfb8-a0bf7392c996', externalId: undefined, - name: 'Student', + name: 'drama', + terms: {} + }, + + /** + * romance + */ + romance: { + codename: 'romance', + id: 'fe8bdfdb-cc13-4890-ab45-a6669e94d1d0', + externalId: undefined, + name: 'romance', + terms: {} + }, + + /** + * sci_fi + */ + sciFi: { + codename: 'sci_fi', + id: '1432c10c-096c-47c5-a045-dcd6dc4af366', + externalId: undefined, + name: 'sci_fi', terms: {} } } }, /** - * ReleaseCategory + * Release category */ - releasecategory: { - codename: 'releasecategory', + releaseCategory: { + codename: 'release_category', externalId: undefined, - id: '09b6a348-0f86-7a68-4af3-7cab9a5c60b7', - name: 'ReleaseCategory', + id: '4dbfc78f-5ea2-4f33-880d-193c75e0b975', + name: 'Release category', terms: { /** - * Global release + * global_release */ globalRelease: { codename: 'global_release', - id: '4acaf439-9f3a-f34a-6211-d3fc6ec7152e', - externalId: undefined, - name: 'Global release', - terms: {} - }, - - /** - * Local release - */ - localRelease: { - codename: 'local_release', - id: '37e55484-f0dc-14eb-bf2a-b0293a0d1b1f', + id: 'afb51aba-cb5a-499a-973c-d5b44fdeafcf', externalId: undefined, - name: 'Local release', + name: 'global_release', terms: {} }, /** - * US only + * us_only */ usOnly: { codename: 'us_only', - id: 'b03d990a-55a9-601e-dd5c-aa2edc8698ca', + id: '3f8bddaf-c203-471b-af76-6539d3e72e89', externalId: undefined, - name: 'US only', + name: 'us_only', terms: {} } } diff --git a/sample/environment/webhooks.ts b/sample/environment/webhooks.ts index 7d33dc3..65bf670 100644 --- a/sample/environment/webhooks.ts +++ b/sample/environment/webhooks.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ diff --git a/sample/environment/workflows.ts b/sample/environment/workflows.ts index 11abd1d..55e18a9 100644 --- a/sample/environment/workflows.ts +++ b/sample/environment/workflows.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ @@ -30,7 +30,7 @@ export const workflows = { published: { name: 'Published', codename: 'published', - id: 'f05b8a85-c6cc-429a-ac6d-21d5edd268fe' + id: 'c199950d-99f0-4983-b711-6c4c91624b22' }, scheduled: { name: 'Scheduled', @@ -40,17 +40,48 @@ export const workflows = { draft: { name: 'Draft', codename: 'draft', - id: 'e3ef0816-2203-4456-bfdc-a735b4f339ab' - }, - review: { - name: 'Review', - codename: 'review', - id: 'c5682935-f5a2-4514-8025-57d8bdf7558d' + id: 'eee6db3b-545a-4785-8e86-e3772c8756f9' }, readyToPublish: { - name: 'Ready to publish', + name: 'ready_to_publish', codename: 'ready_to_publish', - id: 'aaee1d73-f0cc-4185-9e49-844d161c3634' + id: 'f4afd295-cc0b-48e3-9431-176cc1e17e2c' + } + } + }, + + /** + * my_test_workflow + */ + myTestWorkflow: { + codename: 'my_test_workflow', + id: '51036ae0-1a0c-48c6-980e-bf73600ba462', + name: 'my_test_workflow', + steps: { + archived: { + name: 'Archived', + codename: 'archived', + id: '7a535a69-ad34-47f8-806a-def1fdf4d391' + }, + published: { + name: 'Published', + codename: 'published', + id: 'c199950d-99f0-4983-b711-6c4c91624b22' + }, + scheduled: { + name: 'Scheduled', + codename: 'scheduled', + id: '9d2b0228-4d0d-4c23-8b49-01a698857709' + }, + draft3171da5: { + name: 'Draft', + codename: 'draft_3171da5', + id: '3171da5f-679d-49af-a42c-617d83eac222' + }, + readyForReview: { + name: 'ready_for_review', + codename: 'ready_for_review', + id: '20f49208-5e57-4300-b6bd-0f668cbce00b' } } } diff --git a/sample/migration/content-types/actor.ts b/sample/migration/content-types/actor.ts index 4229a92..909e298 100644 --- a/sample/migration/content-types/actor.ts +++ b/sample/migration/content-types/actor.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ @@ -20,45 +20,44 @@ import type { Item } from '../migration.js'; * Actor * * Codename: actor - * Id: 58099989-319f-495f-aa36-cb3710854e36 + * Id: d8900ee2-82f4-4189-a994-4e121582aadf */ export type ActorItem = Item< 'actor', { /** - * First name (text) + * first_name (text) * - * Required: true + * Required: false * Codename: first_name - * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d - * Guidelines: This is the first name of the actor + * Id: 4af5e7ce-88ef-4159-96ae-96a552992f91 */ first_name: MigrationElementModels.TextElement; /** - * Last name (text) + * last_name (text) * - * Required: true + * Required: false * Codename: last_name - * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 + * Id: 0f00b26e-60f3-462d-8110-18180137c3a0 */ last_name: MigrationElementModels.TextElement; /** - * Photo (asset) + * photo (asset) * * Required: false * Codename: photo - * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 + * Id: 069b38ee-385c-410f-b7fe-53ec59a5f139 */ photo: MigrationElementModels.AssetElement; /** - * Url (url_slug) + * url (url_slug) * * Required: false * Codename: url - * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 + * Id: c4b2d64f-af45-45a4-92d8-4829833563ff */ url: MigrationElementModels.UrlSlugElement; } diff --git a/sample/migration/content-types/index.ts b/sample/migration/content-types/index.ts index 3116ea2..83a1c03 100644 --- a/sample/migration/content-types/index.ts +++ b/sample/migration/content-types/index.ts @@ -6,12 +6,14 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ export * from './actor.js'; export * from './movie.js'; +export * from './special_type.js'; +export * from './test.js'; diff --git a/sample/migration/content-types/movie.ts b/sample/migration/content-types/movie.ts index eaa1679..caff7ec 100644 --- a/sample/migration/content-types/movie.ts +++ b/sample/migration/content-types/movie.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ @@ -20,89 +20,98 @@ import type { Item } from '../migration.js'; * Movie * * Codename: movie - * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c + * Id: db7356f6-1d82-42a0-9ebb-07865cffa995 */ export type MovieItem = Item< 'movie', { /** - * Category (multiple_choice) + * Category (taxonomy) * * Required: false * Codename: category - * Id: 9821c252-6414-f549-c17f-cc171dd87713 + * Id: 8c12be35-e3e7-447c-a185-7b5e101ebf12 */ - category: MigrationElementModels.MultipleChoiceElement; + category: MigrationElementModels.TaxonomyElement; /** - * Length (number) + * length (number) * * Required: false * Codename: length - * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c + * Id: e3d07f3a-60c2-4072-846d-c23e51ec833e */ length: MigrationElementModels.NumberElement; /** - * Plot (rich_text) + * plot (rich_text) * * Required: false * Codename: plot - * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce + * Id: ad2e5dc7-8d08-4f74-afeb-25b475f1e6fc */ plot: MigrationElementModels.RichTextElement; /** - * Poster (asset) + * poster (asset) * * Required: false * Codename: poster - * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d + * Id: 9b197f1e-0728-4d14-9814-97f7b8ef01fc */ poster: MigrationElementModels.AssetElement; /** - * ReleaseCategory (taxonomy) + * Release category (taxonomy) * * Required: false * Codename: releasecategory - * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 + * Id: 5faa827f-f262-43c3-8f58-0f354b8d393f */ releasecategory: MigrationElementModels.TaxonomyElement; /** - * Released (date_time) + * released (date_time) * * Required: false * Codename: released - * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 + * Id: 656b9dc9-7bba-4f1f-a2b8-52f7f730a66f */ released: MigrationElementModels.DateTimeElement; /** - * SeoName (url_slug) + * seoname (url_slug) * * Required: false * Codename: seoname - * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c + * Id: 734f94be-5930-4bdf-b05b-f59f5a291675 */ seoname: MigrationElementModels.UrlSlugElement; /** - * Stars (modular_content) + * stars (modular_content) * * Required: false * Codename: stars - * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 + * Id: 55596dd1-e808-415d-95aa-e2be34238d11 */ stars: MigrationElementModels.LinkedItemsElement; /** - * Title (text) + * Category (taxonomy) * - * Required: true + * Required: false + * Codename: taxonomy_snippet_test__test_taxonomy + * Id: c030e3ec-5031-4d7f-af88-5032365733c7 + */ + taxonomy_snippet_test__test_taxonomy: MigrationElementModels.TaxonomyElement; + + /** + * title (text) + * + * Required: false * Codename: title - * Id: 3473187e-dc78-eff2-7099-f690f7042d4a + * Id: 660c851a-a9a1-4378-97a3-1348bc2a4d76 */ title: MigrationElementModels.TextElement; } diff --git a/sample/migration/content-types/special_type.ts b/sample/migration/content-types/special_type.ts new file mode 100644 index 0000000..ac71bf9 --- /dev/null +++ b/sample/migration/content-types/special_type.ts @@ -0,0 +1,37 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Migration Toolkit tests +* Environment: Production +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* +* ------------------------------------------------------------------------------- +**/ + +import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; +import type { Item } from '../migration.js'; + +/** + * My Special type hello + * + * Codename: special_type + * Id: 410fb007-42e3-442d-8cdf-fba4cf50f850 + */ +export type MySpecialTypehelloItem = Item< + 'special_type', + { + /** + * Hello (text) + * + * Required: false + * Codename: hello + * Id: 41d50fe3-0858-494c-9f33-85960821b5d6 + */ + hello: MigrationElementModels.TextElement; + } +>; diff --git a/sample/migration/content-types/test.ts b/sample/migration/content-types/test.ts new file mode 100644 index 0000000..6d7181d --- /dev/null +++ b/sample/migration/content-types/test.ts @@ -0,0 +1,55 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Migration Toolkit tests +* Environment: Production +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* +* ------------------------------------------------------------------------------- +**/ + +import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; +import type { Item } from '../migration.js'; + +/** + * Test + * + * Codename: test + * Id: 81ab0b2c-dd14-41e7-a1ed-868b249ad8bc + */ +export type TestItem = Item< + 'test', + { + /** + * Snippet elem 2 (number) + * + * Required: false + * Codename: my_snippet__snippet_elem_2 + * Id: b2f65646-3310-4a64-af2a-0d9d025a91d0 + */ + my_snippet__snippet_elem_2: MigrationElementModels.NumberElement; + + /** + * Snippet elem1 (text) + * + * Required: false + * Codename: my_snippet__snippet_elem1 + * Id: 3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d + */ + my_snippet__snippet_elem1: MigrationElementModels.TextElement; + + /** + * Text (text) + * + * Required: false + * Codename: text + * Id: 65f61f6a-b69c-47dc-bc38-19855507bf14 + */ + text: MigrationElementModels.TextElement; + } +>; diff --git a/sample/migration/environment/environment.ts b/sample/migration/environment/environment.ts index 901b7eb..03b98ae 100644 --- a/sample/migration/environment/environment.ts +++ b/sample/migration/environment/environment.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ @@ -16,12 +16,12 @@ /** * Type representing all languages */ -export type LanguageCodenames = 'cz' | 'en' | 'German'; +export type LanguageCodenames = 'en' | 'es'; /** * Type representing all content types */ -export type ContentTypeCodenames = 'actor' | 'movie'; +export type ContentTypeCodenames = 'actor' | 'movie' | 'special_type' | 'test'; /** * Type representing all collections @@ -31,9 +31,16 @@ export type CollectionCodenames = 'default'; /** * Type representing all workflows */ -export type WorkflowCodenames = 'default'; +export type WorkflowCodenames = 'default' | 'my_test_workflow'; /** * Type representing all worksflow steps across all workflows */ -export type WorkflowStepCodenames = 'archived' | 'draft' | 'published' | 'ready_to_publish' | 'review' | 'scheduled'; +export type WorkflowStepCodenames = + | 'archived' + | 'draft_3171da5' + | 'draft' + | 'published' + | 'ready_for_review' + | 'ready_to_publish' + | 'scheduled'; diff --git a/sample/migration/environment/index.ts b/sample/migration/environment/index.ts index 2bfdee9..9d42c4e 100644 --- a/sample/migration/environment/index.ts +++ b/sample/migration/environment/index.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ diff --git a/sample/migration/index.ts b/sample/migration/index.ts index aedabaf..82c04f5 100644 --- a/sample/migration/index.ts +++ b/sample/migration/index.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ diff --git a/sample/migration/migration.ts b/sample/migration/migration.ts index 9d3f02b..738a9a0 100644 --- a/sample/migration/migration.ts +++ b/sample/migration/migration.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Movie Database +* Project: Migration Toolkit tests * Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * * ------------------------------------------------------------------------------- **/ From 488721d6109f9cdd3aa4bcd2e66bb3a008496d22 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 4 Sep 2024 10:36:21 +0200 Subject: [PATCH 074/183] Unifies comments wrapping & allow more special characters inside --- lib/core/comment.utils.ts | 7 +- lib/core/core.utils.ts | 13 +- .../delivery-content-type.generator.ts | 16 +- .../delivery/delivery-taxonomy.generator.ts | 8 +- .../environment/environment.generator.ts | 77 +-- .../migration/migration.generator.ts | 23 +- .../delivery/content-type-snippets/index.ts | 2 +- .../content-type-snippets/my_snippet.ts | 2 +- .../taxonomy_snippet_test.ts | 2 +- sample/delivery/content-types/actor.ts | 2 +- sample/delivery/content-types/index.ts | 2 +- sample/delivery/content-types/movie.ts | 2 +- sample/delivery/content-types/special_type.ts | 4 +- sample/delivery/content-types/test.ts | 2 +- sample/delivery/index.ts | 2 +- sample/delivery/taxonomies/category.ts | 2 +- sample/delivery/taxonomies/index.ts | 2 +- .../delivery/taxonomies/release_category.ts | 2 +- sample/environment/assetFolders.ts | 10 +- sample/environment/collections.ts | 2 +- sample/environment/contentTypeSnippets.ts | 2 +- sample/environment/contentTypes.ts | 507 +++++++++--------- sample/environment/index.ts | 2 +- sample/environment/languages.ts | 2 +- sample/environment/roles.ts | 2 +- sample/environment/taxonomies.ts | 2 +- sample/environment/webhooks.ts | 2 +- sample/environment/workflows.ts | 2 +- sample/migration/content-types/actor.ts | 2 +- sample/migration/content-types/index.ts | 2 +- sample/migration/content-types/movie.ts | 2 +- .../migration/content-types/special_type.ts | 4 +- sample/migration/content-types/test.ts | 2 +- sample/migration/environment/environment.ts | 2 +- sample/migration/environment/index.ts | 2 +- sample/migration/index.ts | 2 +- sample/migration/migration.ts | 10 +- 37 files changed, 375 insertions(+), 356 deletions(-) diff --git a/lib/core/comment.utils.ts b/lib/core/comment.utils.ts index bdeb781..c05dab2 100644 --- a/lib/core/comment.utils.ts +++ b/lib/core/comment.utils.ts @@ -3,7 +3,12 @@ import { libMetadata } from '../meta/index.js'; import { toSafeString } from './core.utils.js'; export function wrapComment(comment: string): string { - return `/** \n * ${comment} \n*/`; + return `/**${toSafeComment(comment)}*/`; +} + +export function toSafeComment(text: string): string { + const replaceContent = ''; + return text.replace(/\/\*/g, replaceContent).replace(/\*\//g, replaceContent); } export function getEnvironmentInfoComment(data: { diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 52ae448..6eebb5f 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -57,14 +57,8 @@ export function getStringOrUndefined(text?: string): string { return text ? `'${text}'` : 'undefined'; } -export function toSafeStringCode(text: string): string { - const replaceContent = ''; - return text.replace(/[\s-]/g, replaceContent).replace(/[^a-zA-Z0-9_]/g, replaceContent); -} - export function toSafeString(text: string): string { - const replaceContent = ' '; - return text.replace(/[\s-]/g, replaceContent).replace(/[^a-zA-Z0-9_]/g, replaceContent); + return text; } export function toOutputDirPath(outputDir?: string): string { @@ -74,3 +68,8 @@ export function toOutputDirPath(outputDir?: string): string { function removeLineEndings(value: string): string { return value.replace(/(\r\n|\n|\r)/gm, ''); } + +function toSafeStringCode(text: string): string { + const replaceContent = ''; + return text.replace(/[\s-]/g, replaceContent).replace(/[^a-zA-Z0-9_]/g, replaceContent); +} diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 5404a61..45999b6 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -20,8 +20,8 @@ import { TaxonomyNameResolver, TaxonomyTypeFileNameResolver, toGuidelinesComment, - toSafeString, - uniqueFilter + uniqueFilter, + wrapComment } from '../../core/index.js'; interface ExtractImportsResult { @@ -194,12 +194,12 @@ ${importer.importType({ })} ${contentTypeImports.imports.join('\n')} -/** -* ${toSafeString(typeOrSnippet.name)} +${wrapComment(` +* ${typeOrSnippet.name} * * Id: ${typeOrSnippet.id} -* Codename: ${typeOrSnippet.codename} -*/ +* Codename: ${typeOrSnippet.codename} +`)} export type ${contentTypeImports.typeName} = ${deliveryConfig.sdkTypes.contentItem}<{ ${getElementsCode(flattenedElements)} }>${contentTypeImports.contentTypeExtends ? ` ${contentTypeImports.contentTypeExtends}` : ''}; @@ -234,13 +234,13 @@ export type ${contentTypeImports.typeName} = ${deliveryConfig.sdkTypes.contentIt } return (code += ` - /** + ${wrapComment(` * ${element.title} (${element.type}) * * Required: ${element.isRequired ? 'true' : 'false'} * Codename: ${element.codename} * Id: ${element.id}${element.guidelines ? `\n* Guidelines: ${toGuidelinesComment(element.guidelines)}` : ''} - */ + `)} ${elementName}: ${deliveryConfig.sdkTypes.elements}.${mappedType};`); }, '') ); diff --git a/lib/generators/delivery/delivery-taxonomy.generator.ts b/lib/generators/delivery/delivery-taxonomy.generator.ts index a3fd943..5ba0022 100644 --- a/lib/generators/delivery/delivery-taxonomy.generator.ts +++ b/lib/generators/delivery/delivery-taxonomy.generator.ts @@ -9,7 +9,7 @@ import { sortAlphabetically, TaxonomyNameResolver, TaxonomyTypeFileNameResolver, - toSafeString + wrapComment } from '../../core/index.js'; export interface DeliveryTaxonomyGeneratorConfig { @@ -47,12 +47,12 @@ export function deliveryTaxonomyGenerator(config: DeliveryTaxonomyGeneratorConfi const getModelCode = (taxonomy: Readonly): string => { return ` -/** - * ${toSafeString(taxonomy.name)} +${wrapComment(` + * ${taxonomy.name} * * Codename: ${taxonomy.codename} * Id: ${taxonomy.id} - */ +`)} export type ${taxonomyNameMap(taxonomy)} = ${getTaxonomyTermsCode(taxonomy)}; `; }; diff --git a/lib/generators/environment/environment.generator.ts b/lib/generators/environment/environment.generator.ts index 409ae21..5bf659a 100644 --- a/lib/generators/environment/environment.generator.ts +++ b/lib/generators/environment/environment.generator.ts @@ -20,7 +20,8 @@ import { sortAlphabetically, toCamelCase, toGuidelinesComment, - toSafeString + toSafeString, + wrapComment } from '../../core/index.js'; interface WorkflowStep { @@ -107,9 +108,9 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { const isLast = index === languages.length - 1; return `${code}\n - /** - * ${toSafeString(language.name)} - */ + ${wrapComment(` + * ${language.name} + `)} ${toCamelCase(language.codename)}: { codename: '${language.codename}', id: '${language.id}', @@ -127,9 +128,9 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { const isLast = index === workflows.length - 1; return `${code}\n - /** - * ${toSafeString(workflow.name)} - */ + ${wrapComment(` + * ${workflow.name} + `)} ${toCamelCase(workflow.codename)}: { codename: '${workflow.codename}', id: '${workflow.id}', @@ -145,9 +146,9 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { const isLast = index === assetFolders.length - 1; return `${code}\n - /** - * ${toSafeString(assetFolder.name)} - */ + ${wrapComment(` + * ${assetFolder.name} + `)} ${toCamelCase(assetFolder.codename)}: { codename: '${assetFolder.codename}', id: '${assetFolder.id}', @@ -163,9 +164,9 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { const isLast = index === snippets.length - 1; return `${code}\n - /** - * ${toSafeString(snippet.name)} - */ + ${wrapComment(` + * ${snippet.name} + `)} ${toCamelCase(snippet.codename)}: { codename: '${snippet.codename}', id: '${snippet.id}', @@ -181,9 +182,9 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { const isLast = index === contentTypes.length - 1; return `${code}\n - /** - * ${toSafeString(contentType.name)} - */ + ${wrapComment(` + * ${contentType.name} + `)} ${toCamelCase(contentType.codename)}: { codename: '${contentType.codename}', id: '${contentType.id}', @@ -206,10 +207,10 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { const isLast = index === flattenedElements.length - 1; const elementOptions = getElementOptionsCode(element); - return `${code}\n - /** - * ${toSafeString(element.title)} (${element.type})${element.guidelines ? `\n* Guidelines: ${toGuidelinesComment(element.guidelines)}` : ''} - */ + return `${code} + ${wrapComment(` + * ${element.title} (${element.type})${element.guidelines ? `\n* Guidelines: ${toGuidelinesComment(element.guidelines)}` : ''} + `)} ${toCamelCase(element.codename)}: { codename: '${element.codename}', id: '${element.id}', @@ -231,9 +232,9 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { (code, option, index) => { const isLast = index === element.options.length - 1; return `${code}\n - /** - * ${toSafeString(option.name)} - */ + ${wrapComment(` + * ${option.name} + `)} ${toCamelCase(option.codename ?? option.name)}: { name: '${toSafeString(option.name)}', id: '${option.id}', @@ -253,9 +254,9 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { const isLast = index === taxonomies.length - 1; return `${code}\n - /** - * ${toSafeString(taxonomy.name)} - */ + ${wrapComment(` + * ${taxonomy.name} + `)} ${toCamelCase(taxonomy.codename)}: { codename: '${taxonomy.codename}', externalId: ${getStringOrUndefined(taxonomy.externalId)}, @@ -271,9 +272,9 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { const isLast = index === collections.length - 1; return `${code}\n - /** - * ${toSafeString(collection.name)} - */ + ${wrapComment(` + * ${collection.name} + `)} ${toCamelCase(collection.codename)}: { codename: '${collection.codename}', id: '${collection.id}', @@ -287,9 +288,9 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { const isLast = index === roles.length - 1; return `${code}\n - /** - * ${toSafeString(role.name)} - */ + ${wrapComment(` + * ${role.name} + `)} ${toCamelCase(role.codename ?? role.name)}: { codename: ${getStringOrUndefined(role.codename)}, id: '${role.id}', @@ -303,9 +304,9 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { const isLast = index === webhooks.length - 1; return `${code}\n - /** - * ${toSafeString(webhook.name)} - */ + ${wrapComment(` + * ${webhook.name} + `)} ${toCamelCase(webhook.name)}: { url: '${webhook.url}', id: '${webhook.id}', @@ -322,9 +323,9 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { const isLast = index === sortedTerms.length - 1; return `${code}\n - /** - * ${toSafeString(term.name)} - */ + ${wrapComment(` + * ${term.name} + `)} ${toCamelCase(term.codename)}: { codename: '${term.codename}', id: '${term.id}', diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index edf4b8c..69ab1f7 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -18,7 +18,6 @@ import { sortAlphabetically, toGuidelinesComment, toPascalCase, - toSafeString, uniqueFilter, wrapComment } from '../../core/index.js'; @@ -53,12 +52,12 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { importValue: migrationConfig.localTypeNames.item })} - /** - * ${toSafeString(type.name)} + ${wrapComment(` + * ${type.name} * * Codename: ${type.codename} * Id: ${type.id} - */ + `)} export type ${toPascalCase(type.name)}Item = ${migrationConfig.localTypeNames.item}< '${type.codename}', { @@ -70,13 +69,13 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { ) .map((element) => { return ` - /** - * ${toSafeString(element.title)} (${element.type}) + ${wrapComment(` + * ${element.title} (${element.type}) * * Required: ${element.isRequired ? 'true' : 'false'} * Codename: ${element.codename} * Id: ${element.id}${element.guidelines ? `\n* Guidelines: ${toGuidelinesComment(element.guidelines)}` : ''} - */ + `)} ${element.codename}: ${getElementPropType(element)}`; }) .join(',\n')}, @@ -91,19 +90,19 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { { filename: `${migrationConfig.environmentFolderName}/${migrationConfig.environmentFilename}.ts`, text: ` - ${wrapComment('Type representing all languages')} + ${wrapComment(`\n * Type representing all languages\n`)} ${getLanguageCodenamesType(config.environmentData.languages)} - ${wrapComment('Type representing all content types')} + ${wrapComment(`\n * Type representing all content types\n`)} ${getContentTypeCodenamesType(config.environmentData.types)} - ${wrapComment('Type representing all collections')} + ${wrapComment(`\n * Type representing all collections\n`)} ${getCollectionCodenamesType(config.environmentData.collections)} - ${wrapComment('Type representing all workflows')} + ${wrapComment(`\n * Type representing all workflows\n`)} ${getWorkflowCodenamesType(config.environmentData.workflows)} - ${wrapComment('Type representing all worksflow steps across all workflows')} + ${wrapComment(`\n * Type representing all worksflow steps across all workflows\n`)} ${getWorkflowStepCodenamesType(config.environmentData.workflows)} ` } diff --git a/sample/delivery/content-type-snippets/index.ts b/sample/delivery/content-type-snippets/index.ts index 275c315..dfd7b0d 100644 --- a/sample/delivery/content-type-snippets/index.ts +++ b/sample/delivery/content-type-snippets/index.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/delivery/content-type-snippets/my_snippet.ts b/sample/delivery/content-type-snippets/my_snippet.ts index 8566027..ecedb5b 100644 --- a/sample/delivery/content-type-snippets/my_snippet.ts +++ b/sample/delivery/content-type-snippets/my_snippet.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts b/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts index 8269f84..7e5edde 100644 --- a/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts +++ b/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index 28a2574..c70608f 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/delivery/content-types/index.ts b/sample/delivery/content-types/index.ts index 83a1c03..b3f252d 100644 --- a/sample/delivery/content-types/index.ts +++ b/sample/delivery/content-types/index.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index db57cab..c51bc2a 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/delivery/content-types/special_type.ts b/sample/delivery/content-types/special_type.ts index c00b61e..0a96a6e 100644 --- a/sample/delivery/content-types/special_type.ts +++ b/sample/delivery/content-types/special_type.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * @@ -16,7 +16,7 @@ import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; /** - * My Special type hello + * 😺 My Special type[hello]++🥸'` * * Id: 410fb007-42e3-442d-8cdf-fba4cf50f850 * Codename: special_type diff --git a/sample/delivery/content-types/test.ts b/sample/delivery/content-types/test.ts index 1a21eec..cd826d8 100644 --- a/sample/delivery/content-types/test.ts +++ b/sample/delivery/content-types/test.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/delivery/index.ts b/sample/delivery/index.ts index aa463c5..175bf0c 100644 --- a/sample/delivery/index.ts +++ b/sample/delivery/index.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/delivery/taxonomies/category.ts b/sample/delivery/taxonomies/category.ts index 8873263..bb910f7 100644 --- a/sample/delivery/taxonomies/category.ts +++ b/sample/delivery/taxonomies/category.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/delivery/taxonomies/index.ts b/sample/delivery/taxonomies/index.ts index acfdbc4..7646efe 100644 --- a/sample/delivery/taxonomies/index.ts +++ b/sample/delivery/taxonomies/index.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/delivery/taxonomies/release_category.ts b/sample/delivery/taxonomies/release_category.ts index bfaade8..5aeca92 100644 --- a/sample/delivery/taxonomies/release_category.ts +++ b/sample/delivery/taxonomies/release_category.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/environment/assetFolders.ts b/sample/environment/assetFolders.ts index 4dd2f59..1e96301 100644 --- a/sample/environment/assetFolders.ts +++ b/sample/environment/assetFolders.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * @@ -15,24 +15,24 @@ export const assetFolders = { /** - * my folder + * my-folder */ myFolder: { codename: 'my_folder', id: 'f1c6ba01-3b13-41ce-81e7-3125840b0b0e', externalId: undefined, - name: 'my folder', + name: 'my-folder', folders: {} }, /** - * my folder2 + * my-folder2 */ myFolder2: { codename: 'my_folder2', id: '44a00189-9298-4cf9-b8fb-3f208c3f4f8f', externalId: undefined, - name: 'my folder2', + name: 'my-folder2', folders: {} } } as const; diff --git a/sample/environment/collections.ts b/sample/environment/collections.ts index 39f1c0d..f756fb7 100644 --- a/sample/environment/collections.ts +++ b/sample/environment/collections.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/environment/contentTypeSnippets.ts b/sample/environment/contentTypeSnippets.ts index 5aad5f3..91d7323 100644 --- a/sample/environment/contentTypeSnippets.ts +++ b/sample/environment/contentTypeSnippets.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/environment/contentTypes.ts b/sample/environment/contentTypes.ts index a922ff0..c5b2fac 100644 --- a/sample/environment/contentTypes.ts +++ b/sample/environment/contentTypes.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * @@ -14,263 +14,282 @@ **/ export const contentTypes = { - /** - * Actor - */ - actor: { - codename: 'actor', - id: 'd8900ee2-82f4-4189-a994-4e121582aadf', - externalId: undefined, - name: 'Actor', - elements: { - /** - * first_name (text) - */ - firstName: { - codename: 'first_name', - id: '4af5e7ce-88ef-4159-96ae-96a552992f91', - externalId: undefined, - name: 'first_name', - required: false, - type: 'text' - }, + - /** - * last_name (text) - */ - lastName: { - codename: 'last_name', - id: '0f00b26e-60f3-462d-8110-18180137c3a0', - externalId: undefined, - name: 'last_name', - required: false, - type: 'text' - }, + /** + * Actor + */ + actor: { + codename: 'actor', + id: 'd8900ee2-82f4-4189-a994-4e121582aadf', + externalId: undefined, + name: 'Actor', + elements: { + /** + * first_name (text) + */ + firstName: { + codename: 'first_name', + id: '4af5e7ce-88ef-4159-96ae-96a552992f91', + externalId: undefined, + name: 'first_name', + required: false, + type: 'text' + + }, - /** - * photo (asset) - */ - photo: { - codename: 'photo', - id: '069b38ee-385c-410f-b7fe-53ec59a5f139', - externalId: undefined, - name: 'photo', - required: false, - type: 'asset' - }, + /** + * last_name (text) + */ + lastName: { + codename: 'last_name', + id: '0f00b26e-60f3-462d-8110-18180137c3a0', + externalId: undefined, + name: 'last_name', + required: false, + type: 'text' + + }, - /** - * url (url_slug) - */ - url: { - codename: 'url', - id: 'c4b2d64f-af45-45a4-92d8-4829833563ff', - externalId: undefined, - name: 'url', - required: false, - type: 'url_slug' - } - } - }, + /** + * photo (asset) + */ + photo: { + codename: 'photo', + id: '069b38ee-385c-410f-b7fe-53ec59a5f139', + externalId: undefined, + name: 'photo', + required: false, + type: 'asset' + + }, - /** - * Movie - */ - movie: { - codename: 'movie', - id: 'db7356f6-1d82-42a0-9ebb-07865cffa995', - externalId: undefined, - name: 'Movie', - elements: { - /** - * Category (taxonomy) - */ - category: { - codename: 'category', - id: '8c12be35-e3e7-447c-a185-7b5e101ebf12', - externalId: undefined, - name: 'Category', - required: false, - type: 'taxonomy' - }, + /** + * url (url_slug) + */ + url: { + codename: 'url', + id: 'c4b2d64f-af45-45a4-92d8-4829833563ff', + externalId: undefined, + name: 'url', + required: false, + type: 'url_slug' + + }} + }, - /** - * length (number) - */ - length: { - codename: 'length', - id: 'e3d07f3a-60c2-4072-846d-c23e51ec833e', - externalId: undefined, - name: 'length', - required: false, - type: 'number' - }, - /** - * plot (rich_text) - */ - plot: { - codename: 'plot', - id: 'ad2e5dc7-8d08-4f74-afeb-25b475f1e6fc', - externalId: undefined, - name: 'plot', - required: false, - type: 'rich_text' - }, + /** + * Movie + */ + movie: { + codename: 'movie', + id: 'db7356f6-1d82-42a0-9ebb-07865cffa995', + externalId: undefined, + name: 'Movie', + elements: { + /** + * Category (taxonomy) + */ + category: { + codename: 'category', + id: '8c12be35-e3e7-447c-a185-7b5e101ebf12', + externalId: undefined, + name: 'Category', + required: false, + type: 'taxonomy' + + }, - /** - * poster (asset) - */ - poster: { - codename: 'poster', - id: '9b197f1e-0728-4d14-9814-97f7b8ef01fc', - externalId: undefined, - name: 'poster', - required: false, - type: 'asset' - }, + /** + * length (number) + */ + length: { + codename: 'length', + id: 'e3d07f3a-60c2-4072-846d-c23e51ec833e', + externalId: undefined, + name: 'length', + required: false, + type: 'number' + + }, - /** - * Release category (taxonomy) - */ - releasecategory: { - codename: 'releasecategory', - id: '5faa827f-f262-43c3-8f58-0f354b8d393f', - externalId: undefined, - name: 'Release category', - required: false, - type: 'taxonomy' - }, + /** + * plot (rich_text) + */ + plot: { + codename: 'plot', + id: 'ad2e5dc7-8d08-4f74-afeb-25b475f1e6fc', + externalId: undefined, + name: 'plot', + required: false, + type: 'rich_text' + + }, - /** - * released (date_time) - */ - released: { - codename: 'released', - id: '656b9dc9-7bba-4f1f-a2b8-52f7f730a66f', - externalId: undefined, - name: 'released', - required: false, - type: 'date_time' - }, + /** + * poster (asset) + */ + poster: { + codename: 'poster', + id: '9b197f1e-0728-4d14-9814-97f7b8ef01fc', + externalId: undefined, + name: 'poster', + required: false, + type: 'asset' + + }, - /** - * seoname (url_slug) - */ - seoname: { - codename: 'seoname', - id: '734f94be-5930-4bdf-b05b-f59f5a291675', - externalId: undefined, - name: 'seoname', - required: false, - type: 'url_slug' - }, + /** + * Release category (taxonomy) + */ + releasecategory: { + codename: 'releasecategory', + id: '5faa827f-f262-43c3-8f58-0f354b8d393f', + externalId: undefined, + name: 'Release category', + required: false, + type: 'taxonomy' + + }, - /** - * stars (modular_content) - */ - stars: { - codename: 'stars', - id: '55596dd1-e808-415d-95aa-e2be34238d11', - externalId: undefined, - name: 'stars', - required: false, - type: 'modular_content' - }, + /** + * released (date_time) + */ + released: { + codename: 'released', + id: '656b9dc9-7bba-4f1f-a2b8-52f7f730a66f', + externalId: undefined, + name: 'released', + required: false, + type: 'date_time' + + }, - /** - * Category (taxonomy) - */ - taxonomySnippetTestTestTaxonomy: { - codename: 'taxonomy_snippet_test__test_taxonomy', - id: 'c030e3ec-5031-4d7f-af88-5032365733c7', - externalId: undefined, - name: 'Category', - required: false, - type: 'taxonomy' - }, + /** + * seoname (url_slug) + */ + seoname: { + codename: 'seoname', + id: '734f94be-5930-4bdf-b05b-f59f5a291675', + externalId: undefined, + name: 'seoname', + required: false, + type: 'url_slug' + + }, - /** - * title (text) - */ - title: { - codename: 'title', - id: '660c851a-a9a1-4378-97a3-1348bc2a4d76', - externalId: undefined, - name: 'title', - required: false, - type: 'text' - } - } - }, + /** + * stars (modular_content) + */ + stars: { + codename: 'stars', + id: '55596dd1-e808-415d-95aa-e2be34238d11', + externalId: undefined, + name: 'stars', + required: false, + type: 'modular_content' + + }, - /** - * My Special type hello - */ - specialType: { - codename: 'special_type', - id: '410fb007-42e3-442d-8cdf-fba4cf50f850', - externalId: undefined, - name: ' My Special type hello ', - elements: { - /** - * Hello (text) - */ - hello: { - codename: 'hello', - id: '41d50fe3-0858-494c-9f33-85960821b5d6', - externalId: undefined, - name: 'Hello', - required: false, - type: 'text' - } - } - }, + /** + * Category (taxonomy) + */ + taxonomySnippetTestTestTaxonomy: { + codename: 'taxonomy_snippet_test__test_taxonomy', + id: 'c030e3ec-5031-4d7f-af88-5032365733c7', + externalId: undefined, + name: 'Category', + required: false, + type: 'taxonomy' + + }, - /** - * Test - */ - test: { - codename: 'test', - id: '81ab0b2c-dd14-41e7-a1ed-868b249ad8bc', - externalId: undefined, - name: 'Test', - elements: { - /** - * Snippet elem 2 (number) - */ - mySnippetSnippetElem2: { - codename: 'my_snippet__snippet_elem_2', - id: 'b2f65646-3310-4a64-af2a-0d9d025a91d0', - externalId: undefined, - name: 'Snippet elem 2', - required: false, - type: 'number' - }, + /** + * title (text) + */ + title: { + codename: 'title', + id: '660c851a-a9a1-4378-97a3-1348bc2a4d76', + externalId: undefined, + name: 'title', + required: false, + type: 'text' + + }} + }, - /** - * Snippet elem1 (text) - */ - mySnippetSnippetElem1: { - codename: 'my_snippet__snippet_elem1', - id: '3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d', - externalId: undefined, - name: 'Snippet elem1', - required: false, - type: 'text' - }, - /** - * Text (text) - */ - text: { - codename: 'text', - id: '65f61f6a-b69c-47dc-bc38-19855507bf14', - externalId: undefined, - name: 'Text', - required: false, - type: 'text' - } - } - } -} as const; + /** + * 😺 My Special type[hello]++🥸'` + */ + specialType: { + codename: 'special_type', + id: '410fb007-42e3-442d-8cdf-fba4cf50f850', + externalId: undefined, + name: '😺 My Special type[hello]++🥸'` */', + elements: { + /** + * Hello (text) + */ + hello: { + codename: 'hello', + id: '41d50fe3-0858-494c-9f33-85960821b5d6', + externalId: undefined, + name: 'Hello', + required: false, + type: 'text' + + }} + }, + + + /** + * Test + */ + test: { + codename: 'test', + id: '81ab0b2c-dd14-41e7-a1ed-868b249ad8bc', + externalId: undefined, + name: 'Test', + elements: { + /** + * Snippet elem 2 (number) + */ + mySnippetSnippetElem2: { + codename: 'my_snippet__snippet_elem_2', + id: 'b2f65646-3310-4a64-af2a-0d9d025a91d0', + externalId: undefined, + name: 'Snippet elem 2', + required: false, + type: 'number' + + }, + + /** + * Snippet elem1 (text) + */ + mySnippetSnippetElem1: { + codename: 'my_snippet__snippet_elem1', + id: '3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d', + externalId: undefined, + name: 'Snippet elem1', + required: false, + type: 'text' + + }, + + /** + * Text (text) + */ + text: { + codename: 'text', + id: '65f61f6a-b69c-47dc-bc38-19855507bf14', + externalId: undefined, + name: 'Text', + required: false, + type: 'text' + + }} + } + } as const; \ No newline at end of file diff --git a/sample/environment/index.ts b/sample/environment/index.ts index a01d79b..626c0dd 100644 --- a/sample/environment/index.ts +++ b/sample/environment/index.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/environment/languages.ts b/sample/environment/languages.ts index d0840b0..4455edb 100644 --- a/sample/environment/languages.ts +++ b/sample/environment/languages.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/environment/roles.ts b/sample/environment/roles.ts index 00d4ec0..9ea8254 100644 --- a/sample/environment/roles.ts +++ b/sample/environment/roles.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/environment/taxonomies.ts b/sample/environment/taxonomies.ts index fc6348b..230ba47 100644 --- a/sample/environment/taxonomies.ts +++ b/sample/environment/taxonomies.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/environment/webhooks.ts b/sample/environment/webhooks.ts index 65bf670..7ef5c3e 100644 --- a/sample/environment/webhooks.ts +++ b/sample/environment/webhooks.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/environment/workflows.ts b/sample/environment/workflows.ts index 55e18a9..9f8351b 100644 --- a/sample/environment/workflows.ts +++ b/sample/environment/workflows.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/migration/content-types/actor.ts b/sample/migration/content-types/actor.ts index 909e298..da2b56d 100644 --- a/sample/migration/content-types/actor.ts +++ b/sample/migration/content-types/actor.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/migration/content-types/index.ts b/sample/migration/content-types/index.ts index 83a1c03..b3f252d 100644 --- a/sample/migration/content-types/index.ts +++ b/sample/migration/content-types/index.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/migration/content-types/movie.ts b/sample/migration/content-types/movie.ts index caff7ec..48ee669 100644 --- a/sample/migration/content-types/movie.ts +++ b/sample/migration/content-types/movie.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/migration/content-types/special_type.ts b/sample/migration/content-types/special_type.ts index ac71bf9..bec0175 100644 --- a/sample/migration/content-types/special_type.ts +++ b/sample/migration/content-types/special_type.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * @@ -17,7 +17,7 @@ import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; import type { Item } from '../migration.js'; /** - * My Special type hello + * 😺 My Special type[hello]++🥸'` * * Codename: special_type * Id: 410fb007-42e3-442d-8cdf-fba4cf50f850 diff --git a/sample/migration/content-types/test.ts b/sample/migration/content-types/test.ts index 6d7181d..6a2ed5e 100644 --- a/sample/migration/content-types/test.ts +++ b/sample/migration/content-types/test.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/migration/environment/environment.ts b/sample/migration/environment/environment.ts index 03b98ae..588d69c 100644 --- a/sample/migration/environment/environment.ts +++ b/sample/migration/environment/environment.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/migration/environment/index.ts b/sample/migration/environment/index.ts index 9d42c4e..43890e3 100644 --- a/sample/migration/environment/index.ts +++ b/sample/migration/environment/index.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/migration/index.ts b/sample/migration/index.ts index 82c04f5..9c2f1a5 100644 --- a/sample/migration/index.ts +++ b/sample/migration/index.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * diff --git a/sample/migration/migration.ts b/sample/migration/migration.ts index 738a9a0..9c508fb 100644 --- a/sample/migration/migration.ts +++ b/sample/migration/migration.ts @@ -6,7 +6,7 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit tests +* Project: Migration Toolkit - tests * Environment: Production * Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 * @@ -22,9 +22,7 @@ import type { WorkflowStepCodenames } from './environment/environment.js'; -/** - * System object shared by all individual content type models - */ +/**System object shared by all individual content type models*/ export type ItemSystem = MigrationItemSystem< TCodename, LanguageCodenames, @@ -32,9 +30,7 @@ export type ItemSystem = MigrationItemSy WorkflowCodenames >; -/** - * Item object shared by all individual content type models - */ +/**Item object shared by all individual content type models*/ export type Item = MigrationItem< TElements, ItemSystem, From 0d46b244fcc4a1fb016deda8c18c44285a66479c Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 4 Sep 2024 11:31:38 +0200 Subject: [PATCH 075/183] Use safe property name / value processor, updates samples --- lib/core/comment.utils.ts | 5 +- lib/core/core.utils.ts | 30 +- lib/fetch/kontent-fetcher.ts | 6 +- .../environment/environment.generator.ts | 58 +- .../delivery/content-type-snippets/index.ts | 7 +- .../content-type-snippets/my_snippet.ts | 41 -- .../taxonomy_snippet_test.ts | 34 -- sample/delivery/content-types/actor.ts | 27 +- sample/delivery/content-types/index.ts | 6 +- sample/delivery/content-types/movie.ts | 56 +- sample/delivery/content-types/special_type.ts | 33 -- sample/delivery/content-types/test.ts | 35 -- sample/delivery/index.ts | 4 +- sample/delivery/taxonomies/index.ts | 8 +- .../{release_category.ts => movietype.ts} | 12 +- .../{category.ts => releasecategory.ts} | 12 +- sample/environment/assetFolders.ts | 59 +- sample/environment/collections.ts | 4 +- sample/environment/contentTypeSnippets.ts | 64 +-- sample/environment/contentTypes.ts | 505 +++++++++--------- sample/environment/index.ts | 4 +- sample/environment/languages.ts | 33 +- sample/environment/roles.ts | 35 +- sample/environment/taxonomies.ts | 146 ++--- sample/environment/webhooks.ts | 4 +- sample/environment/workflows.ts | 57 +- sample/migration/content-types/actor.ts | 27 +- sample/migration/content-types/index.ts | 6 +- sample/migration/content-types/movie.ts | 55 +- .../migration/content-types/special_type.ts | 37 -- sample/migration/content-types/test.ts | 55 -- sample/migration/environment/environment.ts | 19 +- sample/migration/environment/index.ts | 4 +- sample/migration/index.ts | 4 +- sample/migration/migration.ts | 4 +- 35 files changed, 614 insertions(+), 882 deletions(-) delete mode 100644 sample/delivery/content-type-snippets/my_snippet.ts delete mode 100644 sample/delivery/content-type-snippets/taxonomy_snippet_test.ts delete mode 100644 sample/delivery/content-types/special_type.ts delete mode 100644 sample/delivery/content-types/test.ts rename sample/delivery/taxonomies/{release_category.ts => movietype.ts} (57%) rename sample/delivery/taxonomies/{category.ts => releasecategory.ts} (56%) delete mode 100644 sample/migration/content-types/special_type.ts delete mode 100644 sample/migration/content-types/test.ts diff --git a/lib/core/comment.utils.ts b/lib/core/comment.utils.ts index c05dab2..fda714b 100644 --- a/lib/core/comment.utils.ts +++ b/lib/core/comment.utils.ts @@ -1,6 +1,5 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import { libMetadata } from '../meta/index.js'; -import { toSafeString } from './core.utils.js'; export function wrapComment(comment: string): string { return `/**${toSafeComment(comment)}*/`; @@ -23,8 +22,8 @@ export function getEnvironmentInfoComment(data: { * * ------------------------------------------------------------------------------- * -* Project: ${toSafeString(data.environmentInfo.name)} -* Environment: ${toSafeString(data.environmentInfo.environment)} +* Project: ${toSafeComment(data.environmentInfo.name)} +* Environment: ${toSafeComment(data.environmentInfo.environment)} * Id: ${data.environmentInfo.id}${data.addTimestamp ? `\n* Generated: ${new Date().toLocaleString()}` : ''} * * ------------------------------------------------------------------------------- diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 6eebb5f..755a782 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -1,4 +1,5 @@ import { camelCasePropertyNameResolver, pascalCasePropertyNameResolver, snakeCasePropertyNameResolver } from '@kontent-ai/delivery-sdk'; +import { createHash } from 'crypto'; import { parse } from 'path'; import { CliAction, LibraryType, ModuleResolution } from './core.models.js'; @@ -50,15 +51,32 @@ export function toSnakeCase(text: string): string { } export function toGuidelinesComment(guidelines: string): string { - return toSafeString(removeLineEndings(guidelines)); + return removeLineEndings(guidelines); } export function getStringOrUndefined(text?: string): string { return text ? `'${text}'` : 'undefined'; } -export function toSafeString(text: string): string { - return text; +export function toSafePropertyName(value: string): string { + const replaceContent = ''; + const withoutNumbers = value.replace(/^\d+/, replaceContent); + const propertyName = withoutNumbers + .replace(/[\s-]/g, replaceContent) + .replace(/[^a-zA-Z0-9_]/g, replaceContent) + .toLowerCase(); + + if (propertyName.length === 0) { + // to prevent empty string being used as property name, use hash + return getPropertyStringHash(value); + } + + return propertyName; +} + +export function toSafePropertyValue(value: string): string { + const replaceContent = ''; + return value.replace(/'/g, replaceContent); } export function toOutputDirPath(outputDir?: string): string { @@ -73,3 +91,9 @@ function toSafeStringCode(text: string): string { const replaceContent = ''; return text.replace(/[\s-]/g, replaceContent).replace(/[^a-zA-Z0-9_]/g, replaceContent); } + +function getPropertyStringHash(text: string): string { + const hash = createHash('sha256'); + hash.update(text); + return `_${hash.digest('hex')}`.slice(0, 10); +} diff --git a/lib/fetch/kontent-fetcher.ts b/lib/fetch/kontent-fetcher.ts index 4c2b5f4..e9922ce 100644 --- a/lib/fetch/kontent-fetcher.ts +++ b/lib/fetch/kontent-fetcher.ts @@ -13,7 +13,7 @@ import { WorkflowModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; -import { GeneratorManagementClient, sortAlphabetically, toSafeString } from '../core/index.js'; +import { GeneratorManagementClient, sortAlphabetically, toSafeComment } from '../core/index.js'; interface KontentFetcherConfig { readonly environmentId: string; @@ -36,8 +36,8 @@ export function kontentFetcher(config: KontentFetcherConfig) { return { async getEnvironmentInfoAsync(): Promise> { const projectInformation = (await client.environmentInformation().toPromise()).data; - console.log(`Project '${chalk.yellow(toSafeString(projectInformation.project.name))}'`); - console.log(`Environment '${chalk.yellow(toSafeString(projectInformation.project.environment))}'\n`); + console.log(`Project '${chalk.yellow(toSafeComment(projectInformation.project.name))}'`); + console.log(`Environment '${chalk.yellow(toSafeComment(projectInformation.project.environment))}'\n`); return projectInformation.project; }, async getWorkflowsAsync(): Promise[]> { diff --git a/lib/generators/environment/environment.generator.ts b/lib/generators/environment/environment.generator.ts index 5bf659a..89f377c 100644 --- a/lib/generators/environment/environment.generator.ts +++ b/lib/generators/environment/environment.generator.ts @@ -18,9 +18,9 @@ import { getFlattenedElements, getStringOrUndefined, sortAlphabetically, - toCamelCase, toGuidelinesComment, - toSafeString, + toSafePropertyName, + toSafePropertyValue, wrapComment } from '../../core/index.js'; @@ -111,10 +111,10 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { ${wrapComment(` * ${language.name} `)} - ${toCamelCase(language.codename)}: { + ${language.codename}: { + name: '${toSafePropertyValue(language.name)}', codename: '${language.codename}', id: '${language.id}', - name: '${toSafeString(language.name)}', isActive: ${language.isActive ? 'true' : 'false'}, isDefault: ${language.isDefault ? 'true' : 'false'}, fallbackLanguageId: ${getStringOrUndefined(language.fallbackLanguage?.id)}, @@ -131,10 +131,10 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { ${wrapComment(` * ${workflow.name} `)} - ${toCamelCase(workflow.codename)}: { + ${workflow.codename}: { + name: '${toSafePropertyValue(workflow.name)}', codename: '${workflow.codename}', id: '${workflow.id}', - name: '${toSafeString(workflow.name)}', steps: ${getProjectWorkflowSteps(workflow)} }${!isLast ? ',\n' : ''}`; }, ''); @@ -149,11 +149,11 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { ${wrapComment(` * ${assetFolder.name} `)} - ${toCamelCase(assetFolder.codename)}: { + ${assetFolder.codename}: { + name: '${toSafePropertyValue(assetFolder.name)}', codename: '${assetFolder.codename}', id: '${assetFolder.id}', externalId: ${getStringOrUndefined(assetFolder.externalId)}, - name: '${toSafeString(assetFolder.name)}', folders: ${getAssetFolders(assetFolder.folders)}}${!isLast ? ',\n' : ''}`; }, '{') + '}' ); @@ -167,11 +167,11 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { ${wrapComment(` * ${snippet.name} `)} - ${toCamelCase(snippet.codename)}: { + ${snippet.codename}: { + name: '${toSafePropertyValue(snippet.name)}', codename: '${snippet.codename}', id: '${snippet.id}', externalId: ${getStringOrUndefined(snippet.externalId)}, - name: '${toSafeString(snippet.name)}', elements: {${getContentTypeElements(snippet.elements)}} }${!isLast ? ',\n' : ''}`; }, ''); @@ -185,11 +185,11 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { ${wrapComment(` * ${contentType.name} `)} - ${toCamelCase(contentType.codename)}: { + ${contentType.codename}: { + name: '${toSafePropertyValue(contentType.name)}', codename: '${contentType.codename}', id: '${contentType.id}', externalId: ${getStringOrUndefined(contentType.externalId)}, - name: '${toSafeString(contentType.name)}', elements: {${getContentTypeElements(contentType.elements)}} }${!isLast ? ',\n' : ''}`; }, ''); @@ -211,11 +211,11 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { ${wrapComment(` * ${element.title} (${element.type})${element.guidelines ? `\n* Guidelines: ${toGuidelinesComment(element.guidelines)}` : ''} `)} - ${toCamelCase(element.codename)}: { + ${element.codename}: { + name: '${toSafePropertyValue(element.title)}', codename: '${element.codename}', id: '${element.id}', externalId: ${getStringOrUndefined(element.externalId)}, - name: '${toSafeString(element.title)}', required: ${element.isRequired}, type: '${element.type}' ${elementOptions ? `, options: ${elementOptions}` : ''} @@ -235,8 +235,8 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { ${wrapComment(` * ${option.name} `)} - ${toCamelCase(option.codename ?? option.name)}: { - name: '${toSafeString(option.name)}', + ${toSafePropertyName(option.codename ?? option.name)}: { + name: '${toSafePropertyValue(option.name)}', id: '${option.id}', codename: ${getStringOrUndefined(option.codename)}, externalId: ${getStringOrUndefined(option.external_id)} @@ -255,13 +255,13 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { return `${code}\n ${wrapComment(` - * ${taxonomy.name} + * ${taxonomy.codename} `)} - ${toCamelCase(taxonomy.codename)}: { + ${taxonomy.codename}: { + name: '${toSafePropertyValue(taxonomy.name)}', codename: '${taxonomy.codename}', externalId: ${getStringOrUndefined(taxonomy.externalId)}, id: '${taxonomy.id}', - name: '${toSafeString(taxonomy.name)}', ${getProjectTaxonomiesTerms(taxonomy.terms)} }${!isLast ? ',\n' : ''}`; }, ''); @@ -275,10 +275,10 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { ${wrapComment(` * ${collection.name} `)} - ${toCamelCase(collection.codename)}: { + ${collection.codename}: { codename: '${collection.codename}', id: '${collection.id}', - name: '${toSafeString(collection.name)}' + name: '${toSafePropertyValue(collection.name)}' }${!isLast ? ',\n' : ''}`; }, ''); }; @@ -291,10 +291,10 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { ${wrapComment(` * ${role.name} `)} - ${toCamelCase(role.codename ?? role.name)}: { + ${toSafePropertyName(role.codename ?? role.name)}: { codename: ${getStringOrUndefined(role.codename)}, id: '${role.id}', - name: '${toSafeString(role.name)}' + name: '${toSafePropertyValue(role.name)}' }${!isLast ? ',\n' : ''}`; }, ''); }; @@ -307,10 +307,10 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { ${wrapComment(` * ${webhook.name} `)} - ${toCamelCase(webhook.name)}: { + ${toSafePropertyName(webhook.name)}: { url: '${webhook.url}', id: '${webhook.id}', - name: '${toSafeString(webhook.name)}' + name: '${toSafePropertyValue(webhook.name)}' }${!isLast ? ',\n' : ''}`; }, ''); }; @@ -326,11 +326,11 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { ${wrapComment(` * ${term.name} `)} - ${toCamelCase(term.codename)}: { + ${term.codename}: { codename: '${term.codename}', id: '${term.id}', externalId: ${getStringOrUndefined(term.externalId)}, - name: '${toSafeString(term.name)}', + name: '${toSafePropertyValue(term.name)}', ${getProjectTaxonomiesTerms(term.terms)} }${!isLast ? ',\n' : ''}`; }, 'terms: {') + '}' @@ -344,8 +344,8 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { return ( code + ` - ${toCamelCase(step.codename)}: { - name: '${toSafeString(step.name)}', + ${step.codename}: { + name: '${toSafePropertyValue(step.name)}', codename: '${step.codename}', id: '${step.id}' },` diff --git a/sample/delivery/content-type-snippets/index.ts b/sample/delivery/content-type-snippets/index.ts index dfd7b0d..f13c990 100644 --- a/sample/delivery/content-type-snippets/index.ts +++ b/sample/delivery/content-type-snippets/index.ts @@ -6,12 +6,11 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ -export * from './my_snippet.js'; -export * from './taxonomy_snippet_test.js'; +export {}; diff --git a/sample/delivery/content-type-snippets/my_snippet.ts b/sample/delivery/content-type-snippets/my_snippet.ts deleted file mode 100644 index ecedb5b..0000000 --- a/sample/delivery/content-type-snippets/my_snippet.ts +++ /dev/null @@ -1,41 +0,0 @@ - -/** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Migration Toolkit - tests -* Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 -* -* ------------------------------------------------------------------------------- -**/ - -import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; - -/** - * My snippet - * - * Id: 3274f9e7-ff1b-43f8-aa32-29b53939cd3e - * Codename: my_snippet - */ -export type MySnippet = IContentItem<{ - /** - * Snippet elem 2 (number) - * - * Required: false - * Codename: my_snippet__snippet_elem_2 - * Id: b2f65646-3310-4a64-af2a-0d9d025a91d0 - */ - mySnippetSnippetElem2: Elements.NumberElement; - /** - * Snippet elem1 (text) - * - * Required: false - * Codename: my_snippet__snippet_elem1 - * Id: 3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d - */ - mySnippetSnippetElem1: Elements.TextElement; -}>; diff --git a/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts b/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts deleted file mode 100644 index 7e5edde..0000000 --- a/sample/delivery/content-type-snippets/taxonomy_snippet_test.ts +++ /dev/null @@ -1,34 +0,0 @@ - -/** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Migration Toolkit - tests -* Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 -* -* ------------------------------------------------------------------------------- -**/ - -import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; -import type { Category } from '../taxonomies/category.js'; - -/** - * Taxonomy snippet test - * - * Id: e8219115-e629-4552-b79b-d9f813272573 - * Codename: taxonomy_snippet_test - */ -export type TaxonomySnippetTest = IContentItem<{ - /** - * Category (taxonomy) - * - * Required: false - * Codename: taxonomy_snippet_test__test_taxonomy - * Id: c030e3ec-5031-4d7f-af88-5032365733c7 - */ - taxonomySnippetTestTestTaxonomy: Elements.TaxonomyElement; -}>; diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index c70608f..c23a5b2 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ @@ -18,40 +18,41 @@ import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; /** * Actor * - * Id: d8900ee2-82f4-4189-a994-4e121582aadf + * Id: 58099989-319f-495f-aa36-cb3710854e36 * Codename: actor */ export type Actor = IContentItem<{ /** - * first_name (text) + * First name (text) * - * Required: false + * Required: true * Codename: first_name - * Id: 4af5e7ce-88ef-4159-96ae-96a552992f91 + * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d + * Guidelines: This is the first name of the actor */ firstName: Elements.TextElement; /** - * last_name (text) + * Last name (text) * - * Required: false + * Required: true * Codename: last_name - * Id: 0f00b26e-60f3-462d-8110-18180137c3a0 + * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 */ lastName: Elements.TextElement; /** - * photo (asset) + * Photo (asset) * * Required: false * Codename: photo - * Id: 069b38ee-385c-410f-b7fe-53ec59a5f139 + * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 */ photo: Elements.AssetsElement; /** - * url (url_slug) + * Url (url_slug) * * Required: false * Codename: url - * Id: c4b2d64f-af45-45a4-92d8-4829833563ff + * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 */ url: Elements.UrlSlugElement; }>; diff --git a/sample/delivery/content-types/index.ts b/sample/delivery/content-types/index.ts index b3f252d..3116ea2 100644 --- a/sample/delivery/content-types/index.ts +++ b/sample/delivery/content-types/index.ts @@ -6,14 +6,12 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ export * from './actor.js'; export * from './movie.js'; -export * from './special_type.js'; -export * from './test.js'; diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index c51bc2a..9cfee0d 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -6,96 +6,94 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; -import type { Category } from '../taxonomies/category.js'; -import type { ReleaseCategory } from '../taxonomies/release_category.js'; -import type { TaxonomySnippetTest } from '../content-type-snippets/taxonomy_snippet_test.js'; +import type { Actor } from '../content-types/actor.js'; +import type { ReleaseCategory } from '../taxonomies/releasecategory.js'; /** * Movie * - * Id: db7356f6-1d82-42a0-9ebb-07865cffa995 + * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c * Codename: movie */ export type Movie = IContentItem<{ /** - * Category (taxonomy) + * Category (multiple_choice) * * Required: false * Codename: category - * Id: 8c12be35-e3e7-447c-a185-7b5e101ebf12 + * Id: 9821c252-6414-f549-c17f-cc171dd87713 */ - category: Elements.TaxonomyElement; + category: Elements.MultipleChoiceElement; /** - * length (number) + * Length (number) * * Required: false * Codename: length - * Id: e3d07f3a-60c2-4072-846d-c23e51ec833e + * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c */ length: Elements.NumberElement; /** - * plot (rich_text) + * Plot (rich_text) * * Required: false * Codename: plot - * Id: ad2e5dc7-8d08-4f74-afeb-25b475f1e6fc + * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce */ plot: Elements.RichTextElement; /** - * poster (asset) + * Poster (asset) * * Required: false * Codename: poster - * Id: 9b197f1e-0728-4d14-9814-97f7b8ef01fc + * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d */ poster: Elements.AssetsElement; /** - * Release category (taxonomy) + * ReleaseCategory (taxonomy) * * Required: false * Codename: releasecategory - * Id: 5faa827f-f262-43c3-8f58-0f354b8d393f + * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 */ releasecategory: Elements.TaxonomyElement; /** - * released (date_time) + * Released (date_time) * * Required: false * Codename: released - * Id: 656b9dc9-7bba-4f1f-a2b8-52f7f730a66f + * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 */ released: Elements.DateTimeElement; /** - * seoname (url_slug) + * SeoName (url_slug) * * Required: false * Codename: seoname - * Id: 734f94be-5930-4bdf-b05b-f59f5a291675 + * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c */ seoname: Elements.UrlSlugElement; /** - * stars (modular_content) + * Stars (modular_content) * * Required: false * Codename: stars - * Id: 55596dd1-e808-415d-95aa-e2be34238d11 + * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 */ - stars: Elements.LinkedItemsElement; + stars: Elements.LinkedItemsElement; /** - * title (text) + * Title (text) * - * Required: false + * Required: true * Codename: title - * Id: 660c851a-a9a1-4378-97a3-1348bc2a4d76 + * Id: 3473187e-dc78-eff2-7099-f690f7042d4a */ title: Elements.TextElement; -}> & - TaxonomySnippetTest; +}>; diff --git a/sample/delivery/content-types/special_type.ts b/sample/delivery/content-types/special_type.ts deleted file mode 100644 index 0a96a6e..0000000 --- a/sample/delivery/content-types/special_type.ts +++ /dev/null @@ -1,33 +0,0 @@ - -/** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Migration Toolkit - tests -* Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 -* -* ------------------------------------------------------------------------------- -**/ - -import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; - -/** - * 😺 My Special type[hello]++🥸'` - * - * Id: 410fb007-42e3-442d-8cdf-fba4cf50f850 - * Codename: special_type - */ -export type MySpecialTypehello = IContentItem<{ - /** - * Hello (text) - * - * Required: false - * Codename: hello - * Id: 41d50fe3-0858-494c-9f33-85960821b5d6 - */ - hello: Elements.TextElement; -}>; diff --git a/sample/delivery/content-types/test.ts b/sample/delivery/content-types/test.ts deleted file mode 100644 index cd826d8..0000000 --- a/sample/delivery/content-types/test.ts +++ /dev/null @@ -1,35 +0,0 @@ - -/** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Migration Toolkit - tests -* Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 -* -* ------------------------------------------------------------------------------- -**/ - -import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; -import type { MySnippet } from '../content-type-snippets/my_snippet.js'; - -/** - * Test - * - * Id: 81ab0b2c-dd14-41e7-a1ed-868b249ad8bc - * Codename: test - */ -export type Test = IContentItem<{ - /** - * Text (text) - * - * Required: false - * Codename: text - * Id: 65f61f6a-b69c-47dc-bc38-19855507bf14 - */ - text: Elements.TextElement; -}> & - MySnippet; diff --git a/sample/delivery/index.ts b/sample/delivery/index.ts index 175bf0c..45e59b5 100644 --- a/sample/delivery/index.ts +++ b/sample/delivery/index.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ diff --git a/sample/delivery/taxonomies/index.ts b/sample/delivery/taxonomies/index.ts index 7646efe..4948198 100644 --- a/sample/delivery/taxonomies/index.ts +++ b/sample/delivery/taxonomies/index.ts @@ -6,12 +6,12 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ -export * from './category.js'; -export * from './release_category.js'; +export * from './movietype.js'; +export * from './releasecategory.js'; diff --git a/sample/delivery/taxonomies/release_category.ts b/sample/delivery/taxonomies/movietype.ts similarity index 57% rename from sample/delivery/taxonomies/release_category.ts rename to sample/delivery/taxonomies/movietype.ts index 5aeca92..503eafb 100644 --- a/sample/delivery/taxonomies/release_category.ts +++ b/sample/delivery/taxonomies/movietype.ts @@ -6,17 +6,17 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ /** - * Release category + * MovieType * - * Codename: release_category - * Id: 4dbfc78f-5ea2-4f33-880d-193c75e0b975 + * Codename: movietype + * Id: 365a17e6-1929-27ab-9f67-a9273c846717 */ -export type ReleaseCategory = 'global_release' | 'us_only'; +export type MovieType = 'blockbuster' | 'cinema_only' | 'film' | 'student' | 'tv'; diff --git a/sample/delivery/taxonomies/category.ts b/sample/delivery/taxonomies/releasecategory.ts similarity index 56% rename from sample/delivery/taxonomies/category.ts rename to sample/delivery/taxonomies/releasecategory.ts index bb910f7..8b83bba 100644 --- a/sample/delivery/taxonomies/category.ts +++ b/sample/delivery/taxonomies/releasecategory.ts @@ -6,17 +6,17 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ /** - * Category + * ReleaseCategory * - * Codename: category - * Id: c1b56389-f00a-4917-95c4-3b02ea3610ea + * Codename: releasecategory + * Id: 09b6a348-0f86-7a68-4af3-7cab9a5c60b7 */ -export type Category = 'action' | 'animation' | 'comedy' | 'drama' | 'romance' | 'sci_fi'; +export type ReleaseCategory = 'global_release' | 'local_release' | 'us_only'; diff --git a/sample/environment/assetFolders.ts b/sample/environment/assetFolders.ts index 1e96301..5a6c19a 100644 --- a/sample/environment/assetFolders.ts +++ b/sample/environment/assetFolders.ts @@ -6,33 +6,66 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ export const assetFolders = { /** - * my-folder + * my folder A */ - myFolder: { - codename: 'my_folder', - id: 'f1c6ba01-3b13-41ce-81e7-3125840b0b0e', + my_folder_a: { + name: 'my folder A', + codename: 'my_folder_a', + id: '6bb4814a-6a5c-4b8c-836e-7f83b008d5d1', externalId: undefined, - name: 'my-folder', - folders: {} + folders: { + /** + * my folder nested A + */ + my_folder_nested_a: { + name: 'my folder nested A', + codename: 'my_folder_nested_a', + id: '555784e5-e92e-4a86-b40b-d642afbf7b4e', + externalId: undefined, + folders: { + /** + * even more nested A + */ + even_more_nested_a: { + name: 'even more nested A', + codename: 'even_more_nested_a', + id: 'd26940cc-6c8d-41e6-93a0-0748c854b100', + externalId: undefined, + folders: {} + }, + + /** + * even more nested B + */ + even_more_nested_b: { + name: 'even more nested B', + codename: 'even_more_nested_b', + id: '97fc4b03-98d2-44b4-8e03-b223a013b0b6', + externalId: undefined, + folders: {} + } + } + } + } }, /** - * my-folder2 + * my folder B */ - myFolder2: { - codename: 'my_folder2', - id: '44a00189-9298-4cf9-b8fb-3f208c3f4f8f', + my_folder_b: { + name: 'my folder B', + codename: 'my_folder_b', + id: '58d1c135-42cb-43c2-a2cd-c615e0a36e83', externalId: undefined, - name: 'my-folder2', folders: {} } } as const; diff --git a/sample/environment/collections.ts b/sample/environment/collections.ts index f756fb7..7e50501 100644 --- a/sample/environment/collections.ts +++ b/sample/environment/collections.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ diff --git a/sample/environment/contentTypeSnippets.ts b/sample/environment/contentTypeSnippets.ts index 91d7323..34f7746 100644 --- a/sample/environment/contentTypeSnippets.ts +++ b/sample/environment/contentTypeSnippets.ts @@ -6,69 +6,11 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ -export const contentTypeSnippets = { - /** - * My snippet - */ - mySnippet: { - codename: 'my_snippet', - id: '3274f9e7-ff1b-43f8-aa32-29b53939cd3e', - externalId: undefined, - name: 'My snippet', - elements: { - /** - * Snippet elem 2 (number) - */ - mySnippetSnippetElem2: { - codename: 'my_snippet__snippet_elem_2', - id: 'b2f65646-3310-4a64-af2a-0d9d025a91d0', - externalId: undefined, - name: 'Snippet elem 2', - required: false, - type: 'number' - }, - - /** - * Snippet elem1 (text) - */ - mySnippetSnippetElem1: { - codename: 'my_snippet__snippet_elem1', - id: '3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d', - externalId: undefined, - name: 'Snippet elem1', - required: false, - type: 'text' - } - } - }, - - /** - * Taxonomy snippet test - */ - taxonomySnippetTest: { - codename: 'taxonomy_snippet_test', - id: 'e8219115-e629-4552-b79b-d9f813272573', - externalId: undefined, - name: 'Taxonomy snippet test', - elements: { - /** - * Category (taxonomy) - */ - taxonomySnippetTestTestTaxonomy: { - codename: 'taxonomy_snippet_test__test_taxonomy', - id: 'c030e3ec-5031-4d7f-af88-5032365733c7', - externalId: undefined, - name: 'Category', - required: false, - type: 'taxonomy' - } - } - } -} as const; +export const contentTypeSnippets = {} as const; diff --git a/sample/environment/contentTypes.ts b/sample/environment/contentTypes.ts index c5b2fac..706e6d3 100644 --- a/sample/environment/contentTypes.ts +++ b/sample/environment/contentTypes.ts @@ -6,290 +6,271 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ export const contentTypes = { - + /** + * Actor + */ + actor: { + name: 'Actor', + codename: 'actor', + id: '58099989-319f-495f-aa36-cb3710854e36', + externalId: undefined, + elements: { + /** + * First name (text) + * Guidelines: This is the first name of the actor + */ + first_name: { + name: 'First name', + codename: 'first_name', + id: '14dd70e5-c42d-f111-9640-c82b443edf1d', + externalId: undefined, + required: true, + type: 'text' + }, - /** - * Actor - */ - actor: { - codename: 'actor', - id: 'd8900ee2-82f4-4189-a994-4e121582aadf', - externalId: undefined, - name: 'Actor', - elements: { - /** - * first_name (text) - */ - firstName: { - codename: 'first_name', - id: '4af5e7ce-88ef-4159-96ae-96a552992f91', - externalId: undefined, - name: 'first_name', - required: false, - type: 'text' - - }, + /** + * Last name (text) + */ + last_name: { + name: 'Last name', + codename: 'last_name', + id: '9f7a0dd4-af3a-95ca-0358-400c14ce7075', + externalId: undefined, + required: true, + type: 'text' + }, - /** - * last_name (text) - */ - lastName: { - codename: 'last_name', - id: '0f00b26e-60f3-462d-8110-18180137c3a0', - externalId: undefined, - name: 'last_name', - required: false, - type: 'text' - - }, + /** + * Photo (asset) + */ + photo: { + name: 'Photo', + codename: 'photo', + id: 'eaec9ba3-9624-6875-04ec-80d0b2e00781', + externalId: undefined, + required: false, + type: 'asset' + }, - /** - * photo (asset) - */ - photo: { - codename: 'photo', - id: '069b38ee-385c-410f-b7fe-53ec59a5f139', - externalId: undefined, - name: 'photo', - required: false, - type: 'asset' - - }, + /** + * Url (url_slug) + */ + url: { + name: 'Url', + codename: 'url', + id: 'c8658782-f209-a573-9c85-430fb4e3e9f0', + externalId: undefined, + required: false, + type: 'url_slug' + } + } + }, - /** - * url (url_slug) - */ - url: { - codename: 'url', - id: 'c4b2d64f-af45-45a4-92d8-4829833563ff', - externalId: undefined, - name: 'url', - required: false, - type: 'url_slug' - - }} - }, + /** + * Movie + */ + movie: { + name: 'Movie', + codename: 'movie', + id: 'b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c', + externalId: undefined, + elements: { + /** + * Category (multiple_choice) + */ + category: { + name: 'Category', + codename: 'category', + id: '9821c252-6414-f549-c17f-cc171dd87713', + externalId: undefined, + required: false, + type: 'multiple_choice', + options: { + /** + * Action + */ + action: { + name: 'Action', + id: '7d453309-8d74-9607-80c4-36dcc1bd005f', + codename: 'action', + externalId: undefined + }, + /** + * Adventure + */ + adventure: { + name: 'Adventure', + id: 'cd8389b0-7628-7739-7b14-3225a50212c1', + codename: 'adventure', + externalId: undefined + }, - /** - * Movie - */ - movie: { - codename: 'movie', - id: 'db7356f6-1d82-42a0-9ebb-07865cffa995', - externalId: undefined, - name: 'Movie', - elements: { - /** - * Category (taxonomy) - */ - category: { - codename: 'category', - id: '8c12be35-e3e7-447c-a185-7b5e101ebf12', - externalId: undefined, - name: 'Category', - required: false, - type: 'taxonomy' - - }, + /** + * Animation + */ + animation: { + name: 'Animation', + id: '54c0590d-6a94-a69a-902d-fceea4fa62f8', + codename: 'animation', + externalId: undefined + }, - /** - * length (number) - */ - length: { - codename: 'length', - id: 'e3d07f3a-60c2-4072-846d-c23e51ec833e', - externalId: undefined, - name: 'length', - required: false, - type: 'number' - - }, + /** + * Comedy + */ + comedy: { + name: 'Comedy', + id: 'd2fe357f-894e-9bc3-550c-c2c400d99c6b', + codename: 'comedy', + externalId: undefined + }, - /** - * plot (rich_text) - */ - plot: { - codename: 'plot', - id: 'ad2e5dc7-8d08-4f74-afeb-25b475f1e6fc', - externalId: undefined, - name: 'plot', - required: false, - type: 'rich_text' - - }, + /** + * Documentary + */ + documentary: { + name: 'Documentary', + id: '19c5e959-c24a-4863-0b4d-453cdef8fe9d', + codename: 'documentary', + externalId: undefined + }, - /** - * poster (asset) - */ - poster: { - codename: 'poster', - id: '9b197f1e-0728-4d14-9814-97f7b8ef01fc', - externalId: undefined, - name: 'poster', - required: false, - type: 'asset' - - }, + /** + * Drama + */ + drama: { + name: 'Drama', + id: '051e74de-f2e0-f405-9ad5-5263221e46f2', + codename: 'drama', + externalId: undefined + }, - /** - * Release category (taxonomy) - */ - releasecategory: { - codename: 'releasecategory', - id: '5faa827f-f262-43c3-8f58-0f354b8d393f', - externalId: undefined, - name: 'Release category', - required: false, - type: 'taxonomy' - - }, + /** + * Romance + */ + romance: { + name: 'Romance', + id: '60550cc7-c986-a59f-b069-7565862fe1c1', + codename: 'romance', + externalId: undefined + }, - /** - * released (date_time) - */ - released: { - codename: 'released', - id: '656b9dc9-7bba-4f1f-a2b8-52f7f730a66f', - externalId: undefined, - name: 'released', - required: false, - type: 'date_time' - - }, - - /** - * seoname (url_slug) - */ - seoname: { - codename: 'seoname', - id: '734f94be-5930-4bdf-b05b-f59f5a291675', - externalId: undefined, - name: 'seoname', - required: false, - type: 'url_slug' - - }, - - /** - * stars (modular_content) - */ - stars: { - codename: 'stars', - id: '55596dd1-e808-415d-95aa-e2be34238d11', - externalId: undefined, - name: 'stars', - required: false, - type: 'modular_content' - - }, + /** + * Sci-fi + */ + sci_fi: { + name: 'Sci-fi', + id: 'b087f774-1f57-9aa8-dab5-2ca88a646824', + codename: 'sci_fi', + externalId: undefined + } + } + }, - /** - * Category (taxonomy) - */ - taxonomySnippetTestTestTaxonomy: { - codename: 'taxonomy_snippet_test__test_taxonomy', - id: 'c030e3ec-5031-4d7f-af88-5032365733c7', - externalId: undefined, - name: 'Category', - required: false, - type: 'taxonomy' - - }, + /** + * Length (number) + */ + length: { + name: 'Length', + codename: 'length', + id: '7e8ecfab-a419-27ee-d8ec-8adb76fd007c', + externalId: undefined, + required: false, + type: 'number' + }, - /** - * title (text) - */ - title: { - codename: 'title', - id: '660c851a-a9a1-4378-97a3-1348bc2a4d76', - externalId: undefined, - name: 'title', - required: false, - type: 'text' - - }} - }, + /** + * Plot (rich_text) + */ + plot: { + name: 'Plot', + codename: 'plot', + id: 'f7ee4f27-27fd-a19b-3c5c-102aae1c50ce', + externalId: undefined, + required: false, + type: 'rich_text' + }, + /** + * Poster (asset) + */ + poster: { + name: 'Poster', + codename: 'poster', + id: 'a39a7237-9503-a1ae-8431-5b6cdb85ae9d', + externalId: undefined, + required: false, + type: 'asset' + }, - /** - * 😺 My Special type[hello]++🥸'` - */ - specialType: { - codename: 'special_type', - id: '410fb007-42e3-442d-8cdf-fba4cf50f850', - externalId: undefined, - name: '😺 My Special type[hello]++🥸'` */', - elements: { - /** - * Hello (text) - */ - hello: { - codename: 'hello', - id: '41d50fe3-0858-494c-9f33-85960821b5d6', - externalId: undefined, - name: 'Hello', - required: false, - type: 'text' - - }} - }, + /** + * ReleaseCategory (taxonomy) + */ + releasecategory: { + name: 'ReleaseCategory', + codename: 'releasecategory', + id: '65f2fd44-1856-bc2b-17c2-decb0635e3d2', + externalId: undefined, + required: false, + type: 'taxonomy' + }, + /** + * Released (date_time) + */ + released: { + name: 'Released', + codename: 'released', + id: '5ccf4644-0d65-5d96-9a32-f4ea21974d51', + externalId: undefined, + required: false, + type: 'date_time' + }, - /** - * Test - */ - test: { - codename: 'test', - id: '81ab0b2c-dd14-41e7-a1ed-868b249ad8bc', - externalId: undefined, - name: 'Test', - elements: { - /** - * Snippet elem 2 (number) - */ - mySnippetSnippetElem2: { - codename: 'my_snippet__snippet_elem_2', - id: 'b2f65646-3310-4a64-af2a-0d9d025a91d0', - externalId: undefined, - name: 'Snippet elem 2', - required: false, - type: 'number' - - }, + /** + * SeoName (url_slug) + */ + seoname: { + name: 'SeoName', + codename: 'seoname', + id: '756cc91a-a090-60f9-a7f0-f505bfbe046c', + externalId: undefined, + required: false, + type: 'url_slug' + }, - /** - * Snippet elem1 (text) - */ - mySnippetSnippetElem1: { - codename: 'my_snippet__snippet_elem1', - id: '3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d', - externalId: undefined, - name: 'Snippet elem1', - required: false, - type: 'text' - - }, + /** + * Stars (modular_content) + */ + stars: { + name: 'Stars', + codename: 'stars', + id: 'aa26a55d-19f8-7501-fea3-b0d9b1eeac71', + externalId: undefined, + required: false, + type: 'modular_content' + }, - /** - * Text (text) - */ - text: { - codename: 'text', - id: '65f61f6a-b69c-47dc-bc38-19855507bf14', - externalId: undefined, - name: 'Text', - required: false, - type: 'text' - - }} - } - } as const; \ No newline at end of file + /** + * Title (text) + */ + title: { + name: 'Title', + codename: 'title', + id: '3473187e-dc78-eff2-7099-f690f7042d4a', + externalId: undefined, + required: true, + type: 'text' + } + } + } +} as const; diff --git a/sample/environment/index.ts b/sample/environment/index.ts index 626c0dd..91a4ee3 100644 --- a/sample/environment/index.ts +++ b/sample/environment/index.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ diff --git a/sample/environment/languages.ts b/sample/environment/languages.ts index 4455edb..3dee4fc 100644 --- a/sample/environment/languages.ts +++ b/sample/environment/languages.ts @@ -6,21 +6,34 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ export const languages = { /** - * Default project language + * cz + */ + cz: { + name: 'cz', + codename: 'cz', + id: '41ccb26f-ceab-04d0-6ffa-9c7c5358aa8f', + isActive: true, + isDefault: false, + fallbackLanguageId: '00000000-0000-0000-0000-000000000000', + externalId: undefined + }, + + /** + * English */ en: { + name: 'English', codename: 'en', id: '00000000-0000-0000-0000-000000000000', - name: 'Default project language', isActive: true, isDefault: true, fallbackLanguageId: '00000000-0000-0000-0000-000000000000', @@ -28,13 +41,13 @@ export const languages = { }, /** - * Spanish + * German */ - es: { - codename: 'es', - id: '71cf90e5-8124-43e3-8ef4-bbb8bdcd22ae', - name: 'Spanish', - isActive: true, + German: { + name: 'German', + codename: 'German', + id: '14f7bcc0-4fd6-4b77-8c22-70e5ccfdae1d', + isActive: false, isDefault: false, fallbackLanguageId: '00000000-0000-0000-0000-000000000000', externalId: undefined diff --git a/sample/environment/roles.ts b/sample/environment/roles.ts index 9ea8254..03cca0d 100644 --- a/sample/environment/roles.ts +++ b/sample/environment/roles.ts @@ -6,20 +6,47 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ export const roles = { + /** + * Content contributor + */ + contentcontributor: { + codename: undefined, + id: 'dca0ac85-274f-429e-b00e-6f74bf917051', + name: 'Content contributor' + }, + + /** + * Developer + */ + developer: { + codename: undefined, + id: 'b3994090-0818-4969-816b-f4c5d3e526f3', + name: 'Developer' + }, + /** * Project manager */ - projectManager: { + projectmanager: { codename: 'project-manager', - id: '5a8e7afd-3dcc-4adc-9f23-bf36a31d61bf', + id: 'af95ac37-4efa-4b92-aa26-db773cd172c6', name: 'Project manager' + }, + + /** + * Reviewer + */ + reviewer: { + codename: undefined, + id: '94478afa-d898-45dd-8300-ba61b6e0eb4b', + name: 'Reviewer' } } as const; diff --git a/sample/environment/taxonomies.ts b/sample/environment/taxonomies.ts index 230ba47..d149620 100644 --- a/sample/environment/taxonomies.ts +++ b/sample/environment/taxonomies.ts @@ -6,119 +6,119 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ export const taxonomies = { /** - * Category + * movietype */ - category: { - codename: 'category', + movietype: { + name: 'MovieType', + codename: 'movietype', externalId: undefined, - id: 'c1b56389-f00a-4917-95c4-3b02ea3610ea', - name: 'Category', + id: '365a17e6-1929-27ab-9f67-a9273c846717', terms: { /** - * action + * Film */ - action: { - codename: 'action', - id: 'e3410312-52d6-4c15-8e23-e5a4cc57a204', + film: { + codename: 'film', + id: '5a2a1927-41a4-294f-5d89-cf0cc045e943', externalId: undefined, - name: 'action', - terms: {} - }, + name: 'Film', + terms: { + /** + * Blockbuster + */ + blockbuster: { + codename: 'blockbuster', + id: '875a4657-1dcd-0415-cb3a-892078f5991a', + externalId: undefined, + name: 'Blockbuster', + terms: {} + }, - /** - * animation - */ - animation: { - codename: 'animation', - id: '2d8a95a8-61c9-4add-94a1-1d7944098144', - externalId: undefined, - name: 'animation', - terms: {} - }, + /** + * Cinema only + */ + cinema_only: { + codename: 'cinema_only', + id: 'e15c4e32-ab7c-57a2-1b66-d8e3566a1dd2', + externalId: undefined, + name: 'Cinema only', + terms: {} + }, - /** - * comedy - */ - comedy: { - codename: 'comedy', - id: 'eddaa24b-fb5c-4a44-8507-8dd7a45fdc39', - externalId: undefined, - name: 'comedy', - terms: {} + /** + * TV + */ + tv: { + codename: 'tv', + id: '47511b09-6c39-fa04-ff59-7c47551e827f', + externalId: undefined, + name: 'TV', + terms: {} + } + } }, /** - * drama + * Student */ - drama: { - codename: 'drama', - id: '7377ea7c-d928-408a-bfb8-a0bf7392c996', + student: { + codename: 'student', + id: 'b107e12c-124d-705f-1029-c0dfdd0b2438', externalId: undefined, - name: 'drama', - terms: {} - }, - - /** - * romance - */ - romance: { - codename: 'romance', - id: 'fe8bdfdb-cc13-4890-ab45-a6669e94d1d0', - externalId: undefined, - name: 'romance', - terms: {} - }, - - /** - * sci_fi - */ - sciFi: { - codename: 'sci_fi', - id: '1432c10c-096c-47c5-a045-dcd6dc4af366', - externalId: undefined, - name: 'sci_fi', + name: 'Student', terms: {} } } }, /** - * Release category + * releasecategory */ - releaseCategory: { - codename: 'release_category', + releasecategory: { + name: 'ReleaseCategory', + codename: 'releasecategory', externalId: undefined, - id: '4dbfc78f-5ea2-4f33-880d-193c75e0b975', - name: 'Release category', + id: '09b6a348-0f86-7a68-4af3-7cab9a5c60b7', terms: { /** - * global_release + * Global release */ - globalRelease: { + global_release: { codename: 'global_release', - id: 'afb51aba-cb5a-499a-973c-d5b44fdeafcf', + id: '4acaf439-9f3a-f34a-6211-d3fc6ec7152e', + externalId: undefined, + name: 'Global release', + terms: {} + }, + + /** + * Local release + */ + local_release: { + codename: 'local_release', + id: '37e55484-f0dc-14eb-bf2a-b0293a0d1b1f', externalId: undefined, - name: 'global_release', + name: 'Local release', terms: {} }, /** - * us_only + * US only */ - usOnly: { + us_only: { codename: 'us_only', - id: '3f8bddaf-c203-471b-af76-6539d3e72e89', + id: 'b03d990a-55a9-601e-dd5c-aa2edc8698ca', externalId: undefined, - name: 'us_only', + name: 'US only', terms: {} } } diff --git a/sample/environment/webhooks.ts b/sample/environment/webhooks.ts index 7ef5c3e..7d33dc3 100644 --- a/sample/environment/webhooks.ts +++ b/sample/environment/webhooks.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ diff --git a/sample/environment/workflows.ts b/sample/environment/workflows.ts index 9f8351b..299fd79 100644 --- a/sample/environment/workflows.ts +++ b/sample/environment/workflows.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ @@ -18,9 +18,9 @@ export const workflows = { * Default */ default: { + name: 'Default', codename: 'default', id: '00000000-0000-0000-0000-000000000000', - name: 'Default', steps: { archived: { name: 'Archived', @@ -30,7 +30,7 @@ export const workflows = { published: { name: 'Published', codename: 'published', - id: 'c199950d-99f0-4983-b711-6c4c91624b22' + id: 'f05b8a85-c6cc-429a-ac6d-21d5edd268fe' }, scheduled: { name: 'Scheduled', @@ -40,48 +40,17 @@ export const workflows = { draft: { name: 'Draft', codename: 'draft', - id: 'eee6db3b-545a-4785-8e86-e3772c8756f9' + id: 'e3ef0816-2203-4456-bfdc-a735b4f339ab' }, - readyToPublish: { - name: 'ready_to_publish', - codename: 'ready_to_publish', - id: 'f4afd295-cc0b-48e3-9431-176cc1e17e2c' - } - } - }, - - /** - * my_test_workflow - */ - myTestWorkflow: { - codename: 'my_test_workflow', - id: '51036ae0-1a0c-48c6-980e-bf73600ba462', - name: 'my_test_workflow', - steps: { - archived: { - name: 'Archived', - codename: 'archived', - id: '7a535a69-ad34-47f8-806a-def1fdf4d391' + review: { + name: 'Review', + codename: 'review', + id: 'c5682935-f5a2-4514-8025-57d8bdf7558d' }, - published: { - name: 'Published', - codename: 'published', - id: 'c199950d-99f0-4983-b711-6c4c91624b22' - }, - scheduled: { - name: 'Scheduled', - codename: 'scheduled', - id: '9d2b0228-4d0d-4c23-8b49-01a698857709' - }, - draft3171da5: { - name: 'Draft', - codename: 'draft_3171da5', - id: '3171da5f-679d-49af-a42c-617d83eac222' - }, - readyForReview: { - name: 'ready_for_review', - codename: 'ready_for_review', - id: '20f49208-5e57-4300-b6bd-0f668cbce00b' + ready_to_publish: { + name: 'Ready to publish', + codename: 'ready_to_publish', + id: 'aaee1d73-f0cc-4185-9e49-844d161c3634' } } } diff --git a/sample/migration/content-types/actor.ts b/sample/migration/content-types/actor.ts index da2b56d..4229a92 100644 --- a/sample/migration/content-types/actor.ts +++ b/sample/migration/content-types/actor.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ @@ -20,44 +20,45 @@ import type { Item } from '../migration.js'; * Actor * * Codename: actor - * Id: d8900ee2-82f4-4189-a994-4e121582aadf + * Id: 58099989-319f-495f-aa36-cb3710854e36 */ export type ActorItem = Item< 'actor', { /** - * first_name (text) + * First name (text) * - * Required: false + * Required: true * Codename: first_name - * Id: 4af5e7ce-88ef-4159-96ae-96a552992f91 + * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d + * Guidelines: This is the first name of the actor */ first_name: MigrationElementModels.TextElement; /** - * last_name (text) + * Last name (text) * - * Required: false + * Required: true * Codename: last_name - * Id: 0f00b26e-60f3-462d-8110-18180137c3a0 + * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 */ last_name: MigrationElementModels.TextElement; /** - * photo (asset) + * Photo (asset) * * Required: false * Codename: photo - * Id: 069b38ee-385c-410f-b7fe-53ec59a5f139 + * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 */ photo: MigrationElementModels.AssetElement; /** - * url (url_slug) + * Url (url_slug) * * Required: false * Codename: url - * Id: c4b2d64f-af45-45a4-92d8-4829833563ff + * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 */ url: MigrationElementModels.UrlSlugElement; } diff --git a/sample/migration/content-types/index.ts b/sample/migration/content-types/index.ts index b3f252d..3116ea2 100644 --- a/sample/migration/content-types/index.ts +++ b/sample/migration/content-types/index.ts @@ -6,14 +6,12 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ export * from './actor.js'; export * from './movie.js'; -export * from './special_type.js'; -export * from './test.js'; diff --git a/sample/migration/content-types/movie.ts b/sample/migration/content-types/movie.ts index 48ee669..eaa1679 100644 --- a/sample/migration/content-types/movie.ts +++ b/sample/migration/content-types/movie.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ @@ -20,98 +20,89 @@ import type { Item } from '../migration.js'; * Movie * * Codename: movie - * Id: db7356f6-1d82-42a0-9ebb-07865cffa995 + * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c */ export type MovieItem = Item< 'movie', { /** - * Category (taxonomy) + * Category (multiple_choice) * * Required: false * Codename: category - * Id: 8c12be35-e3e7-447c-a185-7b5e101ebf12 + * Id: 9821c252-6414-f549-c17f-cc171dd87713 */ - category: MigrationElementModels.TaxonomyElement; + category: MigrationElementModels.MultipleChoiceElement; /** - * length (number) + * Length (number) * * Required: false * Codename: length - * Id: e3d07f3a-60c2-4072-846d-c23e51ec833e + * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c */ length: MigrationElementModels.NumberElement; /** - * plot (rich_text) + * Plot (rich_text) * * Required: false * Codename: plot - * Id: ad2e5dc7-8d08-4f74-afeb-25b475f1e6fc + * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce */ plot: MigrationElementModels.RichTextElement; /** - * poster (asset) + * Poster (asset) * * Required: false * Codename: poster - * Id: 9b197f1e-0728-4d14-9814-97f7b8ef01fc + * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d */ poster: MigrationElementModels.AssetElement; /** - * Release category (taxonomy) + * ReleaseCategory (taxonomy) * * Required: false * Codename: releasecategory - * Id: 5faa827f-f262-43c3-8f58-0f354b8d393f + * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 */ releasecategory: MigrationElementModels.TaxonomyElement; /** - * released (date_time) + * Released (date_time) * * Required: false * Codename: released - * Id: 656b9dc9-7bba-4f1f-a2b8-52f7f730a66f + * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 */ released: MigrationElementModels.DateTimeElement; /** - * seoname (url_slug) + * SeoName (url_slug) * * Required: false * Codename: seoname - * Id: 734f94be-5930-4bdf-b05b-f59f5a291675 + * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c */ seoname: MigrationElementModels.UrlSlugElement; /** - * stars (modular_content) + * Stars (modular_content) * * Required: false * Codename: stars - * Id: 55596dd1-e808-415d-95aa-e2be34238d11 + * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 */ stars: MigrationElementModels.LinkedItemsElement; /** - * Category (taxonomy) + * Title (text) * - * Required: false - * Codename: taxonomy_snippet_test__test_taxonomy - * Id: c030e3ec-5031-4d7f-af88-5032365733c7 - */ - taxonomy_snippet_test__test_taxonomy: MigrationElementModels.TaxonomyElement; - - /** - * title (text) - * - * Required: false + * Required: true * Codename: title - * Id: 660c851a-a9a1-4378-97a3-1348bc2a4d76 + * Id: 3473187e-dc78-eff2-7099-f690f7042d4a */ title: MigrationElementModels.TextElement; } diff --git a/sample/migration/content-types/special_type.ts b/sample/migration/content-types/special_type.ts deleted file mode 100644 index bec0175..0000000 --- a/sample/migration/content-types/special_type.ts +++ /dev/null @@ -1,37 +0,0 @@ - -/** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Migration Toolkit - tests -* Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 -* -* ------------------------------------------------------------------------------- -**/ - -import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; -import type { Item } from '../migration.js'; - -/** - * 😺 My Special type[hello]++🥸'` - * - * Codename: special_type - * Id: 410fb007-42e3-442d-8cdf-fba4cf50f850 - */ -export type MySpecialTypehelloItem = Item< - 'special_type', - { - /** - * Hello (text) - * - * Required: false - * Codename: hello - * Id: 41d50fe3-0858-494c-9f33-85960821b5d6 - */ - hello: MigrationElementModels.TextElement; - } ->; diff --git a/sample/migration/content-types/test.ts b/sample/migration/content-types/test.ts deleted file mode 100644 index 6a2ed5e..0000000 --- a/sample/migration/content-types/test.ts +++ /dev/null @@ -1,55 +0,0 @@ - -/** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Migration Toolkit - tests -* Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 -* -* ------------------------------------------------------------------------------- -**/ - -import type { MigrationElementModels } from '@kontent-ai/migration-toolkit'; -import type { Item } from '../migration.js'; - -/** - * Test - * - * Codename: test - * Id: 81ab0b2c-dd14-41e7-a1ed-868b249ad8bc - */ -export type TestItem = Item< - 'test', - { - /** - * Snippet elem 2 (number) - * - * Required: false - * Codename: my_snippet__snippet_elem_2 - * Id: b2f65646-3310-4a64-af2a-0d9d025a91d0 - */ - my_snippet__snippet_elem_2: MigrationElementModels.NumberElement; - - /** - * Snippet elem1 (text) - * - * Required: false - * Codename: my_snippet__snippet_elem1 - * Id: 3b89ad47-4a72-4b4e-84b0-e8e8a7a3814d - */ - my_snippet__snippet_elem1: MigrationElementModels.TextElement; - - /** - * Text (text) - * - * Required: false - * Codename: text - * Id: 65f61f6a-b69c-47dc-bc38-19855507bf14 - */ - text: MigrationElementModels.TextElement; - } ->; diff --git a/sample/migration/environment/environment.ts b/sample/migration/environment/environment.ts index 588d69c..901b7eb 100644 --- a/sample/migration/environment/environment.ts +++ b/sample/migration/environment/environment.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ @@ -16,12 +16,12 @@ /** * Type representing all languages */ -export type LanguageCodenames = 'en' | 'es'; +export type LanguageCodenames = 'cz' | 'en' | 'German'; /** * Type representing all content types */ -export type ContentTypeCodenames = 'actor' | 'movie' | 'special_type' | 'test'; +export type ContentTypeCodenames = 'actor' | 'movie'; /** * Type representing all collections @@ -31,16 +31,9 @@ export type CollectionCodenames = 'default'; /** * Type representing all workflows */ -export type WorkflowCodenames = 'default' | 'my_test_workflow'; +export type WorkflowCodenames = 'default'; /** * Type representing all worksflow steps across all workflows */ -export type WorkflowStepCodenames = - | 'archived' - | 'draft_3171da5' - | 'draft' - | 'published' - | 'ready_for_review' - | 'ready_to_publish' - | 'scheduled'; +export type WorkflowStepCodenames = 'archived' | 'draft' | 'published' | 'ready_to_publish' | 'review' | 'scheduled'; diff --git a/sample/migration/environment/index.ts b/sample/migration/environment/index.ts index 43890e3..2bfdee9 100644 --- a/sample/migration/environment/index.ts +++ b/sample/migration/environment/index.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ diff --git a/sample/migration/index.ts b/sample/migration/index.ts index 9c2f1a5..aedabaf 100644 --- a/sample/migration/index.ts +++ b/sample/migration/index.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ diff --git a/sample/migration/migration.ts b/sample/migration/migration.ts index 9c508fb..2551401 100644 --- a/sample/migration/migration.ts +++ b/sample/migration/migration.ts @@ -6,9 +6,9 @@ * * ------------------------------------------------------------------------------- * -* Project: Migration Toolkit - tests +* Project: Movie Database * Environment: Production -* Id: 5ddb8f47-a51f-0124-35b1-f6634fa91ae2 +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 * * ------------------------------------------------------------------------------- **/ From 97397530701231a16101aa3eea6c61361aa128fe Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 4 Sep 2024 12:11:32 +0200 Subject: [PATCH 076/183] Preserves order of items fetched from API (fixes https://github.com/kontent-ai/model-generator-js/issues/50) --- lib/core/element.utils.ts | 58 +++-- lib/fetch/kontent-fetcher.ts | 38 +-- .../delivery-content-type.generator.ts | 5 +- .../delivery/delivery-taxonomy.generator.ts | 8 +- .../environment/environment.generator.ts | 21 +- .../migration/migration.generator.ts | 13 +- sample/delivery/content-types/actor.ts | 16 +- sample/delivery/content-types/movie.ts | 64 ++--- sample/delivery/taxonomies/movietype.ts | 2 +- sample/delivery/taxonomies/releasecategory.ts | 2 +- sample/environment/contentTypes.ts | 228 +++++++++--------- sample/environment/languages.ts | 24 +- sample/environment/roles.ts | 16 +- sample/environment/taxonomies.ts | 64 ++--- sample/environment/workflows.ts | 30 +-- sample/migration/content-types/actor.ts | 18 +- sample/migration/content-types/movie.ts | 66 ++--- sample/migration/environment/environment.ts | 4 +- 18 files changed, 329 insertions(+), 348 deletions(-) diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts index f2f40a4..1975347 100644 --- a/lib/core/element.utils.ts +++ b/lib/core/element.utils.ts @@ -2,7 +2,6 @@ import { ContentTypeElements, ContentTypeModels, ContentTypeSnippetModels, Taxon import { isNotUndefined } from '@kontent-ai/migration-toolkit'; import { match } from 'ts-pattern'; import { FlattenedElement } from './core.models.js'; -import { sortAlphabetically } from './core.utils.js'; interface ElementWrapper { readonly element: Readonly; @@ -15,38 +14,35 @@ export function getFlattenedElements( taxonomies: readonly Readonly[], types: readonly Readonly[] ): readonly FlattenedElement[] { - return sortAlphabetically( - elements - .filter((element) => { - return element.type !== 'guidelines'; - }) - .flatMap((element) => { - if (element.type === 'snippet') { - const snippet = snippets.find((snippet) => snippet.id === element.snippet.id); - - if (!snippet) { - throw Error(`Could not find snippet with id '${element.snippet.id}'`); - } + return elements + .filter((element) => { + return element.type !== 'guidelines'; + }) + .flatMap((element) => { + if (element.type === 'snippet') { + const snippet = snippets.find((snippet) => snippet.id === element.snippet.id); - return snippet.elements.map((snippetElement) => { - return { - element: snippetElement, - fromSnippet: snippet - }; - }); + if (!snippet) { + throw Error(`Could not find snippet with id '${element.snippet.id}'`); } - return { - element: element, - fromSnippet: undefined - }; - }) - .map((element) => { - return getFlattenedElement(element, taxonomies, types); - }) - .filter(isNotUndefined), - (element) => element.codename - ); + return snippet.elements.map((snippetElement) => { + return { + element: snippetElement, + fromSnippet: snippet + }; + }); + } + + return { + element: element, + fromSnippet: undefined + }; + }) + .map((element) => { + return getFlattenedElement(element, taxonomies, types); + }) + .filter(isNotUndefined); } function getFlattenedElement( @@ -112,7 +108,7 @@ function extractLinkedItemsAllowedTypes( }) .otherwise(() => []); - return sortAlphabetically(allowedTypeIds.map((id) => types.find((m) => m.id === id)).filter(isNotUndefined), (type) => type.codename); + return allowedTypeIds.map((id) => types.find((m) => m.id === id)).filter(isNotUndefined); } function extractTaxonomy( diff --git a/lib/fetch/kontent-fetcher.ts b/lib/fetch/kontent-fetcher.ts index e9922ce..1ee454d 100644 --- a/lib/fetch/kontent-fetcher.ts +++ b/lib/fetch/kontent-fetcher.ts @@ -13,7 +13,7 @@ import { WorkflowModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; -import { GeneratorManagementClient, sortAlphabetically, toSafeComment } from '../core/index.js'; +import { GeneratorManagementClient, toSafeComment } from '../core/index.js'; interface KontentFetcherConfig { readonly environmentId: string; @@ -41,49 +41,49 @@ export function kontentFetcher(config: KontentFetcherConfig) { return projectInformation.project; }, async getWorkflowsAsync(): Promise[]> { - const items = sortAlphabetically((await client.listWorkflows().toPromise()).data, (item) => item.name); + const items = (await client.listWorkflows().toPromise()).data; console.log(`Fetched '${chalk.yellow(items.length.toString())}' workflows`); - return sortAlphabetically(items, (item) => item.codename); + return items; }, async getRolesAsync(): Promise[]> { - const items = sortAlphabetically((await client.listRoles().toPromise()).data.roles, (item) => item.name); + const items = (await client.listRoles().toPromise()).data.roles; console.log(`Fetched '${chalk.yellow(items.length.toString())}' roles`); - return sortAlphabetically(items, (item) => item.codename ?? item.name); + return items; }, async getAssetFoldersAsync(): Promise[]> { - const items = sortAlphabetically((await client.listAssetFolders().toPromise()).data.items, (item) => item.name); + const items = (await client.listAssetFolders().toPromise()).data.items; console.log(`Fetched '${chalk.yellow(items.length.toString())}' asset folders`); - return sortAlphabetically(items, (item) => item.codename); + return items; }, async getCollectionsAsync(): Promise[]> { - const items = sortAlphabetically((await client.listCollections().toPromise()).data.collections, (item) => item.name); + const items = (await client.listCollections().toPromise()).data.collections; console.log(`Fetched '${chalk.yellow(items.length.toString())}' collections`); - return sortAlphabetically(items, (item) => item.codename); + return items; }, async getWebhooksAsync(): Promise[]> { - const items = sortAlphabetically((await client.listWebhooks().toPromise()).data.webhooks, (item) => item.name); + const items = (await client.listWebhooks().toPromise()).data.webhooks; console.log(`Fetched '${chalk.yellow(items.length.toString())}' webhooks`); - return sortAlphabetically(items, (item) => item.name); + return items; }, async getLanguagesAsync(): Promise[]> { - const items = sortAlphabetically((await client.listLanguages().toAllPromise()).data.items, (item) => item.name); + const items = (await client.listLanguages().toAllPromise()).data.items; console.log(`Fetched '${chalk.yellow(items.length.toString())}' languages`); - return sortAlphabetically(items, (item) => item.codename); + return items; }, async getTypesAsync(): Promise[]> { - const items = sortAlphabetically((await client.listContentTypes().toAllPromise()).data.items, (item) => item.name); + const items = (await client.listContentTypes().toAllPromise()).data.items; console.log(`Fetched '${chalk.yellow(items.length.toString())}' types`); - return sortAlphabetically(items, (item) => item.codename); + return items; }, async getSnippetsAsync(): Promise[]> { - const items = sortAlphabetically((await client.listContentTypeSnippets().toAllPromise()).data.items, (item) => item.name); + const items = (await client.listContentTypeSnippets().toAllPromise()).data.items; console.log(`Fetched '${chalk.yellow(items.length.toString())}' snippets`); - return sortAlphabetically(items, (item) => item.codename); + return items; }, async getTaxonomiesAsync(): Promise[]> { - const items = sortAlphabetically((await client.listTaxonomies().toAllPromise()).data.items, (item) => item.name); + const items = (await client.listTaxonomies().toAllPromise()).data.items; console.log(`Fetched '${chalk.yellow(items.length.toString())}' taxonomies`); - return sortAlphabetically(items, (item) => item.codename); + return items; } }; } diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 45999b6..874b5c8 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -276,10 +276,7 @@ export type ${contentTypeImports.typeName} = ${deliveryConfig.sdkTypes.contentIt return [deliveryConfig.sdkTypes.contentItem]; } - return sortAlphabetically( - types.map((type) => nameResolvers.contentType(type)), - (type) => type - ); + return types.map((type) => nameResolvers.contentType(type)); }; return { diff --git a/lib/generators/delivery/delivery-taxonomy.generator.ts b/lib/generators/delivery/delivery-taxonomy.generator.ts index 5ba0022..1d12c5e 100644 --- a/lib/generators/delivery/delivery-taxonomy.generator.ts +++ b/lib/generators/delivery/delivery-taxonomy.generator.ts @@ -6,7 +6,6 @@ import { mapFilename, mapName, ModuleResolution, - sortAlphabetically, TaxonomyNameResolver, TaxonomyTypeFileNameResolver, wrapComment @@ -58,7 +57,7 @@ export type ${taxonomyNameMap(taxonomy)} = ${getTaxonomyTermsCode(taxonomy)}; }; const getTaxonomyTermsCode = (taxonomy: Readonly): string => { - const taxonomyTermCodenames = sortAlphabetically(getTaxonomyTermCodenames(taxonomy.terms), (codename) => codename); + const taxonomyTermCodenames = getTaxonomyTermCodenames(taxonomy.terms); if (!taxonomyTermCodenames.length) { return `''`; @@ -72,10 +71,7 @@ export type ${taxonomyNameMap(taxonomy)} = ${getTaxonomyTermsCode(taxonomy)}; const getTaxonomyTermCodenames = (taxonomyTerms: readonly Readonly[]): readonly string[] => { return taxonomyTerms.reduce((codenames, taxonomyTerm) => { - return sortAlphabetically( - codenames.concat(getTaxonomyTermCodenames(taxonomyTerm.terms), taxonomyTerm.codename), - (codename) => codename - ); + return codenames.concat(getTaxonomyTermCodenames(taxonomyTerm.terms), taxonomyTerm.codename); }, []); }; diff --git a/lib/generators/environment/environment.generator.ts b/lib/generators/environment/environment.generator.ts index 89f377c..295a24d 100644 --- a/lib/generators/environment/environment.generator.ts +++ b/lib/generators/environment/environment.generator.ts @@ -17,7 +17,6 @@ import { GeneratedFile, getFlattenedElements, getStringOrUndefined, - sortAlphabetically, toGuidelinesComment, toSafePropertyName, toSafePropertyValue, @@ -228,10 +227,9 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { .returnType() .with({ type: 'multiple_choice' }, (element) => { return ( - sortAlphabetically(element.options, (option) => option.codename ?? option.name).reduce( - (code, option, index) => { - const isLast = index === element.options.length - 1; - return `${code}\n + element.options.reduce((code, option, index) => { + const isLast = index === element.options.length - 1; + return `${code}\n ${wrapComment(` * ${option.name} `)} @@ -241,9 +239,7 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { codename: ${getStringOrUndefined(option.codename)}, externalId: ${getStringOrUndefined(option.external_id)} }${!isLast ? ',\n' : ''}`; - }, - '{' - ) + '}' + }, '{') + '}' ); }) .otherwise(() => undefined); @@ -316,11 +312,9 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { }; const getProjectTaxonomiesTerms = (terms: readonly Readonly[]): string => { - const sortedTerms = sortAlphabetically(terms, (item) => item.name); - return ( - sortedTerms.reduce((code, term, index) => { - const isLast = index === sortedTerms.length - 1; + terms.reduce((code, term, index) => { + const isLast = index === terms.length - 1; return `${code}\n ${wrapComment(` @@ -338,7 +332,8 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { }; const getProjectWorkflowSteps = (workflow: Readonly): string => { - const steps: readonly WorkflowStep[] = [workflow.archivedStep, workflow.publishedStep, workflow.scheduledStep, ...workflow.steps]; + // The order of these steps should reflect the order in which they appear in the Kontent UI + const steps: readonly WorkflowStep[] = [...workflow.steps, workflow.scheduledStep, workflow.publishedStep, workflow.archivedStep]; return `{${steps.reduce((code, step) => { return ( diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index 69ab1f7..0c73d1f 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -15,7 +15,6 @@ import { GeneratedFile, getFlattenedElements, ModuleResolution, - sortAlphabetically, toGuidelinesComment, toPascalCase, uniqueFilter, @@ -189,11 +188,9 @@ function getCollectionCodenamesType(collections: readonly Readonly[]): string { - return `export type ${migrationConfig.localTypeNames.workflowStepCodenames} = ${sortAlphabetically( - workflows - .flatMap((workflow) => [...workflow.steps, workflow.publishedStep, workflow.archivedStep, workflow.scheduledStep]) - .map((workflowStep) => `'${workflowStep.codename}'`) - .filter(uniqueFilter), - (codename) => codename - ).join(' | ')};`; + return `export type ${migrationConfig.localTypeNames.workflowStepCodenames} = ${workflows + .flatMap((workflow) => [...workflow.steps, workflow.publishedStep, workflow.archivedStep, workflow.scheduledStep]) + .map((workflowStep) => `'${workflowStep.codename}'`) + .filter(uniqueFilter) + .join(' | ')};`; } diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index c23a5b2..fd9e893 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -22,6 +22,14 @@ import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; * Codename: actor */ export type Actor = IContentItem<{ + /** + * Url (url_slug) + * + * Required: false + * Codename: url + * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 + */ + url: Elements.UrlSlugElement; /** * First name (text) * @@ -47,12 +55,4 @@ export type Actor = IContentItem<{ * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 */ photo: Elements.AssetsElement; - /** - * Url (url_slug) - * - * Required: false - * Codename: url - * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 - */ - url: Elements.UrlSlugElement; }>; diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 9cfee0d..4e28083 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -25,29 +25,37 @@ import type { ReleaseCategory } from '../taxonomies/releasecategory.js'; */ export type Movie = IContentItem<{ /** - * Category (multiple_choice) + * Title (text) + * + * Required: true + * Codename: title + * Id: 3473187e-dc78-eff2-7099-f690f7042d4a + */ + title: Elements.TextElement; + /** + * Plot (rich_text) * * Required: false - * Codename: category - * Id: 9821c252-6414-f549-c17f-cc171dd87713 + * Codename: plot + * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce */ - category: Elements.MultipleChoiceElement; + plot: Elements.RichTextElement; /** - * Length (number) + * Released (date_time) * * Required: false - * Codename: length - * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c + * Codename: released + * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 */ - length: Elements.NumberElement; + released: Elements.DateTimeElement; /** - * Plot (rich_text) + * Length (number) * * Required: false - * Codename: plot - * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce + * Codename: length + * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c */ - plot: Elements.RichTextElement; + length: Elements.NumberElement; /** * Poster (asset) * @@ -57,21 +65,21 @@ export type Movie = IContentItem<{ */ poster: Elements.AssetsElement; /** - * ReleaseCategory (taxonomy) + * Category (multiple_choice) * * Required: false - * Codename: releasecategory - * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 + * Codename: category + * Id: 9821c252-6414-f549-c17f-cc171dd87713 */ - releasecategory: Elements.TaxonomyElement; + category: Elements.MultipleChoiceElement; /** - * Released (date_time) + * Stars (modular_content) * * Required: false - * Codename: released - * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 + * Codename: stars + * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 */ - released: Elements.DateTimeElement; + stars: Elements.LinkedItemsElement; /** * SeoName (url_slug) * @@ -81,19 +89,11 @@ export type Movie = IContentItem<{ */ seoname: Elements.UrlSlugElement; /** - * Stars (modular_content) + * ReleaseCategory (taxonomy) * * Required: false - * Codename: stars - * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 - */ - stars: Elements.LinkedItemsElement; - /** - * Title (text) - * - * Required: true - * Codename: title - * Id: 3473187e-dc78-eff2-7099-f690f7042d4a + * Codename: releasecategory + * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 */ - title: Elements.TextElement; + releasecategory: Elements.TaxonomyElement; }>; diff --git a/sample/delivery/taxonomies/movietype.ts b/sample/delivery/taxonomies/movietype.ts index 503eafb..b2c4c20 100644 --- a/sample/delivery/taxonomies/movietype.ts +++ b/sample/delivery/taxonomies/movietype.ts @@ -19,4 +19,4 @@ * Codename: movietype * Id: 365a17e6-1929-27ab-9f67-a9273c846717 */ -export type MovieType = 'blockbuster' | 'cinema_only' | 'film' | 'student' | 'tv'; +export type MovieType = 'student' | 'tv' | 'blockbuster' | 'cinema_only' | 'film'; diff --git a/sample/delivery/taxonomies/releasecategory.ts b/sample/delivery/taxonomies/releasecategory.ts index 8b83bba..871975c 100644 --- a/sample/delivery/taxonomies/releasecategory.ts +++ b/sample/delivery/taxonomies/releasecategory.ts @@ -19,4 +19,4 @@ * Codename: releasecategory * Id: 09b6a348-0f86-7a68-4af3-7cab9a5c60b7 */ -export type ReleaseCategory = 'global_release' | 'local_release' | 'us_only'; +export type ReleaseCategory = 'global_release' | 'us_only' | 'local_release'; diff --git a/sample/environment/contentTypes.ts b/sample/environment/contentTypes.ts index 706e6d3..70e1881 100644 --- a/sample/environment/contentTypes.ts +++ b/sample/environment/contentTypes.ts @@ -23,6 +23,18 @@ export const contentTypes = { id: '58099989-319f-495f-aa36-cb3710854e36', externalId: undefined, elements: { + /** + * Url (url_slug) + */ + url: { + name: 'Url', + codename: 'url', + id: 'c8658782-f209-a573-9c85-430fb4e3e9f0', + externalId: undefined, + required: false, + type: 'url_slug' + }, + /** * First name (text) * Guidelines: This is the first name of the actor @@ -58,18 +70,6 @@ export const contentTypes = { externalId: undefined, required: false, type: 'asset' - }, - - /** - * Url (url_slug) - */ - url: { - name: 'Url', - codename: 'url', - id: 'c8658782-f209-a573-9c85-430fb4e3e9f0', - externalId: undefined, - required: false, - type: 'url_slug' } } }, @@ -83,6 +83,66 @@ export const contentTypes = { id: 'b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c', externalId: undefined, elements: { + /** + * Title (text) + */ + title: { + name: 'Title', + codename: 'title', + id: '3473187e-dc78-eff2-7099-f690f7042d4a', + externalId: undefined, + required: true, + type: 'text' + }, + + /** + * Plot (rich_text) + */ + plot: { + name: 'Plot', + codename: 'plot', + id: 'f7ee4f27-27fd-a19b-3c5c-102aae1c50ce', + externalId: undefined, + required: false, + type: 'rich_text' + }, + + /** + * Released (date_time) + */ + released: { + name: 'Released', + codename: 'released', + id: '5ccf4644-0d65-5d96-9a32-f4ea21974d51', + externalId: undefined, + required: false, + type: 'date_time' + }, + + /** + * Length (number) + */ + length: { + name: 'Length', + codename: 'length', + id: '7e8ecfab-a419-27ee-d8ec-8adb76fd007c', + externalId: undefined, + required: false, + type: 'number' + }, + + /** + * Poster (asset) + */ + poster: { + name: 'Poster', + codename: 'poster', + id: 'a39a7237-9503-a1ae-8431-5b6cdb85ae9d', + externalId: undefined, + required: false, + type: 'asset' + }, + /** * Category (multiple_choice) */ @@ -94,6 +154,26 @@ export const contentTypes = { required: false, type: 'multiple_choice', options: { + /** + * Sci-fi + */ + sci_fi: { + name: 'Sci-fi', + id: 'b087f774-1f57-9aa8-dab5-2ca88a646824', + codename: 'sci_fi', + externalId: undefined + }, + + /** + * Documentary + */ + documentary: { + name: 'Documentary', + id: '19c5e959-c24a-4863-0b4d-453cdef8fe9d', + codename: 'documentary', + externalId: undefined + }, + /** * Action */ @@ -105,12 +185,12 @@ export const contentTypes = { }, /** - * Adventure + * Romance */ - adventure: { - name: 'Adventure', - id: 'cd8389b0-7628-7739-7b14-3225a50212c1', - codename: 'adventure', + romance: { + name: 'Romance', + id: '60550cc7-c986-a59f-b069-7565862fe1c1', + codename: 'romance', externalId: undefined }, @@ -135,12 +215,12 @@ export const contentTypes = { }, /** - * Documentary + * Adventure */ - documentary: { - name: 'Documentary', - id: '19c5e959-c24a-4863-0b4d-453cdef8fe9d', - codename: 'documentary', + adventure: { + name: 'Adventure', + id: 'cd8389b0-7628-7739-7b14-3225a50212c1', + codename: 'adventure', externalId: undefined }, @@ -152,88 +232,20 @@ export const contentTypes = { id: '051e74de-f2e0-f405-9ad5-5263221e46f2', codename: 'drama', externalId: undefined - }, - - /** - * Romance - */ - romance: { - name: 'Romance', - id: '60550cc7-c986-a59f-b069-7565862fe1c1', - codename: 'romance', - externalId: undefined - }, - - /** - * Sci-fi - */ - sci_fi: { - name: 'Sci-fi', - id: 'b087f774-1f57-9aa8-dab5-2ca88a646824', - codename: 'sci_fi', - externalId: undefined } } }, /** - * Length (number) - */ - length: { - name: 'Length', - codename: 'length', - id: '7e8ecfab-a419-27ee-d8ec-8adb76fd007c', - externalId: undefined, - required: false, - type: 'number' - }, - - /** - * Plot (rich_text) - */ - plot: { - name: 'Plot', - codename: 'plot', - id: 'f7ee4f27-27fd-a19b-3c5c-102aae1c50ce', - externalId: undefined, - required: false, - type: 'rich_text' - }, - - /** - * Poster (asset) - */ - poster: { - name: 'Poster', - codename: 'poster', - id: 'a39a7237-9503-a1ae-8431-5b6cdb85ae9d', - externalId: undefined, - required: false, - type: 'asset' - }, - - /** - * ReleaseCategory (taxonomy) - */ - releasecategory: { - name: 'ReleaseCategory', - codename: 'releasecategory', - id: '65f2fd44-1856-bc2b-17c2-decb0635e3d2', - externalId: undefined, - required: false, - type: 'taxonomy' - }, - - /** - * Released (date_time) + * Stars (modular_content) */ - released: { - name: 'Released', - codename: 'released', - id: '5ccf4644-0d65-5d96-9a32-f4ea21974d51', + stars: { + name: 'Stars', + codename: 'stars', + id: 'aa26a55d-19f8-7501-fea3-b0d9b1eeac71', externalId: undefined, required: false, - type: 'date_time' + type: 'modular_content' }, /** @@ -249,27 +261,15 @@ export const contentTypes = { }, /** - * Stars (modular_content) + * ReleaseCategory (taxonomy) */ - stars: { - name: 'Stars', - codename: 'stars', - id: 'aa26a55d-19f8-7501-fea3-b0d9b1eeac71', + releasecategory: { + name: 'ReleaseCategory', + codename: 'releasecategory', + id: '65f2fd44-1856-bc2b-17c2-decb0635e3d2', externalId: undefined, required: false, - type: 'modular_content' - }, - - /** - * Title (text) - */ - title: { - name: 'Title', - codename: 'title', - id: '3473187e-dc78-eff2-7099-f690f7042d4a', - externalId: undefined, - required: true, - type: 'text' + type: 'taxonomy' } } } diff --git a/sample/environment/languages.ts b/sample/environment/languages.ts index 3dee4fc..ef597a8 100644 --- a/sample/environment/languages.ts +++ b/sample/environment/languages.ts @@ -15,27 +15,27 @@ export const languages = { /** - * cz + * English */ - cz: { - name: 'cz', - codename: 'cz', - id: '41ccb26f-ceab-04d0-6ffa-9c7c5358aa8f', + en: { + name: 'English', + codename: 'en', + id: '00000000-0000-0000-0000-000000000000', isActive: true, - isDefault: false, + isDefault: true, fallbackLanguageId: '00000000-0000-0000-0000-000000000000', externalId: undefined }, /** - * English + * cz */ - en: { - name: 'English', - codename: 'en', - id: '00000000-0000-0000-0000-000000000000', + cz: { + name: 'cz', + codename: 'cz', + id: '41ccb26f-ceab-04d0-6ffa-9c7c5358aa8f', isActive: true, - isDefault: true, + isDefault: false, fallbackLanguageId: '00000000-0000-0000-0000-000000000000', externalId: undefined }, diff --git a/sample/environment/roles.ts b/sample/environment/roles.ts index 03cca0d..471d989 100644 --- a/sample/environment/roles.ts +++ b/sample/environment/roles.ts @@ -24,12 +24,12 @@ export const roles = { }, /** - * Developer + * Reviewer */ - developer: { + reviewer: { codename: undefined, - id: 'b3994090-0818-4969-816b-f4c5d3e526f3', - name: 'Developer' + id: '94478afa-d898-45dd-8300-ba61b6e0eb4b', + name: 'Reviewer' }, /** @@ -42,11 +42,11 @@ export const roles = { }, /** - * Reviewer + * Developer */ - reviewer: { + developer: { codename: undefined, - id: '94478afa-d898-45dd-8300-ba61b6e0eb4b', - name: 'Reviewer' + id: 'b3994090-0818-4969-816b-f4c5d3e526f3', + name: 'Developer' } } as const; diff --git a/sample/environment/taxonomies.ts b/sample/environment/taxonomies.ts index d149620..edaf5c4 100644 --- a/sample/environment/taxonomies.ts +++ b/sample/environment/taxonomies.ts @@ -23,6 +23,17 @@ export const taxonomies = { externalId: undefined, id: '365a17e6-1929-27ab-9f67-a9273c846717', terms: { + /** + * Student + */ + student: { + codename: 'student', + id: 'b107e12c-124d-705f-1029-c0dfdd0b2438', + externalId: undefined, + name: 'Student', + terms: {} + }, + /** * Film */ @@ -32,6 +43,17 @@ export const taxonomies = { externalId: undefined, name: 'Film', terms: { + /** + * TV + */ + tv: { + codename: 'tv', + id: '47511b09-6c39-fa04-ff59-7c47551e827f', + externalId: undefined, + name: 'TV', + terms: {} + }, + /** * Blockbuster */ @@ -52,30 +74,8 @@ export const taxonomies = { externalId: undefined, name: 'Cinema only', terms: {} - }, - - /** - * TV - */ - tv: { - codename: 'tv', - id: '47511b09-6c39-fa04-ff59-7c47551e827f', - externalId: undefined, - name: 'TV', - terms: {} } } - }, - - /** - * Student - */ - student: { - codename: 'student', - id: 'b107e12c-124d-705f-1029-c0dfdd0b2438', - externalId: undefined, - name: 'Student', - terms: {} } } }, @@ -101,24 +101,24 @@ export const taxonomies = { }, /** - * Local release + * US only */ - local_release: { - codename: 'local_release', - id: '37e55484-f0dc-14eb-bf2a-b0293a0d1b1f', + us_only: { + codename: 'us_only', + id: 'b03d990a-55a9-601e-dd5c-aa2edc8698ca', externalId: undefined, - name: 'Local release', + name: 'US only', terms: {} }, /** - * US only + * Local release */ - us_only: { - codename: 'us_only', - id: 'b03d990a-55a9-601e-dd5c-aa2edc8698ca', + local_release: { + codename: 'local_release', + id: '37e55484-f0dc-14eb-bf2a-b0293a0d1b1f', externalId: undefined, - name: 'US only', + name: 'Local release', terms: {} } } diff --git a/sample/environment/workflows.ts b/sample/environment/workflows.ts index 299fd79..4d71db6 100644 --- a/sample/environment/workflows.ts +++ b/sample/environment/workflows.ts @@ -22,21 +22,6 @@ export const workflows = { codename: 'default', id: '00000000-0000-0000-0000-000000000000', steps: { - archived: { - name: 'Archived', - codename: 'archived', - id: '7a535a69-ad34-47f8-806a-def1fdf4d391' - }, - published: { - name: 'Published', - codename: 'published', - id: 'f05b8a85-c6cc-429a-ac6d-21d5edd268fe' - }, - scheduled: { - name: 'Scheduled', - codename: 'scheduled', - id: '9d2b0228-4d0d-4c23-8b49-01a698857709' - }, draft: { name: 'Draft', codename: 'draft', @@ -51,6 +36,21 @@ export const workflows = { name: 'Ready to publish', codename: 'ready_to_publish', id: 'aaee1d73-f0cc-4185-9e49-844d161c3634' + }, + scheduled: { + name: 'Scheduled', + codename: 'scheduled', + id: '9d2b0228-4d0d-4c23-8b49-01a698857709' + }, + published: { + name: 'Published', + codename: 'published', + id: 'f05b8a85-c6cc-429a-ac6d-21d5edd268fe' + }, + archived: { + name: 'Archived', + codename: 'archived', + id: '7a535a69-ad34-47f8-806a-def1fdf4d391' } } } diff --git a/sample/migration/content-types/actor.ts b/sample/migration/content-types/actor.ts index 4229a92..299c4f5 100644 --- a/sample/migration/content-types/actor.ts +++ b/sample/migration/content-types/actor.ts @@ -25,6 +25,15 @@ import type { Item } from '../migration.js'; export type ActorItem = Item< 'actor', { + /** + * Url (url_slug) + * + * Required: false + * Codename: url + * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 + */ + url: MigrationElementModels.UrlSlugElement; + /** * First name (text) * @@ -52,14 +61,5 @@ export type ActorItem = Item< * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 */ photo: MigrationElementModels.AssetElement; - - /** - * Url (url_slug) - * - * Required: false - * Codename: url - * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 - */ - url: MigrationElementModels.UrlSlugElement; } >; diff --git a/sample/migration/content-types/movie.ts b/sample/migration/content-types/movie.ts index eaa1679..f345d38 100644 --- a/sample/migration/content-types/movie.ts +++ b/sample/migration/content-types/movie.ts @@ -26,31 +26,40 @@ export type MovieItem = Item< 'movie', { /** - * Category (multiple_choice) + * Title (text) + * + * Required: true + * Codename: title + * Id: 3473187e-dc78-eff2-7099-f690f7042d4a + */ + title: MigrationElementModels.TextElement; + + /** + * Plot (rich_text) * * Required: false - * Codename: category - * Id: 9821c252-6414-f549-c17f-cc171dd87713 + * Codename: plot + * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce */ - category: MigrationElementModels.MultipleChoiceElement; + plot: MigrationElementModels.RichTextElement; /** - * Length (number) + * Released (date_time) * * Required: false - * Codename: length - * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c + * Codename: released + * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 */ - length: MigrationElementModels.NumberElement; + released: MigrationElementModels.DateTimeElement; /** - * Plot (rich_text) + * Length (number) * * Required: false - * Codename: plot - * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce + * Codename: length + * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c */ - plot: MigrationElementModels.RichTextElement; + length: MigrationElementModels.NumberElement; /** * Poster (asset) @@ -62,22 +71,22 @@ export type MovieItem = Item< poster: MigrationElementModels.AssetElement; /** - * ReleaseCategory (taxonomy) + * Category (multiple_choice) * * Required: false - * Codename: releasecategory - * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 + * Codename: category + * Id: 9821c252-6414-f549-c17f-cc171dd87713 */ - releasecategory: MigrationElementModels.TaxonomyElement; + category: MigrationElementModels.MultipleChoiceElement; /** - * Released (date_time) + * Stars (modular_content) * * Required: false - * Codename: released - * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 + * Codename: stars + * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 */ - released: MigrationElementModels.DateTimeElement; + stars: MigrationElementModels.LinkedItemsElement; /** * SeoName (url_slug) @@ -89,21 +98,12 @@ export type MovieItem = Item< seoname: MigrationElementModels.UrlSlugElement; /** - * Stars (modular_content) + * ReleaseCategory (taxonomy) * * Required: false - * Codename: stars - * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 - */ - stars: MigrationElementModels.LinkedItemsElement; - - /** - * Title (text) - * - * Required: true - * Codename: title - * Id: 3473187e-dc78-eff2-7099-f690f7042d4a + * Codename: releasecategory + * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 */ - title: MigrationElementModels.TextElement; + releasecategory: MigrationElementModels.TaxonomyElement; } >; diff --git a/sample/migration/environment/environment.ts b/sample/migration/environment/environment.ts index 901b7eb..1cd61c2 100644 --- a/sample/migration/environment/environment.ts +++ b/sample/migration/environment/environment.ts @@ -16,7 +16,7 @@ /** * Type representing all languages */ -export type LanguageCodenames = 'cz' | 'en' | 'German'; +export type LanguageCodenames = 'en' | 'cz' | 'German'; /** * Type representing all content types @@ -36,4 +36,4 @@ export type WorkflowCodenames = 'default'; /** * Type representing all worksflow steps across all workflows */ -export type WorkflowStepCodenames = 'archived' | 'draft' | 'published' | 'ready_to_publish' | 'review' | 'scheduled'; +export type WorkflowStepCodenames = 'draft' | 'review' | 'ready_to_publish' | 'published' | 'archived' | 'scheduled'; From 023cd8d291a147b7371e9bd8e088f3b5904bb388 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 9 Sep 2024 10:45:15 +0200 Subject: [PATCH 077/183] Adds support for generating item codenames type & ids/codename obj (fixes https://github.com/kontent-ai/model-generator-js/issues/32) --- README.md | 18 ++- lib/config.ts | 5 + lib/core/core.models.ts | 2 +- lib/core/core.utils.ts | 6 +- lib/fetch/kontent-fetcher.ts | 15 ++ lib/generators/index.ts | 4 + lib/generators/items/items-func.ts | 125 +++++++++++++++++ lib/generators/items/items.generator.ts | 81 +++++++++++ lib/generators/migration/migration-func.ts | 2 +- .../migration/migration.generator.ts | 10 +- lib/node/cli/actions/items-action.ts | 16 +++ lib/node/cli/app.ts | 2 + lib/node/cli/args/args-fetcher.ts | 1 + lib/node/cli/commands.ts | 6 + package.json | 1 + sample/items/codenames/actor.codenames.ts | 37 +++++ sample/items/codenames/index.ts | 17 +++ sample/items/codenames/movie.codenames.ts | 24 ++++ sample/items/index.ts | 17 +++ sample/items/items/actor.items.ts | 128 ++++++++++++++++++ sample/items/items/index.ts | 17 +++ sample/items/items/movie.items.ts | 72 ++++++++++ scripts/tests/item-models.ts | 37 +++++ 23 files changed, 632 insertions(+), 11 deletions(-) create mode 100644 lib/generators/items/items-func.ts create mode 100644 lib/generators/items/items.generator.ts create mode 100644 lib/node/cli/actions/items-action.ts create mode 100644 sample/items/codenames/actor.codenames.ts create mode 100644 sample/items/codenames/index.ts create mode 100644 sample/items/codenames/movie.codenames.ts create mode 100644 sample/items/index.ts create mode 100644 sample/items/items/actor.items.ts create mode 100644 sample/items/items/index.ts create mode 100644 sample/items/items/movie.items.ts create mode 100644 scripts/tests/item-models.ts diff --git a/README.md b/README.md index 8c317f9..6b7f3dc 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ # Kontent.ai Model Generator -The purpose of this library is to help you write better code by using strongly typed objects or Typescript models. There are 3 types of +The purpose of this library is to help you write better code by using strongly typed objects or Typescript models. There are 4 types of models you can generate: 1. `delivery-sdk` - Typescript models for [JS Delivery SDK](https://www.npmjs.com/package/@kontent-ai/delivery-sdk) representing Content @@ -13,6 +13,9 @@ models you can generate: write migration scripts easier 3. `environment` - Strongly typed objects representing all structural objects within an environment (i.e. content types, workflows, taxonomies ...). These models help you write scripts because they provide you a straightforward access to objects properties. +4. `items` - Generates `Type` representing all available item codenames for each content type and object representing `id` and `codenames` + properties of all items. This makes it easy and convenient to reference items in your code. It is not recommended to use this if your + environment contains high number of items. ## Installation @@ -35,6 +38,9 @@ kontent-generate migration-toolkit --environmentId=x --apiKey=y # Environment models used for scripting and strongly typed access to environment objects kontent-generate environment --environmentId=x --apiKey=y + +# Items overview with ids / codenames and Types representing available item codenames +kontent-generate items --environmentId=x --apiKey=y ``` To learn what options are available use the `help` command: @@ -49,7 +55,7 @@ kontent-generate delivery-sdk --help ## Use in code ```typescript -import { generateDeliveryModelsAsync, generateEnvironmentModelsAsync, generateMigrationModelsAsync } from '@kontent-ai/model-generator'; +import { generateDeliveryModelsAsync, generateEnvironmentModelsAsync, generateMigrationModelsAsync, generateItemsAsync } from '@kontent-ai/model-generator'; // delivery-sdk models await generateDeliveryModelsAsync({ @@ -61,10 +67,15 @@ await generateMigrationModelsAsync({ ... }); -// environment models +// environment overview await generateEnvironmentModelsAsync({ ... }); + +// items +await generateItemsAsync({ + ... +}); ``` ## Sample models @@ -74,6 +85,7 @@ To see how models are generated have a look at following sample generated models 1. `delivery-sdk` -> https://github.com/kontent-ai/model-generator-js/tree/master/sample/delivery 2. `migration-toolkit` -> https://github.com/kontent-ai/model-generator-js/tree/master/sample/migration 3. `environment` -> https://github.com/kontent-ai/model-generator-js/tree/master/sample/environment +4. `items` -> https://github.com/kontent-ai/model-generator-js/tree/master/sample/items ## Contribution & Feedback diff --git a/lib/config.ts b/lib/config.ts index 9dcfcf5..e3499ee 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -40,3 +40,8 @@ export const deliveryConfig = { elements: 'Elements' } } as const; + +export const itemsConfig = { + itemsFolderName: 'items', + codenamesFolderName: 'codenames' +} as const; diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index 932b319..e22601b 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -8,7 +8,7 @@ import { TaxonomyModels } from '@kontent-ai/management-sdk'; -export type CliAction = 'delivery-sdk' | 'migration-toolkit' | 'environment'; +export type CliAction = 'delivery-sdk' | 'migration-toolkit' | 'environment' | 'items'; export type LibraryType = '@kontent-ai/migration-toolkit' | '@kontent-ai/delivery-sdk'; export type ModuleResolution = 'nodeNext' | 'node'; export type CaseType = 'camelCase' | 'pascalCase' | 'snakeCase'; diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 755a782..bb37b0b 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -1,6 +1,5 @@ import { camelCasePropertyNameResolver, pascalCasePropertyNameResolver, snakeCasePropertyNameResolver } from '@kontent-ai/delivery-sdk'; import { createHash } from 'crypto'; -import { parse } from 'path'; import { CliAction, LibraryType, ModuleResolution } from './core.models.js'; export function uniqueFilter(value: string, index: number, self: readonly string[]): boolean { @@ -27,8 +26,9 @@ export function getFileNameWithoutExtension(filePath: string): string { return filePath.substring(0, filePath.lastIndexOf('.')); } -export function getFilenameFromPath(filePath: string): string { - return parse(filePath).name; +export function getFilenameFromPath(text: string): string { + const lastIndex = text.lastIndexOf('/'); + return text.substring(lastIndex + 1); } export function sortAlphabetically(arrayToSort: readonly T[], propertySelector: (item: T) => string): readonly T[] { diff --git a/lib/fetch/kontent-fetcher.ts b/lib/fetch/kontent-fetcher.ts index 1ee454d..a92c8fc 100644 --- a/lib/fetch/kontent-fetcher.ts +++ b/lib/fetch/kontent-fetcher.ts @@ -2,6 +2,7 @@ import { HttpService } from '@kontent-ai/core-sdk'; import { AssetFolderModels, CollectionModels, + ContentItemModels, ContentTypeModels, ContentTypeSnippetModels, createManagementClient, @@ -40,6 +41,20 @@ export function kontentFetcher(config: KontentFetcherConfig) { console.log(`Environment '${chalk.yellow(toSafeComment(projectInformation.project.environment))}'\n`); return projectInformation.project; }, + async getItemsAsync(): Promise[]> { + const data = ( + await client + .listContentItems() + .withListQueryConfig({ + responseFetched: (response) => { + console.log(`Fetched '${chalk.yellow(response.data.items.length.toString())}' content items`); + } + }) + .toAllPromise() + ).data; + + return data.items; + }, async getWorkflowsAsync(): Promise[]> { const items = (await client.listWorkflows().toPromise()).data; console.log(`Fetched '${chalk.yellow(items.length.toString())}' workflows`); diff --git a/lib/generators/index.ts b/lib/generators/index.ts index ff63b09..c78743e 100644 --- a/lib/generators/index.ts +++ b/lib/generators/index.ts @@ -10,3 +10,7 @@ export * from './environment/environment.generator.js'; // migration export * from './migration/migration-func.js'; export * from './migration/migration.generator.js'; + +// items +export * from './items/items-func.js'; +export * from './items/items.generator.js'; diff --git a/lib/generators/items/items-func.ts b/lib/generators/items/items-func.ts new file mode 100644 index 0000000..fe59196 --- /dev/null +++ b/lib/generators/items/items-func.ts @@ -0,0 +1,125 @@ +import { EnvironmentModels } from '@kontent-ai/management-sdk'; +import chalk from 'chalk'; +import { Options } from 'prettier'; +import { coreConfig, itemsConfig } from '../../config.js'; +import { + importer as _importer, + GeneratedFile, + getDefaultModuleResolution, + getFilenameFromPath, + ModuleResolution +} from '../../core/index.js'; +import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; +import { fileManager as _fileManager } from '../../files/index.js'; +import { itemsGenerator as _itemsGenerator } from './items.generator.js'; + +export interface GenerateItemsModelsConfig { + readonly environmentId: string; + readonly addTimestamp: boolean; + readonly apiKey: string; + readonly moduleResolution: ModuleResolution; + + readonly outputDir?: string; + readonly baseUrl?: string; + readonly formatOptions?: Readonly; +} + +export async function generateItemsAsync(config: GenerateItemsModelsConfig): Promise { + console.log(chalk.green(`Model generator started \n`)); + console.log(`Generating '${chalk.yellow('migration')}' models\n`); + + const { itemFiles, moduleResolution, environmentInfo, codenameFiles } = await getFilesAsync(config); + + await createFilesAsync({ + moduleResolution, + itemFiles, + codenameFiles, + outputDir: config.outputDir, + formatOptions: config.formatOptions, + addTimestamp: config.addTimestamp, + environmentInfo + }); + + console.log(chalk.green(`\nCompleted`)); +} + +async function getFilesAsync(config: GenerateItemsModelsConfig): Promise<{ + readonly itemFiles: readonly GeneratedFile[]; + readonly codenameFiles: readonly GeneratedFile[]; + readonly moduleResolution: ModuleResolution; + readonly environmentInfo: Readonly; +}> { + const moduleResolution: ModuleResolution = getDefaultModuleResolution(config.moduleResolution); + const kontentFetcher = _kontentFetcher({ + environmentId: config.environmentId, + apiKey: config.apiKey, + baseUrl: config.baseUrl + }); + + const environmentInfo = await kontentFetcher.getEnvironmentInfoAsync(); + + const [items, types] = await Promise.all([kontentFetcher.getItemsAsync(), kontentFetcher.getTypesAsync()]); + + const itemsGenerator = _itemsGenerator({ + moduleResolution: config.moduleResolution, + environmentData: { + environment: environmentInfo, + types: types, + items: items + } + }); + + return { + moduleResolution, + itemFiles: itemsGenerator.getItemFiles(), + codenameFiles: itemsGenerator.getCodenameFiles(), + environmentInfo + }; +} + +async function createFilesAsync(data: { + readonly itemFiles: readonly GeneratedFile[]; + readonly codenameFiles: readonly GeneratedFile[]; + readonly moduleResolution: ModuleResolution; + readonly outputDir?: string; + readonly formatOptions?: Readonly; + readonly environmentInfo: Readonly; + readonly addTimestamp: boolean; +}): Promise { + const fileManager = _fileManager({ + outputDir: data.outputDir, + addTimestamp: data.addTimestamp, + environmentInfo: data.environmentInfo, + formatOptions: data.formatOptions + }); + + const importer = _importer(data.moduleResolution); + + await fileManager.createFilesAsync([ + ...data.itemFiles, + ...data.codenameFiles, + // items barrel file + { + filename: `${itemsConfig.itemsFolderName}/${coreConfig.barrelExportFilename}`, + text: importer.getBarrelExportCode([ + ...data.itemFiles.map((m) => { + return `./${getFilenameFromPath(m.filename)}`; + }) + ]) + }, + // codename barrel file + { + filename: `${itemsConfig.codenamesFolderName}/${coreConfig.barrelExportFilename}`, + text: importer.getBarrelExportCode([ + ...data.codenameFiles.map((m) => { + return `./${getFilenameFromPath(m.filename)}`; + }) + ]) + }, + // main barrel file + { + filename: coreConfig.barrelExportFilename, + text: importer.getBarrelExportCode([`./${itemsConfig.itemsFolderName}/index`, `./${itemsConfig.codenamesFolderName}/index`]) + } + ]); +} diff --git a/lib/generators/items/items.generator.ts b/lib/generators/items/items.generator.ts new file mode 100644 index 0000000..a9de068 --- /dev/null +++ b/lib/generators/items/items.generator.ts @@ -0,0 +1,81 @@ +import { ContentItemModels, ContentTypeModels, EnvironmentModels } from '@kontent-ai/management-sdk'; +import { itemsConfig } from '../../config.js'; +import { GeneratedFile, ModuleResolution, toPascalCase, toSafeComment, wrapComment } from '../../core/index.js'; + +export interface ItemGeneratorConfig { + readonly moduleResolution: ModuleResolution; + + readonly environmentData: { + readonly environment: Readonly; + readonly types: readonly Readonly[]; + readonly items: readonly Readonly[]; + }; +} + +export function itemsGenerator(config: ItemGeneratorConfig) { + const getItemCodenameType = ( + type: Readonly, + items: readonly Readonly[] + ): string => { + return `export type ${toPascalCase(type.codename)}Codenames = ${items.map((item) => `'${item.codename}'`).join(' | ')};`; + }; + + const getItemCodenamesProp = ( + type: Readonly, + items: readonly Readonly[] + ): string => { + const values = items.reduce((code, item, index) => { + const isLast = index === items.length - 1; + + return `${code}\n + ${wrapComment(` + * ${item.name} + `)} + ${item.codename}: { + codename: '${item.codename}', + id: '${item.id}' + }${!isLast ? ',\n' : ''}`; + }, ''); + + return `export const ${type.codename}Items = { + ${values} + } as const;`; + }; + + return { + getItemFiles(): readonly GeneratedFile[] { + return config.environmentData.types.map((type) => { + const typeItems = config.environmentData.items.filter((m) => m.type.id === type.id); + + return { + filename: `${itemsConfig.itemsFolderName}/${type.codename}.items.ts`, + text: ` + ${wrapComment(`\n * Object representing identifiers of available items + * + * ${toSafeComment(type.name)} + * + * Codename: ${type.codename} + * Id: ${type.id}\n`)} + ${getItemCodenamesProp(type, typeItems)}` + }; + }); + }, + getCodenameFiles(): readonly GeneratedFile[] { + return config.environmentData.types.map((type) => { + const typeItems = config.environmentData.items.filter((m) => m.type.id === type.id); + + return { + filename: `${itemsConfig.codenamesFolderName}/${type.codename}.codenames.ts`, + text: ` + ${wrapComment(`\n * Type representing available item codenames + * + * ${toSafeComment(type.name)} + * + * Codename: ${type.codename} + * Id: ${type.id}\n`)} + ${getItemCodenameType(type, typeItems)}` + }; + }); + } + }; +} diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index 00928f9..3b54d10 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -85,7 +85,7 @@ async function getFilesAsync(config: GenerateMigrationModelsConfig): Promise<{ return { moduleResolution, migrationTypeFiles: migrationGenerator.getMigrationTypeFiles(), - migrationItemFiles: migrationGenerator.getMigrationItemFiles(), + migrationItemFiles: migrationGenerator.getMigrationTypeFiles(), environmentFiles: migrationGenerator.getEnvironmentFiles(), environmentInfo }; diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index 0c73d1f..0aeee98 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -150,9 +150,13 @@ function getElementPropType(element: Readonly): string { .with('taxonomy', () => `${migrationConfig.sdkTypeNames.elementModels}.TaxonomyElement`) .with('url_slug', () => `${migrationConfig.sdkTypeNames.elementModels}.UrlSlugElement`) .with('modular_content', () => `${migrationConfig.sdkTypeNames.elementModels}.LinkedItemsElement`) - .otherwise((type) => { - throw Error(`Element type '${type}' is not supported.`); - }); + .with('guidelines', () => { + throw new Error('Guidelines are not supported'); + }) + .with('snippet', () => { + throw new Error('Snippets are not supported'); + }) + .exhaustive(); } function getItemType(): string { diff --git a/lib/node/cli/actions/items-action.ts b/lib/node/cli/actions/items-action.ts new file mode 100644 index 0000000..726e4f6 --- /dev/null +++ b/lib/node/cli/actions/items-action.ts @@ -0,0 +1,16 @@ +import { ModuleResolution } from '../../../core/index.js'; +import { generateItemsAsync } from '../../../generators/index.js'; +import { CliArgumentsFetcher } from '../cli.models.js'; + +export async function itemsActionAsync(cliFetcher: CliArgumentsFetcher): Promise { + await generateItemsAsync({ + // required + environmentId: cliFetcher.getRequiredArgumentValue('environmentId'), + apiKey: cliFetcher.getRequiredArgumentValue('apiKey'), + // optional + baseUrl: cliFetcher.getOptionalArgumentValue('baseUrl'), + outputDir: cliFetcher.getOptionalArgumentValue('outputDir'), + addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), + moduleResolution: cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' + }); +} diff --git a/lib/node/cli/app.ts b/lib/node/cli/app.ts index 8aa27e3..0cf293f 100644 --- a/lib/node/cli/app.ts +++ b/lib/node/cli/app.ts @@ -5,6 +5,7 @@ import { match } from 'ts-pattern'; import { handleError } from '../../core/index.js'; import { deliveryActionAsync } from './actions/delivery-action.js'; import { environmentActionAsync } from './actions/environment-action.js'; +import { itemsActionAsync } from './actions/items-action.js'; import { migrateActionAsync } from './actions/migrate-action.js'; import { argumentsFetcherAsync } from './args/args-fetcher.js'; import { cliArgs } from './commands.js'; @@ -20,6 +21,7 @@ try { .with('delivery-sdk', async () => await deliveryActionAsync(argsFetcher)) .with('migration-toolkit', async () => await migrateActionAsync(argsFetcher)) .with('environment', async () => await environmentActionAsync(argsFetcher)) + .with('items', async () => await itemsActionAsync(argsFetcher)) .otherwise((action) => { throw Error(`Invalid action '${chalk.red(action)}'`); }); diff --git a/lib/node/cli/args/args-fetcher.ts b/lib/node/cli/args/args-fetcher.ts index 352650f..5cee873 100644 --- a/lib/node/cli/args/args-fetcher.ts +++ b/lib/node/cli/args/args-fetcher.ts @@ -28,6 +28,7 @@ export async function argumentsFetcherAsync(): Promise { .with('delivery-sdk', () => 'delivery-sdk') .with('migration-toolkit', () => 'migration-toolkit') .with('environment', () => 'environment') + .with('items', () => 'items') .otherwise(() => { throw Error(`Unsupported command '${chalk.red(command)}'`); }); diff --git a/lib/node/cli/commands.ts b/lib/node/cli/commands.ts index eb07275..8a92c05 100644 --- a/lib/node/cli/commands.ts +++ b/lib/node/cli/commands.ts @@ -63,6 +63,12 @@ export const cliArgs = argumentsSetter() examples: [`kontent-generate ${getCliAction('migration-toolkit')} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], options: [environmentIdOption, apiKeyOption, addTimestampOption, moduleResolutionOption, outputDirOption, baseUrl] }) + .withCommand({ + name: getCliAction('items'), + description: `Overview of all items in the environment and their ids/codenames as well as Type representing all item codenames`, + examples: [`kontent-generate ${getCliAction('items')} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], + options: [environmentIdOption, apiKeyOption, addTimestampOption, moduleResolutionOption, outputDirOption, baseUrl] + }) .withOption({ alias: `h`, name: `help`, diff --git a/package.json b/package.json index db146d7..4a41e18 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "test:delivery": "tsx scripts/tests/delivery-models", "test:environment": "tsx scripts/tests/environment-models", "test:migration": "tsx scripts/tests/migration-models", + "test:items": "tsx scripts/tests/item-models", "test:help": "tsx lib/node/cli/app --help", "test:help:delivery-sdk": "tsx lib/node/cli/app delivery-sdk --help", "lint": "npx eslint lib", diff --git a/sample/items/codenames/actor.codenames.ts b/sample/items/codenames/actor.codenames.ts new file mode 100644 index 0000000..dff3009 --- /dev/null +++ b/sample/items/codenames/actor.codenames.ts @@ -0,0 +1,37 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +/** + * Type representing available item codenames + * + * Actor + * + * Codename: actor + * Id: 58099989-319f-495f-aa36-cb3710854e36 + */ +export type ActorCodenames = + | 'anne_hathaway' + | 'rachel_mcadams' + | 'nathalie_boltt' + | 'kristen_wiig' + | 'joel_edgerton' + | 'billy_crystal' + | 'matt_damon' + | 'jessica_chastain' + | 'sharlto_copley' + | 'domhnall_gleeson' + | 'bill_nighy' + | 'tom_hardy' + | 'christian_bale'; diff --git a/sample/items/codenames/index.ts b/sample/items/codenames/index.ts new file mode 100644 index 0000000..e6e3185 --- /dev/null +++ b/sample/items/codenames/index.ts @@ -0,0 +1,17 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +export * from './actor.codenames.js'; +export * from './movie.codenames.js'; diff --git a/sample/items/codenames/movie.codenames.ts b/sample/items/codenames/movie.codenames.ts new file mode 100644 index 0000000..bc6bf1c --- /dev/null +++ b/sample/items/codenames/movie.codenames.ts @@ -0,0 +1,24 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +/** + * Type representing available item codenames + * + * Movie + * + * Codename: movie + * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c + */ +export type MovieCodenames = 'monsters__inc_' | 'warrior' | 'district_9' | 'the_martian' | '_the_dark_knight_rises' | 'about_time'; diff --git a/sample/items/index.ts b/sample/items/index.ts new file mode 100644 index 0000000..a4b34a0 --- /dev/null +++ b/sample/items/index.ts @@ -0,0 +1,17 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +export * from './codenames/index.js'; +export * from './items/index.js'; diff --git a/sample/items/items/actor.items.ts b/sample/items/items/actor.items.ts new file mode 100644 index 0000000..ddb2475 --- /dev/null +++ b/sample/items/items/actor.items.ts @@ -0,0 +1,128 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +/** + * Object representing identifiers of available items + * + * Actor + * + * Codename: actor + * Id: 58099989-319f-495f-aa36-cb3710854e36 + */ +export const actorItems = { + /** + * Anne Hathaway + */ + anne_hathaway: { + codename: 'anne_hathaway', + id: '04f3fe64-2d62-4db3-84d5-06776c47f543' + }, + + /** + * Rachel McAdams + */ + rachel_mcadams: { + codename: 'rachel_mcadams', + id: '10145fa6-b074-4d2e-9a18-07cf23dff33d' + }, + + /** + * Nathalie Boltt + */ + nathalie_boltt: { + codename: 'nathalie_boltt', + id: '11b2170c-6df8-48d6-af66-4ddafa2a425a' + }, + + /** + * Kristen Wiig + */ + kristen_wiig: { + codename: 'kristen_wiig', + id: '2df17777-b347-4590-be05-cb256bf718e9' + }, + + /** + * Joel Edgerton + */ + joel_edgerton: { + codename: 'joel_edgerton', + id: '3294e4b0-e58b-49d7-85fa-5bc9a86556ec' + }, + + /** + * Billy Crystal + */ + billy_crystal: { + codename: 'billy_crystal', + id: '3e99ea61-7d47-49f0-b271-5757061658ab' + }, + + /** + * Matt Damon + */ + matt_damon: { + codename: 'matt_damon', + id: '69a1cbb3-fcc9-4f50-8631-8298fe106cd5' + }, + + /** + * Jessica Chastain + */ + jessica_chastain: { + codename: 'jessica_chastain', + id: 'a67aacfa-b400-444d-b53e-df1766065034' + }, + + /** + * Sharlto Copley + */ + sharlto_copley: { + codename: 'sharlto_copley', + id: 'c10783cb-c8b8-4fec-8f44-7323ffc3227b' + }, + + /** + * Domhnall Gleeson + */ + domhnall_gleeson: { + codename: 'domhnall_gleeson', + id: 'c37b94d2-56e1-4e0a-9f14-547fe194e0d9' + }, + + /** + * Bill Nighy + */ + bill_nighy: { + codename: 'bill_nighy', + id: 'cddc7576-38b3-4de2-9fb9-2d1ce16daa8b' + }, + + /** + * Tom Hardy + */ + tom_hardy: { + codename: 'tom_hardy', + id: 'd1557cb1-d7ec-4d04-9742-f86b52bc34fc' + }, + + /** + * Christian Bale + */ + christian_bale: { + codename: 'christian_bale', + id: 'f0e9e9fa-91e8-40d5-9527-b7e0ae51fc54' + } +} as const; diff --git a/sample/items/items/index.ts b/sample/items/items/index.ts new file mode 100644 index 0000000..1e9f4d0 --- /dev/null +++ b/sample/items/items/index.ts @@ -0,0 +1,17 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +export * from './actor.items.js'; +export * from './movie.items.js'; diff --git a/sample/items/items/movie.items.ts b/sample/items/items/movie.items.ts new file mode 100644 index 0000000..4055cba --- /dev/null +++ b/sample/items/items/movie.items.ts @@ -0,0 +1,72 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +/** + * Object representing identifiers of available items + * + * Movie + * + * Codename: movie + * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c + */ +export const movieItems = { + /** + * Monsters, Inc. + */ + monsters__inc_: { + codename: 'monsters__inc_', + id: '00e96c5c-22a2-4ecf-811d-28881d1d2eda' + }, + + /** + * Warrior + */ + warrior: { + codename: 'warrior', + id: '325e2acb-1c14-47f6-af9a-27bc8b6c16fe' + }, + + /** + * District 9 + */ + district_9: { + codename: 'district_9', + id: 'e0b67f90-790c-4509-8679-5ca2df42f3b8' + }, + + /** + * The Martian + */ + the_martian: { + codename: 'the_martian', + id: 'e9ac3dd7-8129-4f9a-9112-eb24d84d3ecd' + }, + + /** + * The Dark Knight Rises + */ + _the_dark_knight_rises: { + codename: '_the_dark_knight_rises', + id: 'e9ff5385-0f10-469a-8525-98189e295c0d' + }, + + /** + * About Time + */ + about_time: { + codename: 'about_time', + id: 'f5d741ec-e500-4285-97f0-a30196a655bd' + } +} as const; diff --git a/scripts/tests/item-models.ts b/scripts/tests/item-models.ts new file mode 100644 index 0000000..7f28a05 --- /dev/null +++ b/scripts/tests/item-models.ts @@ -0,0 +1,37 @@ +import chalk from 'chalk'; +import * as dotenv from 'dotenv'; +import { rmSync } from 'fs'; +import { ModuleResolution, generateItemsAsync, handleError } from '../../lib/index.js'; +import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; + +const outputDir: string = './sample/items'; + +try { + // needed to load .env environment to current process when run via package.json script + dotenv.config({ + path: './.env' + }); + + // delete existing models + console.log(`Deleting existing folder '${chalk.yellow(outputDir)}'`); + rmSync(outputDir, { + recursive: true, + force: true + }); + + console.log(`Folder '${chalk.yellow(outputDir)}' deleted successfully`); + + const environmentId = getEnvironmentRequiredValue('ENVIRONMENT_ID'); + const apiKey = getEnvironmentRequiredValue('API_KEY'); + const moduleResolution = getEnvironmentRequiredValue('MODULE_RESOLUTION'); + + await generateItemsAsync({ + addTimestamp: false, + environmentId: environmentId, + apiKey: apiKey, + moduleResolution: moduleResolution?.toLowerCase() === 'node' ? 'node' : 'nodeNext', + outputDir: outputDir + }); +} catch (error) { + handleError(error); +} From 22de18e82616172edc38a3364fad9ebbc6608dd2 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 10 Sep 2024 13:56:19 +0200 Subject: [PATCH 078/183] Updates deps, upgrades to beta version of delivery-sdk & removes element resolvers --- lib/core/core.models.ts | 4 +- lib/core/core.utils.ts | 26 +-- lib/core/resolvers.ts | 21 +-- .../delivery-content-type.generator.ts | 9 +- lib/generators/delivery/delivery-func.ts | 2 - lib/generators/migration/migration-func.ts | 2 +- package-lock.json | 166 ++++++++++-------- package.json | 16 +- sample/delivery/content-types/actor.ts | 4 +- sample/delivery/content-types/movie.ts | 4 +- sample/delivery/taxonomies/movietype.ts | 2 +- sample/delivery/taxonomies/releasecategory.ts | 2 +- 12 files changed, 124 insertions(+), 134 deletions(-) diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index e22601b..e69d033 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -1,4 +1,3 @@ -import { PropertyNameResolver } from '@kontent-ai/delivery-sdk'; import { ContentTypeElements, ContentTypeModels, @@ -11,8 +10,7 @@ import { export type CliAction = 'delivery-sdk' | 'migration-toolkit' | 'environment' | 'items'; export type LibraryType = '@kontent-ai/migration-toolkit' | '@kontent-ai/delivery-sdk'; export type ModuleResolution = 'nodeNext' | 'node'; -export type CaseType = 'camelCase' | 'pascalCase' | 'snakeCase'; -export type GeneratorElementResolver = CaseType | PropertyNameResolver; +export type CaseType = 'camelCase' | 'pascalCase'; export type GeneratorManagementClient = Readonly>; export type LiteralUnion = T | (string & NonNullable); diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index bb37b0b..a86c92b 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -1,4 +1,3 @@ -import { camelCasePropertyNameResolver, pascalCasePropertyNameResolver, snakeCasePropertyNameResolver } from '@kontent-ai/delivery-sdk'; import { createHash } from 'crypto'; import { CliAction, LibraryType, ModuleResolution } from './core.models.js'; @@ -36,20 +35,25 @@ export function sortAlphabetically(arrayToSort: readonly T[], propertySelecto } export function toPascalCase(text: string): string { - // use element resolver from SDK to keep it consistent - return toSafeStringCode(pascalCasePropertyNameResolver('', text)); + return toSafeStringCode( + `${text}` + .toLowerCase() + .replace(new RegExp(/[-_]+/, 'g'), ' ') + .replace(new RegExp(/[^\w\s]/, 'g'), '') + .replace(new RegExp(/\s+(.)(\w*)/, 'g'), ($1, $2, $3) => `${($2 as string).toUpperCase() + $3}`) + .replace(new RegExp(/\w/), (s) => s.toUpperCase()) + ); } export function toCamelCase(text: string): string { - // use element resolver from SDK to keep it consistent - return toSafeStringCode(camelCasePropertyNameResolver('', text)); + return toSafeStringCode( + text + .replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => { + return index === 0 ? word.toLowerCase() : word.toUpperCase(); + }) + .replace(/\s+/g, '') + ); } - -export function toSnakeCase(text: string): string { - // use element resolver from SDK to keep it consistent - return toSafeStringCode(snakeCasePropertyNameResolver('', text)); -} - export function toGuidelinesComment(guidelines: string): string { return removeLineEndings(guidelines); } diff --git a/lib/core/resolvers.ts b/lib/core/resolvers.ts index 86518a7..467af59 100644 --- a/lib/core/resolvers.ts +++ b/lib/core/resolvers.ts @@ -1,7 +1,7 @@ import { ContentTypeElements, ContentTypeModels, ContentTypeSnippetModels, TaxonomyModels } from '@kontent-ai/management-sdk'; import { match, P } from 'ts-pattern'; -import { CaseType, GeneratorElementResolver, ObjectWithCodename, ObjectWithName } from './core.models.js'; -import { toCamelCase, toPascalCase, toSnakeCase } from './core.utils.js'; +import { CaseType, ObjectWithCodename, ObjectWithName } from './core.models.js'; +import { toCamelCase, toPascalCase } from './core.utils.js'; /** File name resolvers */ export type FilenameResolver> = undefined | CaseType | ((item: T & ObjectWithCodename) => string); @@ -43,22 +43,6 @@ export function mapName(resolver: NameResolver, def }; } -export function mapElementName(resolver: GeneratorElementResolver | undefined, defaultCase: CaseType): ElementNameResolver { - return (element) => { - const codename = element.codename; - - if (!codename) { - return undefined; - } - - return match(resolver) - .returnType() - .with(P.instanceOf(Function), (resolver) => resolver('', codename)) - .with(undefined, () => resolveCase(codename, defaultCase)) - .otherwise((resolverType) => resolveCase(codename, resolverType)); - }; -} - function addExtensionToFilename(filename: string, addExtension: boolean): string { return `${filename}${addExtension ? '.ts' : ''}`; } @@ -68,6 +52,5 @@ function resolveCase(text: string, resolverType: CaseType): string { .returnType() .with('camelCase', () => toCamelCase(text)) .with('pascalCase', () => toPascalCase(text)) - .with('snakeCase', () => toSnakeCase(text)) .exhaustive(); } diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 874b5c8..a34943e 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -10,9 +10,7 @@ import { ContentTypeSnippetNameResolver, FlattenedElement, GeneratedFile, - GeneratorElementResolver, getFlattenedElements, - mapElementName, mapFilename, mapName, ModuleResolution, @@ -50,7 +48,6 @@ export interface DeliveryContentTypeGeneratorConfig { readonly contentType?: ContentTypeNameResolver; readonly snippet?: ContentTypeSnippetNameResolver; readonly taxonomy?: TaxonomyNameResolver; - readonly element?: GeneratorElementResolver; }; } @@ -66,7 +63,6 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato const nameResolvers = { snippet: mapName(config.nameResolvers?.snippet, 'pascalCase'), contentType: mapName(config.nameResolvers?.contentType, 'pascalCase'), - element: mapElementName(config.nameResolvers?.element, 'camelCase'), taxonomy: mapName(config.nameResolvers?.taxonomy, 'pascalCase') }; @@ -227,9 +223,8 @@ export type ${contentTypeImports.typeName} = ${deliveryConfig.sdkTypes.contentIt .filter((m) => !m.fromSnippet) .reduce((code, element) => { const mappedType = mapElementType(element); - const elementName = nameResolvers.element(element.originalElement); - if (!mappedType || !elementName) { + if (!mappedType) { return code; } @@ -241,7 +236,7 @@ export type ${contentTypeImports.typeName} = ${deliveryConfig.sdkTypes.contentIt * Codename: ${element.codename} * Id: ${element.id}${element.guidelines ? `\n* Guidelines: ${toGuidelinesComment(element.guidelines)}` : ''} `)} - ${elementName}: ${deliveryConfig.sdkTypes.elements}.${mappedType};`); + ${element.codename}: ${deliveryConfig.sdkTypes.elements}.${mappedType};`); }, '') ); }; diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index 6a09dfb..f6dbb31 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -9,7 +9,6 @@ import { ContentTypeSnippetFileNameResolver, ContentTypeSnippetNameResolver, GeneratedFile, - GeneratorElementResolver, getDefaultModuleResolution, getFilenameFromPath, ModuleResolution, @@ -41,7 +40,6 @@ export interface GenerateDeliveryModelsConfig { readonly contentType?: ContentTypeNameResolver; readonly snippet?: ContentTypeSnippetNameResolver; readonly taxonomy?: TaxonomyNameResolver; - readonly element?: GeneratorElementResolver; }; } diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index 3b54d10..00928f9 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -85,7 +85,7 @@ async function getFilesAsync(config: GenerateMigrationModelsConfig): Promise<{ return { moduleResolution, migrationTypeFiles: migrationGenerator.getMigrationTypeFiles(), - migrationItemFiles: migrationGenerator.getMigrationTypeFiles(), + migrationItemFiles: migrationGenerator.getMigrationItemFiles(), environmentFiles: migrationGenerator.getEnvironmentFiles(), environmentInfo }; diff --git a/package-lock.json b/package-lock.json index 97138d5..cf7508f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,9 +9,9 @@ "version": "7.3.0", "license": "MIT", "dependencies": { - "@kontent-ai/delivery-sdk": "14.11.0", + "@kontent-ai/delivery-sdk": "15.0.0-0", "@kontent-ai/management-sdk": "7.2.0", - "@kontent-ai/migration-toolkit": "1.5.0", + "@kontent-ai/migration-toolkit": "1.5.1", "chalk": "5.3.0", "prettier": "3.3.3", "ts-pattern": "5.3.1", @@ -22,16 +22,16 @@ }, "devDependencies": { "@types/eslint__js": "8.42.3", - "@types/node": "22.5.3", + "@types/node": "22.5.4", "@types/yargs": "17.0.33", - "@typescript-eslint/eslint-plugin": "8.4.0", - "@typescript-eslint/parser": "8.4.0", + "@typescript-eslint/eslint-plugin": "8.5.0", + "@typescript-eslint/parser": "8.5.0", "dotenv-cli": "7.4.2", - "eslint": "9.9.1", + "eslint": "9.10.0", "standard-version": "9.5.0", "tsx": "4.19.0", - "typescript": "5.5.4", - "typescript-eslint": "8.4.0" + "typescript": "5.6.2", + "typescript-eslint": "8.5.0" }, "engines": { "node": ">= 20" @@ -635,9 +635,9 @@ } }, "node_modules/@eslint/js": { - "version": "9.9.1", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.9.1.tgz", - "integrity": "sha512-xIDQRsfg5hNBqHz04H1R3scSVwmI+KUbqjsQKHKQ1DAUSaUjYPReZZmS/5PNiKu1fUvzDd6H7DEDKACSEhu+TQ==", + "version": "9.10.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.10.0.tgz", + "integrity": "sha512-fuXtbiP5GWIn8Fz+LWoOMVf/Jxm+aajZYkhi6CuEm4SxymFM+eUWzbO9qXT+L0iCkL5+KGYMCSGxo686H19S1g==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -652,6 +652,18 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@eslint/plugin-kit": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.1.0.tgz", + "integrity": "sha512-autAXT203ixhqei9xt+qkYOvY8l6LAFIdT2UXc/RPNeUVfqRF1BV94GTJyVPFKT8nFM6MyVJhjLj9E8JWvf5zQ==", + "dev": true, + "dependencies": { + "levn": "^0.4.1" + }, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, "node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", @@ -710,16 +722,16 @@ } }, "node_modules/@kontent-ai/delivery-sdk": { - "version": "14.11.0", - "resolved": "https://registry.npmjs.org/@kontent-ai/delivery-sdk/-/delivery-sdk-14.11.0.tgz", - "integrity": "sha512-Te54qob53ls1Rr/cu8+5zRydHU++JX5Nj9U+RJ2ck9aVqpHvrqpNkuKDc2MoFyzC9tRvfF0w4LdBnWuLtFPrZg==", + "version": "15.0.0-0", + "resolved": "https://registry.npmjs.org/@kontent-ai/delivery-sdk/-/delivery-sdk-15.0.0-0.tgz", + "integrity": "sha512-kZN6i/m9ty+FHPYsvMqf1qbT2ZBcO9it+5NomIylBeDDI/LedleAR3wc5MZ/kWny7LPzwQFOd4qitnMPnNAnOw==", "dependencies": { "@kontent-ai/core-sdk": "10.7.0", "url-parse": "1.5.10", "uuid": "10.0.0" }, "engines": { - "node": ">= 18" + "node": ">= 20" } }, "node_modules/@kontent-ai/management-sdk": { @@ -735,9 +747,9 @@ } }, "node_modules/@kontent-ai/migration-toolkit": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@kontent-ai/migration-toolkit/-/migration-toolkit-1.5.0.tgz", - "integrity": "sha512-PBvzI4Uos38C5AckfKXn0xWtKhHHRMxBtQ6I/7DkhTf4JTinfqIgKECCP7ZK8ksQWNvr6A5mod37ri7RN1tLAA==", + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/@kontent-ai/migration-toolkit/-/migration-toolkit-1.5.1.tgz", + "integrity": "sha512-gj7twSzCIiA8L4UF5CUBg/hHHcG8USnTOR+iJnFyd+YksK9fXqZLXpB9Js1UE6wCdBmBtEC9DzjCSEv2XLdFCg==", "dependencies": { "@kontent-ai-consulting/tools-analytics": "0.0.7", "@kontent-ai/management-sdk": "7.2.0", @@ -849,9 +861,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.5.3", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.3.tgz", - "integrity": "sha512-njripolh85IA9SQGTAqbmnNZTdxv7X/4OYGPz8tgy5JDr8MP+uDBa921GpYEoDDnwm0Hmn5ZPeJgiiSTPoOzkQ==", + "version": "22.5.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.4.tgz", + "integrity": "sha512-FDuKUJQm/ju9fT/SeX/6+gBzoPzlVCzfzmGkwKvRHQVxi4BntVbyIwf6a4Xn62mrvndLiml6z/UBXIdEVjQLXg==", "dev": true, "dependencies": { "undici-types": "~6.19.2" @@ -879,16 +891,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.4.0.tgz", - "integrity": "sha512-rg8LGdv7ri3oAlenMACk9e+AR4wUV0yrrG+XKsGKOK0EVgeEDqurkXMPILG2836fW4ibokTB5v4b6Z9+GYQDEw==", + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.5.0.tgz", + "integrity": "sha512-lHS5hvz33iUFQKuPFGheAB84LwcJ60G8vKnEhnfcK1l8kGVLro2SFYW6K0/tj8FUhRJ0VHyg1oAfg50QGbPPHw==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "8.4.0", - "@typescript-eslint/type-utils": "8.4.0", - "@typescript-eslint/utils": "8.4.0", - "@typescript-eslint/visitor-keys": "8.4.0", + "@typescript-eslint/scope-manager": "8.5.0", + "@typescript-eslint/type-utils": "8.5.0", + "@typescript-eslint/utils": "8.5.0", + "@typescript-eslint/visitor-keys": "8.5.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", @@ -912,15 +924,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.4.0.tgz", - "integrity": "sha512-NHgWmKSgJk5K9N16GIhQ4jSobBoJwrmURaLErad0qlLjrpP5bECYg+wxVTGlGZmJbU03jj/dfnb6V9bw+5icsA==", + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.5.0.tgz", + "integrity": "sha512-gF77eNv0Xz2UJg/NbpWJ0kqAm35UMsvZf1GHj8D9MRFTj/V3tAciIWXfmPLsAAF/vUlpWPvUDyH1jjsr0cMVWw==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "8.4.0", - "@typescript-eslint/types": "8.4.0", - "@typescript-eslint/typescript-estree": "8.4.0", - "@typescript-eslint/visitor-keys": "8.4.0", + "@typescript-eslint/scope-manager": "8.5.0", + "@typescript-eslint/types": "8.5.0", + "@typescript-eslint/typescript-estree": "8.5.0", + "@typescript-eslint/visitor-keys": "8.5.0", "debug": "^4.3.4" }, "engines": { @@ -940,13 +952,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.4.0.tgz", - "integrity": "sha512-n2jFxLeY0JmKfUqy3P70rs6vdoPjHK8P/w+zJcV3fk0b0BwRXC/zxRTEnAsgYT7MwdQDt/ZEbtdzdVC+hcpF0A==", + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.5.0.tgz", + "integrity": "sha512-06JOQ9Qgj33yvBEx6tpC8ecP9o860rsR22hWMEd12WcTRrfaFgHr2RB/CA/B+7BMhHkXT4chg2MyboGdFGawYg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.4.0", - "@typescript-eslint/visitor-keys": "8.4.0" + "@typescript-eslint/types": "8.5.0", + "@typescript-eslint/visitor-keys": "8.5.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -957,13 +969,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.4.0.tgz", - "integrity": "sha512-pu2PAmNrl9KX6TtirVOrbLPLwDmASpZhK/XU7WvoKoCUkdtq9zF7qQ7gna0GBZFN0hci0vHaSusiL2WpsQk37A==", + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.5.0.tgz", + "integrity": "sha512-N1K8Ix+lUM+cIDhL2uekVn/ZD7TZW+9/rwz8DclQpcQ9rk4sIL5CAlBC0CugWKREmDjBzI/kQqU4wkg46jWLYA==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "8.4.0", - "@typescript-eslint/utils": "8.4.0", + "@typescript-eslint/typescript-estree": "8.5.0", + "@typescript-eslint/utils": "8.5.0", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -981,9 +993,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "8.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.4.0.tgz", - "integrity": "sha512-T1RB3KQdskh9t3v/qv7niK6P8yvn7ja1mS7QK7XfRVL6wtZ8/mFs/FHf4fKvTA0rKnqnYxl/uHFNbnEt0phgbw==", + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.5.0.tgz", + "integrity": "sha512-qjkormnQS5wF9pjSi6q60bKUHH44j2APxfh9TQRXK8wbYVeDYYdYJGIROL87LGZZ2gz3Rbmjc736qyL8deVtdw==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -994,13 +1006,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.4.0.tgz", - "integrity": "sha512-kJ2OIP4dQw5gdI4uXsaxUZHRwWAGpREJ9Zq6D5L0BweyOrWsL6Sz0YcAZGWhvKnH7fm1J5YFE1JrQL0c9dd53A==", + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.5.0.tgz", + "integrity": "sha512-vEG2Sf9P8BPQ+d0pxdfndw3xIXaoSjliG0/Ejk7UggByZPKXmJmw3GW5jV2gHNQNawBUyfahoSiCFVov0Ruf7Q==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.4.0", - "@typescript-eslint/visitor-keys": "8.4.0", + "@typescript-eslint/types": "8.5.0", + "@typescript-eslint/visitor-keys": "8.5.0", "debug": "^4.3.4", "fast-glob": "^3.3.2", "is-glob": "^4.0.3", @@ -1022,15 +1034,15 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "8.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.4.0.tgz", - "integrity": "sha512-swULW8n1IKLjRAgciCkTCafyTHHfwVQFt8DovmaF69sKbOxTSFMmIZaSHjqO9i/RV0wIblaawhzvtva8Nmm7lQ==", + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.5.0.tgz", + "integrity": "sha512-6yyGYVL0e+VzGYp60wvkBHiqDWOpT63pdMV2CVG4LVDd5uR6q1qQN/7LafBZtAtNIn/mqXjsSeS5ggv/P0iECw==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "8.4.0", - "@typescript-eslint/types": "8.4.0", - "@typescript-eslint/typescript-estree": "8.4.0" + "@typescript-eslint/scope-manager": "8.5.0", + "@typescript-eslint/types": "8.5.0", + "@typescript-eslint/typescript-estree": "8.5.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1044,12 +1056,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.4.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.4.0.tgz", - "integrity": "sha512-zTQD6WLNTre1hj5wp09nBIDiOc2U5r/qmzo7wxPn4ZgAjHql09EofqhF9WF+fZHzL5aCyaIpPcT2hyxl73kr9A==", + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.5.0.tgz", + "integrity": "sha512-yTPqMnbAZJNy2Xq2XU8AdtOW9tJIr+UQb64aXB9f3B1498Zx9JorVgFJcZpEc9UBuCCrdzKID2RGAMkYcDtZOw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.4.0", + "@typescript-eslint/types": "8.5.0", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -2127,16 +2139,17 @@ } }, "node_modules/eslint": { - "version": "9.9.1", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.9.1.tgz", - "integrity": "sha512-dHvhrbfr4xFQ9/dq+jcVneZMyRYLjggWjk6RVsIiHsP8Rz6yZ8LvZ//iU4TrZF+SXWG+JkNF2OyiZRvzgRDqMg==", + "version": "9.10.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.10.0.tgz", + "integrity": "sha512-Y4D0IgtBZfOcOUAIQTSXBKoNGfY0REGqHJG6+Q81vNippW5YlKjHFj4soMxamKK1NXHUWuBZTLdU3Km+L/pcHw==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.11.0", "@eslint/config-array": "^0.18.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.9.1", + "@eslint/js": "9.10.0", + "@eslint/plugin-kit": "^0.1.0", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.3.0", "@nodelib/fs.walk": "^1.2.8", @@ -2159,7 +2172,6 @@ "is-glob": "^4.0.0", "is-path-inside": "^3.0.3", "json-stable-stringify-without-jsonify": "^1.0.1", - "levn": "^0.4.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", @@ -5143,9 +5155,9 @@ "dev": true }, "node_modules/typescript": { - "version": "5.5.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.4.tgz", - "integrity": "sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==", + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz", + "integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -5156,14 +5168,14 @@ } }, "node_modules/typescript-eslint": { - "version": "8.4.0", - "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.4.0.tgz", - "integrity": "sha512-67qoc3zQZe3CAkO0ua17+7aCLI0dU+sSQd1eKPGq06QE4rfQjstVXR6woHO5qQvGUa550NfGckT4tzh3b3c8Pw==", + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.5.0.tgz", + "integrity": "sha512-uD+XxEoSIvqtm4KE97etm32Tn5MfaZWgWfMMREStLxR6JzvHkc2Tkj7zhTEK5XmtpTmKHNnG8Sot6qDfhHtR1Q==", "dev": true, "dependencies": { - "@typescript-eslint/eslint-plugin": "8.4.0", - "@typescript-eslint/parser": "8.4.0", - "@typescript-eslint/utils": "8.4.0" + "@typescript-eslint/eslint-plugin": "8.5.0", + "@typescript-eslint/parser": "8.5.0", + "@typescript-eslint/utils": "8.5.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" diff --git a/package.json b/package.json index 4a41e18..c091e4b 100644 --- a/package.json +++ b/package.json @@ -54,21 +54,21 @@ "yargs": "17.7.2", "prettier": "3.3.3", "chalk": "5.3.0", - "@kontent-ai/delivery-sdk": "14.11.0", + "@kontent-ai/delivery-sdk": "15.0.0-0", "@kontent-ai/management-sdk": "7.2.0", - "@kontent-ai/migration-toolkit": "1.5.0", + "@kontent-ai/migration-toolkit": "1.5.1", "ts-pattern": "5.3.1" }, "devDependencies": { "@types/yargs": "17.0.33", "standard-version": "9.5.0", - "typescript": "5.5.4", - "@types/node": "22.5.3", + "typescript": "5.6.2", + "@types/node": "22.5.4", "@types/eslint__js": "8.42.3", - "@typescript-eslint/eslint-plugin": "8.4.0", - "typescript-eslint": "8.4.0", - "@typescript-eslint/parser": "8.4.0", - "eslint": "9.9.1", + "@typescript-eslint/eslint-plugin": "8.5.0", + "typescript-eslint": "8.5.0", + "@typescript-eslint/parser": "8.5.0", + "eslint": "9.10.0", "tsx": "4.19.0", "dotenv-cli": "7.4.2" } diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index fd9e893..4351a00 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -38,7 +38,7 @@ export type Actor = IContentItem<{ * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d * Guidelines: This is the first name of the actor */ - firstName: Elements.TextElement; + first_name: Elements.TextElement; /** * Last name (text) * @@ -46,7 +46,7 @@ export type Actor = IContentItem<{ * Codename: last_name * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 */ - lastName: Elements.TextElement; + last_name: Elements.TextElement; /** * Photo (asset) * diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 4e28083..5028071 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -15,7 +15,7 @@ import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; import type { Actor } from '../content-types/actor.js'; -import type { ReleaseCategory } from '../taxonomies/releasecategory.js'; +import type { Releasecategory } from '../taxonomies/releasecategory.js'; /** * Movie @@ -95,5 +95,5 @@ export type Movie = IContentItem<{ * Codename: releasecategory * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 */ - releasecategory: Elements.TaxonomyElement; + releasecategory: Elements.TaxonomyElement; }>; diff --git a/sample/delivery/taxonomies/movietype.ts b/sample/delivery/taxonomies/movietype.ts index b2c4c20..0c9090e 100644 --- a/sample/delivery/taxonomies/movietype.ts +++ b/sample/delivery/taxonomies/movietype.ts @@ -19,4 +19,4 @@ * Codename: movietype * Id: 365a17e6-1929-27ab-9f67-a9273c846717 */ -export type MovieType = 'student' | 'tv' | 'blockbuster' | 'cinema_only' | 'film'; +export type Movietype = 'student' | 'tv' | 'blockbuster' | 'cinema_only' | 'film'; diff --git a/sample/delivery/taxonomies/releasecategory.ts b/sample/delivery/taxonomies/releasecategory.ts index 871975c..d710eec 100644 --- a/sample/delivery/taxonomies/releasecategory.ts +++ b/sample/delivery/taxonomies/releasecategory.ts @@ -19,4 +19,4 @@ * Codename: releasecategory * Id: 09b6a348-0f86-7a68-4af3-7cab9a5c60b7 */ -export type ReleaseCategory = 'global_release' | 'us_only' | 'local_release'; +export type Releasecategory = 'global_release' | 'us_only' | 'local_release'; From 824e167cf6aba3c9efaeff2dbdc641d6aaa41b50 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 10 Sep 2024 13:57:24 +0200 Subject: [PATCH 079/183] Updades migration comments --- lib/generators/migration/migration.generator.ts | 4 ++-- sample/migration/migration.ts | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index 0aeee98..8645c41 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -121,10 +121,10 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { importValue: `${migrationConfig.localTypeNames.collectionCodenames}, ${migrationConfig.localTypeNames.contentTypeCodenames}, ${migrationConfig.localTypeNames.languageCodenames}, ${migrationConfig.localTypeNames.workflowCodenames}, ${migrationConfig.localTypeNames.workflowStepCodenames}` })} - ${wrapComment('System object shared by all individual content type models')} + ${wrapComment('\n * System object shared by all individual content type models\n')} ${getSystemType()} - ${wrapComment('Item object shared by all individual content type models')} + ${wrapComment('\n * Item object shared by all individual content type models\n')} ${getItemType()} ` } diff --git a/sample/migration/migration.ts b/sample/migration/migration.ts index 2551401..9d3f02b 100644 --- a/sample/migration/migration.ts +++ b/sample/migration/migration.ts @@ -22,7 +22,9 @@ import type { WorkflowStepCodenames } from './environment/environment.js'; -/**System object shared by all individual content type models*/ +/** + * System object shared by all individual content type models + */ export type ItemSystem = MigrationItemSystem< TCodename, LanguageCodenames, @@ -30,7 +32,9 @@ export type ItemSystem = MigrationItemSy WorkflowCodenames >; -/**Item object shared by all individual content type models*/ +/** + * Item object shared by all individual content type models + */ export type Item = MigrationItem< TElements, ItemSystem, From 90d6c33bac7e4fc3b8468ea30fbd5dae7d24e797 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 10 Sep 2024 14:01:30 +0200 Subject: [PATCH 080/183] Unifies model func --- .../delivery-content-type.generator.ts | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index a34943e..0e9c2d5 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -71,8 +71,8 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato snippetFiles: readonly GeneratedFile[]; } => { return { - contentTypeFiles: config.environmentData.types.map((type) => createContentTypeModel(type)), - snippetFiles: config.environmentData.snippets.map((contentTypeSnippet) => createContentTypeSnippetModel(contentTypeSnippet)) + contentTypeFiles: config.environmentData.types.map((type) => createTypeModel(type)), + snippetFiles: config.environmentData.snippets.map((contentTypeSnippet) => createTypeModel(contentTypeSnippet)) }; }; @@ -93,8 +93,8 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato elements // only take elements that are not from snippets .filter((m) => !m.fromSnippet) - .map((flattenedElement) => - match(flattenedElement) + .map((flattenedElement) => { + return match(flattenedElement) .returnType() .with({ type: 'taxonomy' }, (taxonomyElement) => { if (!taxonomyElement.assignedTaxonomy) { @@ -126,8 +126,8 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato }); }); }) - .otherwise(() => []) - ) + .otherwise(() => []); + }) .flatMap((m) => m) .filter(isNotUndefined) .filter(uniqueFilter) @@ -202,20 +202,15 @@ export type ${contentTypeImports.typeName} = ${deliveryConfig.sdkTypes.contentIt `; }; - const createContentTypeModel = (type: Readonly): GeneratedFile => { + const createTypeModel = ( + type: Readonly + ): GeneratedFile => { return { filename: `${deliveryConfig.contentTypesFolderName}/${fileResolvers.contentType(type, true)}`, text: getModelCode(type) }; }; - const createContentTypeSnippetModel = (snippet: Readonly): GeneratedFile => { - return { - filename: `${deliveryConfig.contentTypeSnippetsFolderName}/${fileResolvers.snippet(snippet, true)}`, - text: getModelCode(snippet) - }; - }; - const getElementsCode = (flattenedElements: readonly FlattenedElement[]): string => { return ( flattenedElements From cbc578eb3e54e932e006f0e78b4eb7848bd294a7 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 11 Sep 2024 11:32:47 +0200 Subject: [PATCH 081/183] Extends IContentItem with type string literal, fixes subpages element and snippet imports (fixes https://github.com/kontent-ai/model-generator-js/issues/49) --- lib/config.ts | 1 + lib/core/core.utils.ts | 54 +++--- .../delivery-content-type.generator.ts | 166 ++++++++++++------ sample/delivery/content-types/actor.ts | 73 ++++---- sample/delivery/content-types/movie.ts | 153 ++++++++-------- sample/environment/roles.ts | 77 ++++---- 6 files changed, 301 insertions(+), 223 deletions(-) diff --git a/lib/config.ts b/lib/config.ts index e3499ee..80c4490 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -37,6 +37,7 @@ export const deliveryConfig = { sdkTypes: { contentItem: 'IContentItem', + contentItemElements: 'IContentItemElements', elements: 'Elements' } } as const; diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index a86c92b..70caceb 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -35,23 +35,27 @@ export function sortAlphabetically(arrayToSort: readonly T[], propertySelecto } export function toPascalCase(text: string): string { - return toSafeStringCode( - `${text}` - .toLowerCase() - .replace(new RegExp(/[-_]+/, 'g'), ' ') - .replace(new RegExp(/[^\w\s]/, 'g'), '') - .replace(new RegExp(/\s+(.)(\w*)/, 'g'), ($1, $2, $3) => `${($2 as string).toUpperCase() + $3}`) - .replace(new RegExp(/\w/), (s) => s.toUpperCase()) + return prefixWithUnderscoreWhenStartsWithNonAlpha( + toSafeStringCode( + `${text}` + .toLowerCase() + .replace(new RegExp(/[-_]+/, 'g'), ' ') + .replace(new RegExp(/[^\w\s]/, 'g'), '') + .replace(new RegExp(/\s+(.)(\w*)/, 'g'), ($1, $2, $3) => `${($2 as string).toUpperCase() + $3}`) + .replace(new RegExp(/\w/), (s) => s.toUpperCase()) + ) ); } export function toCamelCase(text: string): string { - return toSafeStringCode( - text - .replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => { - return index === 0 ? word.toLowerCase() : word.toUpperCase(); - }) - .replace(/\s+/g, '') + return prefixWithUnderscoreWhenStartsWithNonAlpha( + toSafeStringCode( + text + .replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => { + return index === 0 ? word.toLowerCase() : word.toUpperCase(); + }) + .replace(/\s+/g, '') + ) ); } export function toGuidelinesComment(guidelines: string): string { @@ -63,24 +67,19 @@ export function getStringOrUndefined(text?: string): string { } export function toSafePropertyName(value: string): string { - const replaceContent = ''; - const withoutNumbers = value.replace(/^\d+/, replaceContent); - const propertyName = withoutNumbers - .replace(/[\s-]/g, replaceContent) - .replace(/[^a-zA-Z0-9_]/g, replaceContent) - .toLowerCase(); + const propertyName = toSafeStringCode(value); if (propertyName.length === 0) { // to prevent empty string being used as property name, use hash return getPropertyStringHash(value); } - return propertyName; + return prefixWithUnderscoreWhenStartsWithNonAlpha(value); } export function toSafePropertyValue(value: string): string { - const replaceContent = ''; - return value.replace(/'/g, replaceContent); + const replaceWith = ''; + return value.replace(/'/g, replaceWith); } export function toOutputDirPath(outputDir?: string): string { @@ -92,8 +91,15 @@ function removeLineEndings(value: string): string { } function toSafeStringCode(text: string): string { - const replaceContent = ''; - return text.replace(/[\s-]/g, replaceContent).replace(/[^a-zA-Z0-9_]/g, replaceContent); + const replaceWith = ''; + return text.replace(/[\s-]/g, replaceWith).replace(/[^a-zA-Z0-9_]/g, replaceWith); +} + +export function prefixWithUnderscoreWhenStartsWithNonAlpha(text: string): string { + if (/^[^a-zA-Z]/.test(text)) { + return `_${text}`; + } + return text; } function getPropertyStringHash(text: string): string { diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 0e9c2d5..c688fc6 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -28,6 +28,8 @@ interface ExtractImportsResult { readonly contentTypeExtends: string | undefined; } +type ContentTypeOrSnippet = Readonly; + export interface DeliveryContentTypeGeneratorConfig { readonly moduleResolution: ModuleResolution; @@ -72,7 +74,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato } => { return { contentTypeFiles: config.environmentData.types.map((type) => createTypeModel(type)), - snippetFiles: config.environmentData.snippets.map((contentTypeSnippet) => createTypeModel(contentTypeSnippet)) + snippetFiles: config.environmentData.snippets.map((contentTypeSnippet) => createSnippetModel(contentTypeSnippet)) }; }; @@ -85,10 +87,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato }); }; - const getElementImports = ( - typeOrSnippet: Readonly | Readonly, - elements: readonly FlattenedElement[] - ): readonly string[] => { + const getElementImports = (typeOrSnippet: ContentTypeOrSnippet, elements: readonly FlattenedElement[]): readonly string[] => { return ( elements // only take elements that are not from snippets @@ -119,7 +118,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato return importer.importType({ filePathOrPackage: - typeOrSnippet instanceof ContentTypeModels.ContentType + typeOrSnippet instanceof ContentTypeSnippetModels.ContentTypeSnippet ? `../${deliveryConfig.contentTypesFolderName}/${referencedTypeFilename}.ts` : `./${referencedTypeFilename}.ts`, importValue: `${nameResolvers.contentType(allowedContentType)}` @@ -134,96 +133,154 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato ); }; - const getContentTypeImports = (data: { - readonly typeOrSnippet: Readonly | Readonly; + const getContentTypeModelImports = (data: { + readonly contentType: Readonly; + readonly flattenedElements: readonly FlattenedElement[]; + }): ExtractImportsResult => { + const snippets = data.flattenedElements.map((m) => m.fromSnippet).filter(isNotUndefined); + + return { + imports: sortAlphabetically( + [...getElementImports(data.contentType, data.flattenedElements), ...getSnippetImports(snippets)] + .filter(isNotUndefined) + .filter(uniqueFilter), + (importValue) => importValue + ), + contentTypeExtends: snippets.length + ? `& ${sortAlphabetically( + snippets.map((snippet) => nameResolvers.snippet(snippet)).filter(uniqueFilter), + (snippetName) => snippetName + ).join(' & ')}` + : undefined, + typeName: nameResolvers.contentType(data.contentType) + }; + }; + + const getSnippetModelImports = (data: { + readonly snippet: Readonly; readonly flattenedElements: readonly FlattenedElement[]; }): ExtractImportsResult => { const snippets = data.flattenedElements.map((m) => m.fromSnippet).filter(isNotUndefined); return { imports: sortAlphabetically( - [...getElementImports(data.typeOrSnippet, data.flattenedElements), ...getSnippetImports(snippets)] + [...getElementImports(data.snippet, data.flattenedElements), ...getSnippetImports(snippets)] .filter(isNotUndefined) .filter(uniqueFilter), (importValue) => importValue ), - contentTypeExtends: - data.typeOrSnippet instanceof ContentTypeModels.ContentType && snippets.length - ? `& ${sortAlphabetically( - snippets.map((snippet) => nameResolvers.snippet(snippet)).filter(uniqueFilter), - (snippetName) => snippetName - ).join(' & ')}` - : undefined, - typeName: - data.typeOrSnippet instanceof ContentTypeModels.ContentType - ? nameResolvers.contentType(data.typeOrSnippet) - : nameResolvers.snippet(data.typeOrSnippet) + contentTypeExtends: undefined, + typeName: nameResolvers.snippet(data.snippet) }; }; - const getDeliverySdkContentTypeImports = (flattenedElements: readonly FlattenedElement[]): readonly string[] => { - return sortAlphabetically( - [deliveryConfig.sdkTypes.contentItem, ...(flattenedElements.length ? [deliveryConfig.sdkTypes.elements] : [])], - (m) => m + const getDeliverySdkImports = ( + typeOrSnippet: ContentTypeOrSnippet, + flattenedElements: readonly FlattenedElement[] + ): readonly string[] => { + const mainType = + typeOrSnippet instanceof ContentTypeModels.ContentType + ? deliveryConfig.sdkTypes.contentItem + : deliveryConfig.sdkTypes.contentItemElements; + + return sortAlphabetically([mainType, ...(flattenedElements.length ? [deliveryConfig.sdkTypes.elements] : [])], (m) => m); + }; + + const getSnippetCode = (snippet: Readonly): string => { + const flattenedElements = getFlattenedElements( + snippet.elements, + config.environmentData.snippets, + config.environmentData.taxonomies, + config.environmentData.types ); + + const importsResult = getSnippetModelImports({ + snippet, + flattenedElements + }); + + return ` +${importer.importType({ + filePathOrPackage: deliveryConfig.npmPackageName, + importValue: `${getDeliverySdkImports(snippet, flattenedElements).join(', ')}` +})} +${importsResult.imports.join('\n')} + +${wrapComment(` +* ${snippet.name} +* +* Id: ${snippet.id} +* Codename: ${snippet.codename} +`)} +export interface ${importsResult.typeName} extends ${deliveryConfig.sdkTypes.contentItemElements} +${getElementsCode(flattenedElements)}; +`; }; - const getModelCode = ( - typeOrSnippet: Readonly | Readonly - ): string => { + const getContentTypeCode = (contentType: Readonly): string => { const flattenedElements = getFlattenedElements( - typeOrSnippet.elements, + contentType.elements, config.environmentData.snippets, config.environmentData.taxonomies, config.environmentData.types ); - const contentTypeImports = getContentTypeImports({ - typeOrSnippet, - flattenedElements: flattenedElements + const importsResult = getContentTypeModelImports({ + contentType, + flattenedElements }); return ` ${importer.importType({ filePathOrPackage: deliveryConfig.npmPackageName, - importValue: `${getDeliverySdkContentTypeImports(flattenedElements).join(', ')}` + importValue: `${getDeliverySdkImports(contentType, flattenedElements).join(', ')}` })} -${contentTypeImports.imports.join('\n')} +${importsResult.imports.join('\n')} ${wrapComment(` -* ${typeOrSnippet.name} +* ${contentType.name} * -* Id: ${typeOrSnippet.id} -* Codename: ${typeOrSnippet.codename} +* Id: ${contentType.id} +* Codename: ${contentType.codename} `)} -export type ${contentTypeImports.typeName} = ${deliveryConfig.sdkTypes.contentItem}<{ - ${getElementsCode(flattenedElements)} -}>${contentTypeImports.contentTypeExtends ? ` ${contentTypeImports.contentTypeExtends}` : ''}; +export type ${importsResult.typeName} = ${deliveryConfig.sdkTypes.contentItem}< +${getElementsCode(flattenedElements)}${importsResult.contentTypeExtends ? ` ${importsResult.contentTypeExtends}` : ''}, +'${contentType.codename}'>; `; }; - const createTypeModel = ( - type: Readonly - ): GeneratedFile => { + const createTypeModel = (type: Readonly): GeneratedFile => { return { filename: `${deliveryConfig.contentTypesFolderName}/${fileResolvers.contentType(type, true)}`, - text: getModelCode(type) + text: getContentTypeCode(type) + }; + }; + + const createSnippetModel = (type: Readonly): GeneratedFile => { + return { + filename: `${deliveryConfig.contentTypeSnippetsFolderName}/${fileResolvers.contentType(type, true)}`, + text: getSnippetCode(type) }; }; const getElementsCode = (flattenedElements: readonly FlattenedElement[]): string => { + const filteredElements = flattenedElements + // filter out elements that are from snippets + .filter((m) => !m.fromSnippet); + + if (filteredElements.length === 0) { + return `Record`; + } + return ( - flattenedElements - // filter out elements that are from snippets - .filter((m) => !m.fromSnippet) - .reduce((code, element) => { - const mappedType = mapElementType(element); + filteredElements.reduce((code, element) => { + const mappedType = mapElementType(element); - if (!mappedType) { - return code; - } + if (!mappedType) { + return code; + } - return (code += ` + return (code += ` ${wrapComment(` * ${element.title} (${element.type}) * @@ -232,7 +289,7 @@ export type ${contentTypeImports.typeName} = ${deliveryConfig.sdkTypes.contentIt * Id: ${element.id}${element.guidelines ? `\n* Guidelines: ${toGuidelinesComment(element.guidelines)}` : ''} `)} ${element.codename}: ${deliveryConfig.sdkTypes.elements}.${mappedType};`); - }, '') + }, '{') + '}' ); }; @@ -244,6 +301,9 @@ export type ${contentTypeImports.typeName} = ${deliveryConfig.sdkTypes.contentIt .with({ type: 'modular_content' }, (linkedItemsElement) => { return `LinkedItemsElement<${getLinkedItemsAllowedTypes(linkedItemsElement.allowedContentTypes ?? []).join(' | ')}>`; }) + .with({ type: 'subpages' }, (linkedItemsElement) => { + return `LinkedItemsElement<${getLinkedItemsAllowedTypes(linkedItemsElement.allowedContentTypes ?? []).join(' | ')}>`; + }) .with({ type: 'asset' }, () => 'AssetsElement') .with({ type: 'date_time' }, () => 'DateTimeElement') .with({ type: 'rich_text' }, () => 'RichTextElement') diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index 4351a00..3b0b057 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -21,38 +21,41 @@ import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; * Id: 58099989-319f-495f-aa36-cb3710854e36 * Codename: actor */ -export type Actor = IContentItem<{ - /** - * Url (url_slug) - * - * Required: false - * Codename: url - * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 - */ - url: Elements.UrlSlugElement; - /** - * First name (text) - * - * Required: true - * Codename: first_name - * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d - * Guidelines: This is the first name of the actor - */ - first_name: Elements.TextElement; - /** - * Last name (text) - * - * Required: true - * Codename: last_name - * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 - */ - last_name: Elements.TextElement; - /** - * Photo (asset) - * - * Required: false - * Codename: photo - * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 - */ - photo: Elements.AssetsElement; -}>; +export type Actor = IContentItem< + { + /** + * Url (url_slug) + * + * Required: false + * Codename: url + * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 + */ + url: Elements.UrlSlugElement; + /** + * First name (text) + * + * Required: true + * Codename: first_name + * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d + * Guidelines: This is the first name of the actor + */ + first_name: Elements.TextElement; + /** + * Last name (text) + * + * Required: true + * Codename: last_name + * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 + */ + last_name: Elements.TextElement; + /** + * Photo (asset) + * + * Required: false + * Codename: photo + * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 + */ + photo: Elements.AssetsElement; + }, + 'actor' +>; diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 5028071..96fa4e8 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -14,7 +14,7 @@ **/ import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; -import type { Actor } from '../content-types/actor.js'; +import type { Actor } from './actor.js'; import type { Releasecategory } from '../taxonomies/releasecategory.js'; /** @@ -23,77 +23,80 @@ import type { Releasecategory } from '../taxonomies/releasecategory.js'; * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c * Codename: movie */ -export type Movie = IContentItem<{ - /** - * Title (text) - * - * Required: true - * Codename: title - * Id: 3473187e-dc78-eff2-7099-f690f7042d4a - */ - title: Elements.TextElement; - /** - * Plot (rich_text) - * - * Required: false - * Codename: plot - * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce - */ - plot: Elements.RichTextElement; - /** - * Released (date_time) - * - * Required: false - * Codename: released - * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 - */ - released: Elements.DateTimeElement; - /** - * Length (number) - * - * Required: false - * Codename: length - * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c - */ - length: Elements.NumberElement; - /** - * Poster (asset) - * - * Required: false - * Codename: poster - * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d - */ - poster: Elements.AssetsElement; - /** - * Category (multiple_choice) - * - * Required: false - * Codename: category - * Id: 9821c252-6414-f549-c17f-cc171dd87713 - */ - category: Elements.MultipleChoiceElement; - /** - * Stars (modular_content) - * - * Required: false - * Codename: stars - * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 - */ - stars: Elements.LinkedItemsElement; - /** - * SeoName (url_slug) - * - * Required: false - * Codename: seoname - * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c - */ - seoname: Elements.UrlSlugElement; - /** - * ReleaseCategory (taxonomy) - * - * Required: false - * Codename: releasecategory - * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 - */ - releasecategory: Elements.TaxonomyElement; -}>; +export type Movie = IContentItem< + { + /** + * Title (text) + * + * Required: true + * Codename: title + * Id: 3473187e-dc78-eff2-7099-f690f7042d4a + */ + title: Elements.TextElement; + /** + * Plot (rich_text) + * + * Required: false + * Codename: plot + * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce + */ + plot: Elements.RichTextElement; + /** + * Released (date_time) + * + * Required: false + * Codename: released + * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 + */ + released: Elements.DateTimeElement; + /** + * Length (number) + * + * Required: false + * Codename: length + * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c + */ + length: Elements.NumberElement; + /** + * Poster (asset) + * + * Required: false + * Codename: poster + * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d + */ + poster: Elements.AssetsElement; + /** + * Category (multiple_choice) + * + * Required: false + * Codename: category + * Id: 9821c252-6414-f549-c17f-cc171dd87713 + */ + category: Elements.MultipleChoiceElement; + /** + * Stars (modular_content) + * + * Required: false + * Codename: stars + * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 + */ + stars: Elements.LinkedItemsElement; + /** + * SeoName (url_slug) + * + * Required: false + * Codename: seoname + * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c + */ + seoname: Elements.UrlSlugElement; + /** + * ReleaseCategory (taxonomy) + * + * Required: false + * Codename: releasecategory + * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 + */ + releasecategory: Elements.TaxonomyElement; + }, + 'movie' +>; diff --git a/sample/environment/roles.ts b/sample/environment/roles.ts index 471d989..b431989 100644 --- a/sample/environment/roles.ts +++ b/sample/environment/roles.ts @@ -14,39 +14,44 @@ **/ export const roles = { - /** - * Content contributor - */ - contentcontributor: { - codename: undefined, - id: 'dca0ac85-274f-429e-b00e-6f74bf917051', - name: 'Content contributor' - }, - - /** - * Reviewer - */ - reviewer: { - codename: undefined, - id: '94478afa-d898-45dd-8300-ba61b6e0eb4b', - name: 'Reviewer' - }, - - /** - * Project manager - */ - projectmanager: { - codename: 'project-manager', - id: 'af95ac37-4efa-4b92-aa26-db773cd172c6', - name: 'Project manager' - }, - - /** - * Developer - */ - developer: { - codename: undefined, - id: 'b3994090-0818-4969-816b-f4c5d3e526f3', - name: 'Developer' - } -} as const; + + + /** + * Content contributor + */ + Content contributor: { + codename: undefined, + id: 'dca0ac85-274f-429e-b00e-6f74bf917051', + name: 'Content contributor' + }, + + + /** + * Reviewer + */ + Reviewer: { + codename: undefined, + id: '94478afa-d898-45dd-8300-ba61b6e0eb4b', + name: 'Reviewer' + }, + + + /** + * Project manager + */ + project-manager: { + codename: 'project-manager', + id: 'af95ac37-4efa-4b92-aa26-db773cd172c6', + name: 'Project manager' + }, + + + /** + * Developer + */ + Developer: { + codename: undefined, + id: 'b3994090-0818-4969-816b-f4c5d3e526f3', + name: 'Developer' + } + } as const; \ No newline at end of file From 77007f2b6b9c8a7b8be36e6b4b3cf11509f743e2 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 11 Sep 2024 11:36:29 +0200 Subject: [PATCH 082/183] Fixes toSafePropertyName func --- lib/core/core.utils.ts | 4 +- sample/environment/roles.ts | 77 +++++++++++++++++-------------------- 2 files changed, 38 insertions(+), 43 deletions(-) diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 70caceb..f15ad92 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -67,14 +67,14 @@ export function getStringOrUndefined(text?: string): string { } export function toSafePropertyName(value: string): string { - const propertyName = toSafeStringCode(value); + const propertyName = toCamelCase(value); if (propertyName.length === 0) { // to prevent empty string being used as property name, use hash return getPropertyStringHash(value); } - return prefixWithUnderscoreWhenStartsWithNonAlpha(value); + return prefixWithUnderscoreWhenStartsWithNonAlpha(propertyName); } export function toSafePropertyValue(value: string): string { diff --git a/sample/environment/roles.ts b/sample/environment/roles.ts index b431989..5cf74a3 100644 --- a/sample/environment/roles.ts +++ b/sample/environment/roles.ts @@ -14,44 +14,39 @@ **/ export const roles = { - - - /** - * Content contributor - */ - Content contributor: { - codename: undefined, - id: 'dca0ac85-274f-429e-b00e-6f74bf917051', - name: 'Content contributor' - }, - - - /** - * Reviewer - */ - Reviewer: { - codename: undefined, - id: '94478afa-d898-45dd-8300-ba61b6e0eb4b', - name: 'Reviewer' - }, - - - /** - * Project manager - */ - project-manager: { - codename: 'project-manager', - id: 'af95ac37-4efa-4b92-aa26-db773cd172c6', - name: 'Project manager' - }, - - - /** - * Developer - */ - Developer: { - codename: undefined, - id: 'b3994090-0818-4969-816b-f4c5d3e526f3', - name: 'Developer' - } - } as const; \ No newline at end of file + /** + * Content contributor + */ + contentContributor: { + codename: undefined, + id: 'dca0ac85-274f-429e-b00e-6f74bf917051', + name: 'Content contributor' + }, + + /** + * Reviewer + */ + reviewer: { + codename: undefined, + id: '94478afa-d898-45dd-8300-ba61b6e0eb4b', + name: 'Reviewer' + }, + + /** + * Project manager + */ + projectManager: { + codename: 'project-manager', + id: 'af95ac37-4efa-4b92-aa26-db773cd172c6', + name: 'Project manager' + }, + + /** + * Developer + */ + developer: { + codename: undefined, + id: 'b3994090-0818-4969-816b-f4c5d3e526f3', + name: 'Developer' + } +} as const; From 36254885fd7fe7784b8064f560a06e843d59edc9 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 11 Sep 2024 13:15:06 +0200 Subject: [PATCH 083/183] Implements types support for delivery item system attributes, updates delivery models to use barrel import files --- lib/config.ts | 15 +- lib/fetch/kontent-fetcher.ts | 4 +- .../delivery-content-type.generator.ts | 226 +++++++++++++----- lib/generators/delivery/delivery-func.ts | 45 +++- .../migration/migration.generator.ts | 48 ++-- lib/generators/shared/generator.utils.ts | 27 +++ sample/delivery/content-types/actor.ts | 7 +- sample/delivery/content-types/movie.ts | 11 +- sample/delivery/index.ts | 1 + sample/delivery/system/delivery-types.ts | 39 +++ sample/delivery/system/index.ts | 16 ++ 11 files changed, 320 insertions(+), 119 deletions(-) create mode 100644 lib/generators/shared/generator.utils.ts create mode 100644 sample/delivery/system/delivery-types.ts create mode 100644 sample/delivery/system/index.ts diff --git a/lib/config.ts b/lib/config.ts index 80c4490..a572ada 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -2,6 +2,14 @@ export const coreConfig = { barrelExportFilename: 'index.ts' } as const; +export const sharedTypesConfig = { + languageCodenames: 'LanguageCodenames', + collectionCodenames: 'CollectionCodenames', + workflowCodenames: 'WorkflowCodenames', + workflowStepCodenames: 'WorkflowStepCodenames', + contentTypeCodenames: 'ContentTypeCodenames' +}; + export const migrationConfig = { npmPackageName: '@kontent-ai/migration-toolkit', migrationItemsFolderName: `content-types`, @@ -17,11 +25,6 @@ export const migrationConfig = { }, localTypeNames: { - languageCodenames: 'LanguageCodenames', - collectionCodenames: 'CollectionCodenames', - workflowCodenames: 'WorkflowCodenames', - workflowStepCodenames: 'WorkflowStepCodenames', - contentTypeCodenames: 'ContentTypeCodenames', system: 'ItemSystem', item: 'Item', codename: 'TCodename', @@ -34,6 +37,8 @@ export const deliveryConfig = { contentTypesFolderName: `content-types`, contentTypeSnippetsFolderName: `content-type-snippets`, taxonomiesFolderName: `taxonomies`, + systemTypesFolderName: 'system', + typesFilename: 'delivery-types', sdkTypes: { contentItem: 'IContentItem', diff --git a/lib/fetch/kontent-fetcher.ts b/lib/fetch/kontent-fetcher.ts index a92c8fc..4d93bea 100644 --- a/lib/fetch/kontent-fetcher.ts +++ b/lib/fetch/kontent-fetcher.ts @@ -37,8 +37,8 @@ export function kontentFetcher(config: KontentFetcherConfig) { return { async getEnvironmentInfoAsync(): Promise> { const projectInformation = (await client.environmentInformation().toPromise()).data; - console.log(`Project '${chalk.yellow(toSafeComment(projectInformation.project.name))}'`); - console.log(`Environment '${chalk.yellow(toSafeComment(projectInformation.project.environment))}'\n`); + console.log(`Project '${chalk.cyan(toSafeComment(projectInformation.project.name))}'`); + console.log(`Environment '${chalk.cyan(toSafeComment(projectInformation.project.environment))}'\n`); return projectInformation.project; }, async getItemsAsync(): Promise[]> { diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index c688fc6..7d31c3c 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -1,7 +1,15 @@ -import { ContentTypeModels, ContentTypeSnippetModels, EnvironmentModels, TaxonomyModels } from '@kontent-ai/management-sdk'; +import { + CollectionModels, + ContentTypeModels, + ContentTypeSnippetModels, + EnvironmentModels, + LanguageModels, + TaxonomyModels, + WorkflowModels +} from '@kontent-ai/management-sdk'; import { isNotUndefined } from '@kontent-ai/migration-toolkit'; import { match, P } from 'ts-pattern'; -import { deliveryConfig } from '../../config.js'; +import { deliveryConfig, sharedTypesConfig } from '../../config.js'; import { importer as _importer, ContentTypeFileNameResolver, @@ -21,6 +29,13 @@ import { uniqueFilter, wrapComment } from '../../core/index.js'; +import { + getCollectionCodenamesType, + getContentTypeCodenamesType, + getLanguageCodenamesType, + getWorkflowCodenamesType, + getWorkflowStepCodenamesType +} from '../shared/generator.utils.js'; interface ExtractImportsResult { readonly typeName: string; @@ -36,8 +51,11 @@ export interface DeliveryContentTypeGeneratorConfig { readonly environmentData: { readonly environment: Readonly; readonly types: readonly Readonly[]; - readonly taxonomies: readonly Readonly[]; readonly snippets: readonly Readonly[]; + readonly workflows: readonly Readonly[]; + readonly languages: readonly Readonly[]; + readonly collections: readonly Readonly[]; + readonly taxonomies: readonly Readonly[]; }; readonly fileResolvers?: { @@ -68,69 +86,109 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato taxonomy: mapName(config.nameResolvers?.taxonomy, 'pascalCase') }; - const generateModels = (): { - contentTypeFiles: readonly GeneratedFile[]; - snippetFiles: readonly GeneratedFile[]; - } => { - return { - contentTypeFiles: config.environmentData.types.map((type) => createTypeModel(type)), - snippetFiles: config.environmentData.snippets.map((contentTypeSnippet) => createSnippetModel(contentTypeSnippet)) - }; + const getSystemTypeImports = (): readonly string[] => { + return [ + importer.importType({ + filePathOrPackage: `../${deliveryConfig.systemTypesFolderName}/${deliveryConfig.typesFilename}.ts`, + importValue: [ + sharedTypesConfig.collectionCodenames, + sharedTypesConfig.languageCodenames, + sharedTypesConfig.workflowCodenames, + sharedTypesConfig.workflowStepCodenames + ] + .map((m) => m) + .join(', ') + }) + ]; }; const getSnippetImports = (snippets: readonly Readonly[]): readonly string[] => { - return snippets.map((snippet) => { - return importer.importType({ - filePathOrPackage: `../${deliveryConfig.contentTypeSnippetsFolderName}/${fileResolvers.snippet(snippet, false)}.ts`, - importValue: nameResolvers.snippet(snippet) - }); - }); + if (snippets.length === 0) { + return []; + } + + return [ + importer.importType({ + filePathOrPackage: `../${deliveryConfig.contentTypeSnippetsFolderName}/index.ts`, + importValue: snippets + .map((snippet) => nameResolvers.snippet(snippet)) + .map((m) => m) + .filter(uniqueFilter) + .join(', ') + }) + ]; }; - const getElementImports = (typeOrSnippet: ContentTypeOrSnippet, elements: readonly FlattenedElement[]): readonly string[] => { - return ( - elements - // only take elements that are not from snippets - .filter((m) => !m.fromSnippet) - .map((flattenedElement) => { - return match(flattenedElement) - .returnType() - .with({ type: 'taxonomy' }, (taxonomyElement) => { - if (!taxonomyElement.assignedTaxonomy) { - throw Error(`Invalid taxonomy for element '${taxonomyElement.codename}'`); - } - return importer.importType({ - filePathOrPackage: `../${deliveryConfig.taxonomiesFolderName}/${fileResolvers.taxonomy(taxonomyElement.assignedTaxonomy, false)}.ts`, - importValue: nameResolvers.taxonomy(taxonomyElement.assignedTaxonomy) + const getReferencedTypesImports = (typeOrSnippet: ContentTypeOrSnippet, elements: readonly FlattenedElement[]): readonly string[] => { + const referencedTypeNames = elements + // only take elements that are not from snippets + .filter((m) => !m.fromSnippet) + .map((flattenedElement) => { + return match(flattenedElement) + .returnType() + .with(P.union({ type: 'modular_content' }, { type: 'subpages' }), (linkedItemsOrSubpagesElement) => { + return (linkedItemsOrSubpagesElement.allowedContentTypes ?? []) + .filter((allowedContentType) => { + // filter self-referencing types as they do not need to be importer + if (allowedContentType.codename === typeOrSnippet.codename) { + return false; + } + return true; + }) + .map((allowedContentType) => { + return nameResolvers.contentType(allowedContentType); }); - }) - .with(P.union({ type: 'modular_content' }, { type: 'subpages' }), (linkedItemsOrSubpagesElement) => { - return (linkedItemsOrSubpagesElement.allowedContentTypes ?? []) - .filter((allowedContentType) => { - // filter self-referencing types as they do not need to be importer - if (allowedContentType.codename === typeOrSnippet.codename) { - return false; - } - return true; - }) - .map((allowedContentType) => { - const referencedTypeFilename: string = `${fileResolvers.contentType(allowedContentType, false)}`; - - return importer.importType({ - filePathOrPackage: - typeOrSnippet instanceof ContentTypeSnippetModels.ContentTypeSnippet - ? `../${deliveryConfig.contentTypesFolderName}/${referencedTypeFilename}.ts` - : `./${referencedTypeFilename}.ts`, - importValue: `${nameResolvers.contentType(allowedContentType)}` - }); - }); - }) - .otherwise(() => []); - }) - .flatMap((m) => m) - .filter(isNotUndefined) - .filter(uniqueFilter) - ); + }) + .otherwise(() => []); + }) + .flatMap((m) => m) + .filter(isNotUndefined) + .filter(uniqueFilter); + + if (referencedTypeNames.length === 0) { + return []; + } + + return [ + importer.importType({ + filePathOrPackage: + typeOrSnippet instanceof ContentTypeSnippetModels.ContentTypeSnippet + ? `../${deliveryConfig.contentTypesFolderName}/index.ts` + : `./index.ts`, + importValue: referencedTypeNames.join(', ') + }) + ]; + }; + + const getReferencedTaxonomyImports = (elements: readonly FlattenedElement[]): readonly string[] => { + const taxonomyTypeNames = elements + // only take elements that are not from snippets + .filter((m) => !m.fromSnippet) + .map((flattenedElement) => { + return match(flattenedElement) + .returnType() + .with({ type: 'taxonomy' }, (taxonomyElement) => { + if (!taxonomyElement.assignedTaxonomy) { + throw Error(`Invalid taxonomy for element '${taxonomyElement.codename}'`); + } + + return nameResolvers.taxonomy(taxonomyElement.assignedTaxonomy); + }) + .otherwise(() => undefined); + }) + .filter(isNotUndefined) + .filter(uniqueFilter); + + if (taxonomyTypeNames.length === 0) { + return []; + } + + return [ + importer.importType({ + filePathOrPackage: `../${deliveryConfig.taxonomiesFolderName}/index.ts`, + importValue: taxonomyTypeNames.join(', ') + }) + ]; }; const getContentTypeModelImports = (data: { @@ -141,7 +199,12 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato return { imports: sortAlphabetically( - [...getElementImports(data.contentType, data.flattenedElements), ...getSnippetImports(snippets)] + [ + ...getSystemTypeImports(), + ...getReferencedTypesImports(data.contentType, data.flattenedElements), + ...getReferencedTaxonomyImports(data.flattenedElements), + ...getSnippetImports(snippets) + ] .filter(isNotUndefined) .filter(uniqueFilter), (importValue) => importValue @@ -164,7 +227,11 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato return { imports: sortAlphabetically( - [...getElementImports(data.snippet, data.flattenedElements), ...getSnippetImports(snippets)] + [ + ...getReferencedTypesImports(data.snippet, data.flattenedElements), + ...getReferencedTaxonomyImports(data.flattenedElements), + ...getSnippetImports(snippets) + ] .filter(isNotUndefined) .filter(uniqueFilter), (importValue) => importValue @@ -245,7 +312,7 @@ ${wrapComment(` `)} export type ${importsResult.typeName} = ${deliveryConfig.sdkTypes.contentItem}< ${getElementsCode(flattenedElements)}${importsResult.contentTypeExtends ? ` ${importsResult.contentTypeExtends}` : ''}, -'${contentType.codename}'>; +'${contentType.codename}', ${sharedTypesConfig.languageCodenames}, ${sharedTypesConfig.collectionCodenames}, ${sharedTypesConfig.workflowCodenames}, ${sharedTypesConfig.workflowStepCodenames}>; `; }; @@ -330,6 +397,37 @@ ${getElementsCode(flattenedElements)}${importsResult.contentTypeExtends ? ` ${im }; return { - generateModels + generateModels: (): { + contentTypeFiles: readonly GeneratedFile[]; + snippetFiles: readonly GeneratedFile[]; + } => { + return { + contentTypeFiles: config.environmentData.types.map((type) => createTypeModel(type)), + snippetFiles: config.environmentData.snippets.map((contentTypeSnippet) => createSnippetModel(contentTypeSnippet)) + }; + }, + getSystemFiles(): readonly GeneratedFile[] { + return [ + { + filename: `${deliveryConfig.systemTypesFolderName}/${deliveryConfig.typesFilename}.ts`, + text: ` + ${wrapComment(`\n * Type representing all languages\n`)} + ${getLanguageCodenamesType(config.environmentData.languages)} + + ${wrapComment(`\n * Type representing all content types\n`)} + ${getContentTypeCodenamesType(config.environmentData.types)} + + ${wrapComment(`\n * Type representing all collections\n`)} + ${getCollectionCodenamesType(config.environmentData.collections)} + + ${wrapComment(`\n * Type representing all workflows\n`)} + ${getWorkflowCodenamesType(config.environmentData.workflows)} + + ${wrapComment(`\n * Type representing all worksflow steps across all workflows\n`)} + ${getWorkflowStepCodenamesType(config.environmentData.workflows)} + ` + } + ]; + } }; } diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index f6dbb31..49d9412 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -47,14 +47,15 @@ export async function generateDeliveryModelsAsync(config: GenerateDeliveryModels console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('delivery')}' models\n`); - const { contentTypeFiles, snippetFiles, taxonomyFiles, moduleResolution, environmentInfo } = await getFilesAsync(config); + const { contentTypeFiles, snippetFiles, taxonomyFiles, moduleResolution, environmentInfo, systemFiles } = await getFilesAsync(config); await createFilesAsync( { contentTypeFiles, snippetFiles, taxonomyFiles, - environmentInfo + environmentInfo, + systemFiles }, { formatOptions: config.formatOptions, @@ -71,6 +72,7 @@ async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ readonly contentTypeFiles: readonly GeneratedFile[]; readonly snippetFiles: readonly GeneratedFile[]; readonly taxonomyFiles: readonly GeneratedFile[]; + readonly systemFiles: readonly GeneratedFile[]; readonly moduleResolution: ModuleResolution; readonly environmentInfo: Readonly; }> { @@ -83,23 +85,31 @@ async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ const environmentInfo = await kontentFetcher.getEnvironmentInfoAsync(); - const [taxonomies, types, snippets] = await Promise.all([ + const [taxonomies, types, snippets, languages, collections, workflows] = await Promise.all([ kontentFetcher.getTaxonomiesAsync(), kontentFetcher.getTypesAsync(), - kontentFetcher.getSnippetsAsync() + kontentFetcher.getSnippetsAsync(), + kontentFetcher.getLanguagesAsync(), + kontentFetcher.getCollectionsAsync(), + kontentFetcher.getWorkflowsAsync() ]); - const { contentTypeFiles, snippetFiles } = deliveryContentTypeGenerator({ + const deliveryGenerator = deliveryContentTypeGenerator({ moduleResolution: moduleResolution, environmentData: { environment: environmentInfo, - types: types, - snippets: snippets, - taxonomies: taxonomies + types, + snippets, + taxonomies, + languages, + collections, + workflows }, fileResolvers: config.fileResolvers, nameResolvers: config.nameResolvers - }).generateModels(); + }); + + const { contentTypeFiles, snippetFiles } = deliveryGenerator.generateModels(); const taxonomyFiles = deliveryTaxonomyGenerator({ moduleResolution: moduleResolution, @@ -116,12 +126,14 @@ async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ snippetFiles, taxonomyFiles, moduleResolution, - environmentInfo + environmentInfo, + systemFiles: deliveryGenerator.getSystemFiles() }; } async function createFilesAsync( data: { + readonly systemFiles: readonly GeneratedFile[]; readonly contentTypeFiles: readonly GeneratedFile[]; readonly snippetFiles: readonly GeneratedFile[]; readonly taxonomyFiles: readonly GeneratedFile[]; @@ -147,7 +159,17 @@ async function createFilesAsync( ...data.contentTypeFiles, ...data.snippetFiles, ...data.taxonomyFiles, + // system files + ...data.systemFiles, // barrel files + { + filename: `${deliveryConfig.systemTypesFolderName}/${coreConfig.barrelExportFilename}`, + text: importer.getBarrelExportCode([ + ...data.systemFiles.map((m) => { + return `./${getFilenameFromPath(m.filename)}`; + }) + ]) + }, { filename: `${deliveryConfig.contentTypesFolderName}/${coreConfig.barrelExportFilename}`, text: importer.getBarrelExportCode([ @@ -177,7 +199,8 @@ async function createFilesAsync( text: importer.getBarrelExportCode([ `./${deliveryConfig.contentTypesFolderName}/index`, `./${deliveryConfig.contentTypeSnippetsFolderName}/index`, - `./${deliveryConfig.taxonomiesFolderName}/index` + `./${deliveryConfig.taxonomiesFolderName}/index`, + `./${deliveryConfig.systemTypesFolderName}/index` ]) } ]); diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index 8645c41..d0233ef 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -8,7 +8,7 @@ import { WorkflowModels } from '@kontent-ai/management-sdk'; import { match } from 'ts-pattern'; -import { migrationConfig } from '../../config.js'; +import { migrationConfig, sharedTypesConfig } from '../../config.js'; import { importer as _importer, FlattenedElement, @@ -17,9 +17,15 @@ import { ModuleResolution, toGuidelinesComment, toPascalCase, - uniqueFilter, wrapComment } from '../../core/index.js'; +import { + getCollectionCodenamesType, + getContentTypeCodenamesType, + getLanguageCodenamesType, + getWorkflowCodenamesType, + getWorkflowStepCodenamesType +} from '../shared/generator.utils.js'; export interface MigrationGeneratorConfig { readonly moduleResolution: ModuleResolution; @@ -118,7 +124,7 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { })} ${importer.importType({ filePathOrPackage: `./${migrationConfig.environmentFolderName}/${migrationConfig.environmentFilename}.ts`, - importValue: `${migrationConfig.localTypeNames.collectionCodenames}, ${migrationConfig.localTypeNames.contentTypeCodenames}, ${migrationConfig.localTypeNames.languageCodenames}, ${migrationConfig.localTypeNames.workflowCodenames}, ${migrationConfig.localTypeNames.workflowStepCodenames}` + importValue: `${sharedTypesConfig.collectionCodenames}, ${sharedTypesConfig.contentTypeCodenames}, ${sharedTypesConfig.languageCodenames}, ${sharedTypesConfig.workflowCodenames}, ${sharedTypesConfig.workflowStepCodenames}` })} ${wrapComment('\n * System object shared by all individual content type models\n')} @@ -161,40 +167,16 @@ function getElementPropType(element: Readonly): string { function getItemType(): string { return `export type ${migrationConfig.localTypeNames.item}< - ${migrationConfig.localTypeNames.codename} extends ${migrationConfig.localTypeNames.contentTypeCodenames}, + ${migrationConfig.localTypeNames.codename} extends ${sharedTypesConfig.contentTypeCodenames}, ${migrationConfig.localTypeNames.elements} extends ${migrationConfig.sdkTypeNames.elements} = ${migrationConfig.sdkTypeNames.elements}, - > = ${migrationConfig.sdkTypeNames.item}<${migrationConfig.localTypeNames.elements}, ${migrationConfig.localTypeNames.system}<${migrationConfig.localTypeNames.codename}>, ${migrationConfig.localTypeNames.workflowStepCodenames}>;`; + > = ${migrationConfig.sdkTypeNames.item}<${migrationConfig.localTypeNames.elements}, ${migrationConfig.localTypeNames.system}<${migrationConfig.localTypeNames.codename}>, ${sharedTypesConfig.workflowStepCodenames}>;`; } function getSystemType(): string { - return `export type ${migrationConfig.localTypeNames.system}<${migrationConfig.localTypeNames.codename} extends ${migrationConfig.localTypeNames.contentTypeCodenames}> = ${migrationConfig.sdkTypeNames.system}< + return `export type ${migrationConfig.localTypeNames.system}<${migrationConfig.localTypeNames.codename} extends ${sharedTypesConfig.contentTypeCodenames}> = ${migrationConfig.sdkTypeNames.system}< ${migrationConfig.localTypeNames.codename}, - ${migrationConfig.localTypeNames.languageCodenames}, - ${migrationConfig.localTypeNames.collectionCodenames}, - ${migrationConfig.localTypeNames.workflowCodenames} + ${sharedTypesConfig.languageCodenames}, + ${sharedTypesConfig.collectionCodenames}, + ${sharedTypesConfig.workflowCodenames} >;`; } - -function getLanguageCodenamesType(languages: readonly Readonly[]): string { - return `export type ${migrationConfig.localTypeNames.languageCodenames} = ${languages.map((language) => `'${language.codename}'`).join(' | ')};`; -} - -function getContentTypeCodenamesType(types: readonly Readonly[]): string { - return `export type ${migrationConfig.localTypeNames.contentTypeCodenames} = ${types.map((type) => `'${type.codename}'`).join(' | ')};`; -} - -function getWorkflowCodenamesType(workflows: readonly Readonly[]): string { - return `export type ${migrationConfig.localTypeNames.workflowCodenames} = ${workflows.map((workflow) => `'${workflow.codename}'`).join(' | ')};`; -} - -function getCollectionCodenamesType(collections: readonly Readonly[]): string { - return `export type ${migrationConfig.localTypeNames.collectionCodenames} = ${collections.map((collection) => `'${collection.codename}'`).join(' | ')};`; -} - -function getWorkflowStepCodenamesType(workflows: readonly Readonly[]): string { - return `export type ${migrationConfig.localTypeNames.workflowStepCodenames} = ${workflows - .flatMap((workflow) => [...workflow.steps, workflow.publishedStep, workflow.archivedStep, workflow.scheduledStep]) - .map((workflowStep) => `'${workflowStep.codename}'`) - .filter(uniqueFilter) - .join(' | ')};`; -} diff --git a/lib/generators/shared/generator.utils.ts b/lib/generators/shared/generator.utils.ts new file mode 100644 index 0000000..4f38378 --- /dev/null +++ b/lib/generators/shared/generator.utils.ts @@ -0,0 +1,27 @@ +import { CollectionModels, ContentTypeModels, LanguageModels, WorkflowModels } from '@kontent-ai/management-sdk'; +import { sharedTypesConfig } from '../../config.js'; +import { uniqueFilter } from '../../core/core.utils.js'; + +export function getLanguageCodenamesType(languages: readonly Readonly[]): string { + return `export type ${sharedTypesConfig.languageCodenames} = ${languages.map((language) => `'${language.codename}'`).join(' | ')};`; +} + +export function getContentTypeCodenamesType(types: readonly Readonly[]): string { + return `export type ${sharedTypesConfig.contentTypeCodenames} = ${types.map((type) => `'${type.codename}'`).join(' | ')};`; +} + +export function getWorkflowCodenamesType(workflows: readonly Readonly[]): string { + return `export type ${sharedTypesConfig.workflowCodenames} = ${workflows.map((workflow) => `'${workflow.codename}'`).join(' | ')};`; +} + +export function getCollectionCodenamesType(collections: readonly Readonly[]): string { + return `export type ${sharedTypesConfig.collectionCodenames} = ${collections.map((collection) => `'${collection.codename}'`).join(' | ')};`; +} + +export function getWorkflowStepCodenamesType(workflows: readonly Readonly[]): string { + return `export type ${sharedTypesConfig.workflowStepCodenames} = ${workflows + .flatMap((workflow) => [...workflow.steps, workflow.publishedStep, workflow.archivedStep, workflow.scheduledStep]) + .map((workflowStep) => `'${workflowStep.codename}'`) + .filter(uniqueFilter) + .join(' | ')};`; +} diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index 3b0b057..fe1402b 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -14,6 +14,7 @@ **/ import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; +import type { CollectionCodenames, LanguageCodenames, WorkflowCodenames, WorkflowStepCodenames } from '../system/delivery-types.js'; /** * Actor @@ -57,5 +58,9 @@ export type Actor = IContentItem< */ photo: Elements.AssetsElement; }, - 'actor' + 'actor', + LanguageCodenames, + CollectionCodenames, + WorkflowCodenames, + WorkflowStepCodenames >; diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 96fa4e8..9c61373 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -14,8 +14,9 @@ **/ import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; -import type { Actor } from './actor.js'; -import type { Releasecategory } from '../taxonomies/releasecategory.js'; +import type { Actor } from './index.js'; +import type { CollectionCodenames, LanguageCodenames, WorkflowCodenames, WorkflowStepCodenames } from '../system/delivery-types.js'; +import type { Releasecategory } from '../taxonomies/index.js'; /** * Movie @@ -98,5 +99,9 @@ export type Movie = IContentItem< */ releasecategory: Elements.TaxonomyElement; }, - 'movie' + 'movie', + LanguageCodenames, + CollectionCodenames, + WorkflowCodenames, + WorkflowStepCodenames >; diff --git a/sample/delivery/index.ts b/sample/delivery/index.ts index 45e59b5..e5c5d7a 100644 --- a/sample/delivery/index.ts +++ b/sample/delivery/index.ts @@ -15,4 +15,5 @@ export * from './content-type-snippets/index.js'; export * from './content-types/index.js'; +export * from './system/index.js'; export * from './taxonomies/index.js'; diff --git a/sample/delivery/system/delivery-types.ts b/sample/delivery/system/delivery-types.ts new file mode 100644 index 0000000..1cd61c2 --- /dev/null +++ b/sample/delivery/system/delivery-types.ts @@ -0,0 +1,39 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +/** + * Type representing all languages + */ +export type LanguageCodenames = 'en' | 'cz' | 'German'; + +/** + * Type representing all content types + */ +export type ContentTypeCodenames = 'actor' | 'movie'; + +/** + * Type representing all collections + */ +export type CollectionCodenames = 'default'; + +/** + * Type representing all workflows + */ +export type WorkflowCodenames = 'default'; + +/** + * Type representing all worksflow steps across all workflows + */ +export type WorkflowStepCodenames = 'draft' | 'review' | 'ready_to_publish' | 'published' | 'archived' | 'scheduled'; diff --git a/sample/delivery/system/index.ts b/sample/delivery/system/index.ts new file mode 100644 index 0000000..6ea6387 --- /dev/null +++ b/sample/delivery/system/index.ts @@ -0,0 +1,16 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +export * from './delivery-types.js'; From ecb07f3508252654dfc9d5885a64b83375b8e84b Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 11 Sep 2024 13:27:50 +0200 Subject: [PATCH 084/183] Adds readonly modifier to migration / delivery elements, adds own line for element type prop --- .../delivery-content-type.generator.ts | 5 ++- .../migration/migration.generator.ts | 5 ++- sample/delivery/content-types/actor.ts | 20 +++++---- sample/delivery/content-types/movie.ts | 45 +++++++++++-------- sample/migration/content-types/actor.ts | 20 +++++---- sample/migration/content-types/movie.ts | 45 +++++++++++-------- 6 files changed, 84 insertions(+), 56 deletions(-) diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 7d31c3c..b842b4d 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -349,13 +349,14 @@ ${getElementsCode(flattenedElements)}${importsResult.contentTypeExtends ? ` ${im return (code += ` ${wrapComment(` - * ${element.title} (${element.type}) + * ${element.title} * + * Type: ${element.type} * Required: ${element.isRequired ? 'true' : 'false'} * Codename: ${element.codename} * Id: ${element.id}${element.guidelines ? `\n* Guidelines: ${toGuidelinesComment(element.guidelines)}` : ''} `)} - ${element.codename}: ${deliveryConfig.sdkTypes.elements}.${mappedType};`); + readonly ${element.codename}: ${deliveryConfig.sdkTypes.elements}.${mappedType};`); }, '{') + '}' ); }; diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index d0233ef..5dabf3b 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -75,13 +75,14 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { .map((element) => { return ` ${wrapComment(` - * ${element.title} (${element.type}) + * ${element.title} * + * Type: ${element.type} * Required: ${element.isRequired ? 'true' : 'false'} * Codename: ${element.codename} * Id: ${element.id}${element.guidelines ? `\n* Guidelines: ${toGuidelinesComment(element.guidelines)}` : ''} `)} - ${element.codename}: ${getElementPropType(element)}`; + readonly ${element.codename}: ${getElementPropType(element)}`; }) .join(',\n')}, } diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index fe1402b..a51e2e8 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -25,38 +25,42 @@ import type { CollectionCodenames, LanguageCodenames, WorkflowCodenames, Workflo export type Actor = IContentItem< { /** - * Url (url_slug) + * Url * + * Type: url_slug * Required: false * Codename: url * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 */ - url: Elements.UrlSlugElement; + readonly url: Elements.UrlSlugElement; /** - * First name (text) + * First name * + * Type: text * Required: true * Codename: first_name * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d * Guidelines: This is the first name of the actor */ - first_name: Elements.TextElement; + readonly first_name: Elements.TextElement; /** - * Last name (text) + * Last name * + * Type: text * Required: true * Codename: last_name * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 */ - last_name: Elements.TextElement; + readonly last_name: Elements.TextElement; /** - * Photo (asset) + * Photo * + * Type: asset * Required: false * Codename: photo * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 */ - photo: Elements.AssetsElement; + readonly photo: Elements.AssetsElement; }, 'actor', LanguageCodenames, diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 9c61373..5341105 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -27,77 +27,86 @@ import type { Releasecategory } from '../taxonomies/index.js'; export type Movie = IContentItem< { /** - * Title (text) + * Title * + * Type: text * Required: true * Codename: title * Id: 3473187e-dc78-eff2-7099-f690f7042d4a */ - title: Elements.TextElement; + readonly title: Elements.TextElement; /** - * Plot (rich_text) + * Plot * + * Type: rich_text * Required: false * Codename: plot * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce */ - plot: Elements.RichTextElement; + readonly plot: Elements.RichTextElement; /** - * Released (date_time) + * Released * + * Type: date_time * Required: false * Codename: released * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 */ - released: Elements.DateTimeElement; + readonly released: Elements.DateTimeElement; /** - * Length (number) + * Length * + * Type: number * Required: false * Codename: length * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c */ - length: Elements.NumberElement; + readonly length: Elements.NumberElement; /** - * Poster (asset) + * Poster * + * Type: asset * Required: false * Codename: poster * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d */ - poster: Elements.AssetsElement; + readonly poster: Elements.AssetsElement; /** - * Category (multiple_choice) + * Category * + * Type: multiple_choice * Required: false * Codename: category * Id: 9821c252-6414-f549-c17f-cc171dd87713 */ - category: Elements.MultipleChoiceElement; + readonly category: Elements.MultipleChoiceElement; /** - * Stars (modular_content) + * Stars * + * Type: modular_content * Required: false * Codename: stars * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 */ - stars: Elements.LinkedItemsElement; + readonly stars: Elements.LinkedItemsElement; /** - * SeoName (url_slug) + * SeoName * + * Type: url_slug * Required: false * Codename: seoname * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c */ - seoname: Elements.UrlSlugElement; + readonly seoname: Elements.UrlSlugElement; /** - * ReleaseCategory (taxonomy) + * ReleaseCategory * + * Type: taxonomy * Required: false * Codename: releasecategory * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 */ - releasecategory: Elements.TaxonomyElement; + readonly releasecategory: Elements.TaxonomyElement; }, 'movie', LanguageCodenames, diff --git a/sample/migration/content-types/actor.ts b/sample/migration/content-types/actor.ts index 299c4f5..a02b069 100644 --- a/sample/migration/content-types/actor.ts +++ b/sample/migration/content-types/actor.ts @@ -26,40 +26,44 @@ export type ActorItem = Item< 'actor', { /** - * Url (url_slug) + * Url * + * Type: url_slug * Required: false * Codename: url * Id: c8658782-f209-a573-9c85-430fb4e3e9f0 */ - url: MigrationElementModels.UrlSlugElement; + readonly url: MigrationElementModels.UrlSlugElement; /** - * First name (text) + * First name * + * Type: text * Required: true * Codename: first_name * Id: 14dd70e5-c42d-f111-9640-c82b443edf1d * Guidelines: This is the first name of the actor */ - first_name: MigrationElementModels.TextElement; + readonly first_name: MigrationElementModels.TextElement; /** - * Last name (text) + * Last name * + * Type: text * Required: true * Codename: last_name * Id: 9f7a0dd4-af3a-95ca-0358-400c14ce7075 */ - last_name: MigrationElementModels.TextElement; + readonly last_name: MigrationElementModels.TextElement; /** - * Photo (asset) + * Photo * + * Type: asset * Required: false * Codename: photo * Id: eaec9ba3-9624-6875-04ec-80d0b2e00781 */ - photo: MigrationElementModels.AssetElement; + readonly photo: MigrationElementModels.AssetElement; } >; diff --git a/sample/migration/content-types/movie.ts b/sample/migration/content-types/movie.ts index f345d38..de86bd2 100644 --- a/sample/migration/content-types/movie.ts +++ b/sample/migration/content-types/movie.ts @@ -26,84 +26,93 @@ export type MovieItem = Item< 'movie', { /** - * Title (text) + * Title * + * Type: text * Required: true * Codename: title * Id: 3473187e-dc78-eff2-7099-f690f7042d4a */ - title: MigrationElementModels.TextElement; + readonly title: MigrationElementModels.TextElement; /** - * Plot (rich_text) + * Plot * + * Type: rich_text * Required: false * Codename: plot * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce */ - plot: MigrationElementModels.RichTextElement; + readonly plot: MigrationElementModels.RichTextElement; /** - * Released (date_time) + * Released * + * Type: date_time * Required: false * Codename: released * Id: 5ccf4644-0d65-5d96-9a32-f4ea21974d51 */ - released: MigrationElementModels.DateTimeElement; + readonly released: MigrationElementModels.DateTimeElement; /** - * Length (number) + * Length * + * Type: number * Required: false * Codename: length * Id: 7e8ecfab-a419-27ee-d8ec-8adb76fd007c */ - length: MigrationElementModels.NumberElement; + readonly length: MigrationElementModels.NumberElement; /** - * Poster (asset) + * Poster * + * Type: asset * Required: false * Codename: poster * Id: a39a7237-9503-a1ae-8431-5b6cdb85ae9d */ - poster: MigrationElementModels.AssetElement; + readonly poster: MigrationElementModels.AssetElement; /** - * Category (multiple_choice) + * Category * + * Type: multiple_choice * Required: false * Codename: category * Id: 9821c252-6414-f549-c17f-cc171dd87713 */ - category: MigrationElementModels.MultipleChoiceElement; + readonly category: MigrationElementModels.MultipleChoiceElement; /** - * Stars (modular_content) + * Stars * + * Type: modular_content * Required: false * Codename: stars * Id: aa26a55d-19f8-7501-fea3-b0d9b1eeac71 */ - stars: MigrationElementModels.LinkedItemsElement; + readonly stars: MigrationElementModels.LinkedItemsElement; /** - * SeoName (url_slug) + * SeoName * + * Type: url_slug * Required: false * Codename: seoname * Id: 756cc91a-a090-60f9-a7f0-f505bfbe046c */ - seoname: MigrationElementModels.UrlSlugElement; + readonly seoname: MigrationElementModels.UrlSlugElement; /** - * ReleaseCategory (taxonomy) + * ReleaseCategory * + * Type: taxonomy * Required: false * Codename: releasecategory * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 */ - releasecategory: MigrationElementModels.TaxonomyElement; + readonly releasecategory: MigrationElementModels.TaxonomyElement; } >; From 46e0b96733ad6f7af586b1ca16d29b4199b62b57 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 11 Sep 2024 13:47:23 +0200 Subject: [PATCH 085/183] Adds codename of taxonomy to Delivery taxonomy elements --- lib/config.ts | 2 +- .../delivery/delivery-content-type.generator.ts | 15 +++++++++------ sample/delivery/content-types/actor.ts | 2 +- sample/delivery/content-types/movie.ts | 4 ++-- .../{delivery-types.ts => delivery.codenames.ts} | 0 sample/delivery/system/index.ts | 2 +- 6 files changed, 14 insertions(+), 11 deletions(-) rename sample/delivery/system/{delivery-types.ts => delivery.codenames.ts} (100%) diff --git a/lib/config.ts b/lib/config.ts index a572ada..c0204d8 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -38,7 +38,7 @@ export const deliveryConfig = { contentTypeSnippetsFolderName: `content-type-snippets`, taxonomiesFolderName: `taxonomies`, systemTypesFolderName: 'system', - typesFilename: 'delivery-types', + coreCodenamesFilename: 'delivery.codenames', sdkTypes: { contentItem: 'IContentItem', diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index b842b4d..768c3cd 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -89,7 +89,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato const getSystemTypeImports = (): readonly string[] => { return [ importer.importType({ - filePathOrPackage: `../${deliveryConfig.systemTypesFolderName}/${deliveryConfig.typesFilename}.ts`, + filePathOrPackage: `../${deliveryConfig.systemTypesFolderName}/${deliveryConfig.coreCodenamesFilename}.ts`, importValue: [ sharedTypesConfig.collectionCodenames, sharedTypesConfig.languageCodenames, @@ -378,15 +378,18 @@ ${getElementsCode(flattenedElements)}${importsResult.contentTypeExtends ? ` ${im .with({ type: 'multiple_choice' }, () => 'MultipleChoiceElement') .with({ type: 'url_slug' }, () => 'UrlSlugElement') .with({ type: 'taxonomy' }, (taxonomyElement) => { - const taxonomyName = getTaxonomyTypeName(taxonomyElement); - return taxonomyName ? `TaxonomyElement<${taxonomyName}>` : `TaxonomyElement`; + if (!taxonomyElement.assignedTaxonomy) { + return `TaxonomyElement`; + } + + return `TaxonomyElement<${getTaxonomyTypeName(taxonomyElement.assignedTaxonomy)}, '${taxonomyElement.codename}'>`; }) .with({ type: 'custom' }, () => 'CustomElement') .otherwise(() => undefined); }; - const getTaxonomyTypeName = (element: FlattenedElement): string | undefined => { - return element.assignedTaxonomy ? nameResolvers.taxonomy(element.assignedTaxonomy) : undefined; + const getTaxonomyTypeName = (taxonomy: Readonly): string => { + return nameResolvers.taxonomy(taxonomy); }; const getLinkedItemsAllowedTypes = (types: readonly Readonly[]): readonly string[] => { @@ -410,7 +413,7 @@ ${getElementsCode(flattenedElements)}${importsResult.contentTypeExtends ? ` ${im getSystemFiles(): readonly GeneratedFile[] { return [ { - filename: `${deliveryConfig.systemTypesFolderName}/${deliveryConfig.typesFilename}.ts`, + filename: `${deliveryConfig.systemTypesFolderName}/${deliveryConfig.coreCodenamesFilename}.ts`, text: ` ${wrapComment(`\n * Type representing all languages\n`)} ${getLanguageCodenamesType(config.environmentData.languages)} diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index a51e2e8..e4c2530 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -14,7 +14,7 @@ **/ import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; -import type { CollectionCodenames, LanguageCodenames, WorkflowCodenames, WorkflowStepCodenames } from '../system/delivery-types.js'; +import type { CollectionCodenames, LanguageCodenames, WorkflowCodenames, WorkflowStepCodenames } from '../system/delivery.codenames.js'; /** * Actor diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 5341105..1c93088 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -15,7 +15,7 @@ import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; import type { Actor } from './index.js'; -import type { CollectionCodenames, LanguageCodenames, WorkflowCodenames, WorkflowStepCodenames } from '../system/delivery-types.js'; +import type { CollectionCodenames, LanguageCodenames, WorkflowCodenames, WorkflowStepCodenames } from '../system/delivery.codenames.js'; import type { Releasecategory } from '../taxonomies/index.js'; /** @@ -106,7 +106,7 @@ export type Movie = IContentItem< * Codename: releasecategory * Id: 65f2fd44-1856-bc2b-17c2-decb0635e3d2 */ - readonly releasecategory: Elements.TaxonomyElement; + readonly releasecategory: Elements.TaxonomyElement; }, 'movie', LanguageCodenames, diff --git a/sample/delivery/system/delivery-types.ts b/sample/delivery/system/delivery.codenames.ts similarity index 100% rename from sample/delivery/system/delivery-types.ts rename to sample/delivery/system/delivery.codenames.ts diff --git a/sample/delivery/system/index.ts b/sample/delivery/system/index.ts index 6ea6387..4ddfa2c 100644 --- a/sample/delivery/system/index.ts +++ b/sample/delivery/system/index.ts @@ -13,4 +13,4 @@ * ------------------------------------------------------------------------------- **/ -export * from './delivery-types.js'; +export * from './delivery.codenames.js'; From b9da5d5367d76104e8e2d6b7194b39f595fafd81 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 11 Sep 2024 14:09:13 +0200 Subject: [PATCH 086/183] Adds delivery element typing for multiple choice codenames --- lib/core/core.models.ts | 6 +++ lib/core/element.utils.ts | 21 +++++++++- .../delivery-content-type.generator.ts | 7 +++- sample/delivery/content-types/movie.ts | 38 ++++++++++--------- 4 files changed, 52 insertions(+), 20 deletions(-) diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index e69d033..9e7bc8e 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -35,6 +35,11 @@ export interface OriginalManagementError { }; } +export interface MultipleChoiceOption { + readonly name: string; + readonly codename: string; +} + export interface FlattenedElement { readonly title: string; readonly id: string; @@ -47,6 +52,7 @@ export interface FlattenedElement { readonly originalElement: Readonly; readonly assignedTaxonomy?: Readonly; readonly fromSnippet?: Readonly; + readonly multipleChoiceOptions?: readonly Readonly[]; } export interface GeneratedFile { diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts index 1975347..54ddccb 100644 --- a/lib/core/element.utils.ts +++ b/lib/core/element.utils.ts @@ -1,7 +1,7 @@ import { ContentTypeElements, ContentTypeModels, ContentTypeSnippetModels, TaxonomyModels } from '@kontent-ai/management-sdk'; import { isNotUndefined } from '@kontent-ai/migration-toolkit'; import { match } from 'ts-pattern'; -import { FlattenedElement } from './core.models.js'; +import { FlattenedElement, MultipleChoiceOption } from './core.models.js'; interface ElementWrapper { readonly element: Readonly; @@ -65,7 +65,8 @@ function getFlattenedElement( originalElement: wrapper.element, allowedContentTypes: extractLinkedItemsAllowedTypes(wrapper.element, types), assignedTaxonomy: extractTaxonomy(wrapper.element, taxonomies), - fromSnippet: wrapper.fromSnippet + fromSnippet: wrapper.fromSnippet, + multipleChoiceOptions: extractMultipleChoiceOptions(wrapper.element) }; } @@ -111,6 +112,22 @@ function extractLinkedItemsAllowedTypes( return allowedTypeIds.map((id) => types.find((m) => m.id === id)).filter(isNotUndefined); } +function extractMultipleChoiceOptions( + element: Readonly +): readonly MultipleChoiceOption[] | undefined { + return match(element) + .returnType() + .with({ type: 'multiple_choice' }, (multipleChoiceElement) => { + return multipleChoiceElement.options.map((option) => { + return { + codename: option.codename ?? '', + name: option.name + }; + }); + }) + .otherwise(() => undefined); +} + function extractTaxonomy( element: Readonly, taxonomies: readonly Readonly[] diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 768c3cd..9161fa7 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -375,7 +375,12 @@ ${getElementsCode(flattenedElements)}${importsResult.contentTypeExtends ? ` ${im .with({ type: 'asset' }, () => 'AssetsElement') .with({ type: 'date_time' }, () => 'DateTimeElement') .with({ type: 'rich_text' }, () => 'RichTextElement') - .with({ type: 'multiple_choice' }, () => 'MultipleChoiceElement') + .with({ type: 'multiple_choice' }, (multipleChoiceElement) => { + if (!multipleChoiceElement.multipleChoiceOptions?.length) { + return 'MultipleChoiceElement'; + } + return `MultipleChoiceElement<${multipleChoiceElement.multipleChoiceOptions.map((option) => `'${option.codename}'`).join(' | ')}>`; + }) .with({ type: 'url_slug' }, () => 'UrlSlugElement') .with({ type: 'taxonomy' }, (taxonomyElement) => { if (!taxonomyElement.assignedTaxonomy) { diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 1c93088..2228007 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -1,22 +1,21 @@ - -/** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Movie Database -* Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 -* -* ------------------------------------------------------------------------------- -**/ +/** + * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- + * + * Project: Movie Database + * Environment: Production + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + * + * ------------------------------------------------------------------------------- + **/ import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; -import type { Actor } from './index.js'; import type { CollectionCodenames, LanguageCodenames, WorkflowCodenames, WorkflowStepCodenames } from '../system/delivery.codenames.js'; import type { Releasecategory } from '../taxonomies/index.js'; +import type { Actor } from './index.js'; /** * Movie @@ -43,7 +42,7 @@ export type Movie = IContentItem< * Codename: plot * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce */ - readonly plot: Elements.RichTextElement; + readonly plot: Elements.RichTextElement; /** * Released * @@ -79,7 +78,9 @@ export type Movie = IContentItem< * Codename: category * Id: 9821c252-6414-f549-c17f-cc171dd87713 */ - readonly category: Elements.MultipleChoiceElement; + readonly category: Elements.MultipleChoiceElement< + 'sci_fi' | 'documentary' | 'action' | 'romance' | 'animation' | 'comedy' | 'adventure' | 'drama' + >; /** * Stars * @@ -114,3 +115,6 @@ export type Movie = IContentItem< WorkflowCodenames, WorkflowStepCodenames >; + +const movie: Movie = {}; +const f = movie.elements.plot.linkedItems[0]; From 13b49c86996592ad24bcaf5e94793e7857c98d43 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 11 Sep 2024 14:16:48 +0200 Subject: [PATCH 087/183] Handle cases where allowed linked items are not defined, adds allowed content types to RichTextElement --- lib/core/element.utils.ts | 3 ++ .../delivery-content-type.generator.ts | 13 ++++++- sample/delivery/content-types/movie.ts | 34 +++++++++---------- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts index 54ddccb..a65114a 100644 --- a/lib/core/element.utils.ts +++ b/lib/core/element.utils.ts @@ -107,6 +107,9 @@ function extractLinkedItemsAllowedTypes( .with({ type: 'subpages' }, (linkedItemsElement) => { return linkedItemsElement.allowed_content_types?.map((m) => m.id).filter(isNotUndefined) ?? []; }) + .with({ type: 'rich_text' }, (linkedItemsElement) => { + return linkedItemsElement.allowed_content_types?.map((m) => m.id).filter(isNotUndefined) ?? []; + }) .otherwise(() => []); return allowedTypeIds.map((id) => types.find((m) => m.id === id)).filter(isNotUndefined); diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 9161fa7..1d5cfa5 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -367,14 +367,25 @@ ${getElementsCode(flattenedElements)}${importsResult.contentTypeExtends ? ` ${im .with({ type: 'text' }, () => 'TextElement') .with({ type: 'number' }, () => 'NumberElement') .with({ type: 'modular_content' }, (linkedItemsElement) => { + if (!linkedItemsElement.allowedContentTypes?.length) { + return 'LinkedItemsElement'; + } return `LinkedItemsElement<${getLinkedItemsAllowedTypes(linkedItemsElement.allowedContentTypes ?? []).join(' | ')}>`; }) .with({ type: 'subpages' }, (linkedItemsElement) => { + if (!linkedItemsElement.allowedContentTypes?.length) { + return 'LinkedItemsElement'; + } return `LinkedItemsElement<${getLinkedItemsAllowedTypes(linkedItemsElement.allowedContentTypes ?? []).join(' | ')}>`; }) .with({ type: 'asset' }, () => 'AssetsElement') .with({ type: 'date_time' }, () => 'DateTimeElement') - .with({ type: 'rich_text' }, () => 'RichTextElement') + .with({ type: 'rich_text' }, (richTextElement) => { + if (!richTextElement.allowedContentTypes?.length) { + return 'RichTextElement'; + } + return `RichTextElement<${getLinkedItemsAllowedTypes(richTextElement.allowedContentTypes ?? []).join(' | ')}>`; + }) .with({ type: 'multiple_choice' }, (multipleChoiceElement) => { if (!multipleChoiceElement.multipleChoiceOptions?.length) { return 'MultipleChoiceElement'; diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 2228007..65870e1 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -1,21 +1,22 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; +import type { Actor } from './index.js'; import type { CollectionCodenames, LanguageCodenames, WorkflowCodenames, WorkflowStepCodenames } from '../system/delivery.codenames.js'; import type { Releasecategory } from '../taxonomies/index.js'; -import type { Actor } from './index.js'; /** * Movie @@ -42,7 +43,7 @@ export type Movie = IContentItem< * Codename: plot * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce */ - readonly plot: Elements.RichTextElement; + readonly plot: Elements.RichTextElement; /** * Released * @@ -115,6 +116,3 @@ export type Movie = IContentItem< WorkflowCodenames, WorkflowStepCodenames >; - -const movie: Movie = {}; -const f = movie.elements.plot.linkedItems[0]; From a56bf5f709f2b7c66c8008999edfb938d43a32b4 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 11 Sep 2024 14:30:56 +0200 Subject: [PATCH 088/183] Update element.utils.ts --- lib/core/element.utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts index a65114a..ad5fda8 100644 --- a/lib/core/element.utils.ts +++ b/lib/core/element.utils.ts @@ -100,7 +100,7 @@ function extractLinkedItemsAllowedTypes( types: readonly Readonly[] ): readonly Readonly[] { const allowedTypeIds = match(element) - .returnType[]>() + .returnType() .with({ type: 'modular_content' }, (linkedItemsElement) => { return linkedItemsElement.allowed_content_types?.map((m) => m.id).filter(isNotUndefined) ?? []; }) From 94637fe15fb78e426194ba722dfaceef7d27474a Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 11 Sep 2024 14:36:30 +0200 Subject: [PATCH 089/183] Use named input props for getFlattenedElements --- lib/core/element.utils.ts | 18 +++++++------- .../delivery-content-type.generator.ts | 24 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts index ad5fda8..25735f7 100644 --- a/lib/core/element.utils.ts +++ b/lib/core/element.utils.ts @@ -8,19 +8,19 @@ interface ElementWrapper { readonly fromSnippet: Readonly | undefined; } -export function getFlattenedElements( - elements: readonly Readonly[], - snippets: readonly Readonly[], - taxonomies: readonly Readonly[], - types: readonly Readonly[] -): readonly FlattenedElement[] { - return elements +export function getFlattenedElements(data: { + readonly elements: readonly Readonly[]; + readonly snippets: readonly Readonly[]; + readonly taxonomies: readonly Readonly[]; + readonly types: readonly Readonly[]; +}): readonly FlattenedElement[] { + return data.elements .filter((element) => { return element.type !== 'guidelines'; }) .flatMap((element) => { if (element.type === 'snippet') { - const snippet = snippets.find((snippet) => snippet.id === element.snippet.id); + const snippet = data.snippets.find((snippet) => snippet.id === element.snippet.id); if (!snippet) { throw Error(`Could not find snippet with id '${element.snippet.id}'`); @@ -40,7 +40,7 @@ export function getFlattenedElements( }; }) .map((element) => { - return getFlattenedElement(element, taxonomies, types); + return getFlattenedElement(element, data.taxonomies, data.types); }) .filter(isNotUndefined); } diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 1d5cfa5..e56079b 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -254,12 +254,12 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato }; const getSnippetCode = (snippet: Readonly): string => { - const flattenedElements = getFlattenedElements( - snippet.elements, - config.environmentData.snippets, - config.environmentData.taxonomies, - config.environmentData.types - ); + const flattenedElements = getFlattenedElements({ + elements: snippet.elements, + snippets: config.environmentData.snippets, + taxonomies: config.environmentData.taxonomies, + types: config.environmentData.types + }); const importsResult = getSnippetModelImports({ snippet, @@ -285,12 +285,12 @@ ${getElementsCode(flattenedElements)}; }; const getContentTypeCode = (contentType: Readonly): string => { - const flattenedElements = getFlattenedElements( - contentType.elements, - config.environmentData.snippets, - config.environmentData.taxonomies, - config.environmentData.types - ); + const flattenedElements = getFlattenedElements({ + elements: contentType.elements, + snippets: config.environmentData.snippets, + taxonomies: config.environmentData.taxonomies, + types: config.environmentData.types + }); const importsResult = getContentTypeModelImports({ contentType, From 98bca0907f6f6bece5c24b95070b1664efbfc3f2 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 11 Sep 2024 14:41:53 +0200 Subject: [PATCH 090/183] Minor improvements --- .../delivery-content-type.generator.ts | 21 +++++++++---------- lib/generators/delivery/delivery-func.ts | 1 - .../environment/environment.generator.ts | 12 +++++------ 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index e56079b..c1e3533 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -119,7 +119,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato ]; }; - const getReferencedTypesImports = (typeOrSnippet: ContentTypeOrSnippet, elements: readonly FlattenedElement[]): readonly string[] => { + const getReferencedTypeImports = (typeOrSnippet: ContentTypeOrSnippet, elements: readonly FlattenedElement[]): readonly string[] => { const referencedTypeNames = elements // only take elements that are not from snippets .filter((m) => !m.fromSnippet) @@ -195,13 +195,13 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato readonly contentType: Readonly; readonly flattenedElements: readonly FlattenedElement[]; }): ExtractImportsResult => { - const snippets = data.flattenedElements.map((m) => m.fromSnippet).filter(isNotUndefined); + const snippets = data.flattenedElements.map((flattenedElement) => flattenedElement.fromSnippet).filter(isNotUndefined); return { imports: sortAlphabetically( [ ...getSystemTypeImports(), - ...getReferencedTypesImports(data.contentType, data.flattenedElements), + ...getReferencedTypeImports(data.contentType, data.flattenedElements), ...getReferencedTaxonomyImports(data.flattenedElements), ...getSnippetImports(snippets) ] @@ -223,12 +223,12 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato readonly snippet: Readonly; readonly flattenedElements: readonly FlattenedElement[]; }): ExtractImportsResult => { - const snippets = data.flattenedElements.map((m) => m.fromSnippet).filter(isNotUndefined); + const snippets = data.flattenedElements.map((flattenedElement) => flattenedElement.fromSnippet).filter(isNotUndefined); return { imports: sortAlphabetically( [ - ...getReferencedTypesImports(data.snippet, data.flattenedElements), + ...getReferencedTypeImports(data.snippet, data.flattenedElements), ...getReferencedTaxonomyImports(data.flattenedElements), ...getSnippetImports(snippets) ] @@ -250,7 +250,10 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato ? deliveryConfig.sdkTypes.contentItem : deliveryConfig.sdkTypes.contentItemElements; - return sortAlphabetically([mainType, ...(flattenedElements.length ? [deliveryConfig.sdkTypes.elements] : [])], (m) => m); + return sortAlphabetically( + [mainType, ...(flattenedElements.length ? [deliveryConfig.sdkTypes.elements] : [])], + (importValue) => importValue + ); }; const getSnippetCode = (snippet: Readonly): string => { @@ -398,16 +401,12 @@ ${getElementsCode(flattenedElements)}${importsResult.contentTypeExtends ? ` ${im return `TaxonomyElement`; } - return `TaxonomyElement<${getTaxonomyTypeName(taxonomyElement.assignedTaxonomy)}, '${taxonomyElement.codename}'>`; + return `TaxonomyElement<${nameResolvers.taxonomy(taxonomyElement.assignedTaxonomy)}, '${taxonomyElement.codename}'>`; }) .with({ type: 'custom' }, () => 'CustomElement') .otherwise(() => undefined); }; - const getTaxonomyTypeName = (taxonomy: Readonly): string => { - return nameResolvers.taxonomy(taxonomy); - }; - const getLinkedItemsAllowedTypes = (types: readonly Readonly[]): readonly string[] => { if (!types.length) { return [deliveryConfig.sdkTypes.contentItem]; diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index 49d9412..a810c44 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -159,7 +159,6 @@ async function createFilesAsync( ...data.contentTypeFiles, ...data.snippetFiles, ...data.taxonomyFiles, - // system files ...data.systemFiles, // barrel files { diff --git a/lib/generators/environment/environment.generator.ts b/lib/generators/environment/environment.generator.ts index 295a24d..7ddc2ab 100644 --- a/lib/generators/environment/environment.generator.ts +++ b/lib/generators/environment/environment.generator.ts @@ -195,12 +195,12 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { }; const getContentTypeElements = (elements: readonly Readonly[]): string => { - const flattenedElements = getFlattenedElements( - elements, - config.environmentData.snippets, - config.environmentData.taxonomies, - config.environmentData.types - ); + const flattenedElements = getFlattenedElements({ + elements: elements, + snippets: config.environmentData.snippets, + taxonomies: config.environmentData.taxonomies, + types: config.environmentData.types + }); return flattenedElements.reduce((code, element, index) => { const isLast = index === flattenedElements.length - 1; From 75c5b7b3c0cd3295cb1b7e2d2a99657f127ab018 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 11 Sep 2024 14:42:33 +0200 Subject: [PATCH 091/183] Update migration.generator.ts --- lib/generators/migration/migration.generator.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index 5dabf3b..35a4a93 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -66,12 +66,12 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { export type ${toPascalCase(type.name)}Item = ${migrationConfig.localTypeNames.item}< '${type.codename}', { - ${getFlattenedElements( - type.elements, - config.environmentData.snippets, - config.environmentData.taxonomies, - config.environmentData.types - ) + ${getFlattenedElements({ + elements: type.elements, + snippets: config.environmentData.snippets, + taxonomies: config.environmentData.taxonomies, + types: config.environmentData.types + }) .map((element) => { return ` ${wrapComment(` From 1dcf824e8b05076e856aa56e1cbdc7ea2873328f Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 12 Sep 2024 10:20:59 +0200 Subject: [PATCH 092/183] Removes barrel files, specifically define Public API with named exports --- lib/core/comment.utils.ts | 2 +- lib/core/index.ts | 7 ------- lib/fetch/index.ts | 1 - lib/fetch/kontent-fetcher.ts | 3 ++- lib/files/file-manager.ts | 4 +++- lib/files/index.ts | 1 - lib/format/index.ts | 1 - .../delivery-content-type.generator.ts | 18 +++++++----------- lib/generators/delivery/delivery-func.ts | 14 ++++++-------- .../delivery/delivery-taxonomy.generator.ts | 13 +++---------- lib/generators/environment/environment-func.ts | 14 +++++--------- .../environment/environment.generator.ts | 14 ++++---------- lib/generators/index.ts | 16 ---------------- lib/generators/items/items-func.ts | 14 +++++--------- lib/generators/items/items.generator.ts | 4 +++- lib/generators/migration/migration-func.ts | 14 +++++--------- .../migration/migration.generator.ts | 15 +++++---------- lib/index.ts | 5 ----- lib/meta/index.ts | 1 - lib/node/cli/actions/delivery-action.ts | 4 ++-- lib/node/cli/actions/environment-action.ts | 4 ++-- lib/node/cli/actions/items-action.ts | 4 ++-- lib/node/cli/actions/migrate-action.ts | 4 ++-- lib/node/cli/app.ts | 2 +- lib/node/cli/cli.models.ts | 2 +- lib/node/cli/commands.ts | 2 +- lib/public_api.ts | 8 ++++++++ package.json | 4 ++-- scripts/tests/delivery-models.ts | 4 +++- scripts/tests/environment-models.ts | 4 +++- scripts/tests/item-models.ts | 4 +++- scripts/tests/migration-models.ts | 4 +++- 32 files changed, 82 insertions(+), 129 deletions(-) delete mode 100644 lib/core/index.ts delete mode 100644 lib/fetch/index.ts delete mode 100644 lib/files/index.ts delete mode 100644 lib/format/index.ts delete mode 100644 lib/generators/index.ts delete mode 100644 lib/index.ts delete mode 100644 lib/meta/index.ts create mode 100644 lib/public_api.ts diff --git a/lib/core/comment.utils.ts b/lib/core/comment.utils.ts index fda714b..4a9cdd1 100644 --- a/lib/core/comment.utils.ts +++ b/lib/core/comment.utils.ts @@ -1,5 +1,5 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; -import { libMetadata } from '../meta/index.js'; +import { libMetadata } from '../meta/metadata.js'; export function wrapComment(comment: string): string { return `/**${toSafeComment(comment)}*/`; diff --git a/lib/core/index.ts b/lib/core/index.ts deleted file mode 100644 index b32e185..0000000 --- a/lib/core/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -export * from './comment.utils.js'; -export * from './core.models.js'; -export * from './core.utils.js'; -export * from './element.utils.js'; -export * from './error.utils.js'; -export * from './importer.js'; -export * from './resolvers.js'; diff --git a/lib/fetch/index.ts b/lib/fetch/index.ts deleted file mode 100644 index cddf4da..0000000 --- a/lib/fetch/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './kontent-fetcher.js'; diff --git a/lib/fetch/kontent-fetcher.ts b/lib/fetch/kontent-fetcher.ts index 4d93bea..26ef786 100644 --- a/lib/fetch/kontent-fetcher.ts +++ b/lib/fetch/kontent-fetcher.ts @@ -14,7 +14,8 @@ import { WorkflowModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; -import { GeneratorManagementClient, toSafeComment } from '../core/index.js'; +import { toSafeComment } from '../core/comment.utils.js'; +import { GeneratorManagementClient } from '../core/core.models.js'; interface KontentFetcherConfig { readonly environmentId: string; diff --git a/lib/files/file-manager.ts b/lib/files/file-manager.ts index 65364dc..2d3d1ee 100644 --- a/lib/files/file-manager.ts +++ b/lib/files/file-manager.ts @@ -3,7 +3,9 @@ import chalk from 'chalk'; import * as fs from 'fs'; import { dirname } from 'path'; import { Options } from 'prettier'; -import { GeneratedFile, getEnvironmentInfoComment, toOutputDirPath } from '../core/index.js'; +import { getEnvironmentInfoComment } from '../core/comment.utils.js'; +import { GeneratedFile } from '../core/core.models.js'; +import { toOutputDirPath } from '../core/core.utils.js'; import { formatCodeAsync } from '../format/formatter.js'; export function fileManager(config: { diff --git a/lib/files/index.ts b/lib/files/index.ts deleted file mode 100644 index 217fc65..0000000 --- a/lib/files/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './file-manager.js'; diff --git a/lib/format/index.ts b/lib/format/index.ts deleted file mode 100644 index 435d9c4..0000000 --- a/lib/format/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './formatter.js'; diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index c1e3533..7f1b341 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -10,25 +10,21 @@ import { import { isNotUndefined } from '@kontent-ai/migration-toolkit'; import { match, P } from 'ts-pattern'; import { deliveryConfig, sharedTypesConfig } from '../../config.js'; +import { wrapComment } from '../../core/comment.utils.js'; +import { FlattenedElement, GeneratedFile, ModuleResolution } from '../../core/core.models.js'; +import { sortAlphabetically, toGuidelinesComment, uniqueFilter } from '../../core/core.utils.js'; +import { getFlattenedElements } from '../../core/element.utils.js'; +import { importer as _importer } from '../../core/importer.js'; import { - importer as _importer, ContentTypeFileNameResolver, ContentTypeNameResolver, ContentTypeSnippetFileNameResolver, ContentTypeSnippetNameResolver, - FlattenedElement, - GeneratedFile, - getFlattenedElements, mapFilename, mapName, - ModuleResolution, - sortAlphabetically, TaxonomyNameResolver, - TaxonomyTypeFileNameResolver, - toGuidelinesComment, - uniqueFilter, - wrapComment -} from '../../core/index.js'; + TaxonomyTypeFileNameResolver +} from '../../core/resolvers.js'; import { getCollectionCodenamesType, getContentTypeCodenamesType, diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index a810c44..867c5ff 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -2,21 +2,19 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; import { coreConfig, deliveryConfig } from '../../config.js'; +import { GeneratedFile, ModuleResolution } from '../../core/core.models.js'; +import { getDefaultModuleResolution, getFilenameFromPath } from '../../core/core.utils.js'; +import { importer as _importer } from '../../core/importer.js'; import { - importer as _importer, ContentTypeFileNameResolver, ContentTypeNameResolver, ContentTypeSnippetFileNameResolver, ContentTypeSnippetNameResolver, - GeneratedFile, - getDefaultModuleResolution, - getFilenameFromPath, - ModuleResolution, TaxonomyNameResolver, TaxonomyTypeFileNameResolver -} from '../../core/index.js'; -import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; -import { fileManager as _fileManager } from '../../files/index.js'; +} from '../../core/resolvers.js'; +import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; +import { fileManager as _fileManager } from '../../files/file-manager.js'; import { deliveryContentTypeGenerator } from './delivery-content-type.generator.js'; import { deliveryTaxonomyGenerator } from './delivery-taxonomy.generator.js'; diff --git a/lib/generators/delivery/delivery-taxonomy.generator.ts b/lib/generators/delivery/delivery-taxonomy.generator.ts index 1d12c5e..4fa8558 100644 --- a/lib/generators/delivery/delivery-taxonomy.generator.ts +++ b/lib/generators/delivery/delivery-taxonomy.generator.ts @@ -1,15 +1,8 @@ import { EnvironmentModels, TaxonomyModels } from '@kontent-ai/management-sdk'; - import { deliveryConfig } from '../../config.js'; -import { - GeneratedFile, - mapFilename, - mapName, - ModuleResolution, - TaxonomyNameResolver, - TaxonomyTypeFileNameResolver, - wrapComment -} from '../../core/index.js'; +import { wrapComment } from '../../core/comment.utils.js'; +import { GeneratedFile, ModuleResolution } from '../../core/core.models.js'; +import { TaxonomyNameResolver, TaxonomyTypeFileNameResolver, mapFilename, mapName } from '../../core/resolvers.js'; export interface DeliveryTaxonomyGeneratorConfig { readonly moduleResolution: ModuleResolution; diff --git a/lib/generators/environment/environment-func.ts b/lib/generators/environment/environment-func.ts index 4d78b87..f1d8496 100644 --- a/lib/generators/environment/environment-func.ts +++ b/lib/generators/environment/environment-func.ts @@ -2,15 +2,11 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; import { coreConfig } from '../../config.js'; -import { - importer as _importer, - GeneratedFile, - getDefaultModuleResolution, - getFilenameFromPath, - ModuleResolution -} from '../../core/index.js'; -import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; -import { fileManager as _fileManager } from '../../files/index.js'; +import { GeneratedFile, ModuleResolution } from '../../core/core.models.js'; +import { getDefaultModuleResolution, getFilenameFromPath } from '../../core/core.utils.js'; +import { importer as _importer } from '../../core/importer.js'; +import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; +import { fileManager as _fileManager } from '../../files/file-manager.js'; import { environmentGenerator as _environmentGenerator } from './environment.generator.js'; export interface GenerateEnvironmentModelsConfig { diff --git a/lib/generators/environment/environment.generator.ts b/lib/generators/environment/environment.generator.ts index 7ddc2ab..2213e45 100644 --- a/lib/generators/environment/environment.generator.ts +++ b/lib/generators/environment/environment.generator.ts @@ -12,16 +12,10 @@ import { WorkflowModels } from '@kontent-ai/management-sdk'; import { match } from 'ts-pattern'; -import { - FlattenedElement, - GeneratedFile, - getFlattenedElements, - getStringOrUndefined, - toGuidelinesComment, - toSafePropertyName, - toSafePropertyValue, - wrapComment -} from '../../core/index.js'; +import { wrapComment } from '../../core/comment.utils.js'; +import { FlattenedElement, GeneratedFile } from '../../core/core.models.js'; +import { getStringOrUndefined, toGuidelinesComment, toSafePropertyName, toSafePropertyValue } from '../../core/core.utils.js'; +import { getFlattenedElements } from '../../core/element.utils.js'; interface WorkflowStep { readonly name: string; diff --git a/lib/generators/index.ts b/lib/generators/index.ts deleted file mode 100644 index c78743e..0000000 --- a/lib/generators/index.ts +++ /dev/null @@ -1,16 +0,0 @@ -// delivery -export * from './delivery/delivery-content-type.generator.js'; -export * from './delivery/delivery-func.js'; -export * from './delivery/delivery-taxonomy.generator.js'; - -// project -export * from './environment/environment-func.js'; -export * from './environment/environment.generator.js'; - -// migration -export * from './migration/migration-func.js'; -export * from './migration/migration.generator.js'; - -// items -export * from './items/items-func.js'; -export * from './items/items.generator.js'; diff --git a/lib/generators/items/items-func.ts b/lib/generators/items/items-func.ts index fe59196..f90b951 100644 --- a/lib/generators/items/items-func.ts +++ b/lib/generators/items/items-func.ts @@ -2,15 +2,11 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; import { coreConfig, itemsConfig } from '../../config.js'; -import { - importer as _importer, - GeneratedFile, - getDefaultModuleResolution, - getFilenameFromPath, - ModuleResolution -} from '../../core/index.js'; -import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; -import { fileManager as _fileManager } from '../../files/index.js'; +import { GeneratedFile, ModuleResolution } from '../../core/core.models.js'; +import { getDefaultModuleResolution, getFilenameFromPath } from '../../core/core.utils.js'; +import { importer as _importer } from '../../core/importer.js'; +import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; +import { fileManager as _fileManager } from '../../files/file-manager.js'; import { itemsGenerator as _itemsGenerator } from './items.generator.js'; export interface GenerateItemsModelsConfig { diff --git a/lib/generators/items/items.generator.ts b/lib/generators/items/items.generator.ts index a9de068..b1713ad 100644 --- a/lib/generators/items/items.generator.ts +++ b/lib/generators/items/items.generator.ts @@ -1,6 +1,8 @@ import { ContentItemModels, ContentTypeModels, EnvironmentModels } from '@kontent-ai/management-sdk'; import { itemsConfig } from '../../config.js'; -import { GeneratedFile, ModuleResolution, toPascalCase, toSafeComment, wrapComment } from '../../core/index.js'; +import { toSafeComment, wrapComment } from '../../core/comment.utils.js'; +import { GeneratedFile, ModuleResolution } from '../../core/core.models.js'; +import { toPascalCase } from '../../core/core.utils.js'; export interface ItemGeneratorConfig { readonly moduleResolution: ModuleResolution; diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index 00928f9..c5e227c 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -2,15 +2,11 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; import { coreConfig, migrationConfig } from '../../config.js'; -import { - importer as _importer, - GeneratedFile, - getDefaultModuleResolution, - getFilenameFromPath, - ModuleResolution -} from '../../core/index.js'; -import { kontentFetcher as _kontentFetcher } from '../../fetch/index.js'; -import { fileManager as _fileManager } from '../../files/index.js'; +import { GeneratedFile, ModuleResolution } from '../../core/core.models.js'; +import { getDefaultModuleResolution, getFilenameFromPath } from '../../core/core.utils.js'; +import { importer as _importer } from '../../core/importer.js'; +import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; +import { fileManager as _fileManager } from '../../files/file-manager.js'; import { migrationGenerator as _migrationGenerator } from './migration.generator.js'; export interface GenerateMigrationModelsConfig { diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index 35a4a93..898e8e0 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -9,16 +9,11 @@ import { } from '@kontent-ai/management-sdk'; import { match } from 'ts-pattern'; import { migrationConfig, sharedTypesConfig } from '../../config.js'; -import { - importer as _importer, - FlattenedElement, - GeneratedFile, - getFlattenedElements, - ModuleResolution, - toGuidelinesComment, - toPascalCase, - wrapComment -} from '../../core/index.js'; +import { wrapComment } from '../../core/comment.utils.js'; +import { FlattenedElement, GeneratedFile, ModuleResolution } from '../../core/core.models.js'; +import { toGuidelinesComment, toPascalCase } from '../../core/core.utils.js'; +import { getFlattenedElements } from '../../core/element.utils.js'; +import { importer as _importer } from '../../core/importer.js'; import { getCollectionCodenamesType, getContentTypeCodenamesType, diff --git a/lib/index.ts b/lib/index.ts deleted file mode 100644 index cf601bb..0000000 --- a/lib/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './core/index.js'; -export * from './fetch/index.js'; -export * from './files/index.js'; -export * from './format/index.js'; -export * from './generators/index.js'; diff --git a/lib/meta/index.ts b/lib/meta/index.ts deleted file mode 100644 index fc7693b..0000000 --- a/lib/meta/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './metadata.js'; diff --git a/lib/node/cli/actions/delivery-action.ts b/lib/node/cli/actions/delivery-action.ts index 40520d4..727b4cc 100644 --- a/lib/node/cli/actions/delivery-action.ts +++ b/lib/node/cli/actions/delivery-action.ts @@ -1,5 +1,5 @@ -import { ModuleResolution } from '../../../core/index.js'; -import { generateDeliveryModelsAsync } from '../../../generators/index.js'; +import { ModuleResolution } from '../../../core/core.models.js'; +import { generateDeliveryModelsAsync } from '../../../generators/delivery/delivery-func.js'; import { CliArgumentsFetcher } from '../cli.models.js'; export async function deliveryActionAsync(cliFetcher: CliArgumentsFetcher): Promise { diff --git a/lib/node/cli/actions/environment-action.ts b/lib/node/cli/actions/environment-action.ts index ddca2be..f9fec92 100644 --- a/lib/node/cli/actions/environment-action.ts +++ b/lib/node/cli/actions/environment-action.ts @@ -1,5 +1,5 @@ -import { ModuleResolution } from '../../../core/index.js'; -import { generateEnvironmentModelsAsync } from '../../../generators/index.js'; +import { ModuleResolution } from '../../../core/core.models.js'; +import { generateEnvironmentModelsAsync } from '../../../generators/environment/environment-func.js'; import { CliArgumentsFetcher } from '../cli.models.js'; export async function environmentActionAsync(cliFetcher: CliArgumentsFetcher): Promise { diff --git a/lib/node/cli/actions/items-action.ts b/lib/node/cli/actions/items-action.ts index 726e4f6..95493f2 100644 --- a/lib/node/cli/actions/items-action.ts +++ b/lib/node/cli/actions/items-action.ts @@ -1,5 +1,5 @@ -import { ModuleResolution } from '../../../core/index.js'; -import { generateItemsAsync } from '../../../generators/index.js'; +import { ModuleResolution } from '../../../core/core.models.js'; +import { generateItemsAsync } from '../../../generators/items/items-func.js'; import { CliArgumentsFetcher } from '../cli.models.js'; export async function itemsActionAsync(cliFetcher: CliArgumentsFetcher): Promise { diff --git a/lib/node/cli/actions/migrate-action.ts b/lib/node/cli/actions/migrate-action.ts index 0b596c1..28a0acf 100644 --- a/lib/node/cli/actions/migrate-action.ts +++ b/lib/node/cli/actions/migrate-action.ts @@ -1,5 +1,5 @@ -import { ModuleResolution } from '../../../core/index.js'; -import { generateMigrationModelsAsync } from '../../../generators/index.js'; +import { ModuleResolution } from '../../../core/core.models.js'; +import { generateMigrationModelsAsync } from '../../../generators/migration/migration-func.js'; import { CliArgumentsFetcher } from '../cli.models.js'; export async function migrateActionAsync(cliFetcher: CliArgumentsFetcher): Promise { diff --git a/lib/node/cli/app.ts b/lib/node/cli/app.ts index 0cf293f..467a086 100644 --- a/lib/node/cli/app.ts +++ b/lib/node/cli/app.ts @@ -2,7 +2,7 @@ import chalk from 'chalk'; import { match } from 'ts-pattern'; -import { handleError } from '../../core/index.js'; +import { handleError } from '../../core/error.utils.js'; import { deliveryActionAsync } from './actions/delivery-action.js'; import { environmentActionAsync } from './actions/environment-action.js'; import { itemsActionAsync } from './actions/items-action.js'; diff --git a/lib/node/cli/cli.models.ts b/lib/node/cli/cli.models.ts index c43d162..50e1acf 100644 --- a/lib/node/cli/cli.models.ts +++ b/lib/node/cli/cli.models.ts @@ -1,4 +1,4 @@ -import { CliAction } from '../../core/index.js'; +import { CliAction } from '../../core/core.models.js'; export interface Command { readonly name: string; diff --git a/lib/node/cli/commands.ts b/lib/node/cli/commands.ts index 8a92c05..270e9b6 100644 --- a/lib/node/cli/commands.ts +++ b/lib/node/cli/commands.ts @@ -1,4 +1,4 @@ -import { getCliAction, getLibrary, getModuleResolution } from '../../core/index.js'; +import { getCliAction, getLibrary, getModuleResolution } from '../../core/core.utils.js'; import { argumentsSetter } from './args/args-setter.js'; import { CommandOption } from './cli.models.js'; diff --git a/lib/public_api.ts b/lib/public_api.ts new file mode 100644 index 0000000..8ca89d4 --- /dev/null +++ b/lib/public_api.ts @@ -0,0 +1,8 @@ +/* + * Public API + */ +export { CaseType, ModuleResolution } from './core/core.models.js'; +export { GenerateDeliveryModelsConfig, generateDeliveryModelsAsync } from './generators/delivery/delivery-func.js'; +export { GenerateEnvironmentModelsConfig, generateEnvironmentModelsAsync } from './generators/environment/environment-func.js'; +export { GenerateItemsModelsConfig, generateItemsAsync } from './generators/items/items-func.js'; +export { GenerateMigrationModelsConfig, generateMigrationModelsAsync } from './generators/migration/migration-func.js'; diff --git a/package.json b/package.json index c091e4b..7d1a411 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,8 @@ "Kontent.ai strongly typed models" ], "preferGlobal": true, - "exports": "./dist/es2022/lib/index.js", - "types": "./dist/es2022/lib/index.d.ts", + "exports": "./dist/es2022/lib/public_api.js", + "types": "./dist/es2022/lib/public_api.d.ts", "type": "module", "scripts": { "release": "standard-version && npm run update:version", diff --git a/scripts/tests/delivery-models.ts b/scripts/tests/delivery-models.ts index 149b161..4178f7a 100644 --- a/scripts/tests/delivery-models.ts +++ b/scripts/tests/delivery-models.ts @@ -1,7 +1,9 @@ import chalk from 'chalk'; import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; -import { ModuleResolution, generateDeliveryModelsAsync, handleError } from '../../lib/index.js'; +import { ModuleResolution } from '../../lib/core/core.models.js'; +import { handleError } from '../../lib/core/error.utils.js'; +import { generateDeliveryModelsAsync } from '../../lib/generators/delivery/delivery-func.js'; import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; const outputDir: string = './sample/delivery'; diff --git a/scripts/tests/environment-models.ts b/scripts/tests/environment-models.ts index 83716d3..0216712 100644 --- a/scripts/tests/environment-models.ts +++ b/scripts/tests/environment-models.ts @@ -1,7 +1,9 @@ import chalk from 'chalk'; import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; -import { ModuleResolution, generateEnvironmentModelsAsync, handleError } from '../../lib/index.js'; +import { ModuleResolution } from '../../lib/core/core.models.js'; +import { handleError } from '../../lib/core/error.utils.js'; +import { generateEnvironmentModelsAsync } from '../../lib/generators/environment/environment-func.js'; import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; const outputDir: string = './sample/environment'; diff --git a/scripts/tests/item-models.ts b/scripts/tests/item-models.ts index 7f28a05..484e409 100644 --- a/scripts/tests/item-models.ts +++ b/scripts/tests/item-models.ts @@ -1,7 +1,9 @@ import chalk from 'chalk'; import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; -import { ModuleResolution, generateItemsAsync, handleError } from '../../lib/index.js'; +import { ModuleResolution } from '../../lib/core/core.models.js'; +import { handleError } from '../../lib/core/error.utils.js'; +import { generateItemsAsync } from '../../lib/generators/items/items-func.js'; import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; const outputDir: string = './sample/items'; diff --git a/scripts/tests/migration-models.ts b/scripts/tests/migration-models.ts index e4dda87..8cc8592 100644 --- a/scripts/tests/migration-models.ts +++ b/scripts/tests/migration-models.ts @@ -1,7 +1,9 @@ import chalk from 'chalk'; import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; -import { ModuleResolution, generateMigrationModelsAsync, handleError } from '../../lib/index.js'; +import { ModuleResolution } from '../../lib/core/core.models.js'; +import { handleError } from '../../lib/core/error.utils.js'; +import { generateMigrationModelsAsync } from '../../lib/generators/migration/migration-func.js'; import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; const outputDir: string = './sample/migration'; From ab117d92982597b9d16d4ef0f18931e741742f36 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 12 Sep 2024 10:33:01 +0200 Subject: [PATCH 093/183] Update config.ts --- lib/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/config.ts b/lib/config.ts index c0204d8..5a76ac3 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -8,7 +8,7 @@ export const sharedTypesConfig = { workflowCodenames: 'WorkflowCodenames', workflowStepCodenames: 'WorkflowStepCodenames', contentTypeCodenames: 'ContentTypeCodenames' -}; +} as const; export const migrationConfig = { npmPackageName: '@kontent-ai/migration-toolkit', From 407c9e66031640da4befe75c8c1a77fc584c6cbf Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 12 Sep 2024 10:34:24 +0200 Subject: [PATCH 094/183] Use config value for barrel export filename --- .../delivery/delivery-content-type.generator.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 7f1b341..57c1d06 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -9,7 +9,7 @@ import { } from '@kontent-ai/management-sdk'; import { isNotUndefined } from '@kontent-ai/migration-toolkit'; import { match, P } from 'ts-pattern'; -import { deliveryConfig, sharedTypesConfig } from '../../config.js'; +import { coreConfig, deliveryConfig, sharedTypesConfig } from '../../config.js'; import { wrapComment } from '../../core/comment.utils.js'; import { FlattenedElement, GeneratedFile, ModuleResolution } from '../../core/core.models.js'; import { sortAlphabetically, toGuidelinesComment, uniqueFilter } from '../../core/core.utils.js'; @@ -105,7 +105,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato return [ importer.importType({ - filePathOrPackage: `../${deliveryConfig.contentTypeSnippetsFolderName}/index.ts`, + filePathOrPackage: `../${deliveryConfig.contentTypeSnippetsFolderName}/${coreConfig.barrelExportFilename}`, importValue: snippets .map((snippet) => nameResolvers.snippet(snippet)) .map((m) => m) @@ -149,8 +149,8 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato importer.importType({ filePathOrPackage: typeOrSnippet instanceof ContentTypeSnippetModels.ContentTypeSnippet - ? `../${deliveryConfig.contentTypesFolderName}/index.ts` - : `./index.ts`, + ? `../${deliveryConfig.contentTypesFolderName}/${coreConfig.barrelExportFilename}` + : `./${coreConfig.barrelExportFilename}`, importValue: referencedTypeNames.join(', ') }) ]; @@ -181,7 +181,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato return [ importer.importType({ - filePathOrPackage: `../${deliveryConfig.taxonomiesFolderName}/index.ts`, + filePathOrPackage: `../${deliveryConfig.taxonomiesFolderName}/${coreConfig.barrelExportFilename}`, importValue: taxonomyTypeNames.join(', ') }) ]; From bd05c168cf8fd44f05d94efc51ef7a5565c7ada9 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 16 Sep 2024 10:40:48 +0200 Subject: [PATCH 095/183] updates deps --- package-lock.json | 24 ++++++++++++------------ package.json | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index cf7508f..ad0c0c1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "7.3.0", "license": "MIT", "dependencies": { - "@kontent-ai/delivery-sdk": "15.0.0-0", + "@kontent-ai/delivery-sdk": "15.0.0", "@kontent-ai/management-sdk": "7.2.0", "@kontent-ai/migration-toolkit": "1.5.1", "chalk": "5.3.0", @@ -22,14 +22,14 @@ }, "devDependencies": { "@types/eslint__js": "8.42.3", - "@types/node": "22.5.4", + "@types/node": "22.5.5", "@types/yargs": "17.0.33", "@typescript-eslint/eslint-plugin": "8.5.0", "@typescript-eslint/parser": "8.5.0", "dotenv-cli": "7.4.2", "eslint": "9.10.0", "standard-version": "9.5.0", - "tsx": "4.19.0", + "tsx": "4.19.1", "typescript": "5.6.2", "typescript-eslint": "8.5.0" }, @@ -722,9 +722,9 @@ } }, "node_modules/@kontent-ai/delivery-sdk": { - "version": "15.0.0-0", - "resolved": "https://registry.npmjs.org/@kontent-ai/delivery-sdk/-/delivery-sdk-15.0.0-0.tgz", - "integrity": "sha512-kZN6i/m9ty+FHPYsvMqf1qbT2ZBcO9it+5NomIylBeDDI/LedleAR3wc5MZ/kWny7LPzwQFOd4qitnMPnNAnOw==", + "version": "15.0.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/delivery-sdk/-/delivery-sdk-15.0.0.tgz", + "integrity": "sha512-3JS+4ywOewkrHYwyiH2/Q7E3+3Ou/0XrrQ+Jrx1jYN5BKlFosaAZcperH6zbQihqd11tIeE7lZu4BqoZdntS+Q==", "dependencies": { "@kontent-ai/core-sdk": "10.7.0", "url-parse": "1.5.10", @@ -861,9 +861,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.5.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.4.tgz", - "integrity": "sha512-FDuKUJQm/ju9fT/SeX/6+gBzoPzlVCzfzmGkwKvRHQVxi4BntVbyIwf6a4Xn62mrvndLiml6z/UBXIdEVjQLXg==", + "version": "22.5.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.5.tgz", + "integrity": "sha512-Xjs4y5UPO/CLdzpgR6GirZJx36yScjh73+2NlLlkFRSoQN8B0DpfXPdZGnvVmLRLOsqDpOfTNv7D9trgGhmOIA==", "dev": true, "dependencies": { "undici-types": "~6.19.2" @@ -5106,9 +5106,9 @@ "integrity": "sha512-1RUMKa8jYQdNfmnK4jyzBK3/PS/tnjcZ1CW0v1vWDeYe5RBklc/nquw03MEoB66hVBm4BnlCfmOqDVxHyT1DpA==" }, "node_modules/tsx": { - "version": "4.19.0", - "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.19.0.tgz", - "integrity": "sha512-bV30kM7bsLZKZIOCHeMNVMJ32/LuJzLVajkQI/qf92J2Qr08ueLQvW00PUZGiuLPP760UINwupgUj8qrSCPUKg==", + "version": "4.19.1", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.19.1.tgz", + "integrity": "sha512-0flMz1lh74BR4wOvBjuh9olbnwqCPc35OOlfyzHba0Dc+QNUeWX/Gq2YTbnwcWPO3BMd8fkzRVrHcsR+a7z7rA==", "dev": true, "dependencies": { "esbuild": "~0.23.0", diff --git a/package.json b/package.json index 7d1a411..bac7f10 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "yargs": "17.7.2", "prettier": "3.3.3", "chalk": "5.3.0", - "@kontent-ai/delivery-sdk": "15.0.0-0", + "@kontent-ai/delivery-sdk": "15.0.0", "@kontent-ai/management-sdk": "7.2.0", "@kontent-ai/migration-toolkit": "1.5.1", "ts-pattern": "5.3.1" @@ -63,13 +63,13 @@ "@types/yargs": "17.0.33", "standard-version": "9.5.0", "typescript": "5.6.2", - "@types/node": "22.5.4", + "@types/node": "22.5.5", "@types/eslint__js": "8.42.3", "@typescript-eslint/eslint-plugin": "8.5.0", "typescript-eslint": "8.5.0", "@typescript-eslint/parser": "8.5.0", "eslint": "9.10.0", - "tsx": "4.19.0", + "tsx": "4.19.1", "dotenv-cli": "7.4.2" } } From 9bea623212206f748ddf05d35fab2456192d1df5 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 16 Sep 2024 11:31:57 +0200 Subject: [PATCH 096/183] chore(release): 8.0.0-0 --- CHANGELOG.md | 11 +++++++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92e67ab..cc3f054 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [8.0.0-0](https://github.com/kontent-ai/model-generator-js/compare/v7.4.0...v8.0.0-0) (2024-09-16) + + +### ⚠ BREAKING CHANGES + +* Separates Delivery & Project models + +### Features + +* Separates Delivery & Project models ([a28ec19](https://github.com/kontent-ai/model-generator-js/commit/a28ec195fe0c361a2e75316fd2ea732d1aea1c05)) + ## [7.4.0](https://github.com/kontent-ai/model-generator-js/compare/v7.3.0...v7.4.0) (2024-08-15) diff --git a/package-lock.json b/package-lock.json index ad0c0c1..96b8109 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kontent-ai/model-generator", - "version": "7.3.0", + "version": "8.0.0-0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@kontent-ai/model-generator", - "version": "7.3.0", + "version": "8.0.0-0", "license": "MIT", "dependencies": { "@kontent-ai/delivery-sdk": "15.0.0", diff --git a/package.json b/package.json index bac7f10..cefe39a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kontent-ai/model-generator", - "version": "7.3.0", + "version": "8.0.0-0", "description": "This utility generates strongly-typed models based on Content Types in a Kontent.ai project. These models can be used with SDKs", "bin": { "kontent-generate": "./dist/es2022/lib/code/app.js" From 183ab24d83d0a8f690ab0c21aea73ee309094cbf Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 16 Sep 2024 11:32:23 +0200 Subject: [PATCH 097/183] Update metadata.ts --- lib/meta/metadata.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/meta/metadata.ts b/lib/meta/metadata.ts index 0281976..f1512cd 100644 --- a/lib/meta/metadata.ts +++ b/lib/meta/metadata.ts @@ -1,6 +1,6 @@ export const libMetadata = { name: '@kontent-ai/model-generator', - timestamp: 'Thu, 15 Aug 2024 09:05:18 GMT', - version: '7.4.0' + timestamp: Mon, 16 Sep 2024 09:31:58 GMT, + version: '8.0.0-0' }; From f8871a5e805e00dda531650148d0b6ac14b8fc34 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 16 Sep 2024 11:33:43 +0200 Subject: [PATCH 098/183] Fixes update version script --- lib/meta/metadata.ts | 5 ++--- scripts/update-version.ts | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/meta/metadata.ts b/lib/meta/metadata.ts index f1512cd..21c3b7a 100644 --- a/lib/meta/metadata.ts +++ b/lib/meta/metadata.ts @@ -1,6 +1,5 @@ - export const libMetadata = { - name: '@kontent-ai/model-generator', - timestamp: Mon, 16 Sep 2024 09:31:58 GMT, + name: '@kontent-ai/model-generator', + timestamp: 'Mon, 16 Sep 2024 09:31:58 GMT', version: '8.0.0-0' }; diff --git a/scripts/update-version.ts b/scripts/update-version.ts index 148afe2..d82e176 100644 --- a/scripts/update-version.ts +++ b/scripts/update-version.ts @@ -15,7 +15,7 @@ function createVersionFile(date: Date, filePath: string, propertyName: string): const src = ` export const ${propertyName} = { name: '${PackageJson.name}', - timestamp: ${date.toUTCString()}, + timestamp: '${date.toUTCString()}', version: '${PackageJson.version}' }; `; From 3b9268918de67a99bbc0831adf7fc17d76917723 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 16 Sep 2024 14:01:54 +0200 Subject: [PATCH 099/183] fix: Adds missing references for RichTextElement --- .../delivery-content-type.generator.ts | 29 ++++++++++--------- .../delivery/content-type-snippets/index.ts | 2 +- sample/delivery/content-types/actor.ts | 2 +- sample/delivery/content-types/index.ts | 2 +- sample/delivery/content-types/movie.ts | 2 +- sample/delivery/index.ts | 2 +- sample/delivery/system/delivery.codenames.ts | 2 +- sample/delivery/system/index.ts | 2 +- sample/delivery/taxonomies/index.ts | 2 +- sample/delivery/taxonomies/movietype.ts | 2 +- sample/delivery/taxonomies/releasecategory.ts | 2 +- 11 files changed, 26 insertions(+), 23 deletions(-) diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 57c1d06..1adfba3 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -122,19 +122,22 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato .map((flattenedElement) => { return match(flattenedElement) .returnType() - .with(P.union({ type: 'modular_content' }, { type: 'subpages' }), (linkedItemsOrSubpagesElement) => { - return (linkedItemsOrSubpagesElement.allowedContentTypes ?? []) - .filter((allowedContentType) => { - // filter self-referencing types as they do not need to be importer - if (allowedContentType.codename === typeOrSnippet.codename) { - return false; - } - return true; - }) - .map((allowedContentType) => { - return nameResolvers.contentType(allowedContentType); - }); - }) + .with( + P.union({ type: 'modular_content' }, { type: 'subpages' }, { type: 'rich_text' }), + (alementWithAllowedContentTypes) => { + return (alementWithAllowedContentTypes.allowedContentTypes ?? []) + .filter((allowedContentType) => { + // filter self-referencing types as they do not need to be importer + if (allowedContentType.codename === typeOrSnippet.codename) { + return false; + } + return true; + }) + .map((allowedContentType) => { + return nameResolvers.contentType(allowedContentType); + }); + } + ) .otherwise(() => []); }) .flatMap((m) => m) diff --git a/sample/delivery/content-type-snippets/index.ts b/sample/delivery/content-type-snippets/index.ts index f13c990..0f798e7 100644 --- a/sample/delivery/content-type-snippets/index.ts +++ b/sample/delivery/content-type-snippets/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index e4c2530..c0b7a90 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/delivery/content-types/index.ts b/sample/delivery/content-types/index.ts index 3116ea2..c05bf8f 100644 --- a/sample/delivery/content-types/index.ts +++ b/sample/delivery/content-types/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 65870e1..501df3d 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/delivery/index.ts b/sample/delivery/index.ts index e5c5d7a..05f9c38 100644 --- a/sample/delivery/index.ts +++ b/sample/delivery/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/delivery/system/delivery.codenames.ts b/sample/delivery/system/delivery.codenames.ts index 1cd61c2..4419167 100644 --- a/sample/delivery/system/delivery.codenames.ts +++ b/sample/delivery/system/delivery.codenames.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/delivery/system/index.ts b/sample/delivery/system/index.ts index 4ddfa2c..f68040f 100644 --- a/sample/delivery/system/index.ts +++ b/sample/delivery/system/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/delivery/taxonomies/index.ts b/sample/delivery/taxonomies/index.ts index 4948198..823ef58 100644 --- a/sample/delivery/taxonomies/index.ts +++ b/sample/delivery/taxonomies/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/delivery/taxonomies/movietype.ts b/sample/delivery/taxonomies/movietype.ts index 0c9090e..5d70baf 100644 --- a/sample/delivery/taxonomies/movietype.ts +++ b/sample/delivery/taxonomies/movietype.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/delivery/taxonomies/releasecategory.ts b/sample/delivery/taxonomies/releasecategory.ts index d710eec..ab76cad 100644 --- a/sample/delivery/taxonomies/releasecategory.ts +++ b/sample/delivery/taxonomies/releasecategory.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * From 8e01505ae91121409debec73e741bd9efcc6e73a Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 16 Sep 2024 14:02:11 +0200 Subject: [PATCH 100/183] chore(release): 8.0.0-1 --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc3f054..39f2050 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [8.0.0-1](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-0...v8.0.0-1) (2024-09-16) + + +### Bug Fixes + +* Adds missing references for RichTextElement ([3b92689](https://github.com/kontent-ai/model-generator-js/commit/3b9268918de67a99bbc0831adf7fc17d76917723)) + ## [8.0.0-0](https://github.com/kontent-ai/model-generator-js/compare/v7.4.0...v8.0.0-0) (2024-09-16) diff --git a/package-lock.json b/package-lock.json index 96b8109..6858ce3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-0", + "version": "8.0.0-1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@kontent-ai/model-generator", - "version": "8.0.0-0", + "version": "8.0.0-1", "license": "MIT", "dependencies": { "@kontent-ai/delivery-sdk": "15.0.0", diff --git a/package.json b/package.json index cefe39a..3a1a2e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-0", + "version": "8.0.0-1", "description": "This utility generates strongly-typed models based on Content Types in a Kontent.ai project. These models can be used with SDKs", "bin": { "kontent-generate": "./dist/es2022/lib/code/app.js" From 1f177de0bf0b6f6aab6e063da997a8d948e9fa64 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 16 Sep 2024 14:02:33 +0200 Subject: [PATCH 101/183] chore(release): 8.0.0-2 --- CHANGELOG.md | 2 ++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39f2050..8c9826a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [8.0.0-2](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-1...v8.0.0-2) (2024-09-16) + ## [8.0.0-1](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-0...v8.0.0-1) (2024-09-16) diff --git a/package-lock.json b/package-lock.json index 6858ce3..90b0239 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-1", + "version": "8.0.0-2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@kontent-ai/model-generator", - "version": "8.0.0-1", + "version": "8.0.0-2", "license": "MIT", "dependencies": { "@kontent-ai/delivery-sdk": "15.0.0", diff --git a/package.json b/package.json index 3a1a2e8..89e0c29 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-1", + "version": "8.0.0-2", "description": "This utility generates strongly-typed models based on Content Types in a Kontent.ai project. These models can be used with SDKs", "bin": { "kontent-generate": "./dist/es2022/lib/code/app.js" From a537a8d89a0c3d13ffeaa6bd6d8564af4836b88c Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Thu, 26 Sep 2024 11:24:09 +0200 Subject: [PATCH 102/183] updates deps & moves delivery-sdk/migration-toolkit to dev deps --- package-lock.json | 390 ++++++++++++++++++++++++++++++++++------------ package.json | 18 +-- 2 files changed, 298 insertions(+), 110 deletions(-) diff --git a/package-lock.json b/package-lock.json index 90b0239..e38424e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,29 +9,29 @@ "version": "8.0.0-2", "license": "MIT", "dependencies": { - "@kontent-ai/delivery-sdk": "15.0.0", - "@kontent-ai/management-sdk": "7.2.0", - "@kontent-ai/migration-toolkit": "1.5.1", + "@kontent-ai/management-sdk": "7.3.0", "chalk": "5.3.0", "prettier": "3.3.3", - "ts-pattern": "5.3.1", + "ts-pattern": "5.4.0", "yargs": "17.7.2" }, "bin": { "kontent-generate": "dist/es2022/lib/code/app.js" }, "devDependencies": { + "@kontent-ai/delivery-sdk": "15.1.0", + "@kontent-ai/migration-toolkit": "1.5.1", "@types/eslint__js": "8.42.3", - "@types/node": "22.5.5", + "@types/node": "22.7.2", "@types/yargs": "17.0.33", - "@typescript-eslint/eslint-plugin": "8.5.0", - "@typescript-eslint/parser": "8.5.0", + "@typescript-eslint/eslint-plugin": "8.7.0", + "@typescript-eslint/parser": "8.7.0", "dotenv-cli": "7.4.2", - "eslint": "9.10.0", + "eslint": "9.11.1", "standard-version": "9.5.0", "tsx": "4.19.1", "typescript": "5.6.2", - "typescript-eslint": "8.5.0" + "typescript-eslint": "8.7.0" }, "engines": { "node": ">= 20" @@ -589,6 +589,15 @@ "node": "*" } }, + "node_modules/@eslint/core": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.6.0.tgz", + "integrity": "sha512-8I2Q8ykA4J0x0o7cg67FPVnehcqWTBehu/lmY+bolPFHGjh49YzGBMXTvpqVgEbBdvNCSxj6iFgiIyHzf03lzg==", + "dev": true, + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + } + }, "node_modules/@eslint/eslintrc": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-3.1.0.tgz", @@ -635,9 +644,9 @@ } }, "node_modules/@eslint/js": { - "version": "9.10.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.10.0.tgz", - "integrity": "sha512-fuXtbiP5GWIn8Fz+LWoOMVf/Jxm+aajZYkhi6CuEm4SxymFM+eUWzbO9qXT+L0iCkL5+KGYMCSGxo686H19S1g==", + "version": "9.11.1", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.11.1.tgz", + "integrity": "sha512-/qu+TWz8WwPWc7/HcIJKi+c+MOm46GdVaSlTTQcaqaL53+GsoA6MxWp5PtTx48qbSP7ylM1Kn7nhvkugfJvRSA==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -653,9 +662,9 @@ } }, "node_modules/@eslint/plugin-kit": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.1.0.tgz", - "integrity": "sha512-autAXT203ixhqei9xt+qkYOvY8l6LAFIdT2UXc/RPNeUVfqRF1BV94GTJyVPFKT8nFM6MyVJhjLj9E8JWvf5zQ==", + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@eslint/plugin-kit/-/plugin-kit-0.2.0.tgz", + "integrity": "sha512-vH9PiIMMwvhCx31Af3HiGzsVNULDbyVkHXwlemn/B0TFj/00ho3y55efXrUZTfQipxoHC5u4xq6zblww1zm1Ig==", "dev": true, "dependencies": { "levn": "^0.4.1" @@ -703,6 +712,7 @@ "version": "0.0.7", "resolved": "https://registry.npmjs.org/@kontent-ai-consulting/tools-analytics/-/tools-analytics-0.0.7.tgz", "integrity": "sha512-grkW8hEe4vij3R5uZ0K4DuQiR1HvJhdPqoTF/z/q++8xA2X0X0orgRLbWNgyC9XYuSUiCbojmT64zBJf32RKkw==", + "dev": true, "dependencies": { "@kontent-ai/core-sdk": "10.7.0" }, @@ -714,6 +724,7 @@ "version": "10.7.0", "resolved": "https://registry.npmjs.org/@kontent-ai/core-sdk/-/core-sdk-10.7.0.tgz", "integrity": "sha512-NNS1jatzMzp+XBWNc45bcbZjTFTs4szAFJxKn9oj/4p4+ZXucqYXBs88KCUotXmCCcoeUiFAFn8aQUF2aiTM+Q==", + "dev": true, "dependencies": { "axios": "1.7.4" }, @@ -722,11 +733,12 @@ } }, "node_modules/@kontent-ai/delivery-sdk": { - "version": "15.0.0", - "resolved": "https://registry.npmjs.org/@kontent-ai/delivery-sdk/-/delivery-sdk-15.0.0.tgz", - "integrity": "sha512-3JS+4ywOewkrHYwyiH2/Q7E3+3Ou/0XrrQ+Jrx1jYN5BKlFosaAZcperH6zbQihqd11tIeE7lZu4BqoZdntS+Q==", + "version": "15.1.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/delivery-sdk/-/delivery-sdk-15.1.0.tgz", + "integrity": "sha512-z/Wfp71eb0eqqjnptSktN/5zE9QKIhtPFc6pv+nXFuAt+ZpJRp04+df9c+rKHxLtfXPiQSkIfxJgqkGeAuK3jQ==", + "dev": true, "dependencies": { - "@kontent-ai/core-sdk": "10.7.0", + "@kontent-ai/core-sdk": "10.8.0", "url-parse": "1.5.10", "uuid": "10.0.0" }, @@ -734,22 +746,67 @@ "node": ">= 20" } }, + "node_modules/@kontent-ai/delivery-sdk/node_modules/@kontent-ai/core-sdk": { + "version": "10.8.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/core-sdk/-/core-sdk-10.8.0.tgz", + "integrity": "sha512-6o5kn+ANhJ7vCucWXunxy1qCSSDsN3F86zdLXzPnFaK/qOf4BJGnPda81Alvnt4N7n4e1m9J7uP0tm3tQ/W25Q==", + "dev": true, + "dependencies": { + "axios": "1.7.7" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@kontent-ai/delivery-sdk/node_modules/axios": { + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "dev": true, + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/@kontent-ai/management-sdk": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@kontent-ai/management-sdk/-/management-sdk-7.2.0.tgz", - "integrity": "sha512-vfEzmQDrDdKj+4evxoCjBE/Cpr5FT1L7KdOjwISk5MSaQsUxl8hrBYL7UDo8ln/J5LIO/6aOwxJ7aY4yAwI9yw==", + "version": "7.3.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/management-sdk/-/management-sdk-7.3.0.tgz", + "integrity": "sha512-CUIP+ux6W5guOkCO0U+z0XPUyzFYio35cIHhwf+0/o5RntXM6ubYCdpl/kgna1tpexiTnYovtqc8mvcmFm6Cng==", "dependencies": { - "@kontent-ai/core-sdk": "10.7.0", + "@kontent-ai/core-sdk": "10.8.0", "mime": "3.0.0" }, "engines": { "node": ">= 20" } }, + "node_modules/@kontent-ai/management-sdk/node_modules/@kontent-ai/core-sdk": { + "version": "10.8.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/core-sdk/-/core-sdk-10.8.0.tgz", + "integrity": "sha512-6o5kn+ANhJ7vCucWXunxy1qCSSDsN3F86zdLXzPnFaK/qOf4BJGnPda81Alvnt4N7n4e1m9J7uP0tm3tQ/W25Q==", + "dependencies": { + "axios": "1.7.7" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@kontent-ai/management-sdk/node_modules/axios": { + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/@kontent-ai/migration-toolkit": { "version": "1.5.1", "resolved": "https://registry.npmjs.org/@kontent-ai/migration-toolkit/-/migration-toolkit-1.5.1.tgz", "integrity": "sha512-gj7twSzCIiA8L4UF5CUBg/hHHcG8USnTOR+iJnFyd+YksK9fXqZLXpB9Js1UE6wCdBmBtEC9DzjCSEv2XLdFCg==", + "dev": true, "dependencies": { "@kontent-ai-consulting/tools-analytics": "0.0.7", "@kontent-ai/management-sdk": "7.2.0", @@ -774,10 +831,36 @@ "node": ">=20" } }, + "node_modules/@kontent-ai/migration-toolkit/node_modules/@kontent-ai/management-sdk": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/management-sdk/-/management-sdk-7.2.0.tgz", + "integrity": "sha512-vfEzmQDrDdKj+4evxoCjBE/Cpr5FT1L7KdOjwISk5MSaQsUxl8hrBYL7UDo8ln/J5LIO/6aOwxJ7aY4yAwI9yw==", + "dev": true, + "dependencies": { + "@kontent-ai/core-sdk": "10.7.0", + "mime": "3.0.0" + }, + "engines": { + "node": ">= 20" + } + }, + "node_modules/@kontent-ai/migration-toolkit/node_modules/@kontent-ai/management-sdk/node_modules/mime": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz", + "integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==", + "dev": true, + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/@kontent-ai/migration-toolkit/node_modules/mime": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/mime/-/mime-4.0.4.tgz", "integrity": "sha512-v8yqInVjhXyqP6+Kw4fV3ZzeMRqEW6FotRsKXjRS5VMTNIuXsdRoAvklpoRgSqXm6o9VNH4/C0mgedko9DdLsQ==", + "dev": true, "funding": [ "https://github.com/sponsors/broofa" ], @@ -788,6 +871,12 @@ "node": ">=16" } }, + "node_modules/@kontent-ai/migration-toolkit/node_modules/ts-pattern": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/ts-pattern/-/ts-pattern-5.3.1.tgz", + "integrity": "sha512-1RUMKa8jYQdNfmnK4jyzBK3/PS/tnjcZ1CW0v1vWDeYe5RBklc/nquw03MEoB66hVBm4BnlCfmOqDVxHyT1DpA==", + "dev": true + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -843,9 +932,9 @@ } }, "node_modules/@types/estree": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", - "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz", + "integrity": "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==", "dev": true }, "node_modules/@types/json-schema": { @@ -861,9 +950,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.5.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.5.tgz", - "integrity": "sha512-Xjs4y5UPO/CLdzpgR6GirZJx36yScjh73+2NlLlkFRSoQN8B0DpfXPdZGnvVmLRLOsqDpOfTNv7D9trgGhmOIA==", + "version": "22.7.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.2.tgz", + "integrity": "sha512-866lXSrpGpgyHBZUa2m9YNWqHDjjM0aBTJlNtYaGEw4rqY/dcD7deRVTbBBAJelfA7oaGDbNftXF/TL/A6RgoA==", "dev": true, "dependencies": { "undici-types": "~6.19.2" @@ -891,16 +980,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.5.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.5.0.tgz", - "integrity": "sha512-lHS5hvz33iUFQKuPFGheAB84LwcJ60G8vKnEhnfcK1l8kGVLro2SFYW6K0/tj8FUhRJ0VHyg1oAfg50QGbPPHw==", + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.7.0.tgz", + "integrity": "sha512-RIHOoznhA3CCfSTFiB6kBGLQtB/sox+pJ6jeFu6FxJvqL8qRxq/FfGO/UhsGgQM9oGdXkV4xUgli+dt26biB6A==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "8.5.0", - "@typescript-eslint/type-utils": "8.5.0", - "@typescript-eslint/utils": "8.5.0", - "@typescript-eslint/visitor-keys": "8.5.0", + "@typescript-eslint/scope-manager": "8.7.0", + "@typescript-eslint/type-utils": "8.7.0", + "@typescript-eslint/utils": "8.7.0", + "@typescript-eslint/visitor-keys": "8.7.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", @@ -924,15 +1013,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.5.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.5.0.tgz", - "integrity": "sha512-gF77eNv0Xz2UJg/NbpWJ0kqAm35UMsvZf1GHj8D9MRFTj/V3tAciIWXfmPLsAAF/vUlpWPvUDyH1jjsr0cMVWw==", + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.7.0.tgz", + "integrity": "sha512-lN0btVpj2unxHlNYLI//BQ7nzbMJYBVQX5+pbNXvGYazdlgYonMn4AhhHifQ+J4fGRYA/m1DjaQjx+fDetqBOQ==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "8.5.0", - "@typescript-eslint/types": "8.5.0", - "@typescript-eslint/typescript-estree": "8.5.0", - "@typescript-eslint/visitor-keys": "8.5.0", + "@typescript-eslint/scope-manager": "8.7.0", + "@typescript-eslint/types": "8.7.0", + "@typescript-eslint/typescript-estree": "8.7.0", + "@typescript-eslint/visitor-keys": "8.7.0", "debug": "^4.3.4" }, "engines": { @@ -952,13 +1041,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.5.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.5.0.tgz", - "integrity": "sha512-06JOQ9Qgj33yvBEx6tpC8ecP9o860rsR22hWMEd12WcTRrfaFgHr2RB/CA/B+7BMhHkXT4chg2MyboGdFGawYg==", + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.7.0.tgz", + "integrity": "sha512-87rC0k3ZlDOuz82zzXRtQ7Akv3GKhHs0ti4YcbAJtaomllXoSO8hi7Ix3ccEvCd824dy9aIX+j3d2UMAfCtVpg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.5.0", - "@typescript-eslint/visitor-keys": "8.5.0" + "@typescript-eslint/types": "8.7.0", + "@typescript-eslint/visitor-keys": "8.7.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -969,13 +1058,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.5.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.5.0.tgz", - "integrity": "sha512-N1K8Ix+lUM+cIDhL2uekVn/ZD7TZW+9/rwz8DclQpcQ9rk4sIL5CAlBC0CugWKREmDjBzI/kQqU4wkg46jWLYA==", + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.7.0.tgz", + "integrity": "sha512-tl0N0Mj3hMSkEYhLkjREp54OSb/FI6qyCzfiiclvJvOqre6hsZTGSnHtmFLDU8TIM62G7ygEa1bI08lcuRwEnQ==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "8.5.0", - "@typescript-eslint/utils": "8.5.0", + "@typescript-eslint/typescript-estree": "8.7.0", + "@typescript-eslint/utils": "8.7.0", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -993,9 +1082,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "8.5.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.5.0.tgz", - "integrity": "sha512-qjkormnQS5wF9pjSi6q60bKUHH44j2APxfh9TQRXK8wbYVeDYYdYJGIROL87LGZZ2gz3Rbmjc736qyL8deVtdw==", + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.7.0.tgz", + "integrity": "sha512-LLt4BLHFwSfASHSF2K29SZ+ZCsbQOM+LuarPjRUuHm+Qd09hSe3GCeaQbcCr+Mik+0QFRmep/FyZBO6fJ64U3w==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1006,13 +1095,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.5.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.5.0.tgz", - "integrity": "sha512-vEG2Sf9P8BPQ+d0pxdfndw3xIXaoSjliG0/Ejk7UggByZPKXmJmw3GW5jV2gHNQNawBUyfahoSiCFVov0Ruf7Q==", + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.7.0.tgz", + "integrity": "sha512-MC8nmcGHsmfAKxwnluTQpNqceniT8SteVwd2voYlmiSWGOtjvGXdPl17dYu2797GVscK30Z04WRM28CrKS9WOg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.5.0", - "@typescript-eslint/visitor-keys": "8.5.0", + "@typescript-eslint/types": "8.7.0", + "@typescript-eslint/visitor-keys": "8.7.0", "debug": "^4.3.4", "fast-glob": "^3.3.2", "is-glob": "^4.0.3", @@ -1034,15 +1123,15 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "8.5.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.5.0.tgz", - "integrity": "sha512-6yyGYVL0e+VzGYp60wvkBHiqDWOpT63pdMV2CVG4LVDd5uR6q1qQN/7LafBZtAtNIn/mqXjsSeS5ggv/P0iECw==", + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.7.0.tgz", + "integrity": "sha512-ZbdUdwsl2X/s3CiyAu3gOlfQzpbuG3nTWKPoIvAu1pu5r8viiJvv2NPN2AqArL35NCYtw/lrPPfM4gxrMLNLPw==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "8.5.0", - "@typescript-eslint/types": "8.5.0", - "@typescript-eslint/typescript-estree": "8.5.0" + "@typescript-eslint/scope-manager": "8.7.0", + "@typescript-eslint/types": "8.7.0", + "@typescript-eslint/typescript-estree": "8.7.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1056,12 +1145,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.5.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.5.0.tgz", - "integrity": "sha512-yTPqMnbAZJNy2Xq2XU8AdtOW9tJIr+UQb64aXB9f3B1498Zx9JorVgFJcZpEc9UBuCCrdzKID2RGAMkYcDtZOw==", + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.7.0.tgz", + "integrity": "sha512-b1tx0orFCCh/THWPQa2ZwWzvOeyzzp36vkJYOpVg0u8UVOIsfVrnuC9FqAw9gRKn+rG2VmWQ/zDJZzkxUnj/XQ==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.5.0", + "@typescript-eslint/types": "8.7.0", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -1147,6 +1236,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/array-buffer-byte-length/-/array-buffer-byte-length-1.0.1.tgz", "integrity": "sha512-ahC5W1xgou+KTXix4sAO8Ki12Q+jf4i0+tmk3sC+zgcynshkHxzpXdImBehiUYKKKDwvfFiJl1tZt6ewscS1Mg==", + "dev": true, "dependencies": { "call-bind": "^1.0.5", "is-array-buffer": "^3.0.4" @@ -1182,6 +1272,7 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", "integrity": "sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==", + "dev": true, "dependencies": { "possible-typed-array-names": "^1.0.0" }, @@ -1196,6 +1287,7 @@ "version": "1.7.4", "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.4.tgz", "integrity": "sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==", + "dev": true, "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -1232,7 +1324,8 @@ "node_modules/browser-or-node": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/browser-or-node/-/browser-or-node-3.0.0.tgz", - "integrity": "sha512-iczIdVJzGEYhP5DqQxYM9Hh7Ztpqqi+CXZpSmX8ALFs9ecXkQIeqRyM6TfxEfMVpwhl3dSuDvxdzzo9sUOIVBQ==" + "integrity": "sha512-iczIdVJzGEYhP5DqQxYM9Hh7Ztpqqi+CXZpSmX8ALFs9ecXkQIeqRyM6TfxEfMVpwhl3dSuDvxdzzo9sUOIVBQ==", + "dev": true }, "node_modules/buffer-from": { "version": "1.1.2", @@ -1244,6 +1337,7 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "dev": true, "engines": { "node": ">= 0.8" } @@ -1252,6 +1346,7 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", + "dev": true, "dependencies": { "es-define-property": "^1.0.0", "es-errors": "^1.3.0", @@ -1316,6 +1411,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-4.0.0.tgz", "integrity": "sha512-VGtlMu3x/4DOtIUwEkRezxUZ2lBacNJCHash0N0WeZDBS+7Ux1dm3XWAgWYxLJFMMdOeXMHXorshEFhbMSGelg==", + "dev": true, "dependencies": { "restore-cursor": "^4.0.0" }, @@ -1330,6 +1426,7 @@ "version": "2.9.2", "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.2.tgz", "integrity": "sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==", + "dev": true, "engines": { "node": ">=6" }, @@ -1704,7 +1801,8 @@ "node_modules/core-util-is": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", - "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" + "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", + "dev": true }, "node_modules/cross-spawn": { "version": "7.0.3", @@ -1793,6 +1891,7 @@ "version": "2.2.3", "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-2.2.3.tgz", "integrity": "sha512-ZIwpnevOurS8bpT4192sqAowWM76JDKSHYzMLty3BZGSswgq6pBaH3DhCSW5xVAZICZyKdOBPjwww5wfgT/6PA==", + "dev": true, "dependencies": { "array-buffer-byte-length": "^1.0.0", "call-bind": "^1.0.5", @@ -1830,6 +1929,7 @@ "version": "1.1.4", "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", + "dev": true, "dependencies": { "es-define-property": "^1.0.0", "es-errors": "^1.3.0", @@ -1846,6 +1946,7 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz", "integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==", + "dev": true, "dependencies": { "define-data-property": "^1.0.1", "has-property-descriptors": "^1.0.0", @@ -1900,6 +2001,7 @@ "version": "16.4.5", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "dev": true, "engines": { "node": ">=12" }, @@ -2030,7 +2132,8 @@ "node_modules/emoji-regex": { "version": "10.3.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.3.0.tgz", - "integrity": "sha512-QpLs9D9v9kArv4lfDEgg1X/gN5XLnf/A6l9cs8SPZLRZR3ZkY9+kwIQTxm+fsSej5UMYGE8fdoaZVIBlqG0XTw==" + "integrity": "sha512-QpLs9D9v9kArv4lfDEgg1X/gN5XLnf/A6l9cs8SPZLRZR3ZkY9+kwIQTxm+fsSej5UMYGE8fdoaZVIBlqG0XTw==", + "dev": true }, "node_modules/error-ex": { "version": "1.3.2", @@ -2045,6 +2148,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", + "dev": true, "dependencies": { "get-intrinsic": "^1.2.4" }, @@ -2056,6 +2160,7 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "dev": true, "engines": { "node": ">= 0.4" } @@ -2064,6 +2169,7 @@ "version": "1.1.3", "resolved": "https://registry.npmjs.org/es-get-iterator/-/es-get-iterator-1.1.3.tgz", "integrity": "sha512-sPZmqHBe6JIiTfN5q2pEi//TwxmAFHwj/XEuYjTuse78i8KxaqMTTzxPoFKuzRpDpTJ+0NAbpfenkmH2rePtuw==", + "dev": true, "dependencies": { "call-bind": "^1.0.2", "get-intrinsic": "^1.1.3", @@ -2139,20 +2245,23 @@ } }, "node_modules/eslint": { - "version": "9.10.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.10.0.tgz", - "integrity": "sha512-Y4D0IgtBZfOcOUAIQTSXBKoNGfY0REGqHJG6+Q81vNippW5YlKjHFj4soMxamKK1NXHUWuBZTLdU3Km+L/pcHw==", + "version": "9.11.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.11.1.tgz", + "integrity": "sha512-MobhYKIoAO1s1e4VUrgx1l1Sk2JBR/Gqjjgw8+mfgoLE2xwsHur4gdfTxyTgShrhvdVFTaJSgMiQBl1jv/AWxg==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.11.0", "@eslint/config-array": "^0.18.0", + "@eslint/core": "^0.6.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.10.0", - "@eslint/plugin-kit": "^0.1.0", + "@eslint/js": "9.11.1", + "@eslint/plugin-kit": "^0.2.0", "@humanwhocodes/module-importer": "^1.0.1", "@humanwhocodes/retry": "^0.3.0", "@nodelib/fs.walk": "^1.2.8", + "@types/estree": "^1.0.6", + "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", @@ -2507,6 +2616,7 @@ "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", "integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==", + "dev": true, "dependencies": { "is-callable": "^1.1.3" } @@ -2542,6 +2652,7 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -2550,6 +2661,7 @@ "version": "1.2.3", "resolved": "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz", "integrity": "sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==", + "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -2566,6 +2678,7 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/get-east-asian-width/-/get-east-asian-width-1.2.0.tgz", "integrity": "sha512-2nk+7SIVb14QrgXFHcm84tD4bKQz0RxPuMT8Ag5KPOq7J5fEmAg0UbXdTOSHqNuHSU28k55qnceesxXRZGzKWA==", + "dev": true, "engines": { "node": ">=18" }, @@ -2577,6 +2690,7 @@ "version": "1.2.4", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", + "dev": true, "dependencies": { "es-errors": "^1.3.0", "function-bind": "^1.1.2", @@ -2774,6 +2888,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "dev": true, "dependencies": { "get-intrinsic": "^1.1.3" }, @@ -2827,6 +2942,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz", "integrity": "sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ==", + "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -2844,6 +2960,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", + "dev": true, "dependencies": { "es-define-property": "^1.0.0" }, @@ -2855,6 +2972,7 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -2866,6 +2984,7 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -2877,6 +2996,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "dev": true, "dependencies": { "has-symbols": "^1.0.3" }, @@ -2891,6 +3011,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "dev": true, "dependencies": { "function-bind": "^1.1.2" }, @@ -2922,7 +3043,8 @@ "node_modules/immediate": { "version": "3.0.6", "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", - "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==" + "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==", + "dev": true }, "node_modules/import-fresh": { "version": "3.3.0", @@ -2961,7 +3083,8 @@ "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true }, "node_modules/ini": { "version": "1.3.8", @@ -2973,6 +3096,7 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.7.tgz", "integrity": "sha512-NGnrKwXzSms2qUUih/ILZ5JBqNTSa1+ZmP6flaIp6KmSElgE9qdndzS3cqjrDovwFdmwsGsLdeFgB6suw+1e9g==", + "dev": true, "dependencies": { "es-errors": "^1.3.0", "hasown": "^2.0.0", @@ -2986,6 +3110,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", + "dev": true, "dependencies": { "call-bind": "^1.0.2", "has-tostringtag": "^1.0.0" @@ -3001,6 +3126,7 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/is-array-buffer/-/is-array-buffer-3.0.4.tgz", "integrity": "sha512-wcjaerHw0ydZwfhiKbXJWLDY8A7yV7KhjQOpb83hGgGfId/aQa4TOvwyzn2PuswW2gPCYEL/nEAiSVpdOj1lXw==", + "dev": true, "dependencies": { "call-bind": "^1.0.2", "get-intrinsic": "^1.2.1" @@ -3022,6 +3148,7 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-bigint/-/is-bigint-1.0.4.tgz", "integrity": "sha512-zB9CruMamjym81i2JZ3UMn54PKGsQzsJeo6xvN3HJJ4CAsQNB6iRutp2To77OfCNuoxspsIhzaPoO1zyCEhFOg==", + "dev": true, "dependencies": { "has-bigints": "^1.0.1" }, @@ -3033,6 +3160,7 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.2.tgz", "integrity": "sha512-gDYaKHJmnj4aWxyj6YHyXVpdQawtVLHU5cb+eztPGczf6cjuTdwve5ZIEfgXqH4e57An1D1AKf8CZ3kYrQRqYA==", + "dev": true, "dependencies": { "call-bind": "^1.0.2", "has-tostringtag": "^1.0.0" @@ -3048,6 +3176,7 @@ "version": "1.2.7", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -3074,6 +3203,7 @@ "version": "1.0.5", "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.5.tgz", "integrity": "sha512-9YQaSxsAiSwcvS33MBk3wTCVnWK+HhF8VZR2jRxehM16QcVOdHqPn4VPHmRK4lSr38n9JriurInLcP90xsYNfQ==", + "dev": true, "dependencies": { "has-tostringtag": "^1.0.0" }, @@ -3117,6 +3247,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-2.0.0.tgz", "integrity": "sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==", + "dev": true, "engines": { "node": ">=12" }, @@ -3128,6 +3259,7 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/is-map/-/is-map-2.0.3.tgz", "integrity": "sha512-1Qed0/Hr2m+YqxnM09CjA2d/i6YZNfF6R2oRAOj36eUdS6qIV/huPJNSEpKbupewFs+ZsJlxsjjPbc0/afW6Lw==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -3148,6 +3280,7 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.0.7.tgz", "integrity": "sha512-k1U0IRzLMo7ZlYIfzRu23Oh6MiIFasgpb9X76eqfFZAqwH44UI4KTBvBYIZ1dSL9ZzChTB9ShHfLkR4pdW5krQ==", + "dev": true, "dependencies": { "has-tostringtag": "^1.0.0" }, @@ -3189,6 +3322,7 @@ "version": "1.1.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", "integrity": "sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==", + "dev": true, "dependencies": { "call-bind": "^1.0.2", "has-tostringtag": "^1.0.0" @@ -3204,6 +3338,7 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/is-set/-/is-set-2.0.3.tgz", "integrity": "sha512-iPAjerrse27/ygGLxw+EBR9agv9Y6uLeYVJMu+QNCoouJ1/1ri0mGrcWpfCqFZuzzx3WjtwxG098X+n4OuRkPg==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -3215,6 +3350,7 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/is-shared-array-buffer/-/is-shared-array-buffer-1.0.3.tgz", "integrity": "sha512-nA2hv5XIhLR3uVzDDfCIknerhx8XUKnstuOERPNNIinXG7v9u+ohXF67vxm4TPTEPU6lm61ZkwP3c9PCB97rhg==", + "dev": true, "dependencies": { "call-bind": "^1.0.7" }, @@ -3229,6 +3365,7 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.7.tgz", "integrity": "sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==", + "dev": true, "dependencies": { "has-tostringtag": "^1.0.0" }, @@ -3243,6 +3380,7 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.4.tgz", "integrity": "sha512-C/CPBqKWnvdcxqIARxyOh4v1UUEOCHpgDa0WYgpKDFMszcrPcffg5uhwSgPCLD2WWxmq6isisz87tzT01tuGhg==", + "dev": true, "dependencies": { "has-symbols": "^1.0.2" }, @@ -3269,6 +3407,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-2.0.0.tgz", "integrity": "sha512-FRdAyx5lusK1iHG0TWpVtk9+1i+GjrzRffhDg4ovQ7mcidMQ6mj+MhKPmvh7Xwyv5gIS06ns49CA7Sqg7lC22Q==", + "dev": true, "engines": { "node": ">=18" }, @@ -3280,6 +3419,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/is-weakmap/-/is-weakmap-2.0.2.tgz", "integrity": "sha512-K5pXYOm9wqY1RgjpL3YTkF39tni1XajUIkawTLUo9EZEVUFga5gSQJF8nNS7ZwJQ02y+1YCNYcMh+HIf1ZqE+w==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -3291,6 +3431,7 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/is-weakset/-/is-weakset-2.0.3.tgz", "integrity": "sha512-LvIm3/KWzS9oRFHugab7d+M/GcBXuXX5xZkzPmN+NxihdQlZUQ4dWuSV1xR/sq6upL1TJEDrfBgRepHFdBtSNQ==", + "dev": true, "dependencies": { "call-bind": "^1.0.7", "get-intrinsic": "^1.2.4" @@ -3305,7 +3446,8 @@ "node_modules/isarray": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", - "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==" + "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", + "dev": true }, "node_modules/isexe": { "version": "2.0.0", @@ -3396,6 +3538,7 @@ "version": "3.10.1", "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz", "integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==", + "dev": true, "dependencies": { "lie": "~3.3.0", "pako": "~1.0.2", @@ -3425,6 +3568,7 @@ "version": "3.0.3", "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", "integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==", + "dev": true, "engines": { "node": ">=6" } @@ -3446,6 +3590,7 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==", + "dev": true, "dependencies": { "immediate": "~3.0.5" } @@ -3517,6 +3662,7 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-6.0.0.tgz", "integrity": "sha512-i24m8rpwhmPIS4zscNzK6MSEhk0DUWa/8iYQWxhffV8jkI4Phvs3F+quL5xvS0gdQR0FyTCMMH33Y78dDTzzIw==", + "dev": true, "dependencies": { "chalk": "^5.3.0", "is-unicode-supported": "^1.3.0" @@ -3532,6 +3678,7 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-1.3.0.tgz", "integrity": "sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==", + "dev": true, "engines": { "node": ">=12" }, @@ -3791,6 +3938,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", + "dev": true, "engines": { "node": ">=6" } @@ -3888,6 +4036,7 @@ "version": "1.13.2", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", "integrity": "sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -3899,6 +4048,7 @@ "version": "1.1.6", "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.6.tgz", "integrity": "sha512-F8cZ+KfGlSGi09lJT7/Nd6KJZ9ygtvYC0/UYYLI9nmQKLMnydpB9yvbv9K1uSkEu7FU9vYPmVwLg328tX+ot3Q==", + "dev": true, "dependencies": { "call-bind": "^1.0.7", "define-properties": "^1.2.1" @@ -3914,6 +4064,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", + "dev": true, "engines": { "node": ">= 0.4" } @@ -3922,6 +4073,7 @@ "version": "4.1.5", "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.5.tgz", "integrity": "sha512-byy+U7gp+FVwmyzKPYhW2h5l3crpmGsxl7X2s8y43IgxvG4g3QZ6CffDtsNQy1WsmZpQbO+ybo0AlW7TY6DcBQ==", + "dev": true, "dependencies": { "call-bind": "^1.0.5", "define-properties": "^1.2.1", @@ -3939,6 +4091,7 @@ "version": "5.1.2", "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", + "dev": true, "dependencies": { "mimic-fn": "^2.1.0" }, @@ -3970,6 +4123,7 @@ "version": "8.0.1", "resolved": "https://registry.npmjs.org/ora/-/ora-8.0.1.tgz", "integrity": "sha512-ANIvzobt1rls2BDny5fWZ3ZVKyD6nscLvfFRpQgfWsythlcsVUC9kL0zq6j2Z5z9wwp1kd7wpsD/T9qNPVLCaQ==", + "dev": true, "dependencies": { "chalk": "^5.3.0", "cli-cursor": "^4.0.0", @@ -3992,6 +4146,7 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "dev": true, "engines": { "node": ">=12" }, @@ -4003,6 +4158,7 @@ "version": "7.1.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, "dependencies": { "ansi-regex": "^6.0.1" }, @@ -4017,6 +4173,7 @@ "version": "6.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-6.1.0.tgz", "integrity": "sha512-H0jc0q1vOzlEk0TqAKXKZxdl7kX3OFUzCnNVUnq5Pc3DGo0kpeaMuPqxQn235HibwBEb0/pm9dgKTjXy66fBkg==", + "dev": true, "dependencies": { "yocto-queue": "^1.1.1" }, @@ -4081,7 +4238,8 @@ "node_modules/pako": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", - "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==" + "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==", + "dev": true }, "node_modules/parent-module": { "version": "1.0.1", @@ -4163,6 +4321,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz", "integrity": "sha512-d7Uw+eZoloe0EHDIYoe+bQ5WXnGMOpmiZFTuMWCwpjzzkL2nTjcKiAk4hh8TjnGye2TwWOk3UXucZ+3rbmBa8Q==", + "dev": true, "engines": { "node": ">= 0.4" } @@ -4193,12 +4352,14 @@ "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", + "dev": true }, "node_modules/prompts": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", "integrity": "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==", + "dev": true, "dependencies": { "kleur": "^3.0.3", "sisteransi": "^1.0.5" @@ -4235,7 +4396,8 @@ "node_modules/querystringify": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", - "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==" + "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==", + "dev": true }, "node_modules/queue-microtask": { "version": "1.2.3", @@ -4412,6 +4574,7 @@ "version": "2.3.8", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "dev": true, "dependencies": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -4425,7 +4588,8 @@ "node_modules/readable-stream/node_modules/isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", + "dev": true }, "node_modules/redent": { "version": "3.0.0", @@ -4444,6 +4608,7 @@ "version": "1.5.2", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz", "integrity": "sha512-NcDiDkTLuPR+++OCKB0nWafEmhg/Da8aUPLPMQbK+bxKKCm1/S5he+AqYa4PlMCVBalb4/yxIRub6qkEx5yJbw==", + "dev": true, "dependencies": { "call-bind": "^1.0.6", "define-properties": "^1.2.1", @@ -4468,7 +4633,8 @@ "node_modules/requires-port": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", - "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==" + "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==", + "dev": true }, "node_modules/resolve": { "version": "1.22.8", @@ -4509,6 +4675,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-4.0.0.tgz", "integrity": "sha512-I9fPXU9geO9bHOt9pHHOhOkYerIMsmVaWB0rA2AI9ERh/+x/i7MV5HKBNrg+ljO5eoPVgCcnFuRjJ9uH6I/3eg==", + "dev": true, "dependencies": { "onetime": "^5.1.0", "signal-exit": "^3.0.2" @@ -4556,7 +4723,8 @@ "node_modules/safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "dev": true }, "node_modules/semver": { "version": "7.6.3", @@ -4574,6 +4742,7 @@ "version": "1.2.2", "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", + "dev": true, "dependencies": { "define-data-property": "^1.1.4", "es-errors": "^1.3.0", @@ -4590,6 +4759,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/set-function-name/-/set-function-name-2.0.2.tgz", "integrity": "sha512-7PGFlmtwsEADb0WYyvCMa1t+yke6daIG4Wirafur5kcf+MhUnPms1UeR0CKQdTZD81yESwMHbtn+TR+dMviakQ==", + "dev": true, "dependencies": { "define-data-property": "^1.1.4", "es-errors": "^1.3.0", @@ -4603,7 +4773,8 @@ "node_modules/setimmediate": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", - "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==" + "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==", + "dev": true }, "node_modules/shebang-command": { "version": "2.0.0", @@ -4630,6 +4801,7 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==", + "dev": true, "dependencies": { "call-bind": "^1.0.7", "es-errors": "^1.3.0", @@ -4646,12 +4818,14 @@ "node_modules/signal-exit": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", - "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", + "dev": true }, "node_modules/sisteransi": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", - "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==" + "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==", + "dev": true }, "node_modules/source-map": { "version": "0.6.1", @@ -4881,6 +5055,7 @@ "version": "0.2.2", "resolved": "https://registry.npmjs.org/stdin-discarder/-/stdin-discarder-0.2.2.tgz", "integrity": "sha512-UhDfHmA92YAlNnCfhmq0VeNL5bDbiZGg7sZ2IvPsXubGkiNa9EC+tUTsjBRsYUAz87btI6/1wf4XoVvQ3uRnmQ==", + "dev": true, "engines": { "node": ">=18" }, @@ -4892,6 +5067,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/stop-iteration-iterator/-/stop-iteration-iterator-1.0.0.tgz", "integrity": "sha512-iCGQj+0l0HOdZ2AEeBADlsRC+vsnDsZsbdSiH1yNSjcfKM7fdpCMfqAL/dwF5BLiw/XhRft/Wax6zQbhq2BcjQ==", + "dev": true, "dependencies": { "internal-slot": "^1.0.4" }, @@ -4903,6 +5079,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, "dependencies": { "safe-buffer": "~5.1.0" } @@ -4911,6 +5088,7 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", "integrity": "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==", + "dev": true, "dependencies": { "emoji-regex": "^10.3.0", "get-east-asian-width": "^1.0.0", @@ -4927,6 +5105,7 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "dev": true, "engines": { "node": ">=12" }, @@ -4938,6 +5117,7 @@ "version": "7.1.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, "dependencies": { "ansi-regex": "^6.0.1" }, @@ -5101,9 +5281,9 @@ } }, "node_modules/ts-pattern": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/ts-pattern/-/ts-pattern-5.3.1.tgz", - "integrity": "sha512-1RUMKa8jYQdNfmnK4jyzBK3/PS/tnjcZ1CW0v1vWDeYe5RBklc/nquw03MEoB66hVBm4BnlCfmOqDVxHyT1DpA==" + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/ts-pattern/-/ts-pattern-5.4.0.tgz", + "integrity": "sha512-hgfOMfjlrARCnYtGD/xEAkFHDXuSyuqjzFSltyQCbN689uNvoQL20TVN2XFcLMjfNuwSsQGU+xtH6MrjIwhwUg==" }, "node_modules/tsx": { "version": "4.19.1", @@ -5168,14 +5348,14 @@ } }, "node_modules/typescript-eslint": { - "version": "8.5.0", - "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.5.0.tgz", - "integrity": "sha512-uD+XxEoSIvqtm4KE97etm32Tn5MfaZWgWfMMREStLxR6JzvHkc2Tkj7zhTEK5XmtpTmKHNnG8Sot6qDfhHtR1Q==", + "version": "8.7.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.7.0.tgz", + "integrity": "sha512-nEHbEYJyHwsuf7c3V3RS7Saq+1+la3i0ieR3qP0yjqWSzVmh8Drp47uOl9LjbPANac4S7EFSqvcYIKXUUwIfIQ==", "dev": true, "dependencies": { - "@typescript-eslint/eslint-plugin": "8.5.0", - "@typescript-eslint/parser": "8.5.0", - "@typescript-eslint/utils": "8.5.0" + "@typescript-eslint/eslint-plugin": "8.7.0", + "@typescript-eslint/parser": "8.7.0", + "@typescript-eslint/utils": "8.7.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -5222,6 +5402,7 @@ "version": "1.5.10", "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz", "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", + "dev": true, "dependencies": { "querystringify": "^2.1.1", "requires-port": "^1.0.0" @@ -5230,12 +5411,14 @@ "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", + "dev": true }, "node_modules/uuid": { "version": "10.0.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==", + "dev": true, "funding": [ "https://github.com/sponsors/broofa", "https://github.com/sponsors/ctavan" @@ -5273,6 +5456,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz", "integrity": "sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==", + "dev": true, "dependencies": { "is-bigint": "^1.0.1", "is-boolean-object": "^1.1.0", @@ -5288,6 +5472,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/which-collection/-/which-collection-1.0.2.tgz", "integrity": "sha512-K4jVyjnBdgvc86Y6BkaLZEN933SwYOuBFkdmBu9ZfkcAbdVbpITnDmjvZ/aQjRXQrv5EPkTnD1s39GiiqbngCw==", + "dev": true, "dependencies": { "is-map": "^2.0.3", "is-set": "^2.0.3", @@ -5305,6 +5490,7 @@ "version": "1.1.15", "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.15.tgz", "integrity": "sha512-oV0jmFtUky6CXfkqehVvBP/LSWJ2sy4vWMioiENyJLePrBO/yKyV9OyJySfAKosh+RYkIl5zJCNZ8/4JncrpdA==", + "dev": true, "dependencies": { "available-typed-arrays": "^1.0.7", "call-bind": "^1.0.7", @@ -5447,6 +5633,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.1.1.tgz", "integrity": "sha512-b4JR1PFR10y1mKjhHY9LaGo6tmrgjit7hxVIeAmyMw3jegXR4dhYqLaQF5zMXZxY7tLpMyJeLjr1C4rLmkVe8g==", + "dev": true, "engines": { "node": ">=12.20" }, @@ -5458,6 +5645,7 @@ "version": "3.23.8", "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", + "dev": true, "funding": { "url": "https://github.com/sponsors/colinhacks" } diff --git a/package.json b/package.json index 89e0c29..01c1afc 100644 --- a/package.json +++ b/package.json @@ -54,21 +54,21 @@ "yargs": "17.7.2", "prettier": "3.3.3", "chalk": "5.3.0", - "@kontent-ai/delivery-sdk": "15.0.0", - "@kontent-ai/management-sdk": "7.2.0", - "@kontent-ai/migration-toolkit": "1.5.1", - "ts-pattern": "5.3.1" + "@kontent-ai/management-sdk": "7.3.0", + "ts-pattern": "5.4.0" }, "devDependencies": { + "@kontent-ai/delivery-sdk": "15.1.0", + "@kontent-ai/migration-toolkit": "1.5.1", "@types/yargs": "17.0.33", "standard-version": "9.5.0", "typescript": "5.6.2", - "@types/node": "22.5.5", + "@types/node": "22.7.2", "@types/eslint__js": "8.42.3", - "@typescript-eslint/eslint-plugin": "8.5.0", - "typescript-eslint": "8.5.0", - "@typescript-eslint/parser": "8.5.0", - "eslint": "9.10.0", + "@typescript-eslint/eslint-plugin": "8.7.0", + "typescript-eslint": "8.7.0", + "@typescript-eslint/parser": "8.7.0", + "eslint": "9.11.1", "tsx": "4.19.1", "dotenv-cli": "7.4.2" } From a00dbeecc266cac3870bd35244ca2e7cdac9588f Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 07:59:36 +0200 Subject: [PATCH 103/183] updates deps --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index e38424e..7f94b6a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,7 +22,7 @@ "@kontent-ai/delivery-sdk": "15.1.0", "@kontent-ai/migration-toolkit": "1.5.1", "@types/eslint__js": "8.42.3", - "@types/node": "22.7.2", + "@types/node": "22.7.3", "@types/yargs": "17.0.33", "@typescript-eslint/eslint-plugin": "8.7.0", "@typescript-eslint/parser": "8.7.0", @@ -950,9 +950,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.7.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.2.tgz", - "integrity": "sha512-866lXSrpGpgyHBZUa2m9YNWqHDjjM0aBTJlNtYaGEw4rqY/dcD7deRVTbBBAJelfA7oaGDbNftXF/TL/A6RgoA==", + "version": "22.7.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.3.tgz", + "integrity": "sha512-qXKfhXXqGTyBskvWEzJZPUxSslAiLaB6JGP1ic/XTH9ctGgzdgYguuLP1C601aRTSDNlLb0jbKqXjZ48GNraSA==", "dev": true, "dependencies": { "undici-types": "~6.19.2" diff --git a/package.json b/package.json index 01c1afc..50edf6d 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "@types/yargs": "17.0.33", "standard-version": "9.5.0", "typescript": "5.6.2", - "@types/node": "22.7.2", + "@types/node": "22.7.3", "@types/eslint__js": "8.42.3", "@typescript-eslint/eslint-plugin": "8.7.0", "typescript-eslint": "8.7.0", From 4a8ce44351e539be6e5fb86b67aa75ce5a5ab339 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 10:41:56 +0200 Subject: [PATCH 104/183] Generates codenames of type / snippet elements & uses 'Snippet' type for defining snippets --- lib/config.ts | 3 +- lib/core/element.utils.ts | 8 +-- .../delivery-content-type.generator.ts | 50 ++++++++++++++++--- package-lock.json | 8 +-- package.json | 2 +- sample/delivery/content-types/actor.ts | 8 ++- sample/delivery/content-types/movie.ts | 17 ++++++- 7 files changed, 78 insertions(+), 18 deletions(-) diff --git a/lib/config.ts b/lib/config.ts index 5a76ac3..c1dd9b4 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -43,7 +43,8 @@ export const deliveryConfig = { sdkTypes: { contentItem: 'IContentItem', contentItemElements: 'IContentItemElements', - elements: 'Elements' + elements: 'Elements', + snippet: 'Snippet' } } as const; diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts index 25735f7..3f526cd 100644 --- a/lib/core/element.utils.ts +++ b/lib/core/element.utils.ts @@ -15,9 +15,6 @@ export function getFlattenedElements(data: { readonly types: readonly Readonly[]; }): readonly FlattenedElement[] { return data.elements - .filter((element) => { - return element.type !== 'guidelines'; - }) .flatMap((element) => { if (element.type === 'snippet') { const snippet = data.snippets.find((snippet) => snippet.id === element.snippet.id); @@ -42,7 +39,10 @@ export function getFlattenedElements(data: { .map((element) => { return getFlattenedElement(element, data.taxonomies, data.types); }) - .filter(isNotUndefined); + .filter(isNotUndefined) + .filter((element) => { + return element.type !== 'guidelines'; + }); } function getFlattenedElement( diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 1adfba3..09c3a38 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -245,9 +245,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato flattenedElements: readonly FlattenedElement[] ): readonly string[] => { const mainType = - typeOrSnippet instanceof ContentTypeModels.ContentType - ? deliveryConfig.sdkTypes.contentItem - : deliveryConfig.sdkTypes.contentItemElements; + typeOrSnippet instanceof ContentTypeModels.ContentType ? deliveryConfig.sdkTypes.contentItem : deliveryConfig.sdkTypes.snippet; return sortAlphabetically( [mainType, ...(flattenedElements.length ? [deliveryConfig.sdkTypes.elements] : [])], @@ -268,6 +266,8 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato flattenedElements }); + const nameOfTypeRepresentingAllElementCodenames = getNameOfTypeRepresentingAllElementCodenames(snippet); + return ` ${importer.importType({ filePathOrPackage: deliveryConfig.npmPackageName, @@ -275,14 +275,19 @@ ${importer.importType({ })} ${importsResult.imports.join('\n')} +${wrapComment(` +* Type representing all available element codenames for ${snippet.name} +`)} +${getContentTypeElementCodenamesType(nameOfTypeRepresentingAllElementCodenames, flattenedElements)} + ${wrapComment(` * ${snippet.name} * * Id: ${snippet.id} * Codename: ${snippet.codename} `)} -export interface ${importsResult.typeName} extends ${deliveryConfig.sdkTypes.contentItemElements} -${getElementsCode(flattenedElements)}; +export type ${importsResult.typeName} = ${deliveryConfig.sdkTypes.snippet}<${nameOfTypeRepresentingAllElementCodenames}, +${getElementsCode(flattenedElements)}>; `; }; @@ -299,6 +304,8 @@ ${getElementsCode(flattenedElements)}; flattenedElements }); + const nameOfTypeRepresentingAllElementCodenames = getNameOfTypeRepresentingAllElementCodenames(contentType); + return ` ${importer.importType({ filePathOrPackage: deliveryConfig.npmPackageName, @@ -306,6 +313,11 @@ ${importer.importType({ })} ${importsResult.imports.join('\n')} +${wrapComment(` +* Type representing all available element codenames for ${contentType.name} +`)} +${getContentTypeElementCodenamesType(nameOfTypeRepresentingAllElementCodenames, flattenedElements)} + ${wrapComment(` * ${contentType.name} * @@ -314,7 +326,12 @@ ${wrapComment(` `)} export type ${importsResult.typeName} = ${deliveryConfig.sdkTypes.contentItem}< ${getElementsCode(flattenedElements)}${importsResult.contentTypeExtends ? ` ${importsResult.contentTypeExtends}` : ''}, -'${contentType.codename}', ${sharedTypesConfig.languageCodenames}, ${sharedTypesConfig.collectionCodenames}, ${sharedTypesConfig.workflowCodenames}, ${sharedTypesConfig.workflowStepCodenames}>; +'${contentType.codename}', +${sharedTypesConfig.languageCodenames}, +${sharedTypesConfig.collectionCodenames}, +${sharedTypesConfig.workflowCodenames}, +${sharedTypesConfig.workflowStepCodenames}, +${nameOfTypeRepresentingAllElementCodenames}>; `; }; @@ -363,6 +380,27 @@ ${getElementsCode(flattenedElements)}${importsResult.contentTypeExtends ? ` ${im ); }; + const getNameOfTypeRepresentingAllElementCodenames = (typeOrSnippet: ContentTypeOrSnippet): string => { + return `${ + typeOrSnippet instanceof ContentTypeModels.ContentType + ? nameResolvers.contentType(typeOrSnippet) + : nameResolvers.snippet(typeOrSnippet) + }ElementCodenames`; + }; + + const getContentTypeElementCodenamesType = (typeName: string, flattenedElements: readonly FlattenedElement[]): string => { + if (flattenedElements.length === 0) { + return `export type ${typeName} = never`; + } + + const el = flattenedElements.find((m) => m.codename === 'link__f25fb651_eea8_4a0a_8e39_ac5a0f97ed72'); + if (el) { + console.log(el); + } + + return `export type ${typeName} = ${flattenedElements.map((element) => `'${element.codename}'`).join(' | ')};`; + }; + const mapElementType = (element: FlattenedElement): string | undefined => { return match(element) .returnType() diff --git a/package-lock.json b/package-lock.json index 7f94b6a..6bce18a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "kontent-generate": "dist/es2022/lib/code/app.js" }, "devDependencies": { - "@kontent-ai/delivery-sdk": "15.1.0", + "@kontent-ai/delivery-sdk": "15.2.0", "@kontent-ai/migration-toolkit": "1.5.1", "@types/eslint__js": "8.42.3", "@types/node": "22.7.3", @@ -733,9 +733,9 @@ } }, "node_modules/@kontent-ai/delivery-sdk": { - "version": "15.1.0", - "resolved": "https://registry.npmjs.org/@kontent-ai/delivery-sdk/-/delivery-sdk-15.1.0.tgz", - "integrity": "sha512-z/Wfp71eb0eqqjnptSktN/5zE9QKIhtPFc6pv+nXFuAt+ZpJRp04+df9c+rKHxLtfXPiQSkIfxJgqkGeAuK3jQ==", + "version": "15.2.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/delivery-sdk/-/delivery-sdk-15.2.0.tgz", + "integrity": "sha512-ozo7L9TWDlh3Zo3ZsIL9plj7r1QmrMKMLUz4JpTc5nyNF9ZYws3EUjydUpUvjKR7MYm9OeqQcCgiOTSvc9wwdQ==", "dev": true, "dependencies": { "@kontent-ai/core-sdk": "10.8.0", diff --git a/package.json b/package.json index 50edf6d..bdd84fe 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "ts-pattern": "5.4.0" }, "devDependencies": { - "@kontent-ai/delivery-sdk": "15.1.0", + "@kontent-ai/delivery-sdk": "15.2.0", "@kontent-ai/migration-toolkit": "1.5.1", "@types/yargs": "17.0.33", "standard-version": "9.5.0", diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index c0b7a90..3d93e16 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -16,6 +16,11 @@ import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; import type { CollectionCodenames, LanguageCodenames, WorkflowCodenames, WorkflowStepCodenames } from '../system/delivery.codenames.js'; +/** + * Type representing all available element codenames for Actor + */ +export type ActorElementCodenames = 'url' | 'first_name' | 'last_name' | 'photo'; + /** * Actor * @@ -66,5 +71,6 @@ export type Actor = IContentItem< LanguageCodenames, CollectionCodenames, WorkflowCodenames, - WorkflowStepCodenames + WorkflowStepCodenames, + ActorElementCodenames >; diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 501df3d..09273ad 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -18,6 +18,20 @@ import type { Actor } from './index.js'; import type { CollectionCodenames, LanguageCodenames, WorkflowCodenames, WorkflowStepCodenames } from '../system/delivery.codenames.js'; import type { Releasecategory } from '../taxonomies/index.js'; +/** + * Type representing all available element codenames for Movie + */ +export type MovieElementCodenames = + | 'title' + | 'plot' + | 'released' + | 'length' + | 'poster' + | 'category' + | 'stars' + | 'seoname' + | 'releasecategory'; + /** * Movie * @@ -114,5 +128,6 @@ export type Movie = IContentItem< LanguageCodenames, CollectionCodenames, WorkflowCodenames, - WorkflowStepCodenames + WorkflowStepCodenames, + MovieElementCodenames >; From 94d245d756816f6cc77bae2b32d57f73317c164b Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 10:43:53 +0200 Subject: [PATCH 105/183] Use safe property name for language codename as it may contain "non-codename" characters --- lib/generators/environment/environment.generator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/environment/environment.generator.ts b/lib/generators/environment/environment.generator.ts index 2213e45..7f9bb31 100644 --- a/lib/generators/environment/environment.generator.ts +++ b/lib/generators/environment/environment.generator.ts @@ -104,7 +104,7 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { ${wrapComment(` * ${language.name} `)} - ${language.codename}: { + ${toSafePropertyName(language.codename)}: { name: '${toSafePropertyValue(language.name)}', codename: '${language.codename}', id: '${language.id}', From 6885d76856a2d23df068c531ea98fc5b2547a346 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 10:47:48 +0200 Subject: [PATCH 106/183] fixes https://github.com/kontent-ai/model-generator-js/pull/61#pullrequestreview-2322237389 --- lib/core/importer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/importer.ts b/lib/core/importer.ts index 879256b..fe353a5 100644 --- a/lib/core/importer.ts +++ b/lib/core/importer.ts @@ -23,7 +23,7 @@ export function importer(moduleResolution: ModuleResolution) { } return sortAlphabetically(filenames, (filename) => filename).reduce((barrelCode, filename) => { const path = parse(filename); - return (barrelCode += `export * from '${path.dir}/${path.name}${getExtensionForModuleResolution(moduleResolution)}';`); + return `${barrelCode} export * from '${path.dir}/${path.name}${getExtensionForModuleResolution(moduleResolution)}';`; }, ''); } }; From 02cfa465d1009b7ae7348115bb41884a0011b854 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 11:14:46 +0200 Subject: [PATCH 107/183] Use satisfies in args & sets up CliAction generic argument --- lib/core/core.utils.ts | 14 +------------- lib/node/cli/args/args-setter.ts | 7 ++++--- lib/node/cli/cli.models.ts | 10 +++++----- lib/node/cli/commands.ts | 25 +++++++++++++------------ 4 files changed, 23 insertions(+), 33 deletions(-) diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index f15ad92..98808e7 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -1,22 +1,10 @@ import { createHash } from 'crypto'; -import { CliAction, LibraryType, ModuleResolution } from './core.models.js'; +import { ModuleResolution } from './core.models.js'; export function uniqueFilter(value: string, index: number, self: readonly string[]): boolean { return self.indexOf(value) === index; } -export function getCliAction(cliAction: CliAction): CliAction { - return cliAction; -} - -export function getLibrary(library: LibraryType): LibraryType { - return library; -} - -export function getModuleResolution(module: ModuleResolution): ModuleResolution { - return module; -} - export function getDefaultModuleResolution(moduleResolution: ModuleResolution | undefined): ModuleResolution { return moduleResolution ?? 'node'; } diff --git a/lib/node/cli/args/args-setter.ts b/lib/node/cli/args/args-setter.ts index f1b8a28..cd20835 100644 --- a/lib/node/cli/args/args-setter.ts +++ b/lib/node/cli/args/args-setter.ts @@ -1,12 +1,13 @@ import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; +import { CliAction } from '../../../core/core.models.js'; import { CliArgumentsSetter, Command, CommandOption } from '../cli.models.js'; -export function argumentsSetter(): CliArgumentsSetter { +export function argumentsSetter(): CliArgumentsSetter { const argv = yargs(hideBin(process.argv)); return { - withCommand(command: Command): CliArgumentsSetter { + withCommand(command: Command): CliArgumentsSetter { argv.command(command.name, command.description, (yargs) => { command.examples.forEach((example) => yargs.example(command.name, example)); command.options.forEach((option) => { @@ -21,7 +22,7 @@ export function argumentsSetter(): CliArgumentsSetter { return this; }, - withOption(option: CommandOption): CliArgumentsSetter { + withOption(option: CommandOption): CliArgumentsSetter { argv.option(option.name, { alias: option.alias, description: option.description, diff --git a/lib/node/cli/cli.models.ts b/lib/node/cli/cli.models.ts index 50e1acf..e3b7242 100644 --- a/lib/node/cli/cli.models.ts +++ b/lib/node/cli/cli.models.ts @@ -1,7 +1,7 @@ import { CliAction } from '../../core/core.models.js'; -export interface Command { - readonly name: string; +export interface Command { + readonly name: TAction; readonly description: string; readonly options: readonly CommandOption[]; readonly examples: readonly string[]; @@ -15,9 +15,9 @@ export interface CommandOption { readonly type?: 'boolean' | 'number' | 'string'; } -export type CliArgumentsSetter = { - withCommand(command: Command): CliArgumentsSetter; - withOption(option: CommandOption): CliArgumentsSetter; +export type CliArgumentsSetter = { + withCommand(command: Command): CliArgumentsSetter; + withOption(option: CommandOption): CliArgumentsSetter; registerCommands(): void; }; diff --git a/lib/node/cli/commands.ts b/lib/node/cli/commands.ts index 270e9b6..9d82863 100644 --- a/lib/node/cli/commands.ts +++ b/lib/node/cli/commands.ts @@ -1,4 +1,5 @@ -import { getCliAction, getLibrary, getModuleResolution } from '../../core/core.utils.js'; +import { CliAction, LibraryType } from '../../core/core.models.js'; +import { ModuleResolution } from '../../public_api.js'; import { argumentsSetter } from './args/args-setter.js'; import { CommandOption } from './cli.models.js'; @@ -32,7 +33,7 @@ const addTimestampOption: CommandOption = { const moduleResolutionOption: CommandOption = { name: `moduleResolution`, - description: `Module resolution for imports. Available options are: '${getModuleResolution('node')}', '${getModuleResolution('nodeNext')}'`, + description: `Module resolution for imports. Available options are: '${'node' satisfies ModuleResolution}', '${'nodeNext' satisfies ModuleResolution}'`, type: 'string', isRequired: false }; @@ -46,27 +47,27 @@ const baseUrl: CommandOption = { export const cliArgs = argumentsSetter() .withCommand({ - name: getCliAction('delivery-sdk'), - description: `Generates models for '${getLibrary('@kontent-ai/delivery-sdk')}' library`, - examples: [`kontent-generate ${getCliAction('delivery-sdk')} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], + name: 'delivery-sdk', + description: `Generates models for '${'@kontent-ai/delivery-sdk' satisfies LibraryType}' library`, + examples: [`kontent-generate ${'delivery-sdk' satisfies CliAction} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], options: [environmentIdOption, apiKeyOption, addTimestampOption, moduleResolutionOption, outputDirOption, baseUrl] }) .withCommand({ - name: getCliAction('environment'), + name: 'environment', description: `Generates strongly typed models representing all objects in the environment. This is useful for creating custom tools or scripts where you need to reference objects within your environment`, - examples: [`kontent-generate ${getCliAction('environment')} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], + examples: [`kontent-generate ${'environment' satisfies CliAction} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], options: [environmentIdOption, apiKeyOption, addTimestampOption, moduleResolutionOption, outputDirOption, baseUrl] }) .withCommand({ - name: getCliAction('migration-toolkit'), - description: `Generates models for '${getLibrary('@kontent-ai/migration-toolkit')}' library`, - examples: [`kontent-generate ${getCliAction('migration-toolkit')} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], + name: 'migration-toolkit', + description: `Generates models for '${'@kontent-ai/migration-toolkit' satisfies LibraryType}' library`, + examples: [`kontent-generate ${'migration-toolkit' satisfies CliAction} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], options: [environmentIdOption, apiKeyOption, addTimestampOption, moduleResolutionOption, outputDirOption, baseUrl] }) .withCommand({ - name: getCliAction('items'), + name: 'items', description: `Overview of all items in the environment and their ids/codenames as well as Type representing all item codenames`, - examples: [`kontent-generate ${getCliAction('items')} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], + examples: [`kontent-generate ${'items' satisfies CliAction} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], options: [environmentIdOption, apiKeyOption, addTimestampOption, moduleResolutionOption, outputDirOption, baseUrl] }) .withOption({ From c3ddaa6d5045814ec980995d414ffbb906aa5db3 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 11:15:41 +0200 Subject: [PATCH 108/183] Update core.utils.ts --- lib/core/core.utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 98808e7..a980e51 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -25,7 +25,7 @@ export function sortAlphabetically(arrayToSort: readonly T[], propertySelecto export function toPascalCase(text: string): string { return prefixWithUnderscoreWhenStartsWithNonAlpha( toSafeStringCode( - `${text}` + text .toLowerCase() .replace(new RegExp(/[-_]+/, 'g'), ' ') .replace(new RegExp(/[^\w\s]/, 'g'), '') From 4a26d1bed22a60e93e240f1b996984182e50af31 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 11:21:10 +0200 Subject: [PATCH 109/183] Make param required --- lib/core/core.utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index a980e51..0e16777 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -50,7 +50,7 @@ export function toGuidelinesComment(guidelines: string): string { return removeLineEndings(guidelines); } -export function getStringOrUndefined(text?: string): string { +export function getStringOrUndefined(text: string | undefined): string { return text ? `'${text}'` : 'undefined'; } @@ -70,7 +70,7 @@ export function toSafePropertyValue(value: string): string { return value.replace(/'/g, replaceWith); } -export function toOutputDirPath(outputDir?: string): string { +export function toOutputDirPath(outputDir: string | undefined): string { return outputDir ? `${outputDir}/`.replaceAll('//', '/') : `./`; } From b7dcec4d67cb41f42751f91d3c2735d37bbe6e8d Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 11:21:35 +0200 Subject: [PATCH 110/183] removes "m" modifier --- lib/core/core.utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 0e16777..d0822ba 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -75,7 +75,7 @@ export function toOutputDirPath(outputDir: string | undefined): string { } function removeLineEndings(value: string): string { - return value.replace(/(\r\n|\n|\r)/gm, ''); + return value.replace(/(\r\n|\n|\r)/g, ''); } function toSafeStringCode(text: string): string { From 168ee14ec80369494c42afa8ceb9f79b70f458d6 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 11:31:24 +0200 Subject: [PATCH 111/183] Use ts-pattern to match is_required --- lib/core/element.utils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts index 3f526cd..e15b93a 100644 --- a/lib/core/element.utils.ts +++ b/lib/core/element.utils.ts @@ -71,7 +71,10 @@ function getFlattenedElement( } function isElementRequired(element: Readonly): boolean { - return (<{ is_required?: boolean }>element)['is_required'] === true; + return match(element) + .returnType() + .with({ is_required: true }, () => true) + .otherwise(() => false); } function getElementGuidelines(element: Readonly): string | undefined { From c44b51d5480b0fb3d092f626d2176d32e040306f Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 11:31:44 +0200 Subject: [PATCH 112/183] Rename handleError, convert to local function --- lib/core/error.utils.ts | 38 ++++++++++++++--------------- lib/node/cli/app.ts | 4 +-- scripts/tests/delivery-models.ts | 4 +-- scripts/tests/environment-models.ts | 4 +-- scripts/tests/item-models.ts | 4 +-- scripts/tests/migration-models.ts | 4 +-- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/lib/core/error.utils.ts b/lib/core/error.utils.ts index 1b182da..51a179c 100644 --- a/lib/core/error.utils.ts +++ b/lib/core/error.utils.ts @@ -3,7 +3,25 @@ import chalk from 'chalk'; import { match, P } from 'ts-pattern'; import { ErrorData, OriginalManagementError } from './core.models.js'; -export function extractErrorData(error: unknown): ErrorData { +export function logError(error: unknown): void { + const errorData = extractErrorData(error); + + if (errorData.isUnknownError) { + console.error(error); + } + + if (errorData.requestData) { + console.log(`${chalk.red('Request data')}: ${errorData.requestData}`); + } + + if (errorData.requestUrl) { + console.log(`${chalk.red('Request url')}: ${errorData.requestUrl}`); + } + + console.error(`${chalk.red('Error:')} ${errorData.message}`); +} + +function extractErrorData(error: unknown): ErrorData { return match(error) .returnType() .with(P.instanceOf(SharedModels.ContentManagementBaseKontentError), (error) => { @@ -36,21 +54,3 @@ export function extractErrorData(error: unknown): ErrorData { }; }); } - -export function handleError(error: unknown): void { - const errorData = extractErrorData(error); - - if (errorData.isUnknownError) { - console.error(error); - } - - if (errorData.requestData) { - console.log(`${chalk.red('Request data')}: ${errorData.requestData}`); - } - - if (errorData.requestUrl) { - console.log(`${chalk.red('Request url')}: ${errorData.requestUrl}`); - } - - console.error(`${chalk.red('Error:')} ${errorData.message}`); -} diff --git a/lib/node/cli/app.ts b/lib/node/cli/app.ts index 467a086..b589384 100644 --- a/lib/node/cli/app.ts +++ b/lib/node/cli/app.ts @@ -2,7 +2,7 @@ import chalk from 'chalk'; import { match } from 'ts-pattern'; -import { handleError } from '../../core/error.utils.js'; +import { logError } from '../../core/error.utils.js'; import { deliveryActionAsync } from './actions/delivery-action.js'; import { environmentActionAsync } from './actions/environment-action.js'; import { itemsActionAsync } from './actions/items-action.js'; @@ -26,5 +26,5 @@ try { throw Error(`Invalid action '${chalk.red(action)}'`); }); } catch (error) { - handleError(error); + logError(error); } diff --git a/scripts/tests/delivery-models.ts b/scripts/tests/delivery-models.ts index 4178f7a..e2d3876 100644 --- a/scripts/tests/delivery-models.ts +++ b/scripts/tests/delivery-models.ts @@ -2,7 +2,7 @@ import chalk from 'chalk'; import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; import { ModuleResolution } from '../../lib/core/core.models.js'; -import { handleError } from '../../lib/core/error.utils.js'; +import { logError } from '../../lib/core/error.utils.js'; import { generateDeliveryModelsAsync } from '../../lib/generators/delivery/delivery-func.js'; import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; @@ -35,5 +35,5 @@ try { outputDir: outputDir }); } catch (error) { - handleError(error); + logError(error); } diff --git a/scripts/tests/environment-models.ts b/scripts/tests/environment-models.ts index 0216712..55e35c1 100644 --- a/scripts/tests/environment-models.ts +++ b/scripts/tests/environment-models.ts @@ -2,7 +2,7 @@ import chalk from 'chalk'; import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; import { ModuleResolution } from '../../lib/core/core.models.js'; -import { handleError } from '../../lib/core/error.utils.js'; +import { logError } from '../../lib/core/error.utils.js'; import { generateEnvironmentModelsAsync } from '../../lib/generators/environment/environment-func.js'; import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; @@ -36,5 +36,5 @@ try { outputDir: outputDir }); } catch (error) { - handleError(error); + logError(error); } diff --git a/scripts/tests/item-models.ts b/scripts/tests/item-models.ts index 484e409..fd06b3f 100644 --- a/scripts/tests/item-models.ts +++ b/scripts/tests/item-models.ts @@ -2,7 +2,7 @@ import chalk from 'chalk'; import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; import { ModuleResolution } from '../../lib/core/core.models.js'; -import { handleError } from '../../lib/core/error.utils.js'; +import { logError } from '../../lib/core/error.utils.js'; import { generateItemsAsync } from '../../lib/generators/items/items-func.js'; import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; @@ -35,5 +35,5 @@ try { outputDir: outputDir }); } catch (error) { - handleError(error); + logError(error); } diff --git a/scripts/tests/migration-models.ts b/scripts/tests/migration-models.ts index 8cc8592..44b8534 100644 --- a/scripts/tests/migration-models.ts +++ b/scripts/tests/migration-models.ts @@ -2,7 +2,7 @@ import chalk from 'chalk'; import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; import { ModuleResolution } from '../../lib/core/core.models.js'; -import { handleError } from '../../lib/core/error.utils.js'; +import { logError } from '../../lib/core/error.utils.js'; import { generateMigrationModelsAsync } from '../../lib/generators/migration/migration-func.js'; import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; @@ -35,5 +35,5 @@ try { outputDir: outputDir }); } catch (error) { - handleError(error); + logError(error); } From 12e6b2305b1d6c28bec174e4ff1354d7bd3ce2d4 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 11:33:05 +0200 Subject: [PATCH 113/183] Simplify management client creation --- lib/fetch/kontent-fetcher.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/fetch/kontent-fetcher.ts b/lib/fetch/kontent-fetcher.ts index 26ef786..3ee6dac 100644 --- a/lib/fetch/kontent-fetcher.ts +++ b/lib/fetch/kontent-fetcher.ts @@ -24,16 +24,12 @@ interface KontentFetcherConfig { } export function kontentFetcher(config: KontentFetcherConfig) { - const getManagementClient = (): GeneratorManagementClient => { - return createManagementClient({ - environmentId: config.environmentId, - apiKey: config.apiKey, - baseUrl: config.baseUrl, - httpService: new HttpService({ logErrorsToConsole: false }) - }); - }; - - const client = getManagementClient(); + const client: GeneratorManagementClient = createManagementClient({ + environmentId: config.environmentId, + apiKey: config.apiKey, + baseUrl: config.baseUrl, + httpService: new HttpService({ logErrorsToConsole: false }) + }); return { async getEnvironmentInfoAsync(): Promise> { From ed013904b1692adcf40ab8dc18736687698352b1 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 11:37:22 +0200 Subject: [PATCH 114/183] Uses local impl of isNotUnefined --- lib/core/core.utils.ts | 2 ++ lib/core/element.utils.ts | 2 +- lib/generators/delivery/delivery-content-type.generator.ts | 3 +-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index d0822ba..dd53a20 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -5,6 +5,8 @@ export function uniqueFilter(value: string, index: number, self: readonly string return self.indexOf(value) === index; } +export const isNotUndefined = (item: T | undefined): item is T => item !== undefined; + export function getDefaultModuleResolution(moduleResolution: ModuleResolution | undefined): ModuleResolution { return moduleResolution ?? 'node'; } diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts index e15b93a..e24ed15 100644 --- a/lib/core/element.utils.ts +++ b/lib/core/element.utils.ts @@ -1,7 +1,7 @@ import { ContentTypeElements, ContentTypeModels, ContentTypeSnippetModels, TaxonomyModels } from '@kontent-ai/management-sdk'; -import { isNotUndefined } from '@kontent-ai/migration-toolkit'; import { match } from 'ts-pattern'; import { FlattenedElement, MultipleChoiceOption } from './core.models.js'; +import { isNotUndefined } from './core.utils.js'; interface ElementWrapper { readonly element: Readonly; diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 09c3a38..52ac16e 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -7,12 +7,11 @@ import { TaxonomyModels, WorkflowModels } from '@kontent-ai/management-sdk'; -import { isNotUndefined } from '@kontent-ai/migration-toolkit'; import { match, P } from 'ts-pattern'; import { coreConfig, deliveryConfig, sharedTypesConfig } from '../../config.js'; import { wrapComment } from '../../core/comment.utils.js'; import { FlattenedElement, GeneratedFile, ModuleResolution } from '../../core/core.models.js'; -import { sortAlphabetically, toGuidelinesComment, uniqueFilter } from '../../core/core.utils.js'; +import { isNotUndefined, sortAlphabetically, toGuidelinesComment, uniqueFilter } from '../../core/core.utils.js'; import { getFlattenedElements } from '../../core/element.utils.js'; import { importer as _importer } from '../../core/importer.js'; import { From c05b7b2b98019589ec2ffaf7844ccb8a77aed3b1 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 11:51:27 +0200 Subject: [PATCH 115/183] Use ts-pattern for matching element guidelines --- lib/core/element.utils.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts index e24ed15..6b2c9d3 100644 --- a/lib/core/element.utils.ts +++ b/lib/core/element.utils.ts @@ -1,5 +1,5 @@ import { ContentTypeElements, ContentTypeModels, ContentTypeSnippetModels, TaxonomyModels } from '@kontent-ai/management-sdk'; -import { match } from 'ts-pattern'; +import { match, P } from 'ts-pattern'; import { FlattenedElement, MultipleChoiceOption } from './core.models.js'; import { isNotUndefined } from './core.utils.js'; @@ -78,7 +78,10 @@ function isElementRequired(element: Readonly): string | undefined { - return (<{ guidelines?: string }>element)['guidelines']; + return match(element) + .returnType() + .with({ guidelines: P.string }, (element) => element.guidelines) + .otherwise(() => undefined); } function getElementTitle( From 77483bf7a6ac4501e46f262c6fbb73404abb5ad0 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 12:02:27 +0200 Subject: [PATCH 116/183] Cleans up eslint deps --- package-lock.json | 11 +++++------ package.json | 23 +++++++++++------------ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index 6bce18a..74fa971 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,19 +19,18 @@ "kontent-generate": "dist/es2022/lib/code/app.js" }, "devDependencies": { + "@eslint/js": "^9.11.1", "@kontent-ai/delivery-sdk": "15.2.0", "@kontent-ai/migration-toolkit": "1.5.1", - "@types/eslint__js": "8.42.3", + "@types/eslint__js": "^8.42.3", "@types/node": "22.7.3", "@types/yargs": "17.0.33", - "@typescript-eslint/eslint-plugin": "8.7.0", - "@typescript-eslint/parser": "8.7.0", "dotenv-cli": "7.4.2", - "eslint": "9.11.1", + "eslint": "^9.11.1", "standard-version": "9.5.0", "tsx": "4.19.1", - "typescript": "5.6.2", - "typescript-eslint": "8.7.0" + "typescript": "^5.6.2", + "typescript-eslint": "^8.7.0" }, "engines": { "node": ">= 20" diff --git a/package.json b/package.json index bdd84fe..cf44c89 100644 --- a/package.json +++ b/package.json @@ -51,25 +51,24 @@ "update:version": "tsx ./scripts/update-version.ts" }, "dependencies": { - "yargs": "17.7.2", - "prettier": "3.3.3", - "chalk": "5.3.0", "@kontent-ai/management-sdk": "7.3.0", - "ts-pattern": "5.4.0" + "chalk": "5.3.0", + "prettier": "3.3.3", + "ts-pattern": "5.4.0", + "yargs": "17.7.2" }, "devDependencies": { + "@eslint/js": "^9.11.1", "@kontent-ai/delivery-sdk": "15.2.0", "@kontent-ai/migration-toolkit": "1.5.1", + "@types/eslint__js": "^8.42.3", + "@types/node": "22.7.3", "@types/yargs": "17.0.33", + "dotenv-cli": "7.4.2", + "eslint": "^9.11.1", "standard-version": "9.5.0", - "typescript": "5.6.2", - "@types/node": "22.7.3", - "@types/eslint__js": "8.42.3", - "@typescript-eslint/eslint-plugin": "8.7.0", - "typescript-eslint": "8.7.0", - "@typescript-eslint/parser": "8.7.0", - "eslint": "9.11.1", "tsx": "4.19.1", - "dotenv-cli": "7.4.2" + "typescript": "^5.6.2", + "typescript-eslint": "^8.7.0" } } From 670146763f7264232ab2b7379565396c952f5608 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 12:05:40 +0200 Subject: [PATCH 117/183] Update package.json --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index cf44c89..e157e64 100644 --- a/package.json +++ b/package.json @@ -61,14 +61,14 @@ "@eslint/js": "^9.11.1", "@kontent-ai/delivery-sdk": "15.2.0", "@kontent-ai/migration-toolkit": "1.5.1", - "@types/eslint__js": "^8.42.3", + "@types/eslint__js": "8.42.3", "@types/node": "22.7.3", "@types/yargs": "17.0.33", "dotenv-cli": "7.4.2", - "eslint": "^9.11.1", + "eslint": "9.11.1", "standard-version": "9.5.0", "tsx": "4.19.1", - "typescript": "^5.6.2", - "typescript-eslint": "^8.7.0" + "typescript": "5.6.2", + "typescript-eslint": "8.7.0" } } From d3cfee80661825b5b832f0cda93438c45bb97b31 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 12:12:43 +0200 Subject: [PATCH 118/183] Use ts-pattern instead of type casting --- lib/core/element.utils.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/core/element.utils.ts b/lib/core/element.utils.ts index 6b2c9d3..8ea24b0 100644 --- a/lib/core/element.utils.ts +++ b/lib/core/element.utils.ts @@ -88,17 +88,20 @@ function getElementTitle( element: Readonly, taxonomies: readonly Readonly[] ): string { - if (element.type === 'taxonomy') { - const taxonomyGroupId = element.taxonomy_group?.id; + return match(element) + .returnType() + .with({ type: 'taxonomy' }, (taxonomyElement) => { + const taxonomyGroupId = taxonomyElement.taxonomy_group?.id; - if (!taxonomyGroupId) { - return element.type; - } + if (!taxonomyGroupId) { + return element.type; + } - const taxonomy = taxonomies.find((m) => m.id === taxonomyGroupId); - return taxonomy?.name ?? element.type; - } - return (<{ name?: string }>element).name ?? element.codename ?? 'n/a'; + const taxonomy = taxonomies.find((m) => m.id === taxonomyGroupId); + return taxonomy?.name ?? element.type; + }) + .with({ name: P.string }, (element) => element.name) + .otherwise(() => 'invalidTitle'); } function extractLinkedItemsAllowedTypes( From 81f7db92efac9262bc921149ffda6f01223fca66 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 12:14:21 +0200 Subject: [PATCH 119/183] Use local eslint in lint scripts --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e157e64..4be39df 100644 --- a/package.json +++ b/package.json @@ -44,8 +44,8 @@ "test:items": "tsx scripts/tests/item-models", "test:help": "tsx lib/node/cli/app --help", "test:help:delivery-sdk": "tsx lib/node/cli/app delivery-sdk --help", - "lint": "npx eslint lib", - "lint:fix": "npx eslint lib --fix", + "lint": "eslint lib", + "lint:fix": "eslint lib --fix", "clean": "tsx scripts/clean.ts", "push:tags": "git push --tags", "update:version": "tsx ./scripts/update-version.ts" From 681e49de0a0b5dbd6acfd8d3816b8891b5ee4200 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 12:18:04 +0200 Subject: [PATCH 120/183] Tries lts as node-version --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8d4ef0e..9ed8081 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,7 +5,7 @@ jobs: runs-on: windows-latest strategy: matrix: - node-version: [20.x] + node-version: [lts] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} From 26fc1458ddf95eae77c097758bf849969cd5dc6d Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 12:20:02 +0200 Subject: [PATCH 121/183] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9ed8081..12a444c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,7 +5,7 @@ jobs: runs-on: windows-latest strategy: matrix: - node-version: [lts] + node-version: [lts/*] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} From e921a9485dacfdfdc4a9b4b3d5096c60e5000975 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 12:20:52 +0200 Subject: [PATCH 122/183] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 12a444c..3833c8c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,7 +5,7 @@ jobs: runs-on: windows-latest strategy: matrix: - node-version: [lts/*] + node-version: [latest] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} From 80265802bc77b0d2a0e68ba8efac23a8437eb6e0 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 12:24:56 +0200 Subject: [PATCH 123/183] Update main.yml --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3833c8c..5abb7b3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,10 +3,10 @@ on: [pull_request] jobs: build: runs-on: windows-latest - strategy: - matrix: - node-version: [latest] steps: + - uses: actions/setup-node@v4 + with: + node-version: latest - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 From a989302d23b9e62f6b6a9cb92698e8fad1a35376 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 12:30:11 +0200 Subject: [PATCH 124/183] Update main.yml --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5abb7b3..e94a416 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,10 +3,10 @@ on: [pull_request] jobs: build: runs-on: windows-latest + strategy: + matrix: + node-version: ['latest'] steps: - - uses: actions/setup-node@v4 - with: - node-version: latest - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 From 0331987f0d8a992dcb62300874d46787747504f4 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 12:31:34 +0200 Subject: [PATCH 125/183] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e94a416..3d69561 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,7 +2,7 @@ name: Test on: [pull_request] jobs: build: - runs-on: windows-latest + runs-on: ubuntu-latest strategy: matrix: node-version: ['latest'] From 6c0b1d1f5b077fef11d65ae0f55a89a5ae9fc6f6 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 12:32:32 +0200 Subject: [PATCH 126/183] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3d69561..559791b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: ['latest'] + node-version: [lts/*] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} From 9d83151fe6a31d34106d16497f88bfb3e972a284 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 12:33:03 +0200 Subject: [PATCH 127/183] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 559791b..4bd6db9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [lts/*] + node-version: ['lts/*'] steps: - uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} From ffc5a5acc0ab0bed51aff36eb1fd51dd3ca68b5b Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 12:35:35 +0200 Subject: [PATCH 128/183] Updates GH workflow --- .github/workflows/build.yml | 20 ++++++++++++++++++++ .github/workflows/main.yml | 16 ---------------- .nvmrc | 1 + 3 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/main.yml create mode 100644 .nvmrc diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..40b0302 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,20 @@ +name: Lint & Build + +on: + push: + branches: [main] + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Use Node.js from .nvmrc file + uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + - run: npm ci + - run: npm run fmt:check + - run: npm run lint + - run: npm run build diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 4bd6db9..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Test -on: [pull_request] -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - node-version: ['lts/*'] - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - run: npm i - - run: npm run test:all diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..1a2f5bd --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +lts/* \ No newline at end of file From 129d736b1bc89899da1a5dd8467e6b2e6cc0411c Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 12:36:24 +0200 Subject: [PATCH 129/183] Update build.yml --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 40b0302..3b92be7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,6 +15,5 @@ jobs: with: node-version-file: '.nvmrc' - run: npm ci - - run: npm run fmt:check - run: npm run lint - run: npm run build From 0689fce1f3915e3b8f642ea7fa192a77bd979300 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 12:38:55 +0200 Subject: [PATCH 130/183] Removes lint from build --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4be39df..523cced 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "prepublishOnly": "npm run build && npm run push:tags", "publish:beta": "npm publish --tag=next", "build:es2022": "tsc --p tsconfig.es2022.json", - "build": "npm run lint && npm run clean && npm run build:es2022", + "build": "npm run clean && npm run build:es2022", "test:all": "npm run build", "test:delivery": "tsx scripts/tests/delivery-models", "test:environment": "tsx scripts/tests/environment-models", From 95d7fcadc4f888fbaebdcbd0541dd423a6d60ed0 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 13:02:25 +0200 Subject: [PATCH 131/183] Converts assert -> with import of package.json --- scripts/update-version.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/update-version.ts b/scripts/update-version.ts index d82e176..e6606b2 100644 --- a/scripts/update-version.ts +++ b/scripts/update-version.ts @@ -1,6 +1,6 @@ import chalk from 'chalk'; import fs from 'fs'; -import PackageJson from '../package.json' assert { type: 'json' }; +import { name, version } from '../package.json' with { type: 'json' }; const date = new Date(); const versionFilePath = './lib/meta/metadata.ts'; @@ -10,13 +10,13 @@ createVersionFile(date, versionFilePath, versionProp); function createVersionFile(date: Date, filePath: string, propertyName: string): void { console.log(chalk.cyan(`\nCreating version file at '${filePath}' with prop '${propertyName}'`)); - console.log(chalk.green(`Updating version ${chalk.yellow(PackageJson.version)}`)); + console.log(chalk.green(`Updating version ${chalk.yellow(version)}`)); const src = ` export const ${propertyName} = { - name: '${PackageJson.name}', + name: '${name}', timestamp: '${date.toUTCString()}', - version: '${PackageJson.version}' + version: '${version}' }; `; From 987ce24acc2953657f12d3ca61f1b3279e1720ec Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 13:04:00 +0200 Subject: [PATCH 132/183] Removes 'path' config from dotenv --- scripts/tests/delivery-models.ts | 4 +--- scripts/tests/environment-models.ts | 4 +--- scripts/tests/item-models.ts | 4 +--- scripts/tests/migration-models.ts | 4 +--- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/scripts/tests/delivery-models.ts b/scripts/tests/delivery-models.ts index e2d3876..5df89c1 100644 --- a/scripts/tests/delivery-models.ts +++ b/scripts/tests/delivery-models.ts @@ -10,9 +10,7 @@ const outputDir: string = './sample/delivery'; try { // needed to load .env environment to current process when run via package.json script - dotenv.config({ - path: './.env' - }); + dotenv.config(); // delete existing models console.log(`Deleting existing folder '${chalk.yellow(outputDir)}'`); diff --git a/scripts/tests/environment-models.ts b/scripts/tests/environment-models.ts index 55e35c1..c7df85c 100644 --- a/scripts/tests/environment-models.ts +++ b/scripts/tests/environment-models.ts @@ -10,9 +10,7 @@ const outputDir: string = './sample/environment'; try { // needed to load .env environment to current process when run via package.json script - dotenv.config({ - path: './.env' - }); + dotenv.config(); // delete existing models console.log(`Deleting existing folder '${chalk.yellow(outputDir)}'`); diff --git a/scripts/tests/item-models.ts b/scripts/tests/item-models.ts index fd06b3f..265f584 100644 --- a/scripts/tests/item-models.ts +++ b/scripts/tests/item-models.ts @@ -10,9 +10,7 @@ const outputDir: string = './sample/items'; try { // needed to load .env environment to current process when run via package.json script - dotenv.config({ - path: './.env' - }); + dotenv.config(); // delete existing models console.log(`Deleting existing folder '${chalk.yellow(outputDir)}'`); diff --git a/scripts/tests/migration-models.ts b/scripts/tests/migration-models.ts index 44b8534..d12f284 100644 --- a/scripts/tests/migration-models.ts +++ b/scripts/tests/migration-models.ts @@ -10,9 +10,7 @@ const outputDir: string = './sample/migration'; try { // needed to load .env environment to current process when run via package.json script - dotenv.config({ - path: './.env' - }); + dotenv.config(); // delete existing models console.log(`Deleting existing folder '${chalk.yellow(outputDir)}'`); From 1c34124a8df6746f2a1aa0deeadfb51418ceaab7 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 13:09:14 +0200 Subject: [PATCH 133/183] Renames tests -> samples directory for scripts, updates naming of scripts in package.json --- package.json | 12 ++++++------ scripts/{tests => samples}/delivery-models.ts | 0 scripts/{tests => samples}/environment-models.ts | 0 scripts/{tests => samples}/item-models.ts | 0 scripts/{tests => samples}/migration-models.ts | 0 5 files changed, 6 insertions(+), 6 deletions(-) rename scripts/{tests => samples}/delivery-models.ts (100%) rename scripts/{tests => samples}/environment-models.ts (100%) rename scripts/{tests => samples}/item-models.ts (100%) rename scripts/{tests => samples}/migration-models.ts (100%) diff --git a/package.json b/package.json index 523cced..806e4d2 100644 --- a/package.json +++ b/package.json @@ -38,12 +38,12 @@ "build:es2022": "tsc --p tsconfig.es2022.json", "build": "npm run clean && npm run build:es2022", "test:all": "npm run build", - "test:delivery": "tsx scripts/tests/delivery-models", - "test:environment": "tsx scripts/tests/environment-models", - "test:migration": "tsx scripts/tests/migration-models", - "test:items": "tsx scripts/tests/item-models", - "test:help": "tsx lib/node/cli/app --help", - "test:help:delivery-sdk": "tsx lib/node/cli/app delivery-sdk --help", + "sample:delivery": "tsx scripts/samples/delivery-models", + "sample:environment": "tsx scripts/samples/environment-models", + "sample:migration": "tsx scripts/samples/migration-models", + "sample:items": "tsx scripts/samples/item-models", + "show:help": "tsx lib/node/cli/app --help", + "show:help:delivery-sdk": "tsx lib/node/cli/app delivery-sdk --help", "lint": "eslint lib", "lint:fix": "eslint lib --fix", "clean": "tsx scripts/clean.ts", diff --git a/scripts/tests/delivery-models.ts b/scripts/samples/delivery-models.ts similarity index 100% rename from scripts/tests/delivery-models.ts rename to scripts/samples/delivery-models.ts diff --git a/scripts/tests/environment-models.ts b/scripts/samples/environment-models.ts similarity index 100% rename from scripts/tests/environment-models.ts rename to scripts/samples/environment-models.ts diff --git a/scripts/tests/item-models.ts b/scripts/samples/item-models.ts similarity index 100% rename from scripts/tests/item-models.ts rename to scripts/samples/item-models.ts diff --git a/scripts/tests/migration-models.ts b/scripts/samples/migration-models.ts similarity index 100% rename from scripts/tests/migration-models.ts rename to scripts/samples/migration-models.ts From fd9bc105ac6fead49cc85d224b1a656fca2f58ea Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 13:18:43 +0200 Subject: [PATCH 134/183] Removes "node" folder and moves "cli" under "lib" directly --- lib/{node => }/cli/actions/delivery-action.ts | 4 ++-- lib/{node => }/cli/actions/environment-action.ts | 4 ++-- lib/{node => }/cli/actions/items-action.ts | 4 ++-- lib/{node => }/cli/actions/migrate-action.ts | 4 ++-- lib/{node => }/cli/app.ts | 2 +- lib/{node => }/cli/args/args-fetcher.ts | 2 +- lib/{node => }/cli/args/args-setter.ts | 2 +- lib/{node => }/cli/cli.models.ts | 2 +- lib/{node => }/cli/commands.ts | 4 ++-- package.json | 4 ++-- 10 files changed, 16 insertions(+), 16 deletions(-) rename lib/{node => }/cli/actions/delivery-action.ts (82%) rename lib/{node => }/cli/actions/environment-action.ts (83%) rename lib/{node => }/cli/actions/items-action.ts (83%) rename lib/{node => }/cli/actions/migrate-action.ts (81%) rename lib/{node => }/cli/app.ts (95%) rename lib/{node => }/cli/args/args-fetcher.ts (96%) rename lib/{node => }/cli/args/args-setter.ts (95%) rename lib/{node => }/cli/cli.models.ts (94%) rename lib/{node => }/cli/commands.ts (96%) diff --git a/lib/node/cli/actions/delivery-action.ts b/lib/cli/actions/delivery-action.ts similarity index 82% rename from lib/node/cli/actions/delivery-action.ts rename to lib/cli/actions/delivery-action.ts index 727b4cc..0d1695f 100644 --- a/lib/node/cli/actions/delivery-action.ts +++ b/lib/cli/actions/delivery-action.ts @@ -1,5 +1,5 @@ -import { ModuleResolution } from '../../../core/core.models.js'; -import { generateDeliveryModelsAsync } from '../../../generators/delivery/delivery-func.js'; +import { ModuleResolution } from '../../core/core.models.js'; +import { generateDeliveryModelsAsync } from '../../generators/delivery/delivery-func.js'; import { CliArgumentsFetcher } from '../cli.models.js'; export async function deliveryActionAsync(cliFetcher: CliArgumentsFetcher): Promise { diff --git a/lib/node/cli/actions/environment-action.ts b/lib/cli/actions/environment-action.ts similarity index 83% rename from lib/node/cli/actions/environment-action.ts rename to lib/cli/actions/environment-action.ts index f9fec92..924fb7e 100644 --- a/lib/node/cli/actions/environment-action.ts +++ b/lib/cli/actions/environment-action.ts @@ -1,5 +1,5 @@ -import { ModuleResolution } from '../../../core/core.models.js'; -import { generateEnvironmentModelsAsync } from '../../../generators/environment/environment-func.js'; +import { ModuleResolution } from '../../core/core.models.js'; +import { generateEnvironmentModelsAsync } from '../../generators/environment/environment-func.js'; import { CliArgumentsFetcher } from '../cli.models.js'; export async function environmentActionAsync(cliFetcher: CliArgumentsFetcher): Promise { diff --git a/lib/node/cli/actions/items-action.ts b/lib/cli/actions/items-action.ts similarity index 83% rename from lib/node/cli/actions/items-action.ts rename to lib/cli/actions/items-action.ts index 95493f2..066b5eb 100644 --- a/lib/node/cli/actions/items-action.ts +++ b/lib/cli/actions/items-action.ts @@ -1,5 +1,5 @@ -import { ModuleResolution } from '../../../core/core.models.js'; -import { generateItemsAsync } from '../../../generators/items/items-func.js'; +import { ModuleResolution } from '../../core/core.models.js'; +import { generateItemsAsync } from '../../generators/items/items-func.js'; import { CliArgumentsFetcher } from '../cli.models.js'; export async function itemsActionAsync(cliFetcher: CliArgumentsFetcher): Promise { diff --git a/lib/node/cli/actions/migrate-action.ts b/lib/cli/actions/migrate-action.ts similarity index 81% rename from lib/node/cli/actions/migrate-action.ts rename to lib/cli/actions/migrate-action.ts index 28a0acf..7cf06b0 100644 --- a/lib/node/cli/actions/migrate-action.ts +++ b/lib/cli/actions/migrate-action.ts @@ -1,5 +1,5 @@ -import { ModuleResolution } from '../../../core/core.models.js'; -import { generateMigrationModelsAsync } from '../../../generators/migration/migration-func.js'; +import { ModuleResolution } from '../../core/core.models.js'; +import { generateMigrationModelsAsync } from '../../generators/migration/migration-func.js'; import { CliArgumentsFetcher } from '../cli.models.js'; export async function migrateActionAsync(cliFetcher: CliArgumentsFetcher): Promise { diff --git a/lib/node/cli/app.ts b/lib/cli/app.ts similarity index 95% rename from lib/node/cli/app.ts rename to lib/cli/app.ts index b589384..01fb052 100644 --- a/lib/node/cli/app.ts +++ b/lib/cli/app.ts @@ -2,7 +2,7 @@ import chalk from 'chalk'; import { match } from 'ts-pattern'; -import { logError } from '../../core/error.utils.js'; +import { logError } from '../core/error.utils.js'; import { deliveryActionAsync } from './actions/delivery-action.js'; import { environmentActionAsync } from './actions/environment-action.js'; import { itemsActionAsync } from './actions/items-action.js'; diff --git a/lib/node/cli/args/args-fetcher.ts b/lib/cli/args/args-fetcher.ts similarity index 96% rename from lib/node/cli/args/args-fetcher.ts rename to lib/cli/args/args-fetcher.ts index 5cee873..71a3761 100644 --- a/lib/node/cli/args/args-fetcher.ts +++ b/lib/cli/args/args-fetcher.ts @@ -2,7 +2,7 @@ import chalk from 'chalk'; import { match } from 'ts-pattern'; import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; -import { CliAction, LiteralUnion } from '../../../core/core.models.js'; +import { CliAction, LiteralUnion } from '../../core/core.models.js'; import { CliArgumentsFetcher } from '../cli.models.js'; type ArgvResult = { diff --git a/lib/node/cli/args/args-setter.ts b/lib/cli/args/args-setter.ts similarity index 95% rename from lib/node/cli/args/args-setter.ts rename to lib/cli/args/args-setter.ts index cd20835..e23c2ec 100644 --- a/lib/node/cli/args/args-setter.ts +++ b/lib/cli/args/args-setter.ts @@ -1,6 +1,6 @@ import yargs from 'yargs'; import { hideBin } from 'yargs/helpers'; -import { CliAction } from '../../../core/core.models.js'; +import { CliAction } from '../../core/core.models.js'; import { CliArgumentsSetter, Command, CommandOption } from '../cli.models.js'; export function argumentsSetter(): CliArgumentsSetter { diff --git a/lib/node/cli/cli.models.ts b/lib/cli/cli.models.ts similarity index 94% rename from lib/node/cli/cli.models.ts rename to lib/cli/cli.models.ts index e3b7242..1f4f48f 100644 --- a/lib/node/cli/cli.models.ts +++ b/lib/cli/cli.models.ts @@ -1,4 +1,4 @@ -import { CliAction } from '../../core/core.models.js'; +import { CliAction } from '../core/core.models.js'; export interface Command { readonly name: TAction; diff --git a/lib/node/cli/commands.ts b/lib/cli/commands.ts similarity index 96% rename from lib/node/cli/commands.ts rename to lib/cli/commands.ts index 9d82863..79cf9d2 100644 --- a/lib/node/cli/commands.ts +++ b/lib/cli/commands.ts @@ -1,5 +1,5 @@ -import { CliAction, LibraryType } from '../../core/core.models.js'; -import { ModuleResolution } from '../../public_api.js'; +import { CliAction, LibraryType } from '../core/core.models.js'; +import { ModuleResolution } from '../public_api.js'; import { argumentsSetter } from './args/args-setter.js'; import { CommandOption } from './cli.models.js'; diff --git a/package.json b/package.json index 806e4d2..fce6417 100644 --- a/package.json +++ b/package.json @@ -42,8 +42,8 @@ "sample:environment": "tsx scripts/samples/environment-models", "sample:migration": "tsx scripts/samples/migration-models", "sample:items": "tsx scripts/samples/item-models", - "show:help": "tsx lib/node/cli/app --help", - "show:help:delivery-sdk": "tsx lib/node/cli/app delivery-sdk --help", + "show:help": "tsx lib/cli/app --help", + "show:help:delivery-sdk": "tsx lib/cli/app delivery-sdk --help", "lint": "eslint lib", "lint:fix": "eslint lib --fix", "clean": "tsx scripts/clean.ts", From c494bd4c30c58af704c180e70f58939a9f12a91f Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 13:27:41 +0200 Subject: [PATCH 135/183] Updates readme to use npx samples --- README.md | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6b7f3dc..fccb715 100644 --- a/README.md +++ b/README.md @@ -14,42 +14,46 @@ models you can generate: 3. `environment` - Strongly typed objects representing all structural objects within an environment (i.e. content types, workflows, taxonomies ...). These models help you write scripts because they provide you a straightforward access to objects properties. 4. `items` - Generates `Type` representing all available item codenames for each content type and object representing `id` and `codenames` - properties of all items. This makes it easy and convenient to reference items in your code. It is not recommended to use this if your - environment contains high number of items. + properties of all items. This makes it easy and convenient to reference items in your code. _It is not recommended to use this if your + environment contains high number of items._ ## Installation -Install package globally so you can use it anywhere: +Install as a `dev dependency` to your project or use `npx` ```bash -npm i @kontent-ai/model-generator -g +# Install as dev dependency +npm i --save-dev @kontent-ai/model-generator + +# Run with npx +npx @kontent-ai/model-generator@latest --help ``` -## Use with CLI +## Usage Go to folder where you want to create models and run: ```bash # Models for Delivery SDK -kontent-generate delivery-sdk --environmentId=x --apiKey=y +npx @kontent-ai/model-generator@latest --environmentId=x --apiKey=y # Models for Migration Toolkit -kontent-generate migration-toolkit --environmentId=x --apiKey=y +npx @kontent-ai/model-generator@latest migration-toolkit --environmentId=x --apiKey=y # Environment models used for scripting and strongly typed access to environment objects -kontent-generate environment --environmentId=x --apiKey=y +npx @kontent-ai/model-generator@latest environment --environmentId=x --apiKey=y # Items overview with ids / codenames and Types representing available item codenames -kontent-generate items --environmentId=x --apiKey=y +npx @kontent-ai/model-generator@latest items --environmentId=x --apiKey=y ``` To learn what options are available use the `help` command: ```bash -kontent-generate --help +npx @kontent-ai/model-generator@latest --help # or get help for specific command -kontent-generate delivery-sdk --help +npx @kontent-ai/model-generator@latest delivery-sdk --help ``` ## Use in code From 1c36ae8639b8d045d8272157d1dd317a40f5e37c Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 13:28:37 +0200 Subject: [PATCH 136/183] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fccb715..841374b 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ models you can generate: 3. `environment` - Strongly typed objects representing all structural objects within an environment (i.e. content types, workflows, taxonomies ...). These models help you write scripts because they provide you a straightforward access to objects properties. 4. `items` - Generates `Type` representing all available item codenames for each content type and object representing `id` and `codenames` - properties of all items. This makes it easy and convenient to reference items in your code. _It is not recommended to use this if your - environment contains high number of items._ + properties of all items. This makes it easy and convenient to reference items in your code. **It is not recommended to use this if your + environment contains high number of items.** ## Installation From 0a68b4c9a89687114fc6dcaff02c218f79f5c78d Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 13:31:25 +0200 Subject: [PATCH 137/183] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 841374b..0c570ab 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ models you can generate: 3. `environment` - Strongly typed objects representing all structural objects within an environment (i.e. content types, workflows, taxonomies ...). These models help you write scripts because they provide you a straightforward access to objects properties. 4. `items` - Generates `Type` representing all available item codenames for each content type and object representing `id` and `codenames` - properties of all items. This makes it easy and convenient to reference items in your code. **It is not recommended to use this if your - environment contains high number of items.** + properties of all items. This makes it easy and convenient to reference items in your code. + > It is not recommended to use this if your environment contains high number of items. ## Installation From 4552fc3351e864c1af4f1a46375c01f92786ab1f Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 13:36:50 +0200 Subject: [PATCH 138/183] Removes 'preferGlobal' from package.json --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index fce6417..720dbf1 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "Kontent Model Generator", "Kontent.ai strongly typed models" ], - "preferGlobal": true, "exports": "./dist/es2022/lib/public_api.js", "types": "./dist/es2022/lib/public_api.d.ts", "type": "module", From 0175c0b12243813b5e681ca07fe69ea5fc37521c Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 27 Sep 2024 13:39:35 +0200 Subject: [PATCH 139/183] Updates toPascalCase regex --- lib/core/core.utils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index dd53a20..24cfaa1 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -29,10 +29,10 @@ export function toPascalCase(text: string): string { toSafeStringCode( text .toLowerCase() - .replace(new RegExp(/[-_]+/, 'g'), ' ') - .replace(new RegExp(/[^\w\s]/, 'g'), '') - .replace(new RegExp(/\s+(.)(\w*)/, 'g'), ($1, $2, $3) => `${($2 as string).toUpperCase() + $3}`) - .replace(new RegExp(/\w/), (s) => s.toUpperCase()) + .replace(/[-_]+/g, ' ') + .replace(/[^\w\s]/g, '') + .replace(/\s+(.)(\w*)/g, (_, $2, $3) => `${($2 as string).toUpperCase() + $3}`) + .replace(/\w/, (s) => s.toUpperCase()) ) ); } From 91bdc00b3c0813e19010f2374540e3372e0ce49b Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 30 Sep 2024 08:37:19 +0200 Subject: [PATCH 140/183] Updates the way default module resolution is resolved --- lib/config.ts | 4 ++++ lib/core/core.utils.ts | 5 ----- lib/generators/delivery/delivery-func.ts | 6 +++--- lib/generators/environment/environment-func.ts | 6 +++--- lib/generators/items/items-func.ts | 6 +++--- lib/generators/migration/migration-func.ts | 6 +++--- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/config.ts b/lib/config.ts index c1dd9b4..7bdfa45 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -1,3 +1,7 @@ +import { ModuleResolution } from './core/core.models.js'; + +export const defaultModuleResolution: ModuleResolution = 'node'; + export const coreConfig = { barrelExportFilename: 'index.ts' } as const; diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 24cfaa1..90d2225 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -1,5 +1,4 @@ import { createHash } from 'crypto'; -import { ModuleResolution } from './core.models.js'; export function uniqueFilter(value: string, index: number, self: readonly string[]): boolean { return self.indexOf(value) === index; @@ -7,10 +6,6 @@ export function uniqueFilter(value: string, index: number, self: readonly string export const isNotUndefined = (item: T | undefined): item is T => item !== undefined; -export function getDefaultModuleResolution(moduleResolution: ModuleResolution | undefined): ModuleResolution { - return moduleResolution ?? 'node'; -} - export function getFileNameWithoutExtension(filePath: string): string { return filePath.substring(0, filePath.lastIndexOf('.')); } diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index 867c5ff..6b5545d 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -1,9 +1,9 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; -import { coreConfig, deliveryConfig } from '../../config.js'; +import { coreConfig, defaultModuleResolution, deliveryConfig } from '../../config.js'; import { GeneratedFile, ModuleResolution } from '../../core/core.models.js'; -import { getDefaultModuleResolution, getFilenameFromPath } from '../../core/core.utils.js'; +import { getFilenameFromPath } from '../../core/core.utils.js'; import { importer as _importer } from '../../core/importer.js'; import { ContentTypeFileNameResolver, @@ -74,7 +74,7 @@ async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ readonly moduleResolution: ModuleResolution; readonly environmentInfo: Readonly; }> { - const moduleResolution: ModuleResolution = getDefaultModuleResolution(config.moduleResolution); + const moduleResolution: ModuleResolution = config.moduleResolution ?? defaultModuleResolution; const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, diff --git a/lib/generators/environment/environment-func.ts b/lib/generators/environment/environment-func.ts index f1d8496..29a21c2 100644 --- a/lib/generators/environment/environment-func.ts +++ b/lib/generators/environment/environment-func.ts @@ -1,9 +1,9 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; -import { coreConfig } from '../../config.js'; +import { coreConfig, defaultModuleResolution } from '../../config.js'; import { GeneratedFile, ModuleResolution } from '../../core/core.models.js'; -import { getDefaultModuleResolution, getFilenameFromPath } from '../../core/core.utils.js'; +import { getFilenameFromPath } from '../../core/core.utils.js'; import { importer as _importer } from '../../core/importer.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; import { fileManager as _fileManager } from '../../files/file-manager.js'; @@ -44,7 +44,7 @@ async function getModelsAsync(config: GenerateEnvironmentModelsConfig): Promise< moduleResolution: ModuleResolution; readonly environmentInfo: Readonly; }> { - const moduleResolution: ModuleResolution = getDefaultModuleResolution(config.moduleResolution); + const moduleResolution: ModuleResolution = config.moduleResolution ?? defaultModuleResolution; const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, diff --git a/lib/generators/items/items-func.ts b/lib/generators/items/items-func.ts index f90b951..59637f1 100644 --- a/lib/generators/items/items-func.ts +++ b/lib/generators/items/items-func.ts @@ -1,9 +1,9 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; -import { coreConfig, itemsConfig } from '../../config.js'; +import { coreConfig, defaultModuleResolution, itemsConfig } from '../../config.js'; import { GeneratedFile, ModuleResolution } from '../../core/core.models.js'; -import { getDefaultModuleResolution, getFilenameFromPath } from '../../core/core.utils.js'; +import { getFilenameFromPath } from '../../core/core.utils.js'; import { importer as _importer } from '../../core/importer.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; import { fileManager as _fileManager } from '../../files/file-manager.js'; @@ -45,7 +45,7 @@ async function getFilesAsync(config: GenerateItemsModelsConfig): Promise<{ readonly moduleResolution: ModuleResolution; readonly environmentInfo: Readonly; }> { - const moduleResolution: ModuleResolution = getDefaultModuleResolution(config.moduleResolution); + const moduleResolution: ModuleResolution = config.moduleResolution ?? defaultModuleResolution; const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index c5e227c..14fb6b0 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -1,9 +1,9 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; -import { coreConfig, migrationConfig } from '../../config.js'; +import { coreConfig, defaultModuleResolution, migrationConfig } from '../../config.js'; import { GeneratedFile, ModuleResolution } from '../../core/core.models.js'; -import { getDefaultModuleResolution, getFilenameFromPath } from '../../core/core.utils.js'; +import { getFilenameFromPath } from '../../core/core.utils.js'; import { importer as _importer } from '../../core/importer.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; import { fileManager as _fileManager } from '../../files/file-manager.js'; @@ -47,7 +47,7 @@ async function getFilesAsync(config: GenerateMigrationModelsConfig): Promise<{ readonly moduleResolution: ModuleResolution; readonly environmentInfo: Readonly; }> { - const moduleResolution: ModuleResolution = getDefaultModuleResolution(config.moduleResolution); + const moduleResolution: ModuleResolution = config.moduleResolution ?? defaultModuleResolution; const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, From 0803a6f9c0076bdb4ed86a3ecaa61cd949cef852 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 30 Sep 2024 09:02:20 +0200 Subject: [PATCH 141/183] renames generator.utils & creates local function to generate types --- .../delivery-content-type.generator.ts | 2 +- .../migration/migration.generator.ts | 2 +- ...or.utils.ts => type-codename.generator.ts} | 24 +++++++++++++------ 3 files changed, 19 insertions(+), 9 deletions(-) rename lib/generators/shared/{generator.utils.ts => type-codename.generator.ts} (51%) diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 52ac16e..4c75090 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -30,7 +30,7 @@ import { getLanguageCodenamesType, getWorkflowCodenamesType, getWorkflowStepCodenamesType -} from '../shared/generator.utils.js'; +} from '../shared/type-codename.generator.js'; interface ExtractImportsResult { readonly typeName: string; diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index 898e8e0..bbf762e 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -20,7 +20,7 @@ import { getLanguageCodenamesType, getWorkflowCodenamesType, getWorkflowStepCodenamesType -} from '../shared/generator.utils.js'; +} from '../shared/type-codename.generator.js'; export interface MigrationGeneratorConfig { readonly moduleResolution: ModuleResolution; diff --git a/lib/generators/shared/generator.utils.ts b/lib/generators/shared/type-codename.generator.ts similarity index 51% rename from lib/generators/shared/generator.utils.ts rename to lib/generators/shared/type-codename.generator.ts index 4f38378..9648c16 100644 --- a/lib/generators/shared/generator.utils.ts +++ b/lib/generators/shared/type-codename.generator.ts @@ -2,26 +2,36 @@ import { CollectionModels, ContentTypeModels, LanguageModels, WorkflowModels } f import { sharedTypesConfig } from '../../config.js'; import { uniqueFilter } from '../../core/core.utils.js'; +interface ItemWithCodename { + readonly codename: string; +} + export function getLanguageCodenamesType(languages: readonly Readonly[]): string { - return `export type ${sharedTypesConfig.languageCodenames} = ${languages.map((language) => `'${language.codename}'`).join(' | ')};`; + return getTypeWithCodenames(sharedTypesConfig.languageCodenames, languages); } export function getContentTypeCodenamesType(types: readonly Readonly[]): string { - return `export type ${sharedTypesConfig.contentTypeCodenames} = ${types.map((type) => `'${type.codename}'`).join(' | ')};`; + return getTypeWithCodenames(sharedTypesConfig.contentTypeCodenames, types); } export function getWorkflowCodenamesType(workflows: readonly Readonly[]): string { - return `export type ${sharedTypesConfig.workflowCodenames} = ${workflows.map((workflow) => `'${workflow.codename}'`).join(' | ')};`; + return getTypeWithCodenames(sharedTypesConfig.workflowCodenames, workflows); } export function getCollectionCodenamesType(collections: readonly Readonly[]): string { - return `export type ${sharedTypesConfig.collectionCodenames} = ${collections.map((collection) => `'${collection.codename}'`).join(' | ')};`; + return getTypeWithCodenames(sharedTypesConfig.collectionCodenames, collections); } export function getWorkflowStepCodenamesType(workflows: readonly Readonly[]): string { - return `export type ${sharedTypesConfig.workflowStepCodenames} = ${workflows - .flatMap((workflow) => [...workflow.steps, workflow.publishedStep, workflow.archivedStep, workflow.scheduledStep]) - .map((workflowStep) => `'${workflowStep.codename}'`) + return getTypeWithCodenames( + sharedTypesConfig.workflowStepCodenames, + workflows.flatMap((workflow) => [...workflow.steps, workflow.publishedStep, workflow.archivedStep, workflow.scheduledStep]) + ); +} + +function getTypeWithCodenames(typeName: string, items: readonly ItemWithCodename[]): string { + return `export type ${typeName} = ${items + .map((item) => `'${item.codename}'`) .filter(uniqueFilter) .join(' | ')};`; } From 04f34d8d6a41560877a4e1cdc80469eca2a4e230 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 30 Sep 2024 09:46:01 +0200 Subject: [PATCH 142/183] Reuses existing type instead --- lib/generators/shared/type-codename.generator.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/generators/shared/type-codename.generator.ts b/lib/generators/shared/type-codename.generator.ts index 9648c16..3593ecf 100644 --- a/lib/generators/shared/type-codename.generator.ts +++ b/lib/generators/shared/type-codename.generator.ts @@ -1,11 +1,8 @@ import { CollectionModels, ContentTypeModels, LanguageModels, WorkflowModels } from '@kontent-ai/management-sdk'; import { sharedTypesConfig } from '../../config.js'; +import { ObjectWithCodename } from '../../core/core.models.js'; import { uniqueFilter } from '../../core/core.utils.js'; -interface ItemWithCodename { - readonly codename: string; -} - export function getLanguageCodenamesType(languages: readonly Readonly[]): string { return getTypeWithCodenames(sharedTypesConfig.languageCodenames, languages); } @@ -29,7 +26,7 @@ export function getWorkflowStepCodenamesType(workflows: readonly Readonly `'${item.codename}'`) .filter(uniqueFilter) From 1e37d34e866d94c98f045732532aea47489359d7 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 30 Sep 2024 11:53:04 +0200 Subject: [PATCH 143/183] Refactors the way files / barrel files are created to make it more streamlined and centralized --- lib/core/core.models.ts | 5 + lib/files/file-manager.ts | 53 +++++++-- .../delivery-content-type.generator.ts | 37 +++--- lib/generators/delivery/delivery-func.ts | 112 +++--------------- .../delivery/delivery-taxonomy.generator.ts | 15 ++- .../environment/environment-func.ts | 52 ++------ .../environment/environment.generator.ts | 83 ++++++------- lib/generators/items/items-func.ts | 69 ++--------- lib/generators/items/items.generator.ts | 40 ++++--- lib/generators/migration/migration-func.ts | 78 ++---------- .../migration/migration.generator.ts | 45 ++++--- sample/environment/assetFolders.ts | 2 +- sample/environment/collections.ts | 2 +- sample/environment/contentTypeSnippets.ts | 2 +- sample/environment/contentTypes.ts | 2 +- sample/environment/index.ts | 2 +- sample/environment/languages.ts | 4 +- sample/environment/roles.ts | 2 +- sample/environment/taxonomies.ts | 2 +- sample/environment/webhooks.ts | 2 +- sample/environment/workflows.ts | 2 +- sample/items/codenames/actor.codenames.ts | 2 +- sample/items/codenames/index.ts | 2 +- sample/items/codenames/movie.codenames.ts | 2 +- sample/items/index.ts | 2 +- sample/items/items/actor.items.ts | 2 +- sample/items/items/index.ts | 2 +- sample/items/items/movie.items.ts | 2 +- sample/migration/content-types/actor.ts | 2 +- sample/migration/content-types/index.ts | 2 +- sample/migration/content-types/movie.ts | 2 +- sample/migration/environment/environment.ts | 2 +- sample/migration/environment/index.ts | 2 +- sample/migration/index.ts | 2 +- sample/migration/migration.ts | 2 +- 35 files changed, 247 insertions(+), 392 deletions(-) diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index 9e7bc8e..7788f3b 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -60,6 +60,11 @@ export interface GeneratedFile { readonly text: string; } +export interface GeneratedSet { + readonly files: readonly GeneratedFile[]; + readonly folderName: string | undefined; +} + export type ObjectWithCodename = { readonly codename: string; }; diff --git a/lib/files/file-manager.ts b/lib/files/file-manager.ts index 2d3d1ee..b3588aa 100644 --- a/lib/files/file-manager.ts +++ b/lib/files/file-manager.ts @@ -3,34 +3,38 @@ import chalk from 'chalk'; import * as fs from 'fs'; import { dirname } from 'path'; import { Options } from 'prettier'; +import { coreConfig } from '../config.js'; import { getEnvironmentInfoComment } from '../core/comment.utils.js'; -import { GeneratedFile } from '../core/core.models.js'; +import { GeneratedFile, GeneratedSet, ModuleResolution } from '../core/core.models.js'; import { toOutputDirPath } from '../core/core.utils.js'; +import { importer as _importer } from '../core/importer.js'; import { formatCodeAsync } from '../format/formatter.js'; export function fileManager(config: { + readonly moduleResolution: ModuleResolution; readonly outputDir: string | undefined; readonly formatOptions: Readonly | undefined; readonly environmentInfo: Readonly; readonly addTimestamp: boolean; }) { const fixedOutputDir = toOutputDirPath(config.outputDir); + const importer = _importer(config.moduleResolution); - const createFileOnFsAsync = async (text: string, filePath: string, formatOptions: Readonly | undefined): Promise => { + const createFileOnFsAsync = async (text: string, filePath: string): Promise => { const fullFilePath = `${fixedOutputDir.endsWith('/') ? fixedOutputDir : `${fixedOutputDir}/`}${filePath}`; const fileContent = `${getEnvironmentInfoComment({ environmentInfo: config.environmentInfo, addTimestamp: config.addTimestamp - })}\n\n${await getFormattedCodeAsync(text, filePath, formatOptions)}`; + })}\n\n${await getFormattedCodeAsync(text, filePath)}`; ensureDirectoryExistence(fullFilePath); fs.writeFileSync('./' + fullFilePath, fileContent, {}); console.log(`Created '${chalk.yellow(fullFilePath)}'`); }; - const getFormattedCodeAsync = async (code: string, filePath: string, formatOptions: Readonly | undefined): Promise => { + const getFormattedCodeAsync = async (code: string, filePath: string): Promise => { try { - return await formatCodeAsync(code, formatOptions); + return await formatCodeAsync(code, config.formatOptions); } catch { console.log(`Failed to format file '${chalk.red(filePath)}'. Skipping prettier for this file.`); return code; @@ -49,12 +53,47 @@ export function fileManager(config: { const createFilesAsync = async (files: readonly GeneratedFile[]): Promise => { await Promise.all( files.map(async (file) => { - return await createFileOnFsAsync(file.text, file.filename, config.formatOptions); + return await createFileOnFsAsync(file.text, file.filename); }) ); }; + const createSetAsync = async (set: GeneratedSet): Promise => { + const setFolder = set.folderName ? `${set.folderName}/` : ''; + + await createFilesAsync([ + ...set.files.map((file) => { + return { + filename: `${setFolder}${file.filename}`, + text: file.text + }; + }), + { + filename: `${setFolder}${coreConfig.barrelExportFilename}`, + text: importer.getBarrelExportCode(set.files.map((m) => `./${m.filename}`)) + } + ]); + }; + return { - createFilesAsync + createFilesAsync, + createSetAsync, + createSetsAsync: async (sets: readonly GeneratedSet[]): Promise => { + await Promise.all(sets.map((set) => createSetAsync(set))); + await createFileOnFsAsync( + importer.getBarrelExportCode( + sets.flatMap((set) => { + if (!set.folderName) { + // include file paths themselves if there is no folder + return set.files.map((file) => `./${file.filename}`); + } + + const setFolder = set.folderName ? `${set.folderName}/` : ''; + return `./${setFolder}${coreConfig.barrelExportFilename}`; + }) + ), + coreConfig.barrelExportFilename + ); + } }; } diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 4c75090..2f686f5 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -10,7 +10,7 @@ import { import { match, P } from 'ts-pattern'; import { coreConfig, deliveryConfig, sharedTypesConfig } from '../../config.js'; import { wrapComment } from '../../core/comment.utils.js'; -import { FlattenedElement, GeneratedFile, ModuleResolution } from '../../core/core.models.js'; +import { FlattenedElement, GeneratedFile, GeneratedSet, ModuleResolution } from '../../core/core.models.js'; import { isNotUndefined, sortAlphabetically, toGuidelinesComment, uniqueFilter } from '../../core/core.utils.js'; import { getFlattenedElements } from '../../core/element.utils.js'; import { importer as _importer } from '../../core/importer.js'; @@ -336,14 +336,14 @@ ${nameOfTypeRepresentingAllElementCodenames}>; const createTypeModel = (type: Readonly): GeneratedFile => { return { - filename: `${deliveryConfig.contentTypesFolderName}/${fileResolvers.contentType(type, true)}`, + filename: fileResolvers.contentType(type, true), text: getContentTypeCode(type) }; }; const createSnippetModel = (type: Readonly): GeneratedFile => { return { - filename: `${deliveryConfig.contentTypeSnippetsFolderName}/${fileResolvers.contentType(type, true)}`, + filename: fileResolvers.contentType(type, true), text: getSnippetCode(type) }; }; @@ -453,19 +453,27 @@ ${nameOfTypeRepresentingAllElementCodenames}>; return { generateModels: (): { - contentTypeFiles: readonly GeneratedFile[]; - snippetFiles: readonly GeneratedFile[]; + contentTypeFiles: GeneratedSet; + snippetFiles: GeneratedSet; } => { return { - contentTypeFiles: config.environmentData.types.map((type) => createTypeModel(type)), - snippetFiles: config.environmentData.snippets.map((contentTypeSnippet) => createSnippetModel(contentTypeSnippet)) + contentTypeFiles: { + folderName: deliveryConfig.contentTypesFolderName, + files: config.environmentData.types.map((type) => createTypeModel(type)) + }, + snippetFiles: { + folderName: deliveryConfig.contentTypeSnippetsFolderName, + files: config.environmentData.snippets.map((contentTypeSnippet) => createSnippetModel(contentTypeSnippet)) + } }; }, - getSystemFiles(): readonly GeneratedFile[] { - return [ - { - filename: `${deliveryConfig.systemTypesFolderName}/${deliveryConfig.coreCodenamesFilename}.ts`, - text: ` + getSystemFiles(): GeneratedSet { + return { + folderName: deliveryConfig.systemTypesFolderName, + files: [ + { + filename: `${deliveryConfig.coreCodenamesFilename}.ts`, + text: ` ${wrapComment(`\n * Type representing all languages\n`)} ${getLanguageCodenamesType(config.environmentData.languages)} @@ -481,8 +489,9 @@ ${nameOfTypeRepresentingAllElementCodenames}>; ${wrapComment(`\n * Type representing all worksflow steps across all workflows\n`)} ${getWorkflowStepCodenamesType(config.environmentData.workflows)} ` - } - ]; + } + ] + }; } }; } diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index 6b5545d..6722a01 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -1,10 +1,8 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; -import { coreConfig, defaultModuleResolution, deliveryConfig } from '../../config.js'; -import { GeneratedFile, ModuleResolution } from '../../core/core.models.js'; -import { getFilenameFromPath } from '../../core/core.utils.js'; -import { importer as _importer } from '../../core/importer.js'; +import { defaultModuleResolution } from '../../config.js'; +import { GeneratedSet, ModuleResolution } from '../../core/core.models.js'; import { ContentTypeFileNameResolver, ContentTypeNameResolver, @@ -47,30 +45,24 @@ export async function generateDeliveryModelsAsync(config: GenerateDeliveryModels const { contentTypeFiles, snippetFiles, taxonomyFiles, moduleResolution, environmentInfo, systemFiles } = await getFilesAsync(config); - await createFilesAsync( - { - contentTypeFiles, - snippetFiles, - taxonomyFiles, - environmentInfo, - systemFiles - }, - { - formatOptions: config.formatOptions, - moduleResolution: moduleResolution, - outputDir: config.outputDir, - addTimestamp: config.addTimestamp - } - ); + const fileManager = _fileManager({ + outputDir: config.outputDir, + addTimestamp: config.addTimestamp, + environmentInfo: environmentInfo, + formatOptions: config.formatOptions, + moduleResolution: moduleResolution + }); + + await fileManager.createSetsAsync([contentTypeFiles, snippetFiles, taxonomyFiles, systemFiles]); console.log(chalk.green(`\nCompleted`)); } async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ - readonly contentTypeFiles: readonly GeneratedFile[]; - readonly snippetFiles: readonly GeneratedFile[]; - readonly taxonomyFiles: readonly GeneratedFile[]; - readonly systemFiles: readonly GeneratedFile[]; + readonly contentTypeFiles: GeneratedSet; + readonly snippetFiles: GeneratedSet; + readonly taxonomyFiles: GeneratedSet; + readonly systemFiles: GeneratedSet; readonly moduleResolution: ModuleResolution; readonly environmentInfo: Readonly; }> { @@ -128,77 +120,3 @@ async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ systemFiles: deliveryGenerator.getSystemFiles() }; } - -async function createFilesAsync( - data: { - readonly systemFiles: readonly GeneratedFile[]; - readonly contentTypeFiles: readonly GeneratedFile[]; - readonly snippetFiles: readonly GeneratedFile[]; - readonly taxonomyFiles: readonly GeneratedFile[]; - readonly environmentInfo: Readonly; - }, - config: { - readonly addTimestamp: boolean; - readonly outputDir: string | undefined; - readonly moduleResolution: ModuleResolution; - readonly formatOptions: Readonly | undefined; - } -): Promise { - const fileManager = _fileManager({ - outputDir: config.outputDir, - addTimestamp: config.addTimestamp, - environmentInfo: data.environmentInfo, - formatOptions: config.formatOptions - }); - - const importer = _importer(config.moduleResolution); - - await fileManager.createFilesAsync([ - ...data.contentTypeFiles, - ...data.snippetFiles, - ...data.taxonomyFiles, - ...data.systemFiles, - // barrel files - { - filename: `${deliveryConfig.systemTypesFolderName}/${coreConfig.barrelExportFilename}`, - text: importer.getBarrelExportCode([ - ...data.systemFiles.map((m) => { - return `./${getFilenameFromPath(m.filename)}`; - }) - ]) - }, - { - filename: `${deliveryConfig.contentTypesFolderName}/${coreConfig.barrelExportFilename}`, - text: importer.getBarrelExportCode([ - ...data.contentTypeFiles.map((m) => { - return `./${getFilenameFromPath(m.filename)}`; - }) - ]) - }, - { - filename: `${deliveryConfig.contentTypeSnippetsFolderName}/${coreConfig.barrelExportFilename}`, - text: importer.getBarrelExportCode([ - ...data.snippetFiles.map((m) => { - return `./${getFilenameFromPath(m.filename)}`; - }) - ]) - }, - { - filename: `${deliveryConfig.taxonomiesFolderName}/${coreConfig.barrelExportFilename}`, - text: importer.getBarrelExportCode([ - ...data.taxonomyFiles.map((m) => { - return `./${getFilenameFromPath(m.filename)}`; - }) - ]) - }, - { - filename: coreConfig.barrelExportFilename, - text: importer.getBarrelExportCode([ - `./${deliveryConfig.contentTypesFolderName}/index`, - `./${deliveryConfig.contentTypeSnippetsFolderName}/index`, - `./${deliveryConfig.taxonomiesFolderName}/index`, - `./${deliveryConfig.systemTypesFolderName}/index` - ]) - } - ]); -} diff --git a/lib/generators/delivery/delivery-taxonomy.generator.ts b/lib/generators/delivery/delivery-taxonomy.generator.ts index 4fa8558..2e3ef09 100644 --- a/lib/generators/delivery/delivery-taxonomy.generator.ts +++ b/lib/generators/delivery/delivery-taxonomy.generator.ts @@ -1,7 +1,7 @@ import { EnvironmentModels, TaxonomyModels } from '@kontent-ai/management-sdk'; import { deliveryConfig } from '../../config.js'; import { wrapComment } from '../../core/comment.utils.js'; -import { GeneratedFile, ModuleResolution } from '../../core/core.models.js'; +import { GeneratedFile, GeneratedSet, ModuleResolution } from '../../core/core.models.js'; import { TaxonomyNameResolver, TaxonomyTypeFileNameResolver, mapFilename, mapName } from '../../core/resolvers.js'; export interface DeliveryTaxonomyGeneratorConfig { @@ -24,15 +24,18 @@ export function deliveryTaxonomyGenerator(config: DeliveryTaxonomyGeneratorConfi const taxonomyFileNameMap = mapFilename(config.fileResolvers?.taxonomy); const taxonomyNameMap = mapName(config.nameResolvers?.taxonomy, 'pascalCase'); - const generateTaxonomyTypes = (): readonly GeneratedFile[] => { - return config.environmentData.taxonomies.map((taxonomy) => { - return getTaxonomyFile(taxonomy); - }); + const generateTaxonomyTypes = (): GeneratedSet => { + return { + folderName: deliveryConfig.taxonomiesFolderName, + files: config.environmentData.taxonomies.map((taxonomy) => { + return getTaxonomyFile(taxonomy); + }) + }; }; const getTaxonomyFile = (taxonomy: Readonly): GeneratedFile => { return { - filename: `${deliveryConfig.taxonomiesFolderName}/${taxonomyFileNameMap(taxonomy, true)}`, + filename: taxonomyFileNameMap(taxonomy, true), text: getModelCode(taxonomy) }; }; diff --git a/lib/generators/environment/environment-func.ts b/lib/generators/environment/environment-func.ts index 29a21c2..8a34126 100644 --- a/lib/generators/environment/environment-func.ts +++ b/lib/generators/environment/environment-func.ts @@ -1,10 +1,8 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; -import { coreConfig, defaultModuleResolution } from '../../config.js'; -import { GeneratedFile, ModuleResolution } from '../../core/core.models.js'; -import { getFilenameFromPath } from '../../core/core.utils.js'; -import { importer as _importer } from '../../core/importer.js'; +import { defaultModuleResolution } from '../../config.js'; +import { GeneratedSet, ModuleResolution } from '../../core/core.models.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; import { fileManager as _fileManager } from '../../files/file-manager.js'; import { environmentGenerator as _environmentGenerator } from './environment.generator.js'; @@ -27,20 +25,21 @@ export async function generateEnvironmentModelsAsync(config: GenerateEnvironment const { moduleResolution, environmentFiles: projectFiles, environmentInfo } = await getModelsAsync(config); - await createFilesAsync({ - moduleResolution, - projectFiles, - outputDir: config.outputDir, - formatOptions: config.formatOptions, + const fileManager = _fileManager({ addTimestamp: config.addTimestamp, - environmentInfo + environmentInfo: environmentInfo, + formatOptions: config.formatOptions, + outputDir: config.outputDir, + moduleResolution: moduleResolution }); + await fileManager.createSetsAsync([projectFiles]); + console.log(chalk.green(`\nCompleted`)); } async function getModelsAsync(config: GenerateEnvironmentModelsConfig): Promise<{ - environmentFiles: readonly GeneratedFile[]; + environmentFiles: GeneratedSet; moduleResolution: ModuleResolution; readonly environmentInfo: Readonly; }> { @@ -84,34 +83,3 @@ async function getModelsAsync(config: GenerateEnvironmentModelsConfig): Promise< moduleResolution: moduleResolution }; } - -async function createFilesAsync(data: { - readonly projectFiles: readonly GeneratedFile[]; - readonly moduleResolution: ModuleResolution; - readonly outputDir?: string; - readonly addTimestamp: boolean; - readonly environmentInfo: Readonly; - readonly formatOptions?: Readonly; -}): Promise { - const fileManager = _fileManager({ - addTimestamp: data.addTimestamp, - environmentInfo: data.environmentInfo, - formatOptions: data.formatOptions, - outputDir: data.outputDir - }); - - const importer = _importer(data.moduleResolution); - - await fileManager.createFilesAsync([ - ...data.projectFiles, - // barrel file - { - filename: coreConfig.barrelExportFilename, - text: importer.getBarrelExportCode([ - ...data.projectFiles.map((m) => { - return `./${getFilenameFromPath(m.filename)}`; - }) - ]) - } - ]); -} diff --git a/lib/generators/environment/environment.generator.ts b/lib/generators/environment/environment.generator.ts index 7f9bb31..c698997 100644 --- a/lib/generators/environment/environment.generator.ts +++ b/lib/generators/environment/environment.generator.ts @@ -13,7 +13,7 @@ import { } from '@kontent-ai/management-sdk'; import { match } from 'ts-pattern'; import { wrapComment } from '../../core/comment.utils.js'; -import { FlattenedElement, GeneratedFile } from '../../core/core.models.js'; +import { FlattenedElement, GeneratedSet } from '../../core/core.models.js'; import { getStringOrUndefined, toGuidelinesComment, toSafePropertyName, toSafePropertyValue } from '../../core/core.utils.js'; import { getFlattenedElements } from '../../core/element.utils.js'; @@ -39,61 +39,64 @@ export interface ProjectGeneratorConfig { } export function environmentGenerator(config: ProjectGeneratorConfig) { - const generateEnvironmentModels = (): readonly GeneratedFile[] => { - return [ - { - text: `export const languages = { + const generateEnvironmentModels = (): GeneratedSet => { + return { + folderName: undefined, + files: [ + { + text: `export const languages = { ${getProjectLanguages(config.environmentData.languages)} } as const;`, - filename: 'languages.ts' - }, - { - text: `export const collections = { + filename: 'languages.ts' + }, + { + text: `export const collections = { ${getCollections(config.environmentData.collections)} } as const;`, - filename: 'collections.ts' - }, - { - text: `export const contentTypes = { + filename: 'collections.ts' + }, + { + text: `export const contentTypes = { ${getProjectContentTypes(config.environmentData.types)} } as const;`, - filename: 'contentTypes.ts' - }, - { - text: `export const contentTypeSnippets = { + filename: 'contentTypes.ts' + }, + { + text: `export const contentTypeSnippets = { ${getProjectContentTypeSnippets(config.environmentData.snippets)} } as const;`, - filename: 'contentTypeSnippets.ts' - }, - { - text: `export const taxonomies = { + filename: 'contentTypeSnippets.ts' + }, + { + text: `export const taxonomies = { ${getProjectTaxonomies(config.environmentData.taxonomies)} } as const;`, - filename: 'taxonomies.ts' - }, - { - text: `export const workflows = { + filename: 'taxonomies.ts' + }, + { + text: `export const workflows = { ${getProjectWorkflows(config.environmentData.workflows)} } as const;`, - filename: 'workflows.ts' - }, - { - text: `export const roles = { + filename: 'workflows.ts' + }, + { + text: `export const roles = { ${getRoles(config.environmentData.roles)} } as const;`, - filename: 'roles.ts' - }, - { - text: `export const assetFolders = ${getAssetFolders(config.environmentData.assetFolders)} as const;`, - filename: 'assetFolders.ts' - }, - { - text: `export const webhooks = { + filename: 'roles.ts' + }, + { + text: `export const assetFolders = ${getAssetFolders(config.environmentData.assetFolders)} as const;`, + filename: 'assetFolders.ts' + }, + { + text: `export const webhooks = { ${getWebhooks(config.environmentData.webhooks)} } as const;`, - filename: 'webhooks.ts' - } - ]; + filename: 'webhooks.ts' + } + ] + }; }; const getProjectLanguages = (languages: readonly Readonly[]): string => { diff --git a/lib/generators/items/items-func.ts b/lib/generators/items/items-func.ts index 59637f1..0e0559c 100644 --- a/lib/generators/items/items-func.ts +++ b/lib/generators/items/items-func.ts @@ -1,10 +1,8 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; -import { coreConfig, defaultModuleResolution, itemsConfig } from '../../config.js'; -import { GeneratedFile, ModuleResolution } from '../../core/core.models.js'; -import { getFilenameFromPath } from '../../core/core.utils.js'; -import { importer as _importer } from '../../core/importer.js'; +import { defaultModuleResolution } from '../../config.js'; +import { GeneratedSet, ModuleResolution } from '../../core/core.models.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; import { fileManager as _fileManager } from '../../files/file-manager.js'; import { itemsGenerator as _itemsGenerator } from './items.generator.js'; @@ -26,22 +24,22 @@ export async function generateItemsAsync(config: GenerateItemsModelsConfig): Pro const { itemFiles, moduleResolution, environmentInfo, codenameFiles } = await getFilesAsync(config); - await createFilesAsync({ - moduleResolution, - itemFiles, - codenameFiles, + const fileManager = _fileManager({ outputDir: config.outputDir, - formatOptions: config.formatOptions, addTimestamp: config.addTimestamp, - environmentInfo + environmentInfo: environmentInfo, + formatOptions: config.formatOptions, + moduleResolution: moduleResolution }); + await fileManager.createSetsAsync([itemFiles, codenameFiles]); + console.log(chalk.green(`\nCompleted`)); } async function getFilesAsync(config: GenerateItemsModelsConfig): Promise<{ - readonly itemFiles: readonly GeneratedFile[]; - readonly codenameFiles: readonly GeneratedFile[]; + readonly itemFiles: GeneratedSet; + readonly codenameFiles: GeneratedSet; readonly moduleResolution: ModuleResolution; readonly environmentInfo: Readonly; }> { @@ -72,50 +70,3 @@ async function getFilesAsync(config: GenerateItemsModelsConfig): Promise<{ environmentInfo }; } - -async function createFilesAsync(data: { - readonly itemFiles: readonly GeneratedFile[]; - readonly codenameFiles: readonly GeneratedFile[]; - readonly moduleResolution: ModuleResolution; - readonly outputDir?: string; - readonly formatOptions?: Readonly; - readonly environmentInfo: Readonly; - readonly addTimestamp: boolean; -}): Promise { - const fileManager = _fileManager({ - outputDir: data.outputDir, - addTimestamp: data.addTimestamp, - environmentInfo: data.environmentInfo, - formatOptions: data.formatOptions - }); - - const importer = _importer(data.moduleResolution); - - await fileManager.createFilesAsync([ - ...data.itemFiles, - ...data.codenameFiles, - // items barrel file - { - filename: `${itemsConfig.itemsFolderName}/${coreConfig.barrelExportFilename}`, - text: importer.getBarrelExportCode([ - ...data.itemFiles.map((m) => { - return `./${getFilenameFromPath(m.filename)}`; - }) - ]) - }, - // codename barrel file - { - filename: `${itemsConfig.codenamesFolderName}/${coreConfig.barrelExportFilename}`, - text: importer.getBarrelExportCode([ - ...data.codenameFiles.map((m) => { - return `./${getFilenameFromPath(m.filename)}`; - }) - ]) - }, - // main barrel file - { - filename: coreConfig.barrelExportFilename, - text: importer.getBarrelExportCode([`./${itemsConfig.itemsFolderName}/index`, `./${itemsConfig.codenamesFolderName}/index`]) - } - ]); -} diff --git a/lib/generators/items/items.generator.ts b/lib/generators/items/items.generator.ts index b1713ad..dd9258d 100644 --- a/lib/generators/items/items.generator.ts +++ b/lib/generators/items/items.generator.ts @@ -1,7 +1,7 @@ import { ContentItemModels, ContentTypeModels, EnvironmentModels } from '@kontent-ai/management-sdk'; import { itemsConfig } from '../../config.js'; import { toSafeComment, wrapComment } from '../../core/comment.utils.js'; -import { GeneratedFile, ModuleResolution } from '../../core/core.models.js'; +import { GeneratedSet, ModuleResolution } from '../../core/core.models.js'; import { toPascalCase } from '../../core/core.utils.js'; export interface ItemGeneratorConfig { @@ -45,13 +45,15 @@ export function itemsGenerator(config: ItemGeneratorConfig) { }; return { - getItemFiles(): readonly GeneratedFile[] { - return config.environmentData.types.map((type) => { - const typeItems = config.environmentData.items.filter((m) => m.type.id === type.id); + getItemFiles(): GeneratedSet { + return { + folderName: itemsConfig.itemsFolderName, + files: config.environmentData.types.map((type) => { + const typeItems = config.environmentData.items.filter((m) => m.type.id === type.id); - return { - filename: `${itemsConfig.itemsFolderName}/${type.codename}.items.ts`, - text: ` + return { + filename: `${type.codename}.items.ts`, + text: ` ${wrapComment(`\n * Object representing identifiers of available items * * ${toSafeComment(type.name)} @@ -59,16 +61,19 @@ export function itemsGenerator(config: ItemGeneratorConfig) { * Codename: ${type.codename} * Id: ${type.id}\n`)} ${getItemCodenamesProp(type, typeItems)}` - }; - }); + }; + }) + }; }, - getCodenameFiles(): readonly GeneratedFile[] { - return config.environmentData.types.map((type) => { - const typeItems = config.environmentData.items.filter((m) => m.type.id === type.id); + getCodenameFiles(): GeneratedSet { + return { + folderName: itemsConfig.codenamesFolderName, + files: config.environmentData.types.map((type) => { + const typeItems = config.environmentData.items.filter((m) => m.type.id === type.id); - return { - filename: `${itemsConfig.codenamesFolderName}/${type.codename}.codenames.ts`, - text: ` + return { + filename: `${type.codename}.codenames.ts`, + text: ` ${wrapComment(`\n * Type representing available item codenames * * ${toSafeComment(type.name)} @@ -76,8 +81,9 @@ export function itemsGenerator(config: ItemGeneratorConfig) { * Codename: ${type.codename} * Id: ${type.id}\n`)} ${getItemCodenameType(type, typeItems)}` - }; - }); + }; + }) + }; } }; } diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index 14fb6b0..5975365 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -1,10 +1,8 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; -import { coreConfig, defaultModuleResolution, migrationConfig } from '../../config.js'; -import { GeneratedFile, ModuleResolution } from '../../core/core.models.js'; -import { getFilenameFromPath } from '../../core/core.utils.js'; -import { importer as _importer } from '../../core/importer.js'; +import { defaultModuleResolution } from '../../config.js'; +import { GeneratedSet, ModuleResolution } from '../../core/core.models.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; import { fileManager as _fileManager } from '../../files/file-manager.js'; import { migrationGenerator as _migrationGenerator } from './migration.generator.js'; @@ -26,24 +24,23 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode const { migrationItemFiles, migrationTypeFiles, moduleResolution, environmentInfo, environmentFiles } = await getFilesAsync(config); - await createFilesAsync({ - migrationItemFiles, - environmentFiles, - migrationTypeFiles, - moduleResolution, + const fileManager = _fileManager({ outputDir: config.outputDir, - formatOptions: config.formatOptions, addTimestamp: config.addTimestamp, - environmentInfo + environmentInfo: environmentInfo, + formatOptions: config.formatOptions, + moduleResolution: moduleResolution }); + await fileManager.createSetsAsync([migrationItemFiles, migrationTypeFiles, environmentFiles]); + console.log(chalk.green(`\nCompleted`)); } async function getFilesAsync(config: GenerateMigrationModelsConfig): Promise<{ - readonly migrationTypeFiles: readonly GeneratedFile[]; - readonly migrationItemFiles: readonly GeneratedFile[]; - readonly environmentFiles: readonly GeneratedFile[]; + readonly migrationTypeFiles: GeneratedSet; + readonly migrationItemFiles: GeneratedSet; + readonly environmentFiles: GeneratedSet; readonly moduleResolution: ModuleResolution; readonly environmentInfo: Readonly; }> { @@ -86,56 +83,3 @@ async function getFilesAsync(config: GenerateMigrationModelsConfig): Promise<{ environmentInfo }; } - -async function createFilesAsync(data: { - readonly migrationTypeFiles: readonly GeneratedFile[]; - readonly environmentFiles: readonly GeneratedFile[]; - readonly migrationItemFiles: readonly GeneratedFile[]; - readonly moduleResolution: ModuleResolution; - readonly outputDir?: string; - readonly formatOptions?: Readonly; - readonly environmentInfo: Readonly; - readonly addTimestamp: boolean; -}): Promise { - const fileManager = _fileManager({ - outputDir: data.outputDir, - addTimestamp: data.addTimestamp, - environmentInfo: data.environmentInfo, - formatOptions: data.formatOptions - }); - - const importer = _importer(data.moduleResolution); - - await fileManager.createFilesAsync([ - ...data.migrationTypeFiles, - ...data.environmentFiles, - ...data.migrationItemFiles, - // items barrel file - { - filename: `${migrationConfig.migrationItemsFolderName}/${coreConfig.barrelExportFilename}`, - text: importer.getBarrelExportCode([ - ...data.migrationItemFiles.map((m) => { - return `./${getFilenameFromPath(m.filename)}`; - }) - ]) - }, - // environment barrel file - { - filename: `${migrationConfig.environmentFolderName}/${coreConfig.barrelExportFilename}`, - text: importer.getBarrelExportCode([ - ...data.environmentFiles.map((m) => { - return `./${getFilenameFromPath(m.filename)}`; - }) - ]) - }, - // main barrel file - { - filename: coreConfig.barrelExportFilename, - text: importer.getBarrelExportCode([ - `./${migrationConfig.migrationItemsFolderName}/index`, - `./${migrationConfig.environmentFolderName}/index`, - ...data.migrationTypeFiles.map((file) => `./${file.filename}`) - ]) - } - ]); -} diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index bbf762e..b023b85 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -10,7 +10,7 @@ import { import { match } from 'ts-pattern'; import { migrationConfig, sharedTypesConfig } from '../../config.js'; import { wrapComment } from '../../core/comment.utils.js'; -import { FlattenedElement, GeneratedFile, ModuleResolution } from '../../core/core.models.js'; +import { FlattenedElement, GeneratedFile, GeneratedSet, ModuleResolution } from '../../core/core.models.js'; import { toGuidelinesComment, toPascalCase } from '../../core/core.utils.js'; import { getFlattenedElements } from '../../core/element.utils.js'; import { importer as _importer } from '../../core/importer.js'; @@ -41,7 +41,7 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { const getMigrationItemType = (type: Readonly): GeneratedFile => { return { - filename: `${migrationConfig.migrationItemsFolderName}/${type.codename}.ts`, + filename: `${type.codename}.ts`, text: ` ${importer.importType({ filePathOrPackage: migrationConfig.npmPackageName, @@ -86,11 +86,13 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { }; return { - getEnvironmentFiles(): readonly GeneratedFile[] { - return [ - { - filename: `${migrationConfig.environmentFolderName}/${migrationConfig.environmentFilename}.ts`, - text: ` + getEnvironmentFiles(): GeneratedSet { + return { + folderName: migrationConfig.environmentFolderName, + files: [ + { + filename: `${migrationConfig.environmentFilename}.ts`, + text: ` ${wrapComment(`\n * Type representing all languages\n`)} ${getLanguageCodenamesType(config.environmentData.languages)} @@ -106,14 +108,17 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { ${wrapComment(`\n * Type representing all worksflow steps across all workflows\n`)} ${getWorkflowStepCodenamesType(config.environmentData.workflows)} ` - } - ]; + } + ] + }; }, - getMigrationTypeFiles(): readonly GeneratedFile[] { - return [ - { - filename: `${migrationConfig.migrationTypesFilename}.ts`, - text: ` + getMigrationTypeFiles(): GeneratedSet { + return { + folderName: undefined, + files: [ + { + filename: `${migrationConfig.migrationTypesFilename}.ts`, + text: ` ${importer.importType({ filePathOrPackage: migrationConfig.npmPackageName, importValue: `${migrationConfig.sdkTypeNames.item}, ${migrationConfig.sdkTypeNames.system}, ${migrationConfig.sdkTypeNames.elements}` @@ -129,11 +134,15 @@ export function migrationGenerator(config: MigrationGeneratorConfig) { ${wrapComment('\n * Item object shared by all individual content type models\n')} ${getItemType()} ` - } - ]; + } + ] + }; }, - getMigrationItemFiles(): readonly GeneratedFile[] { - return config.environmentData.types.map((type) => getMigrationItemType(type)); + getMigrationItemFiles(): GeneratedSet { + return { + folderName: migrationConfig.migrationItemsFolderName, + files: config.environmentData.types.map((type) => getMigrationItemType(type)) + }; } }; } diff --git a/sample/environment/assetFolders.ts b/sample/environment/assetFolders.ts index 5a6c19a..156c402 100644 --- a/sample/environment/assetFolders.ts +++ b/sample/environment/assetFolders.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/environment/collections.ts b/sample/environment/collections.ts index 7e50501..e1c4057 100644 --- a/sample/environment/collections.ts +++ b/sample/environment/collections.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/environment/contentTypeSnippets.ts b/sample/environment/contentTypeSnippets.ts index 34f7746..7c6cbba 100644 --- a/sample/environment/contentTypeSnippets.ts +++ b/sample/environment/contentTypeSnippets.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/environment/contentTypes.ts b/sample/environment/contentTypes.ts index 70e1881..4ce7cb4 100644 --- a/sample/environment/contentTypes.ts +++ b/sample/environment/contentTypes.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/environment/index.ts b/sample/environment/index.ts index 91a4ee3..b536195 100644 --- a/sample/environment/index.ts +++ b/sample/environment/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/environment/languages.ts b/sample/environment/languages.ts index ef597a8..ea2742c 100644 --- a/sample/environment/languages.ts +++ b/sample/environment/languages.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * @@ -43,7 +43,7 @@ export const languages = { /** * German */ - German: { + german: { name: 'German', codename: 'German', id: '14f7bcc0-4fd6-4b77-8c22-70e5ccfdae1d', diff --git a/sample/environment/roles.ts b/sample/environment/roles.ts index 5cf74a3..0450265 100644 --- a/sample/environment/roles.ts +++ b/sample/environment/roles.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/environment/taxonomies.ts b/sample/environment/taxonomies.ts index edaf5c4..79ad7da 100644 --- a/sample/environment/taxonomies.ts +++ b/sample/environment/taxonomies.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/environment/webhooks.ts b/sample/environment/webhooks.ts index 7d33dc3..ffa2841 100644 --- a/sample/environment/webhooks.ts +++ b/sample/environment/webhooks.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/environment/workflows.ts b/sample/environment/workflows.ts index 4d71db6..47eefcf 100644 --- a/sample/environment/workflows.ts +++ b/sample/environment/workflows.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/items/codenames/actor.codenames.ts b/sample/items/codenames/actor.codenames.ts index dff3009..8744866 100644 --- a/sample/items/codenames/actor.codenames.ts +++ b/sample/items/codenames/actor.codenames.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/items/codenames/index.ts b/sample/items/codenames/index.ts index e6e3185..ac86f7f 100644 --- a/sample/items/codenames/index.ts +++ b/sample/items/codenames/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/items/codenames/movie.codenames.ts b/sample/items/codenames/movie.codenames.ts index bc6bf1c..14be4c1 100644 --- a/sample/items/codenames/movie.codenames.ts +++ b/sample/items/codenames/movie.codenames.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/items/index.ts b/sample/items/index.ts index a4b34a0..b219167 100644 --- a/sample/items/index.ts +++ b/sample/items/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/items/items/actor.items.ts b/sample/items/items/actor.items.ts index ddb2475..3281965 100644 --- a/sample/items/items/actor.items.ts +++ b/sample/items/items/actor.items.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/items/items/index.ts b/sample/items/items/index.ts index 1e9f4d0..4ba9dc6 100644 --- a/sample/items/items/index.ts +++ b/sample/items/items/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/items/items/movie.items.ts b/sample/items/items/movie.items.ts index 4055cba..5c731c4 100644 --- a/sample/items/items/movie.items.ts +++ b/sample/items/items/movie.items.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/migration/content-types/actor.ts b/sample/migration/content-types/actor.ts index a02b069..e39f60f 100644 --- a/sample/migration/content-types/actor.ts +++ b/sample/migration/content-types/actor.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/migration/content-types/index.ts b/sample/migration/content-types/index.ts index 3116ea2..c05bf8f 100644 --- a/sample/migration/content-types/index.ts +++ b/sample/migration/content-types/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/migration/content-types/movie.ts b/sample/migration/content-types/movie.ts index de86bd2..506f899 100644 --- a/sample/migration/content-types/movie.ts +++ b/sample/migration/content-types/movie.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/migration/environment/environment.ts b/sample/migration/environment/environment.ts index 1cd61c2..4419167 100644 --- a/sample/migration/environment/environment.ts +++ b/sample/migration/environment/environment.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/migration/environment/index.ts b/sample/migration/environment/index.ts index 2bfdee9..ad44f85 100644 --- a/sample/migration/environment/index.ts +++ b/sample/migration/environment/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/migration/index.ts b/sample/migration/index.ts index aedabaf..945a217 100644 --- a/sample/migration/index.ts +++ b/sample/migration/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * diff --git a/sample/migration/migration.ts b/sample/migration/migration.ts index 9d3f02b..1f9e0bb 100644 --- a/sample/migration/migration.ts +++ b/sample/migration/migration.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@7.4.0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. * * (c) Kontent.ai * From 3e937793747a25fadc672003831963ff7417000b Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 30 Sep 2024 11:55:25 +0200 Subject: [PATCH 144/183] Simplifies regex --- lib/core/core.utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 90d2225..0afa9b4 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -36,7 +36,7 @@ export function toCamelCase(text: string): string { return prefixWithUnderscoreWhenStartsWithNonAlpha( toSafeStringCode( text - .replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => { + .replace(/(?:^\w|\b\w)/g, (word, index) => { return index === 0 ? word.toLowerCase() : word.toUpperCase(); }) .replace(/\s+/g, '') From 71f4aea9ad3cd639ac9f38108faf5e7ca942f436 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 30 Sep 2024 13:12:12 +0200 Subject: [PATCH 145/183] Refactors 'moduleResolution' option to use 'ModuleFileExtension' which accepts 'js' | 'ts' | 'none' options. Make the option required in generator config --- .env.template | 2 +- README.md | 8 ++++++- lib/cli/actions/delivery-action.ts | 4 ++-- lib/cli/actions/environment-action.ts | 4 ++-- lib/cli/actions/items-action.ts | 4 ++-- lib/cli/actions/migrate-action.ts | 4 ++-- lib/cli/arg.utils.ts | 18 +++++++++++++++ lib/cli/commands.ts | 17 +++++++------- lib/config.ts | 4 ++-- lib/core/core.models.ts | 4 ++-- lib/core/importer.ts | 17 ++++++-------- lib/files/file-manager.ts | 10 ++++---- .../delivery-content-type.generator.ts | 6 ++--- lib/generators/delivery/delivery-func.ts | 21 ++++++----------- .../delivery/delivery-taxonomy.generator.ts | 4 ++-- .../environment/environment-func.ts | 23 ++++++++----------- lib/generators/items/items-func.ts | 18 ++++----------- lib/generators/items/items.generator.ts | 4 +--- lib/generators/migration/migration-func.ts | 19 +++++---------- .../migration/migration.generator.ts | 6 ++--- lib/public_api.ts | 2 +- scripts/samples/delivery-models.ts | 6 ++--- scripts/samples/environment-models.ts | 7 +++--- scripts/samples/item-models.ts | 6 ++--- scripts/samples/migration-models.ts | 6 ++--- 25 files changed, 108 insertions(+), 116 deletions(-) create mode 100644 lib/cli/arg.utils.ts diff --git a/.env.template b/.env.template index 00209f3..27a9a73 100644 --- a/.env.template +++ b/.env.template @@ -1,4 +1,4 @@ API_KEY=x ENVIRONMENT_ID=y ADD_TIMESTAMP=true -MODULE_RESOLUTION=node +MODULE_EXTENSION=js diff --git a/README.md b/README.md index 0c570ab..bfb2839 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Go to folder where you want to create models and run: ```bash # Models for Delivery SDK -npx @kontent-ai/model-generator@latest --environmentId=x --apiKey=y +npx @kontent-ai/model-generator@latest delivery --environmentId=x --apiKey=y # Models for Migration Toolkit npx @kontent-ai/model-generator@latest migration-toolkit --environmentId=x --apiKey=y @@ -47,6 +47,12 @@ npx @kontent-ai/model-generator@latest environment --environmentId=x --apiKey=y npx @kontent-ai/model-generator@latest items --environmentId=x --apiKey=y ``` +Run with more options: + +```bash +npx @kontent-ai/model-generator@latest delivery --environmentId=x --apiKey=y --moduleFileExtension=js --outputDir=kontent-models --addTimestamp=false +``` + To learn what options are available use the `help` command: ```bash diff --git a/lib/cli/actions/delivery-action.ts b/lib/cli/actions/delivery-action.ts index 0d1695f..302b5e2 100644 --- a/lib/cli/actions/delivery-action.ts +++ b/lib/cli/actions/delivery-action.ts @@ -1,5 +1,5 @@ -import { ModuleResolution } from '../../core/core.models.js'; import { generateDeliveryModelsAsync } from '../../generators/delivery/delivery-func.js'; +import { parseModuleFileExtension } from '../arg.utils.js'; import { CliArgumentsFetcher } from '../cli.models.js'; export async function deliveryActionAsync(cliFetcher: CliArgumentsFetcher): Promise { @@ -11,6 +11,6 @@ export async function deliveryActionAsync(cliFetcher: CliArgumentsFetcher): Prom baseUrl: cliFetcher.getOptionalArgumentValue('baseUrl'), outputDir: cliFetcher.getOptionalArgumentValue('outputDir'), addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), - moduleResolution: cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' + moduleFileExtension: parseModuleFileExtension(cliFetcher.getOptionalArgumentValue('moduleFileExtension')) }); } diff --git a/lib/cli/actions/environment-action.ts b/lib/cli/actions/environment-action.ts index 924fb7e..c090208 100644 --- a/lib/cli/actions/environment-action.ts +++ b/lib/cli/actions/environment-action.ts @@ -1,5 +1,5 @@ -import { ModuleResolution } from '../../core/core.models.js'; import { generateEnvironmentModelsAsync } from '../../generators/environment/environment-func.js'; +import { parseModuleFileExtension } from '../arg.utils.js'; import { CliArgumentsFetcher } from '../cli.models.js'; export async function environmentActionAsync(cliFetcher: CliArgumentsFetcher): Promise { @@ -11,7 +11,7 @@ export async function environmentActionAsync(cliFetcher: CliArgumentsFetcher): P baseUrl: cliFetcher.getOptionalArgumentValue('baseUrl'), outputDir: cliFetcher.getOptionalArgumentValue('outputDir'), addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), - moduleResolution: cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext', + moduleFileExtension: parseModuleFileExtension(cliFetcher.getOptionalArgumentValue('moduleFileExtension')), isEnterpriseSubscription: cliFetcher.getBooleanArgumentValue('isEnterpriseSubscription', false) }); } diff --git a/lib/cli/actions/items-action.ts b/lib/cli/actions/items-action.ts index 066b5eb..902f2e9 100644 --- a/lib/cli/actions/items-action.ts +++ b/lib/cli/actions/items-action.ts @@ -1,5 +1,5 @@ -import { ModuleResolution } from '../../core/core.models.js'; import { generateItemsAsync } from '../../generators/items/items-func.js'; +import { parseModuleFileExtension } from '../arg.utils.js'; import { CliArgumentsFetcher } from '../cli.models.js'; export async function itemsActionAsync(cliFetcher: CliArgumentsFetcher): Promise { @@ -11,6 +11,6 @@ export async function itemsActionAsync(cliFetcher: CliArgumentsFetcher): Promise baseUrl: cliFetcher.getOptionalArgumentValue('baseUrl'), outputDir: cliFetcher.getOptionalArgumentValue('outputDir'), addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), - moduleResolution: cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' + moduleFileExtension: parseModuleFileExtension(cliFetcher.getOptionalArgumentValue('moduleFileExtension')) }); } diff --git a/lib/cli/actions/migrate-action.ts b/lib/cli/actions/migrate-action.ts index 7cf06b0..c7ee7e9 100644 --- a/lib/cli/actions/migrate-action.ts +++ b/lib/cli/actions/migrate-action.ts @@ -1,5 +1,5 @@ -import { ModuleResolution } from '../../core/core.models.js'; import { generateMigrationModelsAsync } from '../../generators/migration/migration-func.js'; +import { parseModuleFileExtension } from '../arg.utils.js'; import { CliArgumentsFetcher } from '../cli.models.js'; export async function migrateActionAsync(cliFetcher: CliArgumentsFetcher): Promise { @@ -11,6 +11,6 @@ export async function migrateActionAsync(cliFetcher: CliArgumentsFetcher): Promi baseUrl: cliFetcher.getOptionalArgumentValue('baseUrl'), outputDir: cliFetcher.getOptionalArgumentValue('outputDir'), addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), - moduleResolution: cliFetcher.getOptionalArgumentValue('moduleResolution') === 'node' ? 'node' : 'nodeNext' + moduleFileExtension: parseModuleFileExtension(cliFetcher.getOptionalArgumentValue('moduleFileExtension')) }); } diff --git a/lib/cli/arg.utils.ts b/lib/cli/arg.utils.ts new file mode 100644 index 0000000..1b707eb --- /dev/null +++ b/lib/cli/arg.utils.ts @@ -0,0 +1,18 @@ +import { defaultModuleFileExtension } from '../config.js'; +import { LiteralUnion, ModuleFileExtension } from '../core/core.models.js'; + +export function parseModuleFileExtension(moduleFileExtension: LiteralUnion | undefined): ModuleFileExtension { + if (moduleFileExtension === 'js') { + return 'js'; + } + + if (moduleFileExtension === 'ts') { + return 'ts'; + } + + if (moduleFileExtension === 'none') { + return 'none'; + } + + return defaultModuleFileExtension; +} diff --git a/lib/cli/commands.ts b/lib/cli/commands.ts index 79cf9d2..22542d8 100644 --- a/lib/cli/commands.ts +++ b/lib/cli/commands.ts @@ -1,5 +1,4 @@ -import { CliAction, LibraryType } from '../core/core.models.js'; -import { ModuleResolution } from '../public_api.js'; +import { CliAction, LibraryType, ModuleFileExtension } from '../core/core.models.js'; import { argumentsSetter } from './args/args-setter.js'; import { CommandOption } from './cli.models.js'; @@ -31,9 +30,9 @@ const addTimestampOption: CommandOption = { isRequired: false }; -const moduleResolutionOption: CommandOption = { - name: `moduleResolution`, - description: `Module resolution for imports. Available options are: '${'node' satisfies ModuleResolution}', '${'nodeNext' satisfies ModuleResolution}'`, +const ModuleFileExtensionOption: CommandOption = { + name: `ModuleFileExtension`, + description: `Module resolution for imports. Available options are: '${'js' satisfies ModuleFileExtension}', '${'ts' satisfies ModuleFileExtension}' or '${'none' satisfies ModuleFileExtension}' (no extension) }`, type: 'string', isRequired: false }; @@ -50,25 +49,25 @@ export const cliArgs = argumentsSetter() name: 'delivery-sdk', description: `Generates models for '${'@kontent-ai/delivery-sdk' satisfies LibraryType}' library`, examples: [`kontent-generate ${'delivery-sdk' satisfies CliAction} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], - options: [environmentIdOption, apiKeyOption, addTimestampOption, moduleResolutionOption, outputDirOption, baseUrl] + options: [environmentIdOption, apiKeyOption, addTimestampOption, ModuleFileExtensionOption, outputDirOption, baseUrl] }) .withCommand({ name: 'environment', description: `Generates strongly typed models representing all objects in the environment. This is useful for creating custom tools or scripts where you need to reference objects within your environment`, examples: [`kontent-generate ${'environment' satisfies CliAction} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], - options: [environmentIdOption, apiKeyOption, addTimestampOption, moduleResolutionOption, outputDirOption, baseUrl] + options: [environmentIdOption, apiKeyOption, addTimestampOption, ModuleFileExtensionOption, outputDirOption, baseUrl] }) .withCommand({ name: 'migration-toolkit', description: `Generates models for '${'@kontent-ai/migration-toolkit' satisfies LibraryType}' library`, examples: [`kontent-generate ${'migration-toolkit' satisfies CliAction} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], - options: [environmentIdOption, apiKeyOption, addTimestampOption, moduleResolutionOption, outputDirOption, baseUrl] + options: [environmentIdOption, apiKeyOption, addTimestampOption, ModuleFileExtensionOption, outputDirOption, baseUrl] }) .withCommand({ name: 'items', description: `Overview of all items in the environment and their ids/codenames as well as Type representing all item codenames`, examples: [`kontent-generate ${'items' satisfies CliAction} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], - options: [environmentIdOption, apiKeyOption, addTimestampOption, moduleResolutionOption, outputDirOption, baseUrl] + options: [environmentIdOption, apiKeyOption, addTimestampOption, ModuleFileExtensionOption, outputDirOption, baseUrl] }) .withOption({ alias: `h`, diff --git a/lib/config.ts b/lib/config.ts index 7bdfa45..c0a94a9 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -1,6 +1,6 @@ -import { ModuleResolution } from './core/core.models.js'; +import { ModuleFileExtension } from './core/core.models.js'; -export const defaultModuleResolution: ModuleResolution = 'node'; +export const defaultModuleFileExtension: ModuleFileExtension = 'js'; export const coreConfig = { barrelExportFilename: 'index.ts' diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index 7788f3b..c87ea07 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -9,10 +9,10 @@ import { export type CliAction = 'delivery-sdk' | 'migration-toolkit' | 'environment' | 'items'; export type LibraryType = '@kontent-ai/migration-toolkit' | '@kontent-ai/delivery-sdk'; -export type ModuleResolution = 'nodeNext' | 'node'; +export type ModuleFileExtension = 'js' | 'ts' | 'none'; export type CaseType = 'camelCase' | 'pascalCase'; export type GeneratorManagementClient = Readonly>; -export type LiteralUnion = T | (string & NonNullable); +export type LiteralUnion = T | (string & NonNullable); export interface ErrorData { readonly message: string; diff --git a/lib/core/importer.ts b/lib/core/importer.ts index fe353a5..b08d30d 100644 --- a/lib/core/importer.ts +++ b/lib/core/importer.ts @@ -1,19 +1,16 @@ import { parse } from 'path'; -import { LibraryType, LiteralUnion, ModuleResolution } from './core.models.js'; +import { LibraryType, LiteralUnion, ModuleFileExtension } from './core.models.js'; import { getFileNameWithoutExtension, sortAlphabetically } from './core.utils.js'; -export function importer(moduleResolution: ModuleResolution) { - const getExtensionForModuleResolution = (moduleResolution: ModuleResolution): string => { - return moduleResolution === 'nodeNext' ? '.js' : ''; - }; +export function importer(moduleFileExtension: ModuleFileExtension) { + const importExtension = moduleFileExtension === 'none' ? '' : `.${moduleFileExtension}`; return { importType: (data: { readonly filePathOrPackage: LiteralUnion; readonly importValue: string }): string => { const isExternalLib = !data.filePathOrPackage.endsWith('.js') && !data.filePathOrPackage.endsWith('.ts'); - const resolvedFilePath = - moduleResolution === 'nodeNext' && !isExternalLib - ? `${getFileNameWithoutExtension(data.filePathOrPackage)}.js` - : data.filePathOrPackage; + const resolvedFilePath = isExternalLib + ? data.filePathOrPackage + : `${getFileNameWithoutExtension(data.filePathOrPackage)}${importExtension}`; return `import type { ${data.importValue} } from '${resolvedFilePath}';`; }, @@ -23,7 +20,7 @@ export function importer(moduleResolution: ModuleResolution) { } return sortAlphabetically(filenames, (filename) => filename).reduce((barrelCode, filename) => { const path = parse(filename); - return `${barrelCode} export * from '${path.dir}/${path.name}${getExtensionForModuleResolution(moduleResolution)}';`; + return `${barrelCode} export * from '${path.dir}/${path.name}${importExtension}';`; }, ''); } }; diff --git a/lib/files/file-manager.ts b/lib/files/file-manager.ts index b3588aa..3a80ff3 100644 --- a/lib/files/file-manager.ts +++ b/lib/files/file-manager.ts @@ -5,20 +5,20 @@ import { dirname } from 'path'; import { Options } from 'prettier'; import { coreConfig } from '../config.js'; import { getEnvironmentInfoComment } from '../core/comment.utils.js'; -import { GeneratedFile, GeneratedSet, ModuleResolution } from '../core/core.models.js'; +import { GeneratedFile, GeneratedSet, ModuleFileExtension } from '../core/core.models.js'; import { toOutputDirPath } from '../core/core.utils.js'; import { importer as _importer } from '../core/importer.js'; import { formatCodeAsync } from '../format/formatter.js'; export function fileManager(config: { - readonly moduleResolution: ModuleResolution; - readonly outputDir: string | undefined; - readonly formatOptions: Readonly | undefined; + readonly moduleFileExtension: ModuleFileExtension; + readonly outputDir?: string; + readonly formatOptions?: Readonly; readonly environmentInfo: Readonly; readonly addTimestamp: boolean; }) { const fixedOutputDir = toOutputDirPath(config.outputDir); - const importer = _importer(config.moduleResolution); + const importer = _importer(config.moduleFileExtension); const createFileOnFsAsync = async (text: string, filePath: string): Promise => { const fullFilePath = `${fixedOutputDir.endsWith('/') ? fixedOutputDir : `${fixedOutputDir}/`}${filePath}`; diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 2f686f5..9422344 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -10,7 +10,7 @@ import { import { match, P } from 'ts-pattern'; import { coreConfig, deliveryConfig, sharedTypesConfig } from '../../config.js'; import { wrapComment } from '../../core/comment.utils.js'; -import { FlattenedElement, GeneratedFile, GeneratedSet, ModuleResolution } from '../../core/core.models.js'; +import { FlattenedElement, GeneratedFile, GeneratedSet, ModuleFileExtension } from '../../core/core.models.js'; import { isNotUndefined, sortAlphabetically, toGuidelinesComment, uniqueFilter } from '../../core/core.utils.js'; import { getFlattenedElements } from '../../core/element.utils.js'; import { importer as _importer } from '../../core/importer.js'; @@ -41,7 +41,7 @@ interface ExtractImportsResult { type ContentTypeOrSnippet = Readonly; export interface DeliveryContentTypeGeneratorConfig { - readonly moduleResolution: ModuleResolution; + readonly moduleFileExtension: ModuleFileExtension; readonly environmentData: { readonly environment: Readonly; @@ -73,7 +73,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato taxonomy: mapFilename(config.fileResolvers?.taxonomy) }; - const importer = _importer(config.moduleResolution); + const importer = _importer(config.moduleFileExtension); const nameResolvers = { snippet: mapName(config.nameResolvers?.snippet, 'pascalCase'), diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index 6722a01..9428437 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -1,8 +1,7 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; -import { defaultModuleResolution } from '../../config.js'; -import { GeneratedSet, ModuleResolution } from '../../core/core.models.js'; +import { GeneratedSet, ModuleFileExtension } from '../../core/core.models.js'; import { ContentTypeFileNameResolver, ContentTypeNameResolver, @@ -21,7 +20,7 @@ export interface GenerateDeliveryModelsConfig { readonly addTimestamp: boolean; readonly apiKey: string; - readonly moduleResolution?: ModuleResolution; + readonly moduleFileExtension: ModuleFileExtension; readonly baseUrl?: string; readonly outputDir?: string; readonly formatOptions?: Readonly; @@ -43,14 +42,11 @@ export async function generateDeliveryModelsAsync(config: GenerateDeliveryModels console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('delivery')}' models\n`); - const { contentTypeFiles, snippetFiles, taxonomyFiles, moduleResolution, environmentInfo, systemFiles } = await getFilesAsync(config); + const { contentTypeFiles, snippetFiles, taxonomyFiles, environmentInfo, systemFiles } = await getFilesAsync(config); const fileManager = _fileManager({ - outputDir: config.outputDir, - addTimestamp: config.addTimestamp, - environmentInfo: environmentInfo, - formatOptions: config.formatOptions, - moduleResolution: moduleResolution + ...config, + environmentInfo: environmentInfo }); await fileManager.createSetsAsync([contentTypeFiles, snippetFiles, taxonomyFiles, systemFiles]); @@ -63,10 +59,8 @@ async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ readonly snippetFiles: GeneratedSet; readonly taxonomyFiles: GeneratedSet; readonly systemFiles: GeneratedSet; - readonly moduleResolution: ModuleResolution; readonly environmentInfo: Readonly; }> { - const moduleResolution: ModuleResolution = config.moduleResolution ?? defaultModuleResolution; const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, @@ -85,7 +79,7 @@ async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ ]); const deliveryGenerator = deliveryContentTypeGenerator({ - moduleResolution: moduleResolution, + moduleFileExtension: config.moduleFileExtension, environmentData: { environment: environmentInfo, types, @@ -102,7 +96,7 @@ async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ const { contentTypeFiles, snippetFiles } = deliveryGenerator.generateModels(); const taxonomyFiles = deliveryTaxonomyGenerator({ - moduleResolution: moduleResolution, + moduleFileExtension: config.moduleFileExtension, environmentData: { environment: environmentInfo, taxonomies: taxonomies @@ -115,7 +109,6 @@ async function getFilesAsync(config: GenerateDeliveryModelsConfig): Promise<{ contentTypeFiles, snippetFiles, taxonomyFiles, - moduleResolution, environmentInfo, systemFiles: deliveryGenerator.getSystemFiles() }; diff --git a/lib/generators/delivery/delivery-taxonomy.generator.ts b/lib/generators/delivery/delivery-taxonomy.generator.ts index 2e3ef09..d7d61e3 100644 --- a/lib/generators/delivery/delivery-taxonomy.generator.ts +++ b/lib/generators/delivery/delivery-taxonomy.generator.ts @@ -1,11 +1,11 @@ import { EnvironmentModels, TaxonomyModels } from '@kontent-ai/management-sdk'; import { deliveryConfig } from '../../config.js'; import { wrapComment } from '../../core/comment.utils.js'; -import { GeneratedFile, GeneratedSet, ModuleResolution } from '../../core/core.models.js'; +import { GeneratedFile, GeneratedSet, ModuleFileExtension } from '../../core/core.models.js'; import { TaxonomyNameResolver, TaxonomyTypeFileNameResolver, mapFilename, mapName } from '../../core/resolvers.js'; export interface DeliveryTaxonomyGeneratorConfig { - readonly moduleResolution: ModuleResolution; + readonly moduleFileExtension: ModuleFileExtension; readonly environmentData: { readonly environment: Readonly; diff --git a/lib/generators/environment/environment-func.ts b/lib/generators/environment/environment-func.ts index 8a34126..32d45b5 100644 --- a/lib/generators/environment/environment-func.ts +++ b/lib/generators/environment/environment-func.ts @@ -1,8 +1,8 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; -import { defaultModuleResolution } from '../../config.js'; -import { GeneratedSet, ModuleResolution } from '../../core/core.models.js'; +import { defaultModuleFileExtension } from '../../config.js'; +import { GeneratedSet, ModuleFileExtension } from '../../core/core.models.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; import { fileManager as _fileManager } from '../../files/file-manager.js'; import { environmentGenerator as _environmentGenerator } from './environment.generator.js'; @@ -13,7 +13,7 @@ export interface GenerateEnvironmentModelsConfig { readonly isEnterpriseSubscription: boolean; readonly apiKey: string; - readonly moduleResolution?: ModuleResolution; + readonly moduleFileExtension: ModuleFileExtension; readonly baseUrl?: string; readonly outputDir?: string; readonly formatOptions?: Readonly; @@ -23,27 +23,24 @@ export async function generateEnvironmentModelsAsync(config: GenerateEnvironment console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('project')}' models\n`); - const { moduleResolution, environmentFiles: projectFiles, environmentInfo } = await getModelsAsync(config); + const { environmentFiles, environmentInfo } = await getModelsAsync(config); const fileManager = _fileManager({ - addTimestamp: config.addTimestamp, - environmentInfo: environmentInfo, - formatOptions: config.formatOptions, - outputDir: config.outputDir, - moduleResolution: moduleResolution + ...config, + environmentInfo: environmentInfo }); - await fileManager.createSetsAsync([projectFiles]); + await fileManager.createSetsAsync([environmentFiles]); console.log(chalk.green(`\nCompleted`)); } async function getModelsAsync(config: GenerateEnvironmentModelsConfig): Promise<{ environmentFiles: GeneratedSet; - moduleResolution: ModuleResolution; + moduleFileExtension: ModuleFileExtension; readonly environmentInfo: Readonly; }> { - const moduleResolution: ModuleResolution = config.moduleResolution ?? defaultModuleResolution; + const moduleFileExtension: ModuleFileExtension = config.moduleFileExtension ?? defaultModuleFileExtension; const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, @@ -80,6 +77,6 @@ async function getModelsAsync(config: GenerateEnvironmentModelsConfig): Promise< webhooks: webooks } }).generateEnvironmentModels(), - moduleResolution: moduleResolution + moduleFileExtension: moduleFileExtension }; } diff --git a/lib/generators/items/items-func.ts b/lib/generators/items/items-func.ts index 0e0559c..4178f4b 100644 --- a/lib/generators/items/items-func.ts +++ b/lib/generators/items/items-func.ts @@ -1,8 +1,7 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; -import { defaultModuleResolution } from '../../config.js'; -import { GeneratedSet, ModuleResolution } from '../../core/core.models.js'; +import { GeneratedSet, ModuleFileExtension } from '../../core/core.models.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; import { fileManager as _fileManager } from '../../files/file-manager.js'; import { itemsGenerator as _itemsGenerator } from './items.generator.js'; @@ -11,7 +10,7 @@ export interface GenerateItemsModelsConfig { readonly environmentId: string; readonly addTimestamp: boolean; readonly apiKey: string; - readonly moduleResolution: ModuleResolution; + readonly moduleFileExtension: ModuleFileExtension; readonly outputDir?: string; readonly baseUrl?: string; @@ -22,14 +21,11 @@ export async function generateItemsAsync(config: GenerateItemsModelsConfig): Pro console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('migration')}' models\n`); - const { itemFiles, moduleResolution, environmentInfo, codenameFiles } = await getFilesAsync(config); + const { itemFiles, environmentInfo, codenameFiles } = await getFilesAsync(config); const fileManager = _fileManager({ - outputDir: config.outputDir, - addTimestamp: config.addTimestamp, - environmentInfo: environmentInfo, - formatOptions: config.formatOptions, - moduleResolution: moduleResolution + ...config, + environmentInfo: environmentInfo }); await fileManager.createSetsAsync([itemFiles, codenameFiles]); @@ -40,10 +36,8 @@ export async function generateItemsAsync(config: GenerateItemsModelsConfig): Pro async function getFilesAsync(config: GenerateItemsModelsConfig): Promise<{ readonly itemFiles: GeneratedSet; readonly codenameFiles: GeneratedSet; - readonly moduleResolution: ModuleResolution; readonly environmentInfo: Readonly; }> { - const moduleResolution: ModuleResolution = config.moduleResolution ?? defaultModuleResolution; const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, @@ -55,7 +49,6 @@ async function getFilesAsync(config: GenerateItemsModelsConfig): Promise<{ const [items, types] = await Promise.all([kontentFetcher.getItemsAsync(), kontentFetcher.getTypesAsync()]); const itemsGenerator = _itemsGenerator({ - moduleResolution: config.moduleResolution, environmentData: { environment: environmentInfo, types: types, @@ -64,7 +57,6 @@ async function getFilesAsync(config: GenerateItemsModelsConfig): Promise<{ }); return { - moduleResolution, itemFiles: itemsGenerator.getItemFiles(), codenameFiles: itemsGenerator.getCodenameFiles(), environmentInfo diff --git a/lib/generators/items/items.generator.ts b/lib/generators/items/items.generator.ts index dd9258d..1f67c9a 100644 --- a/lib/generators/items/items.generator.ts +++ b/lib/generators/items/items.generator.ts @@ -1,12 +1,10 @@ import { ContentItemModels, ContentTypeModels, EnvironmentModels } from '@kontent-ai/management-sdk'; import { itemsConfig } from '../../config.js'; import { toSafeComment, wrapComment } from '../../core/comment.utils.js'; -import { GeneratedSet, ModuleResolution } from '../../core/core.models.js'; +import { GeneratedSet } from '../../core/core.models.js'; import { toPascalCase } from '../../core/core.utils.js'; export interface ItemGeneratorConfig { - readonly moduleResolution: ModuleResolution; - readonly environmentData: { readonly environment: Readonly; readonly types: readonly Readonly[]; diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index 5975365..66d6b78 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -1,8 +1,7 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; -import { defaultModuleResolution } from '../../config.js'; -import { GeneratedSet, ModuleResolution } from '../../core/core.models.js'; +import { GeneratedSet, ModuleFileExtension } from '../../core/core.models.js'; import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; import { fileManager as _fileManager } from '../../files/file-manager.js'; import { migrationGenerator as _migrationGenerator } from './migration.generator.js'; @@ -11,7 +10,7 @@ export interface GenerateMigrationModelsConfig { readonly environmentId: string; readonly addTimestamp: boolean; readonly apiKey: string; - readonly moduleResolution: ModuleResolution; + readonly moduleFileExtension: ModuleFileExtension; readonly outputDir?: string; readonly baseUrl?: string; @@ -22,14 +21,11 @@ export async function generateMigrationModelsAsync(config: GenerateMigrationMode console.log(chalk.green(`Model generator started \n`)); console.log(`Generating '${chalk.yellow('migration')}' models\n`); - const { migrationItemFiles, migrationTypeFiles, moduleResolution, environmentInfo, environmentFiles } = await getFilesAsync(config); + const { migrationItemFiles, migrationTypeFiles, environmentInfo, environmentFiles } = await getFilesAsync(config); const fileManager = _fileManager({ - outputDir: config.outputDir, - addTimestamp: config.addTimestamp, - environmentInfo: environmentInfo, - formatOptions: config.formatOptions, - moduleResolution: moduleResolution + ...config, + environmentInfo: environmentInfo }); await fileManager.createSetsAsync([migrationItemFiles, migrationTypeFiles, environmentFiles]); @@ -41,10 +37,8 @@ async function getFilesAsync(config: GenerateMigrationModelsConfig): Promise<{ readonly migrationTypeFiles: GeneratedSet; readonly migrationItemFiles: GeneratedSet; readonly environmentFiles: GeneratedSet; - readonly moduleResolution: ModuleResolution; readonly environmentInfo: Readonly; }> { - const moduleResolution: ModuleResolution = config.moduleResolution ?? defaultModuleResolution; const kontentFetcher = _kontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, @@ -63,7 +57,7 @@ async function getFilesAsync(config: GenerateMigrationModelsConfig): Promise<{ ]); const migrationGenerator = _migrationGenerator({ - moduleResolution: config.moduleResolution, + moduleFileExtension: config.moduleFileExtension, environmentData: { environment: environmentInfo, taxonomies: taxonomies, @@ -76,7 +70,6 @@ async function getFilesAsync(config: GenerateMigrationModelsConfig): Promise<{ }); return { - moduleResolution, migrationTypeFiles: migrationGenerator.getMigrationTypeFiles(), migrationItemFiles: migrationGenerator.getMigrationItemFiles(), environmentFiles: migrationGenerator.getEnvironmentFiles(), diff --git a/lib/generators/migration/migration.generator.ts b/lib/generators/migration/migration.generator.ts index b023b85..6ffab40 100644 --- a/lib/generators/migration/migration.generator.ts +++ b/lib/generators/migration/migration.generator.ts @@ -10,7 +10,7 @@ import { import { match } from 'ts-pattern'; import { migrationConfig, sharedTypesConfig } from '../../config.js'; import { wrapComment } from '../../core/comment.utils.js'; -import { FlattenedElement, GeneratedFile, GeneratedSet, ModuleResolution } from '../../core/core.models.js'; +import { FlattenedElement, GeneratedFile, GeneratedSet, ModuleFileExtension } from '../../core/core.models.js'; import { toGuidelinesComment, toPascalCase } from '../../core/core.utils.js'; import { getFlattenedElements } from '../../core/element.utils.js'; import { importer as _importer } from '../../core/importer.js'; @@ -23,7 +23,7 @@ import { } from '../shared/type-codename.generator.js'; export interface MigrationGeneratorConfig { - readonly moduleResolution: ModuleResolution; + readonly moduleFileExtension: ModuleFileExtension; readonly environmentData: { readonly environment: Readonly; @@ -37,7 +37,7 @@ export interface MigrationGeneratorConfig { } export function migrationGenerator(config: MigrationGeneratorConfig) { - const importer = _importer(config.moduleResolution); + const importer = _importer(config.moduleFileExtension); const getMigrationItemType = (type: Readonly): GeneratedFile => { return { diff --git a/lib/public_api.ts b/lib/public_api.ts index 8ca89d4..ae38344 100644 --- a/lib/public_api.ts +++ b/lib/public_api.ts @@ -1,7 +1,7 @@ /* * Public API */ -export { CaseType, ModuleResolution } from './core/core.models.js'; +export { CaseType, ModuleFileExtension } from './core/core.models.js'; export { GenerateDeliveryModelsConfig, generateDeliveryModelsAsync } from './generators/delivery/delivery-func.js'; export { GenerateEnvironmentModelsConfig, generateEnvironmentModelsAsync } from './generators/environment/environment-func.js'; export { GenerateItemsModelsConfig, generateItemsAsync } from './generators/items/items-func.js'; diff --git a/scripts/samples/delivery-models.ts b/scripts/samples/delivery-models.ts index 5df89c1..6af7a8f 100644 --- a/scripts/samples/delivery-models.ts +++ b/scripts/samples/delivery-models.ts @@ -1,7 +1,7 @@ import chalk from 'chalk'; import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; -import { ModuleResolution } from '../../lib/core/core.models.js'; +import { parseModuleFileExtension } from '../../lib/cli/arg.utils.js'; import { logError } from '../../lib/core/error.utils.js'; import { generateDeliveryModelsAsync } from '../../lib/generators/delivery/delivery-func.js'; import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; @@ -23,13 +23,13 @@ try { const environmentId = getEnvironmentRequiredValue('ENVIRONMENT_ID'); const apiKey = getEnvironmentRequiredValue('API_KEY'); - const moduleResolution = getEnvironmentRequiredValue('MODULE_RESOLUTION'); + const moduleFileExtension = parseModuleFileExtension(getEnvironmentRequiredValue('MODULE_EXTENSION')); await generateDeliveryModelsAsync({ addTimestamp: false, environmentId: environmentId, apiKey: apiKey, - moduleResolution: moduleResolution?.toLowerCase() === 'node' ? 'node' : 'nodeNext', + moduleFileExtension: moduleFileExtension, outputDir: outputDir }); } catch (error) { diff --git a/scripts/samples/environment-models.ts b/scripts/samples/environment-models.ts index c7df85c..4cb6e7f 100644 --- a/scripts/samples/environment-models.ts +++ b/scripts/samples/environment-models.ts @@ -1,7 +1,7 @@ import chalk from 'chalk'; import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; -import { ModuleResolution } from '../../lib/core/core.models.js'; +import { parseModuleFileExtension } from '../../lib/cli/arg.utils.js'; import { logError } from '../../lib/core/error.utils.js'; import { generateEnvironmentModelsAsync } from '../../lib/generators/environment/environment-func.js'; import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; @@ -23,13 +23,12 @@ try { const environmentId = getEnvironmentRequiredValue('ENVIRONMENT_ID'); const apiKey = getEnvironmentRequiredValue('API_KEY'); - const moduleResolution = getEnvironmentRequiredValue('MODULE_RESOLUTION'); - + const moduleFileExtension = parseModuleFileExtension(getEnvironmentRequiredValue('MODULE_EXTENSION')); await generateEnvironmentModelsAsync({ addTimestamp: false, environmentId: environmentId, apiKey: apiKey, - moduleResolution: moduleResolution?.toLowerCase() === 'node' ? 'node' : 'nodeNext', + moduleFileExtension: moduleFileExtension, isEnterpriseSubscription: true, outputDir: outputDir }); diff --git a/scripts/samples/item-models.ts b/scripts/samples/item-models.ts index 265f584..45b7d49 100644 --- a/scripts/samples/item-models.ts +++ b/scripts/samples/item-models.ts @@ -1,7 +1,7 @@ import chalk from 'chalk'; import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; -import { ModuleResolution } from '../../lib/core/core.models.js'; +import { parseModuleFileExtension } from '../../lib/cli/arg.utils.js'; import { logError } from '../../lib/core/error.utils.js'; import { generateItemsAsync } from '../../lib/generators/items/items-func.js'; import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; @@ -23,13 +23,13 @@ try { const environmentId = getEnvironmentRequiredValue('ENVIRONMENT_ID'); const apiKey = getEnvironmentRequiredValue('API_KEY'); - const moduleResolution = getEnvironmentRequiredValue('MODULE_RESOLUTION'); + const moduleFileExtension = parseModuleFileExtension(getEnvironmentRequiredValue('MODULE_EXTENSION')); await generateItemsAsync({ addTimestamp: false, environmentId: environmentId, apiKey: apiKey, - moduleResolution: moduleResolution?.toLowerCase() === 'node' ? 'node' : 'nodeNext', + moduleFileExtension: moduleFileExtension, outputDir: outputDir }); } catch (error) { diff --git a/scripts/samples/migration-models.ts b/scripts/samples/migration-models.ts index d12f284..6fab82e 100644 --- a/scripts/samples/migration-models.ts +++ b/scripts/samples/migration-models.ts @@ -1,7 +1,7 @@ import chalk from 'chalk'; import * as dotenv from 'dotenv'; import { rmSync } from 'fs'; -import { ModuleResolution } from '../../lib/core/core.models.js'; +import { parseModuleFileExtension } from '../../lib/cli/arg.utils.js'; import { logError } from '../../lib/core/error.utils.js'; import { generateMigrationModelsAsync } from '../../lib/generators/migration/migration-func.js'; import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; @@ -23,13 +23,13 @@ try { const environmentId = getEnvironmentRequiredValue('ENVIRONMENT_ID'); const apiKey = getEnvironmentRequiredValue('API_KEY'); - const moduleResolution = getEnvironmentRequiredValue('MODULE_RESOLUTION'); + const moduleFileExtension = parseModuleFileExtension(getEnvironmentRequiredValue('MODULE_EXTENSION')); await generateMigrationModelsAsync({ addTimestamp: false, environmentId: environmentId, apiKey: apiKey, - moduleResolution: moduleResolution?.toLowerCase() === 'node' ? 'node' : 'nodeNext', + moduleFileExtension: moduleFileExtension, outputDir: outputDir }); } catch (error) { From 6016428e04ca295ea818e0f0b56d444fea7e1ca2 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 30 Sep 2024 13:16:41 +0200 Subject: [PATCH 146/183] Update commands.ts --- lib/cli/commands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli/commands.ts b/lib/cli/commands.ts index 22542d8..d6ec893 100644 --- a/lib/cli/commands.ts +++ b/lib/cli/commands.ts @@ -31,7 +31,7 @@ const addTimestampOption: CommandOption = { }; const ModuleFileExtensionOption: CommandOption = { - name: `ModuleFileExtension`, + name: `moduleFileExtension`, description: `Module resolution for imports. Available options are: '${'js' satisfies ModuleFileExtension}', '${'ts' satisfies ModuleFileExtension}' or '${'none' satisfies ModuleFileExtension}' (no extension) }`, type: 'string', isRequired: false From 321f102cad70c9f734a057ac32f09a84fd028f4c Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 1 Oct 2024 13:28:50 +0200 Subject: [PATCH 147/183] updates deps & moves delivery sdk from devDeps to deps --- package-lock.json | 243 ++++++++++++++-------------------------------- package.json | 6 +- 2 files changed, 75 insertions(+), 174 deletions(-) diff --git a/package-lock.json b/package-lock.json index 74fa971..d07ebdf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "@kontent-ai/management-sdk": "7.3.0", + "@kontent-ai/migration-toolkit": "1.5.1", "chalk": "5.3.0", "prettier": "3.3.3", "ts-pattern": "5.4.0", @@ -21,16 +22,15 @@ "devDependencies": { "@eslint/js": "^9.11.1", "@kontent-ai/delivery-sdk": "15.2.0", - "@kontent-ai/migration-toolkit": "1.5.1", - "@types/eslint__js": "^8.42.3", - "@types/node": "22.7.3", + "@types/eslint__js": "8.42.3", + "@types/node": "22.7.4", "@types/yargs": "17.0.33", "dotenv-cli": "7.4.2", - "eslint": "^9.11.1", + "eslint": "9.11.1", "standard-version": "9.5.0", "tsx": "4.19.1", - "typescript": "^5.6.2", - "typescript-eslint": "^8.7.0" + "typescript": "5.6.2", + "typescript-eslint": "8.8.0" }, "engines": { "node": ">= 20" @@ -711,7 +711,6 @@ "version": "0.0.7", "resolved": "https://registry.npmjs.org/@kontent-ai-consulting/tools-analytics/-/tools-analytics-0.0.7.tgz", "integrity": "sha512-grkW8hEe4vij3R5uZ0K4DuQiR1HvJhdPqoTF/z/q++8xA2X0X0orgRLbWNgyC9XYuSUiCbojmT64zBJf32RKkw==", - "dev": true, "dependencies": { "@kontent-ai/core-sdk": "10.7.0" }, @@ -723,7 +722,6 @@ "version": "10.7.0", "resolved": "https://registry.npmjs.org/@kontent-ai/core-sdk/-/core-sdk-10.7.0.tgz", "integrity": "sha512-NNS1jatzMzp+XBWNc45bcbZjTFTs4szAFJxKn9oj/4p4+ZXucqYXBs88KCUotXmCCcoeUiFAFn8aQUF2aiTM+Q==", - "dev": true, "dependencies": { "axios": "1.7.4" }, @@ -805,7 +803,6 @@ "version": "1.5.1", "resolved": "https://registry.npmjs.org/@kontent-ai/migration-toolkit/-/migration-toolkit-1.5.1.tgz", "integrity": "sha512-gj7twSzCIiA8L4UF5CUBg/hHHcG8USnTOR+iJnFyd+YksK9fXqZLXpB9Js1UE6wCdBmBtEC9DzjCSEv2XLdFCg==", - "dev": true, "dependencies": { "@kontent-ai-consulting/tools-analytics": "0.0.7", "@kontent-ai/management-sdk": "7.2.0", @@ -834,7 +831,6 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/@kontent-ai/management-sdk/-/management-sdk-7.2.0.tgz", "integrity": "sha512-vfEzmQDrDdKj+4evxoCjBE/Cpr5FT1L7KdOjwISk5MSaQsUxl8hrBYL7UDo8ln/J5LIO/6aOwxJ7aY4yAwI9yw==", - "dev": true, "dependencies": { "@kontent-ai/core-sdk": "10.7.0", "mime": "3.0.0" @@ -847,7 +843,6 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz", "integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==", - "dev": true, "bin": { "mime": "cli.js" }, @@ -859,7 +854,6 @@ "version": "4.0.4", "resolved": "https://registry.npmjs.org/mime/-/mime-4.0.4.tgz", "integrity": "sha512-v8yqInVjhXyqP6+Kw4fV3ZzeMRqEW6FotRsKXjRS5VMTNIuXsdRoAvklpoRgSqXm6o9VNH4/C0mgedko9DdLsQ==", - "dev": true, "funding": [ "https://github.com/sponsors/broofa" ], @@ -873,8 +867,7 @@ "node_modules/@kontent-ai/migration-toolkit/node_modules/ts-pattern": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/ts-pattern/-/ts-pattern-5.3.1.tgz", - "integrity": "sha512-1RUMKa8jYQdNfmnK4jyzBK3/PS/tnjcZ1CW0v1vWDeYe5RBklc/nquw03MEoB66hVBm4BnlCfmOqDVxHyT1DpA==", - "dev": true + "integrity": "sha512-1RUMKa8jYQdNfmnK4jyzBK3/PS/tnjcZ1CW0v1vWDeYe5RBklc/nquw03MEoB66hVBm4BnlCfmOqDVxHyT1DpA==" }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", @@ -949,9 +942,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.7.3", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.3.tgz", - "integrity": "sha512-qXKfhXXqGTyBskvWEzJZPUxSslAiLaB6JGP1ic/XTH9ctGgzdgYguuLP1C601aRTSDNlLb0jbKqXjZ48GNraSA==", + "version": "22.7.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.4.tgz", + "integrity": "sha512-y+NPi1rFzDs1NdQHHToqeiX2TIS79SWEAw9GYhkkx8bD0ChpfqC+n2j5OXOCpzfojBEBt6DnEnnG9MY0zk1XLg==", "dev": true, "dependencies": { "undici-types": "~6.19.2" @@ -979,16 +972,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.7.0.tgz", - "integrity": "sha512-RIHOoznhA3CCfSTFiB6kBGLQtB/sox+pJ6jeFu6FxJvqL8qRxq/FfGO/UhsGgQM9oGdXkV4xUgli+dt26biB6A==", + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.8.0.tgz", + "integrity": "sha512-wORFWjU30B2WJ/aXBfOm1LX9v9nyt9D3jsSOxC3cCaTQGCW5k4jNpmjFv3U7p/7s4yvdjHzwtv2Sd2dOyhjS0A==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "8.7.0", - "@typescript-eslint/type-utils": "8.7.0", - "@typescript-eslint/utils": "8.7.0", - "@typescript-eslint/visitor-keys": "8.7.0", + "@typescript-eslint/scope-manager": "8.8.0", + "@typescript-eslint/type-utils": "8.8.0", + "@typescript-eslint/utils": "8.8.0", + "@typescript-eslint/visitor-keys": "8.8.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", @@ -1012,15 +1005,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.7.0.tgz", - "integrity": "sha512-lN0btVpj2unxHlNYLI//BQ7nzbMJYBVQX5+pbNXvGYazdlgYonMn4AhhHifQ+J4fGRYA/m1DjaQjx+fDetqBOQ==", + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.8.0.tgz", + "integrity": "sha512-uEFUsgR+tl8GmzmLjRqz+VrDv4eoaMqMXW7ruXfgThaAShO9JTciKpEsB+TvnfFfbg5IpujgMXVV36gOJRLtZg==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "8.7.0", - "@typescript-eslint/types": "8.7.0", - "@typescript-eslint/typescript-estree": "8.7.0", - "@typescript-eslint/visitor-keys": "8.7.0", + "@typescript-eslint/scope-manager": "8.8.0", + "@typescript-eslint/types": "8.8.0", + "@typescript-eslint/typescript-estree": "8.8.0", + "@typescript-eslint/visitor-keys": "8.8.0", "debug": "^4.3.4" }, "engines": { @@ -1040,13 +1033,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.7.0.tgz", - "integrity": "sha512-87rC0k3ZlDOuz82zzXRtQ7Akv3GKhHs0ti4YcbAJtaomllXoSO8hi7Ix3ccEvCd824dy9aIX+j3d2UMAfCtVpg==", + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.8.0.tgz", + "integrity": "sha512-EL8eaGC6gx3jDd8GwEFEV091210U97J0jeEHrAYvIYosmEGet4wJ+g0SYmLu+oRiAwbSA5AVrt6DxLHfdd+bUg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.7.0", - "@typescript-eslint/visitor-keys": "8.7.0" + "@typescript-eslint/types": "8.8.0", + "@typescript-eslint/visitor-keys": "8.8.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1057,13 +1050,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.7.0.tgz", - "integrity": "sha512-tl0N0Mj3hMSkEYhLkjREp54OSb/FI6qyCzfiiclvJvOqre6hsZTGSnHtmFLDU8TIM62G7ygEa1bI08lcuRwEnQ==", + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.8.0.tgz", + "integrity": "sha512-IKwJSS7bCqyCeG4NVGxnOP6lLT9Okc3Zj8hLO96bpMkJab+10HIfJbMouLrlpyOr3yrQ1cA413YPFiGd1mW9/Q==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "8.7.0", - "@typescript-eslint/utils": "8.7.0", + "@typescript-eslint/typescript-estree": "8.8.0", + "@typescript-eslint/utils": "8.8.0", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -1081,9 +1074,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.7.0.tgz", - "integrity": "sha512-LLt4BLHFwSfASHSF2K29SZ+ZCsbQOM+LuarPjRUuHm+Qd09hSe3GCeaQbcCr+Mik+0QFRmep/FyZBO6fJ64U3w==", + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.8.0.tgz", + "integrity": "sha512-QJwc50hRCgBd/k12sTykOJbESe1RrzmX6COk8Y525C9l7oweZ+1lw9JiU56im7Amm8swlz00DRIlxMYLizr2Vw==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1094,13 +1087,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.7.0.tgz", - "integrity": "sha512-MC8nmcGHsmfAKxwnluTQpNqceniT8SteVwd2voYlmiSWGOtjvGXdPl17dYu2797GVscK30Z04WRM28CrKS9WOg==", + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.8.0.tgz", + "integrity": "sha512-ZaMJwc/0ckLz5DaAZ+pNLmHv8AMVGtfWxZe/x2JVEkD5LnmhWiQMMcYT7IY7gkdJuzJ9P14fRy28lUrlDSWYdw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.7.0", - "@typescript-eslint/visitor-keys": "8.7.0", + "@typescript-eslint/types": "8.8.0", + "@typescript-eslint/visitor-keys": "8.8.0", "debug": "^4.3.4", "fast-glob": "^3.3.2", "is-glob": "^4.0.3", @@ -1122,15 +1115,15 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.7.0.tgz", - "integrity": "sha512-ZbdUdwsl2X/s3CiyAu3gOlfQzpbuG3nTWKPoIvAu1pu5r8viiJvv2NPN2AqArL35NCYtw/lrPPfM4gxrMLNLPw==", + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.8.0.tgz", + "integrity": "sha512-QE2MgfOTem00qrlPgyByaCHay9yb1+9BjnMFnSFkUKQfu7adBXDTnCAivURnuPPAG/qiB+kzKkZKmKfaMT0zVg==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "8.7.0", - "@typescript-eslint/types": "8.7.0", - "@typescript-eslint/typescript-estree": "8.7.0" + "@typescript-eslint/scope-manager": "8.8.0", + "@typescript-eslint/types": "8.8.0", + "@typescript-eslint/typescript-estree": "8.8.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1144,12 +1137,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.7.0.tgz", - "integrity": "sha512-b1tx0orFCCh/THWPQa2ZwWzvOeyzzp36vkJYOpVg0u8UVOIsfVrnuC9FqAw9gRKn+rG2VmWQ/zDJZzkxUnj/XQ==", + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.8.0.tgz", + "integrity": "sha512-8mq51Lx6Hpmd7HnA2fcHQo3YgfX1qbccxQOgZcb4tvasu//zXRaA1j5ZRFeCw/VRAdFi4mRM9DnZw0Nu0Q2d1g==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.7.0", + "@typescript-eslint/types": "8.8.0", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -1235,7 +1228,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/array-buffer-byte-length/-/array-buffer-byte-length-1.0.1.tgz", "integrity": "sha512-ahC5W1xgou+KTXix4sAO8Ki12Q+jf4i0+tmk3sC+zgcynshkHxzpXdImBehiUYKKKDwvfFiJl1tZt6ewscS1Mg==", - "dev": true, "dependencies": { "call-bind": "^1.0.5", "is-array-buffer": "^3.0.4" @@ -1271,7 +1263,6 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", "integrity": "sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==", - "dev": true, "dependencies": { "possible-typed-array-names": "^1.0.0" }, @@ -1286,7 +1277,6 @@ "version": "1.7.4", "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.4.tgz", "integrity": "sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==", - "dev": true, "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -1323,8 +1313,7 @@ "node_modules/browser-or-node": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/browser-or-node/-/browser-or-node-3.0.0.tgz", - "integrity": "sha512-iczIdVJzGEYhP5DqQxYM9Hh7Ztpqqi+CXZpSmX8ALFs9ecXkQIeqRyM6TfxEfMVpwhl3dSuDvxdzzo9sUOIVBQ==", - "dev": true + "integrity": "sha512-iczIdVJzGEYhP5DqQxYM9Hh7Ztpqqi+CXZpSmX8ALFs9ecXkQIeqRyM6TfxEfMVpwhl3dSuDvxdzzo9sUOIVBQ==" }, "node_modules/buffer-from": { "version": "1.1.2", @@ -1336,7 +1325,6 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", - "dev": true, "engines": { "node": ">= 0.8" } @@ -1345,7 +1333,6 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", - "dev": true, "dependencies": { "es-define-property": "^1.0.0", "es-errors": "^1.3.0", @@ -1410,7 +1397,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-4.0.0.tgz", "integrity": "sha512-VGtlMu3x/4DOtIUwEkRezxUZ2lBacNJCHash0N0WeZDBS+7Ux1dm3XWAgWYxLJFMMdOeXMHXorshEFhbMSGelg==", - "dev": true, "dependencies": { "restore-cursor": "^4.0.0" }, @@ -1425,7 +1411,6 @@ "version": "2.9.2", "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.2.tgz", "integrity": "sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==", - "dev": true, "engines": { "node": ">=6" }, @@ -1800,8 +1785,7 @@ "node_modules/core-util-is": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", - "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", - "dev": true + "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" }, "node_modules/cross-spawn": { "version": "7.0.3", @@ -1890,7 +1874,6 @@ "version": "2.2.3", "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-2.2.3.tgz", "integrity": "sha512-ZIwpnevOurS8bpT4192sqAowWM76JDKSHYzMLty3BZGSswgq6pBaH3DhCSW5xVAZICZyKdOBPjwww5wfgT/6PA==", - "dev": true, "dependencies": { "array-buffer-byte-length": "^1.0.0", "call-bind": "^1.0.5", @@ -1928,7 +1911,6 @@ "version": "1.1.4", "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", - "dev": true, "dependencies": { "es-define-property": "^1.0.0", "es-errors": "^1.3.0", @@ -1945,7 +1927,6 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz", "integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==", - "dev": true, "dependencies": { "define-data-property": "^1.0.1", "has-property-descriptors": "^1.0.0", @@ -2000,7 +1981,6 @@ "version": "16.4.5", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", - "dev": true, "engines": { "node": ">=12" }, @@ -2131,8 +2111,7 @@ "node_modules/emoji-regex": { "version": "10.3.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.3.0.tgz", - "integrity": "sha512-QpLs9D9v9kArv4lfDEgg1X/gN5XLnf/A6l9cs8SPZLRZR3ZkY9+kwIQTxm+fsSej5UMYGE8fdoaZVIBlqG0XTw==", - "dev": true + "integrity": "sha512-QpLs9D9v9kArv4lfDEgg1X/gN5XLnf/A6l9cs8SPZLRZR3ZkY9+kwIQTxm+fsSej5UMYGE8fdoaZVIBlqG0XTw==" }, "node_modules/error-ex": { "version": "1.3.2", @@ -2147,7 +2126,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", - "dev": true, "dependencies": { "get-intrinsic": "^1.2.4" }, @@ -2159,7 +2137,6 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", - "dev": true, "engines": { "node": ">= 0.4" } @@ -2168,7 +2145,6 @@ "version": "1.1.3", "resolved": "https://registry.npmjs.org/es-get-iterator/-/es-get-iterator-1.1.3.tgz", "integrity": "sha512-sPZmqHBe6JIiTfN5q2pEi//TwxmAFHwj/XEuYjTuse78i8KxaqMTTzxPoFKuzRpDpTJ+0NAbpfenkmH2rePtuw==", - "dev": true, "dependencies": { "call-bind": "^1.0.2", "get-intrinsic": "^1.1.3", @@ -2615,7 +2591,6 @@ "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", "integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==", - "dev": true, "dependencies": { "is-callable": "^1.1.3" } @@ -2651,7 +2626,6 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", - "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -2660,7 +2634,6 @@ "version": "1.2.3", "resolved": "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz", "integrity": "sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==", - "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -2677,7 +2650,6 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/get-east-asian-width/-/get-east-asian-width-1.2.0.tgz", "integrity": "sha512-2nk+7SIVb14QrgXFHcm84tD4bKQz0RxPuMT8Ag5KPOq7J5fEmAg0UbXdTOSHqNuHSU28k55qnceesxXRZGzKWA==", - "dev": true, "engines": { "node": ">=18" }, @@ -2689,7 +2661,6 @@ "version": "1.2.4", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", - "dev": true, "dependencies": { "es-errors": "^1.3.0", "function-bind": "^1.1.2", @@ -2887,7 +2858,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", - "dev": true, "dependencies": { "get-intrinsic": "^1.1.3" }, @@ -2941,7 +2911,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz", "integrity": "sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ==", - "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -2959,7 +2928,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", - "dev": true, "dependencies": { "es-define-property": "^1.0.0" }, @@ -2971,7 +2939,6 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", - "dev": true, "engines": { "node": ">= 0.4" }, @@ -2983,7 +2950,6 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", - "dev": true, "engines": { "node": ">= 0.4" }, @@ -2995,7 +2961,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", - "dev": true, "dependencies": { "has-symbols": "^1.0.3" }, @@ -3010,7 +2975,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", - "dev": true, "dependencies": { "function-bind": "^1.1.2" }, @@ -3042,8 +3006,7 @@ "node_modules/immediate": { "version": "3.0.6", "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", - "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==", - "dev": true + "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==" }, "node_modules/import-fresh": { "version": "3.3.0", @@ -3082,8 +3045,7 @@ "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, "node_modules/ini": { "version": "1.3.8", @@ -3095,7 +3057,6 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.7.tgz", "integrity": "sha512-NGnrKwXzSms2qUUih/ILZ5JBqNTSa1+ZmP6flaIp6KmSElgE9qdndzS3cqjrDovwFdmwsGsLdeFgB6suw+1e9g==", - "dev": true, "dependencies": { "es-errors": "^1.3.0", "hasown": "^2.0.0", @@ -3109,7 +3070,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", - "dev": true, "dependencies": { "call-bind": "^1.0.2", "has-tostringtag": "^1.0.0" @@ -3125,7 +3085,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/is-array-buffer/-/is-array-buffer-3.0.4.tgz", "integrity": "sha512-wcjaerHw0ydZwfhiKbXJWLDY8A7yV7KhjQOpb83hGgGfId/aQa4TOvwyzn2PuswW2gPCYEL/nEAiSVpdOj1lXw==", - "dev": true, "dependencies": { "call-bind": "^1.0.2", "get-intrinsic": "^1.2.1" @@ -3147,7 +3106,6 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-bigint/-/is-bigint-1.0.4.tgz", "integrity": "sha512-zB9CruMamjym81i2JZ3UMn54PKGsQzsJeo6xvN3HJJ4CAsQNB6iRutp2To77OfCNuoxspsIhzaPoO1zyCEhFOg==", - "dev": true, "dependencies": { "has-bigints": "^1.0.1" }, @@ -3159,7 +3117,6 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.2.tgz", "integrity": "sha512-gDYaKHJmnj4aWxyj6YHyXVpdQawtVLHU5cb+eztPGczf6cjuTdwve5ZIEfgXqH4e57An1D1AKf8CZ3kYrQRqYA==", - "dev": true, "dependencies": { "call-bind": "^1.0.2", "has-tostringtag": "^1.0.0" @@ -3175,7 +3132,6 @@ "version": "1.2.7", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==", - "dev": true, "engines": { "node": ">= 0.4" }, @@ -3202,7 +3158,6 @@ "version": "1.0.5", "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.5.tgz", "integrity": "sha512-9YQaSxsAiSwcvS33MBk3wTCVnWK+HhF8VZR2jRxehM16QcVOdHqPn4VPHmRK4lSr38n9JriurInLcP90xsYNfQ==", - "dev": true, "dependencies": { "has-tostringtag": "^1.0.0" }, @@ -3246,7 +3201,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-2.0.0.tgz", "integrity": "sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==", - "dev": true, "engines": { "node": ">=12" }, @@ -3258,7 +3212,6 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/is-map/-/is-map-2.0.3.tgz", "integrity": "sha512-1Qed0/Hr2m+YqxnM09CjA2d/i6YZNfF6R2oRAOj36eUdS6qIV/huPJNSEpKbupewFs+ZsJlxsjjPbc0/afW6Lw==", - "dev": true, "engines": { "node": ">= 0.4" }, @@ -3279,7 +3232,6 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.0.7.tgz", "integrity": "sha512-k1U0IRzLMo7ZlYIfzRu23Oh6MiIFasgpb9X76eqfFZAqwH44UI4KTBvBYIZ1dSL9ZzChTB9ShHfLkR4pdW5krQ==", - "dev": true, "dependencies": { "has-tostringtag": "^1.0.0" }, @@ -3321,7 +3273,6 @@ "version": "1.1.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", "integrity": "sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==", - "dev": true, "dependencies": { "call-bind": "^1.0.2", "has-tostringtag": "^1.0.0" @@ -3337,7 +3288,6 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/is-set/-/is-set-2.0.3.tgz", "integrity": "sha512-iPAjerrse27/ygGLxw+EBR9agv9Y6uLeYVJMu+QNCoouJ1/1ri0mGrcWpfCqFZuzzx3WjtwxG098X+n4OuRkPg==", - "dev": true, "engines": { "node": ">= 0.4" }, @@ -3349,7 +3299,6 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/is-shared-array-buffer/-/is-shared-array-buffer-1.0.3.tgz", "integrity": "sha512-nA2hv5XIhLR3uVzDDfCIknerhx8XUKnstuOERPNNIinXG7v9u+ohXF67vxm4TPTEPU6lm61ZkwP3c9PCB97rhg==", - "dev": true, "dependencies": { "call-bind": "^1.0.7" }, @@ -3364,7 +3313,6 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.7.tgz", "integrity": "sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==", - "dev": true, "dependencies": { "has-tostringtag": "^1.0.0" }, @@ -3379,7 +3327,6 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.4.tgz", "integrity": "sha512-C/CPBqKWnvdcxqIARxyOh4v1UUEOCHpgDa0WYgpKDFMszcrPcffg5uhwSgPCLD2WWxmq6isisz87tzT01tuGhg==", - "dev": true, "dependencies": { "has-symbols": "^1.0.2" }, @@ -3406,7 +3353,6 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-2.0.0.tgz", "integrity": "sha512-FRdAyx5lusK1iHG0TWpVtk9+1i+GjrzRffhDg4ovQ7mcidMQ6mj+MhKPmvh7Xwyv5gIS06ns49CA7Sqg7lC22Q==", - "dev": true, "engines": { "node": ">=18" }, @@ -3418,7 +3364,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/is-weakmap/-/is-weakmap-2.0.2.tgz", "integrity": "sha512-K5pXYOm9wqY1RgjpL3YTkF39tni1XajUIkawTLUo9EZEVUFga5gSQJF8nNS7ZwJQ02y+1YCNYcMh+HIf1ZqE+w==", - "dev": true, "engines": { "node": ">= 0.4" }, @@ -3430,7 +3375,6 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/is-weakset/-/is-weakset-2.0.3.tgz", "integrity": "sha512-LvIm3/KWzS9oRFHugab7d+M/GcBXuXX5xZkzPmN+NxihdQlZUQ4dWuSV1xR/sq6upL1TJEDrfBgRepHFdBtSNQ==", - "dev": true, "dependencies": { "call-bind": "^1.0.7", "get-intrinsic": "^1.2.4" @@ -3445,8 +3389,7 @@ "node_modules/isarray": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", - "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", - "dev": true + "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==" }, "node_modules/isexe": { "version": "2.0.0", @@ -3537,7 +3480,6 @@ "version": "3.10.1", "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz", "integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==", - "dev": true, "dependencies": { "lie": "~3.3.0", "pako": "~1.0.2", @@ -3567,7 +3509,6 @@ "version": "3.0.3", "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", "integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==", - "dev": true, "engines": { "node": ">=6" } @@ -3589,7 +3530,6 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==", - "dev": true, "dependencies": { "immediate": "~3.0.5" } @@ -3661,7 +3601,6 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-6.0.0.tgz", "integrity": "sha512-i24m8rpwhmPIS4zscNzK6MSEhk0DUWa/8iYQWxhffV8jkI4Phvs3F+quL5xvS0gdQR0FyTCMMH33Y78dDTzzIw==", - "dev": true, "dependencies": { "chalk": "^5.3.0", "is-unicode-supported": "^1.3.0" @@ -3677,7 +3616,6 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-1.3.0.tgz", "integrity": "sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==", - "dev": true, "engines": { "node": ">=12" }, @@ -3937,7 +3875,6 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", - "dev": true, "engines": { "node": ">=6" } @@ -4035,7 +3972,6 @@ "version": "1.13.2", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", "integrity": "sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==", - "dev": true, "engines": { "node": ">= 0.4" }, @@ -4047,7 +3983,6 @@ "version": "1.1.6", "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.6.tgz", "integrity": "sha512-F8cZ+KfGlSGi09lJT7/Nd6KJZ9ygtvYC0/UYYLI9nmQKLMnydpB9yvbv9K1uSkEu7FU9vYPmVwLg328tX+ot3Q==", - "dev": true, "dependencies": { "call-bind": "^1.0.7", "define-properties": "^1.2.1" @@ -4063,7 +3998,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", - "dev": true, "engines": { "node": ">= 0.4" } @@ -4072,7 +4006,6 @@ "version": "4.1.5", "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.5.tgz", "integrity": "sha512-byy+U7gp+FVwmyzKPYhW2h5l3crpmGsxl7X2s8y43IgxvG4g3QZ6CffDtsNQy1WsmZpQbO+ybo0AlW7TY6DcBQ==", - "dev": true, "dependencies": { "call-bind": "^1.0.5", "define-properties": "^1.2.1", @@ -4090,7 +4023,6 @@ "version": "5.1.2", "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", - "dev": true, "dependencies": { "mimic-fn": "^2.1.0" }, @@ -4122,7 +4054,6 @@ "version": "8.0.1", "resolved": "https://registry.npmjs.org/ora/-/ora-8.0.1.tgz", "integrity": "sha512-ANIvzobt1rls2BDny5fWZ3ZVKyD6nscLvfFRpQgfWsythlcsVUC9kL0zq6j2Z5z9wwp1kd7wpsD/T9qNPVLCaQ==", - "dev": true, "dependencies": { "chalk": "^5.3.0", "cli-cursor": "^4.0.0", @@ -4145,7 +4076,6 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", - "dev": true, "engines": { "node": ">=12" }, @@ -4157,7 +4087,6 @@ "version": "7.1.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", - "dev": true, "dependencies": { "ansi-regex": "^6.0.1" }, @@ -4172,7 +4101,6 @@ "version": "6.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-6.1.0.tgz", "integrity": "sha512-H0jc0q1vOzlEk0TqAKXKZxdl7kX3OFUzCnNVUnq5Pc3DGo0kpeaMuPqxQn235HibwBEb0/pm9dgKTjXy66fBkg==", - "dev": true, "dependencies": { "yocto-queue": "^1.1.1" }, @@ -4237,8 +4165,7 @@ "node_modules/pako": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", - "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==", - "dev": true + "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==" }, "node_modules/parent-module": { "version": "1.0.1", @@ -4320,7 +4247,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz", "integrity": "sha512-d7Uw+eZoloe0EHDIYoe+bQ5WXnGMOpmiZFTuMWCwpjzzkL2nTjcKiAk4hh8TjnGye2TwWOk3UXucZ+3rbmBa8Q==", - "dev": true, "engines": { "node": ">= 0.4" } @@ -4351,14 +4277,12 @@ "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", - "dev": true + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" }, "node_modules/prompts": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", "integrity": "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==", - "dev": true, "dependencies": { "kleur": "^3.0.3", "sisteransi": "^1.0.5" @@ -4573,7 +4497,6 @@ "version": "2.3.8", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", - "dev": true, "dependencies": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -4587,8 +4510,7 @@ "node_modules/readable-stream/node_modules/isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", - "dev": true + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" }, "node_modules/redent": { "version": "3.0.0", @@ -4607,7 +4529,6 @@ "version": "1.5.2", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz", "integrity": "sha512-NcDiDkTLuPR+++OCKB0nWafEmhg/Da8aUPLPMQbK+bxKKCm1/S5he+AqYa4PlMCVBalb4/yxIRub6qkEx5yJbw==", - "dev": true, "dependencies": { "call-bind": "^1.0.6", "define-properties": "^1.2.1", @@ -4674,7 +4595,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-4.0.0.tgz", "integrity": "sha512-I9fPXU9geO9bHOt9pHHOhOkYerIMsmVaWB0rA2AI9ERh/+x/i7MV5HKBNrg+ljO5eoPVgCcnFuRjJ9uH6I/3eg==", - "dev": true, "dependencies": { "onetime": "^5.1.0", "signal-exit": "^3.0.2" @@ -4722,8 +4642,7 @@ "node_modules/safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "dev": true + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, "node_modules/semver": { "version": "7.6.3", @@ -4741,7 +4660,6 @@ "version": "1.2.2", "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", - "dev": true, "dependencies": { "define-data-property": "^1.1.4", "es-errors": "^1.3.0", @@ -4758,7 +4676,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/set-function-name/-/set-function-name-2.0.2.tgz", "integrity": "sha512-7PGFlmtwsEADb0WYyvCMa1t+yke6daIG4Wirafur5kcf+MhUnPms1UeR0CKQdTZD81yESwMHbtn+TR+dMviakQ==", - "dev": true, "dependencies": { "define-data-property": "^1.1.4", "es-errors": "^1.3.0", @@ -4772,8 +4689,7 @@ "node_modules/setimmediate": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", - "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==", - "dev": true + "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==" }, "node_modules/shebang-command": { "version": "2.0.0", @@ -4800,7 +4716,6 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==", - "dev": true, "dependencies": { "call-bind": "^1.0.7", "es-errors": "^1.3.0", @@ -4817,14 +4732,12 @@ "node_modules/signal-exit": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", - "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", - "dev": true + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" }, "node_modules/sisteransi": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", - "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==", - "dev": true + "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==" }, "node_modules/source-map": { "version": "0.6.1", @@ -5054,7 +4967,6 @@ "version": "0.2.2", "resolved": "https://registry.npmjs.org/stdin-discarder/-/stdin-discarder-0.2.2.tgz", "integrity": "sha512-UhDfHmA92YAlNnCfhmq0VeNL5bDbiZGg7sZ2IvPsXubGkiNa9EC+tUTsjBRsYUAz87btI6/1wf4XoVvQ3uRnmQ==", - "dev": true, "engines": { "node": ">=18" }, @@ -5066,7 +4978,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/stop-iteration-iterator/-/stop-iteration-iterator-1.0.0.tgz", "integrity": "sha512-iCGQj+0l0HOdZ2AEeBADlsRC+vsnDsZsbdSiH1yNSjcfKM7fdpCMfqAL/dwF5BLiw/XhRft/Wax6zQbhq2BcjQ==", - "dev": true, "dependencies": { "internal-slot": "^1.0.4" }, @@ -5078,7 +4989,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, "dependencies": { "safe-buffer": "~5.1.0" } @@ -5087,7 +4997,6 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", "integrity": "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==", - "dev": true, "dependencies": { "emoji-regex": "^10.3.0", "get-east-asian-width": "^1.0.0", @@ -5104,7 +5013,6 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", - "dev": true, "engines": { "node": ">=12" }, @@ -5116,7 +5024,6 @@ "version": "7.1.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", - "dev": true, "dependencies": { "ansi-regex": "^6.0.1" }, @@ -5347,14 +5254,14 @@ } }, "node_modules/typescript-eslint": { - "version": "8.7.0", - "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.7.0.tgz", - "integrity": "sha512-nEHbEYJyHwsuf7c3V3RS7Saq+1+la3i0ieR3qP0yjqWSzVmh8Drp47uOl9LjbPANac4S7EFSqvcYIKXUUwIfIQ==", + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.8.0.tgz", + "integrity": "sha512-BjIT/VwJ8+0rVO01ZQ2ZVnjE1svFBiRczcpr1t1Yxt7sT25VSbPfrJtDsQ8uQTy2pilX5nI9gwxhUyLULNentw==", "dev": true, "dependencies": { - "@typescript-eslint/eslint-plugin": "8.7.0", - "@typescript-eslint/parser": "8.7.0", - "@typescript-eslint/utils": "8.7.0" + "@typescript-eslint/eslint-plugin": "8.8.0", + "@typescript-eslint/parser": "8.8.0", + "@typescript-eslint/utils": "8.8.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -5410,8 +5317,7 @@ "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", - "dev": true + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" }, "node_modules/uuid": { "version": "10.0.0", @@ -5455,7 +5361,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz", "integrity": "sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==", - "dev": true, "dependencies": { "is-bigint": "^1.0.1", "is-boolean-object": "^1.1.0", @@ -5471,7 +5376,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/which-collection/-/which-collection-1.0.2.tgz", "integrity": "sha512-K4jVyjnBdgvc86Y6BkaLZEN933SwYOuBFkdmBu9ZfkcAbdVbpITnDmjvZ/aQjRXQrv5EPkTnD1s39GiiqbngCw==", - "dev": true, "dependencies": { "is-map": "^2.0.3", "is-set": "^2.0.3", @@ -5489,7 +5393,6 @@ "version": "1.1.15", "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.15.tgz", "integrity": "sha512-oV0jmFtUky6CXfkqehVvBP/LSWJ2sy4vWMioiENyJLePrBO/yKyV9OyJySfAKosh+RYkIl5zJCNZ8/4JncrpdA==", - "dev": true, "dependencies": { "available-typed-arrays": "^1.0.7", "call-bind": "^1.0.7", @@ -5632,7 +5535,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.1.1.tgz", "integrity": "sha512-b4JR1PFR10y1mKjhHY9LaGo6tmrgjit7hxVIeAmyMw3jegXR4dhYqLaQF5zMXZxY7tLpMyJeLjr1C4rLmkVe8g==", - "dev": true, "engines": { "node": ">=12.20" }, @@ -5644,7 +5546,6 @@ "version": "3.23.8", "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", - "dev": true, "funding": { "url": "https://github.com/sponsors/colinhacks" } diff --git a/package.json b/package.json index 720dbf1..0b57624 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ }, "dependencies": { "@kontent-ai/management-sdk": "7.3.0", + "@kontent-ai/migration-toolkit": "1.5.1", "chalk": "5.3.0", "prettier": "3.3.3", "ts-pattern": "5.4.0", @@ -59,15 +60,14 @@ "devDependencies": { "@eslint/js": "^9.11.1", "@kontent-ai/delivery-sdk": "15.2.0", - "@kontent-ai/migration-toolkit": "1.5.1", "@types/eslint__js": "8.42.3", - "@types/node": "22.7.3", + "@types/node": "22.7.4", "@types/yargs": "17.0.33", "dotenv-cli": "7.4.2", "eslint": "9.11.1", "standard-version": "9.5.0", "tsx": "4.19.1", "typescript": "5.6.2", - "typescript-eslint": "8.7.0" + "typescript-eslint": "8.8.0" } } From a7254cd81b0222df80d47ea334692f1db2047446 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 1 Oct 2024 13:29:09 +0200 Subject: [PATCH 148/183] Update package.json --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 0b57624..bfb8a95 100644 --- a/package.json +++ b/package.json @@ -51,15 +51,15 @@ }, "dependencies": { "@kontent-ai/management-sdk": "7.3.0", - "@kontent-ai/migration-toolkit": "1.5.1", + "@kontent-ai/delivery-sdk": "15.2.0", "chalk": "5.3.0", "prettier": "3.3.3", "ts-pattern": "5.4.0", "yargs": "17.7.2" }, "devDependencies": { - "@eslint/js": "^9.11.1", - "@kontent-ai/delivery-sdk": "15.2.0", + "@eslint/js": "9.11.1", + "@kontent-ai/migration-toolkit": "1.5.1", "@types/eslint__js": "8.42.3", "@types/node": "22.7.4", "@types/yargs": "17.0.33", From 229228687fa950cf62bb1721ac78dba2b1721a0f Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 1 Oct 2024 15:40:14 +0200 Subject: [PATCH 149/183] Refactors items generator to use Delivery API instead of Management API to fetch items --- .env.template | 1 + README.md | 4 +- lib/cli/actions/items-action.ts | 5 +- lib/cli/arg.utils.ts | 20 ++++- lib/cli/args/args-fetcher.ts | 3 + lib/cli/cli.models.ts | 1 + lib/cli/commands.ts | 69 ++++++++++---- lib/config.ts | 3 +- lib/core/core.models.ts | 3 + lib/fetch/delivery-kontent-fetcher.ts | 43 +++++++++ ...tcher.ts => management-kontent-fetcher.ts} | 2 +- lib/generators/delivery/delivery-func.ts | 2 +- .../environment/environment-func.ts | 2 +- lib/generators/items/items-func.ts | 25 ++++-- lib/generators/items/items.generator.ts | 74 +++++++++------ lib/generators/migration/migration-func.ts | 2 +- lib/public_api.ts | 2 +- sample/items/codenames/actor.codenames.ts | 19 ++-- sample/items/codenames/movie.codenames.ts | 24 ----- sample/items/items/actor.items.ts | 89 ++++++++++--------- sample/items/items/movie.items.ts | 72 --------------- scripts/samples/item-models.ts | 8 +- 22 files changed, 262 insertions(+), 211 deletions(-) create mode 100644 lib/fetch/delivery-kontent-fetcher.ts rename lib/fetch/{kontent-fetcher.ts => management-kontent-fetcher.ts} (98%) delete mode 100644 sample/items/codenames/movie.codenames.ts delete mode 100644 sample/items/items/movie.items.ts diff --git a/.env.template b/.env.template index 27a9a73..01fdf0f 100644 --- a/.env.template +++ b/.env.template @@ -2,3 +2,4 @@ API_KEY=x ENVIRONMENT_ID=y ADD_TIMESTAMP=true MODULE_EXTENSION=js +DELIVERY_API_KEY=y diff --git a/README.md b/README.md index bfb2839..ea453a5 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,9 @@ npx @kontent-ai/model-generator@latest migration-toolkit --environmentId=x --api npx @kontent-ai/model-generator@latest environment --environmentId=x --apiKey=y # Items overview with ids / codenames and Types representing available item codenames -npx @kontent-ai/model-generator@latest items --environmentId=x --apiKey=y +# 'deliveryApiKey' option is required for 'preview' or 'secure' api modes +# 'contentTypes' option is CSV of content type codenames and can be used to narrow down generated items +npx @kontent-ai/model-generator@latest items --environmentId=x --apiKey=y --deliveryApiKey=y --apiMode=preview --contentTypes=a,b,c ``` Run with more options: diff --git a/lib/cli/actions/items-action.ts b/lib/cli/actions/items-action.ts index 902f2e9..0484b36 100644 --- a/lib/cli/actions/items-action.ts +++ b/lib/cli/actions/items-action.ts @@ -1,5 +1,5 @@ import { generateItemsAsync } from '../../generators/items/items-func.js'; -import { parseModuleFileExtension } from '../arg.utils.js'; +import { parseDeliveryApiMode, parseModuleFileExtension } from '../arg.utils.js'; import { CliArgumentsFetcher } from '../cli.models.js'; export async function itemsActionAsync(cliFetcher: CliArgumentsFetcher): Promise { @@ -8,9 +8,12 @@ export async function itemsActionAsync(cliFetcher: CliArgumentsFetcher): Promise environmentId: cliFetcher.getRequiredArgumentValue('environmentId'), apiKey: cliFetcher.getRequiredArgumentValue('apiKey'), // optional + deliveryApiKey: cliFetcher.getOptionalArgumentValue('deliveryApiKey'), baseUrl: cliFetcher.getOptionalArgumentValue('baseUrl'), outputDir: cliFetcher.getOptionalArgumentValue('outputDir'), addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), + apiMode: parseDeliveryApiMode(cliFetcher.getOptionalArgumentValue('apiMode')), + filterByTypeCodenames: cliFetcher.getOptionalArgumentArrayVaue('contentTypes') ?? [], moduleFileExtension: parseModuleFileExtension(cliFetcher.getOptionalArgumentValue('moduleFileExtension')) }); } diff --git a/lib/cli/arg.utils.ts b/lib/cli/arg.utils.ts index 1b707eb..d8d9318 100644 --- a/lib/cli/arg.utils.ts +++ b/lib/cli/arg.utils.ts @@ -1,5 +1,5 @@ -import { defaultModuleFileExtension } from '../config.js'; -import { LiteralUnion, ModuleFileExtension } from '../core/core.models.js'; +import { defaultDeliveryApiMode, defaultModuleFileExtension } from '../config.js'; +import { DeliveryApiMode, LiteralUnion, ModuleFileExtension } from '../core/core.models.js'; export function parseModuleFileExtension(moduleFileExtension: LiteralUnion | undefined): ModuleFileExtension { if (moduleFileExtension === 'js') { @@ -16,3 +16,19 @@ export function parseModuleFileExtension(moduleFileExtension: LiteralUnion | undefined): DeliveryApiMode { + if (apiMode === 'default') { + return 'default'; + } + + if (apiMode === 'preview') { + return 'preview'; + } + + if (apiMode === 'secure') { + return 'secure'; + } + + return defaultDeliveryApiMode; +} diff --git a/lib/cli/args/args-fetcher.ts b/lib/cli/args/args-fetcher.ts index 71a3761..27cd727 100644 --- a/lib/cli/args/args-fetcher.ts +++ b/lib/cli/args/args-fetcher.ts @@ -51,6 +51,9 @@ export async function argumentsFetcherAsync(): Promise { } return value.toLowerCase() === 'true'.toLowerCase(); + }, + getOptionalArgumentArrayVaue(argName: string): readonly string[] { + return getOptionalArgumentValue(argName)?.split(',') ?? []; } }; } diff --git a/lib/cli/cli.models.ts b/lib/cli/cli.models.ts index 1f4f48f..86dc17a 100644 --- a/lib/cli/cli.models.ts +++ b/lib/cli/cli.models.ts @@ -26,4 +26,5 @@ export type CliArgumentsFetcher = { getOptionalArgumentValue(argName: string): string | undefined; getRequiredArgumentValue(argName: string): string; getBooleanArgumentValue(argName: string, defaultValue: boolean): boolean; + getOptionalArgumentArrayVaue(argName: string): readonly string[]; }; diff --git a/lib/cli/commands.ts b/lib/cli/commands.ts index d6ec893..9123ad8 100644 --- a/lib/cli/commands.ts +++ b/lib/cli/commands.ts @@ -1,43 +1,64 @@ -import { CliAction, LibraryType, ModuleFileExtension } from '../core/core.models.js'; +import { CliAction, DeliveryApiMode, LibraryType, ModuleFileExtension } from '../core/core.models.js'; import { argumentsSetter } from './args/args-setter.js'; import { CommandOption } from './cli.models.js'; -const environmentIdOption: CommandOption = { +export const environmentIdOption: CommandOption = { name: `environmentId`, description: `Id of the environment`, type: 'string', isRequired: true }; -const apiKeyOption: CommandOption = { +export const managementApiKeyOption: CommandOption = { name: `apiKey`, description: `Management API key`, type: 'string', isRequired: true }; -const outputDirOption: CommandOption = { +export const deliveryApiKeyOption: CommandOption = { + name: `apiKey`, + description: `Delivery API key`, + type: 'string', + isRequired: true +}; + +export const outputDirOption: CommandOption = { name: `outputDir`, description: `Relative directory path where directory will be created`, type: 'string', isRequired: false }; -const addTimestampOption: CommandOption = { +export const addTimestampOption: CommandOption = { name: `outputDir`, description: `Indicates whether timestamp should be generated for every file`, type: 'boolean', isRequired: false }; -const ModuleFileExtensionOption: CommandOption = { +export const ModuleFileExtensionOption: CommandOption = { name: `moduleFileExtension`, description: `Module resolution for imports. Available options are: '${'js' satisfies ModuleFileExtension}', '${'ts' satisfies ModuleFileExtension}' or '${'none' satisfies ModuleFileExtension}' (no extension) }`, type: 'string', isRequired: false }; -const baseUrl: CommandOption = { +export const apiModeOption: CommandOption = { + name: `apiMode`, + description: `API mode for Delivery. Options are '${'default' satisfies DeliveryApiMode}', '${'preview' satisfies DeliveryApiMode}' or '${'secure' satisfies DeliveryApiMode}'`, + type: 'string', + isRequired: false +}; + +export const contentTypes: CommandOption = { + name: `contentTypes`, + description: `CSV of content types to generate models for. If not provided, all items will be generated`, + type: 'string', + isRequired: false +}; + +export const baseUrl: CommandOption = { name: `baseUrl`, description: `Base URL for Management API`, type: 'string', @@ -48,26 +69,42 @@ export const cliArgs = argumentsSetter() .withCommand({ name: 'delivery-sdk', description: `Generates models for '${'@kontent-ai/delivery-sdk' satisfies LibraryType}' library`, - examples: [`kontent-generate ${'delivery-sdk' satisfies CliAction} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], - options: [environmentIdOption, apiKeyOption, addTimestampOption, ModuleFileExtensionOption, outputDirOption, baseUrl] + examples: [ + `kontent-generate ${'delivery-sdk' satisfies CliAction} --${environmentIdOption.name}=x --${managementApiKeyOption.name}=x` + ], + options: [environmentIdOption, managementApiKeyOption, addTimestampOption, ModuleFileExtensionOption, outputDirOption, baseUrl] }) .withCommand({ name: 'environment', description: `Generates strongly typed models representing all objects in the environment. This is useful for creating custom tools or scripts where you need to reference objects within your environment`, - examples: [`kontent-generate ${'environment' satisfies CliAction} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], - options: [environmentIdOption, apiKeyOption, addTimestampOption, ModuleFileExtensionOption, outputDirOption, baseUrl] + examples: [ + `kontent-generate ${'environment' satisfies CliAction} --${environmentIdOption.name}=x --${managementApiKeyOption.name}=x` + ], + options: [environmentIdOption, managementApiKeyOption, addTimestampOption, ModuleFileExtensionOption, outputDirOption, baseUrl] }) .withCommand({ name: 'migration-toolkit', description: `Generates models for '${'@kontent-ai/migration-toolkit' satisfies LibraryType}' library`, - examples: [`kontent-generate ${'migration-toolkit' satisfies CliAction} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], - options: [environmentIdOption, apiKeyOption, addTimestampOption, ModuleFileExtensionOption, outputDirOption, baseUrl] + examples: [ + `kontent-generate ${'migration-toolkit' satisfies CliAction} --${environmentIdOption.name}=x --${managementApiKeyOption.name}=x` + ], + options: [environmentIdOption, managementApiKeyOption, addTimestampOption, ModuleFileExtensionOption, outputDirOption, baseUrl] }) .withCommand({ name: 'items', - description: `Overview of all items in the environment and their ids/codenames as well as Type representing all item codenames`, - examples: [`kontent-generate ${'items' satisfies CliAction} --${environmentIdOption.name}=x --${apiKeyOption.name}=x`], - options: [environmentIdOption, apiKeyOption, addTimestampOption, ModuleFileExtensionOption, outputDirOption, baseUrl] + description: `Overview of all items in the environment and their ids/codenames as well as Type representing all item codenames.`, + examples: [ + `kontent-generate ${'items' satisfies CliAction} --${environmentIdOption.name}=x --${managementApiKeyOption.name}=x --${deliveryApiKeyOption.name}=x --${apiModeOption.name}=preview --${contentTypes.name}=a,b,c` + ], + options: [ + environmentIdOption, + managementApiKeyOption, + deliveryApiKeyOption, + addTimestampOption, + ModuleFileExtensionOption, + outputDirOption, + baseUrl + ] }) .withOption({ alias: `h`, diff --git a/lib/config.ts b/lib/config.ts index c0a94a9..39cc327 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -1,6 +1,7 @@ -import { ModuleFileExtension } from './core/core.models.js'; +import { DeliveryApiMode, ModuleFileExtension } from './core/core.models.js'; export const defaultModuleFileExtension: ModuleFileExtension = 'js'; +export const defaultDeliveryApiMode: DeliveryApiMode = 'default'; export const coreConfig = { barrelExportFilename: 'index.ts' diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index c87ea07..8e2f5aa 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -1,3 +1,4 @@ +import { IDeliveryClient } from '@kontent-ai/delivery-sdk'; import { ContentTypeElements, ContentTypeModels, @@ -11,7 +12,9 @@ export type CliAction = 'delivery-sdk' | 'migration-toolkit' | 'environment' | ' export type LibraryType = '@kontent-ai/migration-toolkit' | '@kontent-ai/delivery-sdk'; export type ModuleFileExtension = 'js' | 'ts' | 'none'; export type CaseType = 'camelCase' | 'pascalCase'; +export type DeliveryApiMode = 'preview' | 'secure' | 'default'; export type GeneratorManagementClient = Readonly>; +export type GeneratorDeliveryClient = Readonly; export type LiteralUnion = T | (string & NonNullable); export interface ErrorData { diff --git a/lib/fetch/delivery-kontent-fetcher.ts b/lib/fetch/delivery-kontent-fetcher.ts new file mode 100644 index 0000000..83ab126 --- /dev/null +++ b/lib/fetch/delivery-kontent-fetcher.ts @@ -0,0 +1,43 @@ +import { HttpService } from '@kontent-ai/core-sdk'; +import { createDeliveryClient, IContentItem, ItemsFeedQuery } from '@kontent-ai/delivery-sdk'; +import chalk from 'chalk'; +import { DeliveryApiMode, GeneratorDeliveryClient } from '../core/core.models.js'; +import { sortAlphabetically } from '../core/core.utils.js'; + +interface KontentFetcherConfig { + readonly environmentId: string; + readonly apiKey: string | undefined; + readonly baseUrl?: string; + readonly apiMode: DeliveryApiMode; +} + +export function deliveryKontentFetcher(config: KontentFetcherConfig) { + const client: GeneratorDeliveryClient = createDeliveryClient({ + environmentId: config.environmentId, + defaultQueryConfig: { + usePreviewMode: config.apiMode === 'preview', + useSecuredMode: config.apiMode === 'secure' + }, + secureApiKey: config.apiMode === 'secure' ? config.apiKey : undefined, + previewApiKey: config.apiMode === 'preview' ? config.apiKey : undefined, + proxy: { + baseUrl: config.baseUrl + }, + httpService: new HttpService({ logErrorsToConsole: false }) + }); + + const getItemsQuery = (filterByTypeCodenames: readonly string[]): ItemsFeedQuery => { + return filterByTypeCodenames.length > 0 ? client.itemsFeed().types(filterByTypeCodenames.map((m) => m)) : client.itemsFeed(); + }; + + return { + async getItemsAsync(filterByTypeCodenames: readonly string[]): Promise[]> { + const items = sortAlphabetically( + (await getItemsQuery(filterByTypeCodenames).toAllPromise()).data.items, + (m) => m.system.codename + ); + console.log(`Fetched '${chalk.yellow(items.length.toString())}' content items`); + return items; + } + }; +} diff --git a/lib/fetch/kontent-fetcher.ts b/lib/fetch/management-kontent-fetcher.ts similarity index 98% rename from lib/fetch/kontent-fetcher.ts rename to lib/fetch/management-kontent-fetcher.ts index 3ee6dac..cef3151 100644 --- a/lib/fetch/kontent-fetcher.ts +++ b/lib/fetch/management-kontent-fetcher.ts @@ -23,7 +23,7 @@ interface KontentFetcherConfig { readonly baseUrl?: string; } -export function kontentFetcher(config: KontentFetcherConfig) { +export function managementKontentFetcher(config: KontentFetcherConfig) { const client: GeneratorManagementClient = createManagementClient({ environmentId: config.environmentId, apiKey: config.apiKey, diff --git a/lib/generators/delivery/delivery-func.ts b/lib/generators/delivery/delivery-func.ts index 9428437..deaaee3 100644 --- a/lib/generators/delivery/delivery-func.ts +++ b/lib/generators/delivery/delivery-func.ts @@ -10,7 +10,7 @@ import { TaxonomyNameResolver, TaxonomyTypeFileNameResolver } from '../../core/resolvers.js'; -import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; +import { managementKontentFetcher as _kontentFetcher } from '../../fetch/management-kontent-fetcher.js'; import { fileManager as _fileManager } from '../../files/file-manager.js'; import { deliveryContentTypeGenerator } from './delivery-content-type.generator.js'; import { deliveryTaxonomyGenerator } from './delivery-taxonomy.generator.js'; diff --git a/lib/generators/environment/environment-func.ts b/lib/generators/environment/environment-func.ts index 32d45b5..ba6ca16 100644 --- a/lib/generators/environment/environment-func.ts +++ b/lib/generators/environment/environment-func.ts @@ -3,7 +3,7 @@ import chalk from 'chalk'; import { Options } from 'prettier'; import { defaultModuleFileExtension } from '../../config.js'; import { GeneratedSet, ModuleFileExtension } from '../../core/core.models.js'; -import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; +import { managementKontentFetcher as _kontentFetcher } from '../../fetch/management-kontent-fetcher.js'; import { fileManager as _fileManager } from '../../files/file-manager.js'; import { environmentGenerator as _environmentGenerator } from './environment.generator.js'; diff --git a/lib/generators/items/items-func.ts b/lib/generators/items/items-func.ts index 4178f4b..8c5ee55 100644 --- a/lib/generators/items/items-func.ts +++ b/lib/generators/items/items-func.ts @@ -1,8 +1,9 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; -import { GeneratedSet, ModuleFileExtension } from '../../core/core.models.js'; -import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; +import { DeliveryApiMode, GeneratedSet, ModuleFileExtension } from '../../core/core.models.js'; +import { deliveryKontentFetcher as _deliveryKontentFetcher } from '../../fetch/delivery-kontent-fetcher.js'; +import { managementKontentFetcher as _managementKontentFetcher } from '../../fetch/management-kontent-fetcher.js'; import { fileManager as _fileManager } from '../../files/file-manager.js'; import { itemsGenerator as _itemsGenerator } from './items.generator.js'; @@ -11,7 +12,10 @@ export interface GenerateItemsModelsConfig { readonly addTimestamp: boolean; readonly apiKey: string; readonly moduleFileExtension: ModuleFileExtension; + readonly apiMode: DeliveryApiMode; + readonly filterByTypeCodenames: readonly string[]; + readonly deliveryApiKey?: string; readonly outputDir?: string; readonly baseUrl?: string; readonly formatOptions?: Readonly; @@ -38,19 +42,28 @@ async function getFilesAsync(config: GenerateItemsModelsConfig): Promise<{ readonly codenameFiles: GeneratedSet; readonly environmentInfo: Readonly; }> { - const kontentFetcher = _kontentFetcher({ + const deliveryKontentFetcher = _deliveryKontentFetcher({ + environmentId: config.environmentId, + apiMode: config.apiMode, + apiKey: config.deliveryApiKey, + baseUrl: config.baseUrl + }); + + const managementKontentFetcher = _managementKontentFetcher({ environmentId: config.environmentId, apiKey: config.apiKey, baseUrl: config.baseUrl }); - const environmentInfo = await kontentFetcher.getEnvironmentInfoAsync(); + const environmentInfo = await managementKontentFetcher.getEnvironmentInfoAsync(); - const [items, types] = await Promise.all([kontentFetcher.getItemsAsync(), kontentFetcher.getTypesAsync()]); + const [items, types] = await Promise.all([ + deliveryKontentFetcher.getItemsAsync(config.filterByTypeCodenames), + managementKontentFetcher.getTypesAsync() + ]); const itemsGenerator = _itemsGenerator({ environmentData: { - environment: environmentInfo, types: types, items: items } diff --git a/lib/generators/items/items.generator.ts b/lib/generators/items/items.generator.ts index 1f67c9a..2b62239 100644 --- a/lib/generators/items/items.generator.ts +++ b/lib/generators/items/items.generator.ts @@ -1,4 +1,6 @@ -import { ContentItemModels, ContentTypeModels, EnvironmentModels } from '@kontent-ai/management-sdk'; +import { IContentItem } from '@kontent-ai/delivery-sdk'; +import { ContentTypeModels } from '@kontent-ai/management-sdk'; +import Chalk from 'chalk'; import { itemsConfig } from '../../config.js'; import { toSafeComment, wrapComment } from '../../core/comment.utils.js'; import { GeneratedSet } from '../../core/core.models.js'; @@ -6,59 +8,70 @@ import { toPascalCase } from '../../core/core.utils.js'; export interface ItemGeneratorConfig { readonly environmentData: { - readonly environment: Readonly; + readonly items: readonly Readonly[]; readonly types: readonly Readonly[]; - readonly items: readonly Readonly[]; }; } export function itemsGenerator(config: ItemGeneratorConfig) { - const getItemCodenameType = ( - type: Readonly, - items: readonly Readonly[] - ): string => { - return `export type ${toPascalCase(type.codename)}Codenames = ${items.map((item) => `'${item.codename}'`).join(' | ')};`; + const getItemCodenameType = (typeCodename: string, items: readonly Readonly[]): string => { + return `export type ${toPascalCase(typeCodename)}Codenames = ${items.map((item) => `'${item.system.codename}'`).join(' | ')};`; }; - const getItemCodenamesProp = ( - type: Readonly, - items: readonly Readonly[] - ): string => { + const getItemCodenamesProp = (typeCodename: string, items: readonly Readonly[]): string => { const values = items.reduce((code, item, index) => { const isLast = index === items.length - 1; return `${code}\n ${wrapComment(` - * ${item.name} + * ${item.system.name} `)} - ${item.codename}: { - codename: '${item.codename}', - id: '${item.id}' + ${item.system.codename}: { + codename: '${item.system.codename}', + id: '${item.system.id}' }${!isLast ? ',\n' : ''}`; }, ''); - return `export const ${type.codename}Items = { + return `export const ${typeCodename}Items = { ${values} } as const;`; }; + const groupItemsByType = (items: readonly Readonly[]): Map[]> => { + return items.reduce[]>>((itemsByType, item) => { + const existingGroupItems = itemsByType.get(item.system.type); + if (existingGroupItems) { + itemsByType.set(item.system.type, [...existingGroupItems, item]); + } else { + itemsByType.set(item.system.type, [item]); + } + + return itemsByType; + }, new Map[]>()); + }; + return { getItemFiles(): GeneratedSet { return { folderName: itemsConfig.itemsFolderName, - files: config.environmentData.types.map((type) => { - const typeItems = config.environmentData.items.filter((m) => m.type.id === type.id); + files: Array.from(groupItemsByType(config.environmentData.items)).map(([typeCodename, items]) => { + const type = config.environmentData.types.find((t) => t.codename.toLowerCase() === typeCodename.toLowerCase()); + + if (!type) { + throw new Error(`Type with codename '${Chalk.red(typeCodename)}' not found`); + } return { - filename: `${type.codename}.items.ts`, + filename: `${typeCodename}.items.ts`, text: ` ${wrapComment(`\n * Object representing identifiers of available items - * + * * ${toSafeComment(type.name)} * * Codename: ${type.codename} - * Id: ${type.id}\n`)} - ${getItemCodenamesProp(type, typeItems)}` + * Id: ${type.id} + * Codename: ${typeCodename}\n`)} + ${getItemCodenamesProp(typeCodename, items)}` }; }) }; @@ -66,19 +79,24 @@ export function itemsGenerator(config: ItemGeneratorConfig) { getCodenameFiles(): GeneratedSet { return { folderName: itemsConfig.codenamesFolderName, - files: config.environmentData.types.map((type) => { - const typeItems = config.environmentData.items.filter((m) => m.type.id === type.id); + files: Array.from(groupItemsByType(config.environmentData.items)).map(([typeCodename, items]) => { + const type = config.environmentData.types.find((t) => t.codename.toLowerCase() === typeCodename.toLowerCase()); + + if (!type) { + throw new Error(`Type with codename '${Chalk.red(typeCodename)}' not found`); + } return { - filename: `${type.codename}.codenames.ts`, + filename: `${typeCodename}.codenames.ts`, text: ` ${wrapComment(`\n * Type representing available item codenames * * ${toSafeComment(type.name)} * * Codename: ${type.codename} - * Id: ${type.id}\n`)} - ${getItemCodenameType(type, typeItems)}` + * Id: ${type.id} + * Codename: ${typeCodename}\n`)} + ${getItemCodenameType(typeCodename, items)}` }; }) }; diff --git a/lib/generators/migration/migration-func.ts b/lib/generators/migration/migration-func.ts index 66d6b78..95a41e5 100644 --- a/lib/generators/migration/migration-func.ts +++ b/lib/generators/migration/migration-func.ts @@ -2,7 +2,7 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; import { GeneratedSet, ModuleFileExtension } from '../../core/core.models.js'; -import { kontentFetcher as _kontentFetcher } from '../../fetch/kontent-fetcher.js'; +import { managementKontentFetcher as _kontentFetcher } from '../../fetch/management-kontent-fetcher.js'; import { fileManager as _fileManager } from '../../files/file-manager.js'; import { migrationGenerator as _migrationGenerator } from './migration.generator.js'; diff --git a/lib/public_api.ts b/lib/public_api.ts index ae38344..279d64a 100644 --- a/lib/public_api.ts +++ b/lib/public_api.ts @@ -1,7 +1,7 @@ /* * Public API */ -export { CaseType, ModuleFileExtension } from './core/core.models.js'; +export { CaseType, DeliveryApiMode, ModuleFileExtension } from './core/core.models.js'; export { GenerateDeliveryModelsConfig, generateDeliveryModelsAsync } from './generators/delivery/delivery-func.js'; export { GenerateEnvironmentModelsConfig, generateEnvironmentModelsAsync } from './generators/environment/environment-func.js'; export { GenerateItemsModelsConfig, generateItemsAsync } from './generators/items/items-func.js'; diff --git a/sample/items/codenames/actor.codenames.ts b/sample/items/codenames/actor.codenames.ts index 8744866..daf932e 100644 --- a/sample/items/codenames/actor.codenames.ts +++ b/sample/items/codenames/actor.codenames.ts @@ -20,18 +20,19 @@ * * Codename: actor * Id: 58099989-319f-495f-aa36-cb3710854e36 + * Codename: actor */ export type ActorCodenames = | 'anne_hathaway' - | 'rachel_mcadams' - | 'nathalie_boltt' - | 'kristen_wiig' - | 'joel_edgerton' + | 'bill_nighy' | 'billy_crystal' - | 'matt_damon' + | 'christian_bale' + | 'domhnall_gleeson' | 'jessica_chastain' + | 'joel_edgerton' + | 'kristen_wiig' + | 'matt_damon' + | 'nathalie_boltt' + | 'rachel_mcadams' | 'sharlto_copley' - | 'domhnall_gleeson' - | 'bill_nighy' - | 'tom_hardy' - | 'christian_bale'; + | 'tom_hardy'; diff --git a/sample/items/codenames/movie.codenames.ts b/sample/items/codenames/movie.codenames.ts deleted file mode 100644 index 14be4c1..0000000 --- a/sample/items/codenames/movie.codenames.ts +++ /dev/null @@ -1,24 +0,0 @@ - -/** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Movie Database -* Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 -* -* ------------------------------------------------------------------------------- -**/ - -/** - * Type representing available item codenames - * - * Movie - * - * Codename: movie - * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c - */ -export type MovieCodenames = 'monsters__inc_' | 'warrior' | 'district_9' | 'the_martian' | '_the_dark_knight_rises' | 'about_time'; diff --git a/sample/items/items/actor.items.ts b/sample/items/items/actor.items.ts index 3281965..ac17ee1 100644 --- a/sample/items/items/actor.items.ts +++ b/sample/items/items/actor.items.ts @@ -20,6 +20,7 @@ * * Codename: actor * Id: 58099989-319f-495f-aa36-cb3710854e36 + * Codename: actor */ export const actorItems = { /** @@ -31,27 +32,43 @@ export const actorItems = { }, /** - * Rachel McAdams + * Bill Nighy */ - rachel_mcadams: { - codename: 'rachel_mcadams', - id: '10145fa6-b074-4d2e-9a18-07cf23dff33d' + bill_nighy: { + codename: 'bill_nighy', + id: 'cddc7576-38b3-4de2-9fb9-2d1ce16daa8b' }, /** - * Nathalie Boltt + * Billy Crystal */ - nathalie_boltt: { - codename: 'nathalie_boltt', - id: '11b2170c-6df8-48d6-af66-4ddafa2a425a' + billy_crystal: { + codename: 'billy_crystal', + id: '3e99ea61-7d47-49f0-b271-5757061658ab' }, /** - * Kristen Wiig + * Christian Bale */ - kristen_wiig: { - codename: 'kristen_wiig', - id: '2df17777-b347-4590-be05-cb256bf718e9' + christian_bale: { + codename: 'christian_bale', + id: 'f0e9e9fa-91e8-40d5-9527-b7e0ae51fc54' + }, + + /** + * Domhnall Gleeson + */ + domhnall_gleeson: { + codename: 'domhnall_gleeson', + id: 'c37b94d2-56e1-4e0a-9f14-547fe194e0d9' + }, + + /** + * Jessica Chastain + */ + jessica_chastain: { + codename: 'jessica_chastain', + id: 'a67aacfa-b400-444d-b53e-df1766065034' }, /** @@ -63,11 +80,11 @@ export const actorItems = { }, /** - * Billy Crystal + * Kristen Wiig */ - billy_crystal: { - codename: 'billy_crystal', - id: '3e99ea61-7d47-49f0-b271-5757061658ab' + kristen_wiig: { + codename: 'kristen_wiig', + id: '2df17777-b347-4590-be05-cb256bf718e9' }, /** @@ -79,35 +96,27 @@ export const actorItems = { }, /** - * Jessica Chastain - */ - jessica_chastain: { - codename: 'jessica_chastain', - id: 'a67aacfa-b400-444d-b53e-df1766065034' - }, - - /** - * Sharlto Copley + * Nathalie Boltt */ - sharlto_copley: { - codename: 'sharlto_copley', - id: 'c10783cb-c8b8-4fec-8f44-7323ffc3227b' + nathalie_boltt: { + codename: 'nathalie_boltt', + id: '11b2170c-6df8-48d6-af66-4ddafa2a425a' }, /** - * Domhnall Gleeson + * Rachel McAdams */ - domhnall_gleeson: { - codename: 'domhnall_gleeson', - id: 'c37b94d2-56e1-4e0a-9f14-547fe194e0d9' + rachel_mcadams: { + codename: 'rachel_mcadams', + id: '10145fa6-b074-4d2e-9a18-07cf23dff33d' }, /** - * Bill Nighy + * Sharlto Copley */ - bill_nighy: { - codename: 'bill_nighy', - id: 'cddc7576-38b3-4de2-9fb9-2d1ce16daa8b' + sharlto_copley: { + codename: 'sharlto_copley', + id: 'c10783cb-c8b8-4fec-8f44-7323ffc3227b' }, /** @@ -116,13 +125,5 @@ export const actorItems = { tom_hardy: { codename: 'tom_hardy', id: 'd1557cb1-d7ec-4d04-9742-f86b52bc34fc' - }, - - /** - * Christian Bale - */ - christian_bale: { - codename: 'christian_bale', - id: 'f0e9e9fa-91e8-40d5-9527-b7e0ae51fc54' } } as const; diff --git a/sample/items/items/movie.items.ts b/sample/items/items/movie.items.ts deleted file mode 100644 index 5c731c4..0000000 --- a/sample/items/items/movie.items.ts +++ /dev/null @@ -1,72 +0,0 @@ - -/** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Movie Database -* Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 -* -* ------------------------------------------------------------------------------- -**/ - -/** - * Object representing identifiers of available items - * - * Movie - * - * Codename: movie - * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c - */ -export const movieItems = { - /** - * Monsters, Inc. - */ - monsters__inc_: { - codename: 'monsters__inc_', - id: '00e96c5c-22a2-4ecf-811d-28881d1d2eda' - }, - - /** - * Warrior - */ - warrior: { - codename: 'warrior', - id: '325e2acb-1c14-47f6-af9a-27bc8b6c16fe' - }, - - /** - * District 9 - */ - district_9: { - codename: 'district_9', - id: 'e0b67f90-790c-4509-8679-5ca2df42f3b8' - }, - - /** - * The Martian - */ - the_martian: { - codename: 'the_martian', - id: 'e9ac3dd7-8129-4f9a-9112-eb24d84d3ecd' - }, - - /** - * The Dark Knight Rises - */ - _the_dark_knight_rises: { - codename: '_the_dark_knight_rises', - id: 'e9ff5385-0f10-469a-8525-98189e295c0d' - }, - - /** - * About Time - */ - about_time: { - codename: 'about_time', - id: 'f5d741ec-e500-4285-97f0-a30196a655bd' - } -} as const; diff --git a/scripts/samples/item-models.ts b/scripts/samples/item-models.ts index 45b7d49..d366d0b 100644 --- a/scripts/samples/item-models.ts +++ b/scripts/samples/item-models.ts @@ -4,7 +4,7 @@ import { rmSync } from 'fs'; import { parseModuleFileExtension } from '../../lib/cli/arg.utils.js'; import { logError } from '../../lib/core/error.utils.js'; import { generateItemsAsync } from '../../lib/generators/items/items-func.js'; -import { getEnvironmentRequiredValue } from '../utils/test.utils.js'; +import { getEnvironmentOptionalValue, getEnvironmentRequiredValue } from '../utils/test.utils.js'; const outputDir: string = './sample/items'; @@ -23,6 +23,7 @@ try { const environmentId = getEnvironmentRequiredValue('ENVIRONMENT_ID'); const apiKey = getEnvironmentRequiredValue('API_KEY'); + const deliveryApiKey = getEnvironmentOptionalValue('DELIVERY_API_KEY'); const moduleFileExtension = parseModuleFileExtension(getEnvironmentRequiredValue('MODULE_EXTENSION')); await generateItemsAsync({ @@ -30,7 +31,10 @@ try { environmentId: environmentId, apiKey: apiKey, moduleFileExtension: moduleFileExtension, - outputDir: outputDir + outputDir: outputDir, + apiMode: 'default', + deliveryApiKey: deliveryApiKey, + filterByTypeCodenames: [] }); } catch (error) { logError(error); From b71036186bdd0502e4ed78c1a32e65a048ed0580 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 1 Oct 2024 15:40:21 +0200 Subject: [PATCH 150/183] updates samples --- sample/items/codenames/movie.codenames.ts | 25 ++++++++ sample/items/items/movie.items.ts | 73 +++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 sample/items/codenames/movie.codenames.ts create mode 100644 sample/items/items/movie.items.ts diff --git a/sample/items/codenames/movie.codenames.ts b/sample/items/codenames/movie.codenames.ts new file mode 100644 index 0000000..c11a52b --- /dev/null +++ b/sample/items/codenames/movie.codenames.ts @@ -0,0 +1,25 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +/** + * Type representing available item codenames + * + * Movie + * + * Codename: movie + * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c + * Codename: movie + */ +export type MovieCodenames = '_the_dark_knight_rises' | 'about_time' | 'district_9' | 'monsters__inc_' | 'the_martian' | 'warrior'; diff --git a/sample/items/items/movie.items.ts b/sample/items/items/movie.items.ts new file mode 100644 index 0000000..a0d0dfd --- /dev/null +++ b/sample/items/items/movie.items.ts @@ -0,0 +1,73 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +/** + * Object representing identifiers of available items + * + * Movie + * + * Codename: movie + * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c + * Codename: movie + */ +export const movieItems = { + /** + * The Dark Knight Rises + */ + _the_dark_knight_rises: { + codename: '_the_dark_knight_rises', + id: 'e9ff5385-0f10-469a-8525-98189e295c0d' + }, + + /** + * About Time + */ + about_time: { + codename: 'about_time', + id: 'f5d741ec-e500-4285-97f0-a30196a655bd' + }, + + /** + * District 9 + */ + district_9: { + codename: 'district_9', + id: 'e0b67f90-790c-4509-8679-5ca2df42f3b8' + }, + + /** + * Monsters, Inc. + */ + monsters__inc_: { + codename: 'monsters__inc_', + id: '00e96c5c-22a2-4ecf-811d-28881d1d2eda' + }, + + /** + * The Martian + */ + the_martian: { + codename: 'the_martian', + id: 'e9ac3dd7-8129-4f9a-9112-eb24d84d3ecd' + }, + + /** + * Warrior + */ + warrior: { + codename: 'warrior', + id: '325e2acb-1c14-47f6-af9a-27bc8b6c16fe' + } +} as const; From fbd6f2990fb18b35f79e8367c5309f0451e6c7f8 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 1 Oct 2024 15:51:01 +0200 Subject: [PATCH 151/183] Uses strongly typed arg names instead of string, adds few missing options, separates delivery / management base url --- lib/cli/actions/delivery-action.ts | 20 +++++++--- lib/cli/actions/environment-action.ts | 23 +++++++---- lib/cli/actions/items-action.ts | 31 ++++++++++----- lib/cli/actions/migrate-action.ts | 20 +++++++--- lib/cli/commands.ts | 57 ++++++++++++++++++++++----- lib/generators/items/items-func.ts | 3 +- 6 files changed, 116 insertions(+), 38 deletions(-) diff --git a/lib/cli/actions/delivery-action.ts b/lib/cli/actions/delivery-action.ts index 302b5e2..b4aa536 100644 --- a/lib/cli/actions/delivery-action.ts +++ b/lib/cli/actions/delivery-action.ts @@ -1,16 +1,24 @@ import { generateDeliveryModelsAsync } from '../../generators/delivery/delivery-func.js'; import { parseModuleFileExtension } from '../arg.utils.js'; import { CliArgumentsFetcher } from '../cli.models.js'; +import { + addTimestampOption, + environmentIdOption, + managementApiKeyOption, + managementBaseUrlOption, + moduleFileExtensionOption, + outputDirOption +} from '../commands.js'; export async function deliveryActionAsync(cliFetcher: CliArgumentsFetcher): Promise { await generateDeliveryModelsAsync({ // required - environmentId: cliFetcher.getRequiredArgumentValue('environmentId'), - apiKey: cliFetcher.getRequiredArgumentValue('apiKey'), + environmentId: cliFetcher.getRequiredArgumentValue(environmentIdOption.name), + apiKey: cliFetcher.getRequiredArgumentValue(managementApiKeyOption.name), // optional - baseUrl: cliFetcher.getOptionalArgumentValue('baseUrl'), - outputDir: cliFetcher.getOptionalArgumentValue('outputDir'), - addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), - moduleFileExtension: parseModuleFileExtension(cliFetcher.getOptionalArgumentValue('moduleFileExtension')) + baseUrl: cliFetcher.getOptionalArgumentValue(managementBaseUrlOption.name), + outputDir: cliFetcher.getOptionalArgumentValue(outputDirOption.name), + addTimestamp: cliFetcher.getBooleanArgumentValue(addTimestampOption.name, false), + moduleFileExtension: parseModuleFileExtension(cliFetcher.getOptionalArgumentValue(moduleFileExtensionOption.name)) }); } diff --git a/lib/cli/actions/environment-action.ts b/lib/cli/actions/environment-action.ts index c090208..f84c290 100644 --- a/lib/cli/actions/environment-action.ts +++ b/lib/cli/actions/environment-action.ts @@ -1,17 +1,26 @@ import { generateEnvironmentModelsAsync } from '../../generators/environment/environment-func.js'; import { parseModuleFileExtension } from '../arg.utils.js'; import { CliArgumentsFetcher } from '../cli.models.js'; +import { + addTimestampOption, + environmentIdOption, + isEnterpriseSubscriptionOption, + managementApiKeyOption, + managementBaseUrlOption, + moduleFileExtensionOption, + outputDirOption +} from '../commands.js'; export async function environmentActionAsync(cliFetcher: CliArgumentsFetcher): Promise { await generateEnvironmentModelsAsync({ // required - environmentId: cliFetcher.getRequiredArgumentValue('environmentId'), - apiKey: cliFetcher.getRequiredArgumentValue('apiKey'), + environmentId: cliFetcher.getRequiredArgumentValue(environmentIdOption.name), + apiKey: cliFetcher.getRequiredArgumentValue(managementApiKeyOption.name), // optional - baseUrl: cliFetcher.getOptionalArgumentValue('baseUrl'), - outputDir: cliFetcher.getOptionalArgumentValue('outputDir'), - addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), - moduleFileExtension: parseModuleFileExtension(cliFetcher.getOptionalArgumentValue('moduleFileExtension')), - isEnterpriseSubscription: cliFetcher.getBooleanArgumentValue('isEnterpriseSubscription', false) + baseUrl: cliFetcher.getOptionalArgumentValue(managementBaseUrlOption.name), + outputDir: cliFetcher.getOptionalArgumentValue(outputDirOption.name), + addTimestamp: cliFetcher.getBooleanArgumentValue(addTimestampOption.name, false), + moduleFileExtension: parseModuleFileExtension(cliFetcher.getOptionalArgumentValue(moduleFileExtensionOption.name)), + isEnterpriseSubscription: cliFetcher.getBooleanArgumentValue(isEnterpriseSubscriptionOption.name, false) }); } diff --git a/lib/cli/actions/items-action.ts b/lib/cli/actions/items-action.ts index 0484b36..0ef6ac6 100644 --- a/lib/cli/actions/items-action.ts +++ b/lib/cli/actions/items-action.ts @@ -1,19 +1,32 @@ import { generateItemsAsync } from '../../generators/items/items-func.js'; import { parseDeliveryApiMode, parseModuleFileExtension } from '../arg.utils.js'; import { CliArgumentsFetcher } from '../cli.models.js'; +import { + addTimestampOption, + apiModeOption, + contentTypesOption, + deliveryApiKeyOption, + deliveryBaseUrlOption, + environmentIdOption, + managementApiKeyOption, + managementBaseUrlOption, + moduleFileExtensionOption, + outputDirOption +} from '../commands.js'; export async function itemsActionAsync(cliFetcher: CliArgumentsFetcher): Promise { await generateItemsAsync({ // required - environmentId: cliFetcher.getRequiredArgumentValue('environmentId'), - apiKey: cliFetcher.getRequiredArgumentValue('apiKey'), + environmentId: cliFetcher.getRequiredArgumentValue(environmentIdOption.name), + apiKey: cliFetcher.getRequiredArgumentValue(managementApiKeyOption.name), // optional - deliveryApiKey: cliFetcher.getOptionalArgumentValue('deliveryApiKey'), - baseUrl: cliFetcher.getOptionalArgumentValue('baseUrl'), - outputDir: cliFetcher.getOptionalArgumentValue('outputDir'), - addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), - apiMode: parseDeliveryApiMode(cliFetcher.getOptionalArgumentValue('apiMode')), - filterByTypeCodenames: cliFetcher.getOptionalArgumentArrayVaue('contentTypes') ?? [], - moduleFileExtension: parseModuleFileExtension(cliFetcher.getOptionalArgumentValue('moduleFileExtension')) + deliveryApiKey: cliFetcher.getOptionalArgumentValue(deliveryApiKeyOption.name), + baseUrl: cliFetcher.getOptionalArgumentValue(managementBaseUrlOption.name), + deliveryBaseUrl: cliFetcher.getOptionalArgumentValue(deliveryBaseUrlOption.name), + outputDir: cliFetcher.getOptionalArgumentValue(outputDirOption.name), + addTimestamp: cliFetcher.getBooleanArgumentValue(addTimestampOption.name, false), + apiMode: parseDeliveryApiMode(cliFetcher.getOptionalArgumentValue(apiModeOption.name)), + filterByTypeCodenames: cliFetcher.getOptionalArgumentArrayVaue(contentTypesOption.name) ?? [], + moduleFileExtension: parseModuleFileExtension(cliFetcher.getOptionalArgumentValue(moduleFileExtensionOption.name)) }); } diff --git a/lib/cli/actions/migrate-action.ts b/lib/cli/actions/migrate-action.ts index c7ee7e9..3be36c2 100644 --- a/lib/cli/actions/migrate-action.ts +++ b/lib/cli/actions/migrate-action.ts @@ -1,16 +1,24 @@ import { generateMigrationModelsAsync } from '../../generators/migration/migration-func.js'; import { parseModuleFileExtension } from '../arg.utils.js'; import { CliArgumentsFetcher } from '../cli.models.js'; +import { + addTimestampOption, + environmentIdOption, + managementApiKeyOption, + managementBaseUrlOption, + moduleFileExtensionOption, + outputDirOption +} from '../commands.js'; export async function migrateActionAsync(cliFetcher: CliArgumentsFetcher): Promise { await generateMigrationModelsAsync({ // required - environmentId: cliFetcher.getRequiredArgumentValue('environmentId'), - apiKey: cliFetcher.getRequiredArgumentValue('apiKey'), + environmentId: cliFetcher.getRequiredArgumentValue(environmentIdOption.name), + apiKey: cliFetcher.getRequiredArgumentValue(managementApiKeyOption.name), // optional - baseUrl: cliFetcher.getOptionalArgumentValue('baseUrl'), - outputDir: cliFetcher.getOptionalArgumentValue('outputDir'), - addTimestamp: cliFetcher.getBooleanArgumentValue('addTimestamp', false), - moduleFileExtension: parseModuleFileExtension(cliFetcher.getOptionalArgumentValue('moduleFileExtension')) + baseUrl: cliFetcher.getOptionalArgumentValue(managementBaseUrlOption.name), + outputDir: cliFetcher.getOptionalArgumentValue(outputDirOption.name), + addTimestamp: cliFetcher.getBooleanArgumentValue(addTimestampOption.name, false), + moduleFileExtension: parseModuleFileExtension(cliFetcher.getOptionalArgumentValue(moduleFileExtensionOption.name)) }); } diff --git a/lib/cli/commands.ts b/lib/cli/commands.ts index 9123ad8..a40f688 100644 --- a/lib/cli/commands.ts +++ b/lib/cli/commands.ts @@ -37,7 +37,7 @@ export const addTimestampOption: CommandOption = { isRequired: false }; -export const ModuleFileExtensionOption: CommandOption = { +export const moduleFileExtensionOption: CommandOption = { name: `moduleFileExtension`, description: `Module resolution for imports. Available options are: '${'js' satisfies ModuleFileExtension}', '${'ts' satisfies ModuleFileExtension}' or '${'none' satisfies ModuleFileExtension}' (no extension) }`, type: 'string', @@ -51,20 +51,34 @@ export const apiModeOption: CommandOption = { isRequired: false }; -export const contentTypes: CommandOption = { +export const contentTypesOption: CommandOption = { name: `contentTypes`, description: `CSV of content types to generate models for. If not provided, all items will be generated`, type: 'string', isRequired: false }; -export const baseUrl: CommandOption = { +export const isEnterpriseSubscriptionOption: CommandOption = { + name: `isEnterpriseSubscription`, + description: `Indicates if the subscription is Enterprise. If true, the generator will generate models for Enterprise features`, + type: 'boolean', + isRequired: false +}; + +export const managementBaseUrlOption: CommandOption = { name: `baseUrl`, description: `Base URL for Management API`, type: 'string', isRequired: false }; +export const deliveryBaseUrlOption: CommandOption = { + name: `deliveryBaseUrl`, + description: `Base URL for Delivery API`, + type: 'string', + isRequired: false +}; + export const cliArgs = argumentsSetter() .withCommand({ name: 'delivery-sdk', @@ -72,7 +86,14 @@ export const cliArgs = argumentsSetter() examples: [ `kontent-generate ${'delivery-sdk' satisfies CliAction} --${environmentIdOption.name}=x --${managementApiKeyOption.name}=x` ], - options: [environmentIdOption, managementApiKeyOption, addTimestampOption, ModuleFileExtensionOption, outputDirOption, baseUrl] + options: [ + environmentIdOption, + managementApiKeyOption, + addTimestampOption, + moduleFileExtensionOption, + outputDirOption, + managementBaseUrlOption + ] }) .withCommand({ name: 'environment', @@ -80,7 +101,15 @@ export const cliArgs = argumentsSetter() examples: [ `kontent-generate ${'environment' satisfies CliAction} --${environmentIdOption.name}=x --${managementApiKeyOption.name}=x` ], - options: [environmentIdOption, managementApiKeyOption, addTimestampOption, ModuleFileExtensionOption, outputDirOption, baseUrl] + options: [ + environmentIdOption, + managementApiKeyOption, + addTimestampOption, + moduleFileExtensionOption, + outputDirOption, + managementBaseUrlOption, + isEnterpriseSubscriptionOption + ] }) .withCommand({ name: 'migration-toolkit', @@ -88,22 +117,32 @@ export const cliArgs = argumentsSetter() examples: [ `kontent-generate ${'migration-toolkit' satisfies CliAction} --${environmentIdOption.name}=x --${managementApiKeyOption.name}=x` ], - options: [environmentIdOption, managementApiKeyOption, addTimestampOption, ModuleFileExtensionOption, outputDirOption, baseUrl] + options: [ + environmentIdOption, + managementApiKeyOption, + addTimestampOption, + moduleFileExtensionOption, + outputDirOption, + managementBaseUrlOption + ] }) .withCommand({ name: 'items', description: `Overview of all items in the environment and their ids/codenames as well as Type representing all item codenames.`, examples: [ - `kontent-generate ${'items' satisfies CliAction} --${environmentIdOption.name}=x --${managementApiKeyOption.name}=x --${deliveryApiKeyOption.name}=x --${apiModeOption.name}=preview --${contentTypes.name}=a,b,c` + `kontent-generate ${'items' satisfies CliAction} --${environmentIdOption.name}=x --${managementApiKeyOption.name}=x --${deliveryApiKeyOption.name}=x --${apiModeOption.name}=preview --${contentTypesOption.name}=a,b,c` ], options: [ environmentIdOption, managementApiKeyOption, deliveryApiKeyOption, addTimestampOption, - ModuleFileExtensionOption, + moduleFileExtensionOption, outputDirOption, - baseUrl + managementBaseUrlOption, + apiModeOption, + contentTypesOption, + deliveryBaseUrlOption ] }) .withOption({ diff --git a/lib/generators/items/items-func.ts b/lib/generators/items/items-func.ts index 8c5ee55..62c4e28 100644 --- a/lib/generators/items/items-func.ts +++ b/lib/generators/items/items-func.ts @@ -18,6 +18,7 @@ export interface GenerateItemsModelsConfig { readonly deliveryApiKey?: string; readonly outputDir?: string; readonly baseUrl?: string; + readonly deliveryBaseUrl?: string; readonly formatOptions?: Readonly; } @@ -46,7 +47,7 @@ async function getFilesAsync(config: GenerateItemsModelsConfig): Promise<{ environmentId: config.environmentId, apiMode: config.apiMode, apiKey: config.deliveryApiKey, - baseUrl: config.baseUrl + baseUrl: config.deliveryBaseUrl }); const managementKontentFetcher = _managementKontentFetcher({ From 7e9029ec54a8fe6b5568734f74ab0e69c3aa208b Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 1 Oct 2024 16:03:04 +0200 Subject: [PATCH 152/183] Adds ability to specify what files are generated for items generator --- lib/cli/actions/items-action.ts | 4 ++++ lib/cli/commands.ts | 18 +++++++++++++++++- lib/core/core.utils.ts | 22 +++++++++++++--------- lib/generators/items/items-func.ts | 13 ++++++++----- scripts/samples/item-models.ts | 4 +++- 5 files changed, 45 insertions(+), 16 deletions(-) diff --git a/lib/cli/actions/items-action.ts b/lib/cli/actions/items-action.ts index 0ef6ac6..405d87d 100644 --- a/lib/cli/actions/items-action.ts +++ b/lib/cli/actions/items-action.ts @@ -8,6 +8,8 @@ import { deliveryApiKeyOption, deliveryBaseUrlOption, environmentIdOption, + generateObjectsOption, + generateTypesOption, managementApiKeyOption, managementBaseUrlOption, moduleFileExtensionOption, @@ -20,6 +22,8 @@ export async function itemsActionAsync(cliFetcher: CliArgumentsFetcher): Promise environmentId: cliFetcher.getRequiredArgumentValue(environmentIdOption.name), apiKey: cliFetcher.getRequiredArgumentValue(managementApiKeyOption.name), // optional + generateTypes: cliFetcher.getBooleanArgumentValue(generateTypesOption.name, false), + generateObjects: cliFetcher.getBooleanArgumentValue(generateObjectsOption.name, false), deliveryApiKey: cliFetcher.getOptionalArgumentValue(deliveryApiKeyOption.name), baseUrl: cliFetcher.getOptionalArgumentValue(managementBaseUrlOption.name), deliveryBaseUrl: cliFetcher.getOptionalArgumentValue(deliveryBaseUrlOption.name), diff --git a/lib/cli/commands.ts b/lib/cli/commands.ts index a40f688..64dcdd4 100644 --- a/lib/cli/commands.ts +++ b/lib/cli/commands.ts @@ -79,6 +79,20 @@ export const deliveryBaseUrlOption: CommandOption = { isRequired: false }; +export const generateTypesOption: CommandOption = { + name: `generateTypes`, + description: `Indicates if Typescript types representing data are generated`, + type: 'boolean', + isRequired: false +}; + +export const generateObjectsOption: CommandOption = { + name: `generateTypes`, + description: `Indicates if objects (const variables) representing data are generated`, + type: 'boolean', + isRequired: false +}; + export const cliArgs = argumentsSetter() .withCommand({ name: 'delivery-sdk', @@ -142,7 +156,9 @@ export const cliArgs = argumentsSetter() managementBaseUrlOption, apiModeOption, contentTypesOption, - deliveryBaseUrlOption + deliveryBaseUrlOption, + generateTypesOption, + generateObjectsOption ] }) .withOption({ diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 0afa9b4..1030588 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -71,15 +71,6 @@ export function toOutputDirPath(outputDir: string | undefined): string { return outputDir ? `${outputDir}/`.replaceAll('//', '/') : `./`; } -function removeLineEndings(value: string): string { - return value.replace(/(\r\n|\n|\r)/g, ''); -} - -function toSafeStringCode(text: string): string { - const replaceWith = ''; - return text.replace(/[\s-]/g, replaceWith).replace(/[^a-zA-Z0-9_]/g, replaceWith); -} - export function prefixWithUnderscoreWhenStartsWithNonAlpha(text: string): string { if (/^[^a-zA-Z]/.test(text)) { return `_${text}`; @@ -87,8 +78,21 @@ export function prefixWithUnderscoreWhenStartsWithNonAlpha(text: string): string return text; } +export function singleItemToArray(item: T | undefined): readonly T[] { + return item ? [item] : []; +} + function getPropertyStringHash(text: string): string { const hash = createHash('sha256'); hash.update(text); return `_${hash.digest('hex')}`.slice(0, 10); } + +function removeLineEndings(value: string): string { + return value.replace(/(\r\n|\n|\r)/g, ''); +} + +function toSafeStringCode(text: string): string { + const replaceWith = ''; + return text.replace(/[\s-]/g, replaceWith).replace(/[^a-zA-Z0-9_]/g, replaceWith); +} diff --git a/lib/generators/items/items-func.ts b/lib/generators/items/items-func.ts index 62c4e28..92a030c 100644 --- a/lib/generators/items/items-func.ts +++ b/lib/generators/items/items-func.ts @@ -2,6 +2,7 @@ import { EnvironmentModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; import { Options } from 'prettier'; import { DeliveryApiMode, GeneratedSet, ModuleFileExtension } from '../../core/core.models.js'; +import { singleItemToArray } from '../../core/core.utils.js'; import { deliveryKontentFetcher as _deliveryKontentFetcher } from '../../fetch/delivery-kontent-fetcher.js'; import { managementKontentFetcher as _managementKontentFetcher } from '../../fetch/management-kontent-fetcher.js'; import { fileManager as _fileManager } from '../../files/file-manager.js'; @@ -14,6 +15,8 @@ export interface GenerateItemsModelsConfig { readonly moduleFileExtension: ModuleFileExtension; readonly apiMode: DeliveryApiMode; readonly filterByTypeCodenames: readonly string[]; + readonly generateTypes: boolean; + readonly generateObjects: boolean; readonly deliveryApiKey?: string; readonly outputDir?: string; @@ -33,14 +36,14 @@ export async function generateItemsAsync(config: GenerateItemsModelsConfig): Pro environmentInfo: environmentInfo }); - await fileManager.createSetsAsync([itemFiles, codenameFiles]); + await fileManager.createSetsAsync([...singleItemToArray(itemFiles), ...singleItemToArray(codenameFiles)]); console.log(chalk.green(`\nCompleted`)); } async function getFilesAsync(config: GenerateItemsModelsConfig): Promise<{ - readonly itemFiles: GeneratedSet; - readonly codenameFiles: GeneratedSet; + readonly itemFiles: GeneratedSet | undefined; + readonly codenameFiles: GeneratedSet | undefined; readonly environmentInfo: Readonly; }> { const deliveryKontentFetcher = _deliveryKontentFetcher({ @@ -71,8 +74,8 @@ async function getFilesAsync(config: GenerateItemsModelsConfig): Promise<{ }); return { - itemFiles: itemsGenerator.getItemFiles(), - codenameFiles: itemsGenerator.getCodenameFiles(), + itemFiles: config.generateObjects ? itemsGenerator.getItemFiles() : undefined, + codenameFiles: config.generateTypes ? itemsGenerator.getCodenameFiles() : undefined, environmentInfo }; } diff --git a/scripts/samples/item-models.ts b/scripts/samples/item-models.ts index d366d0b..2a31b8b 100644 --- a/scripts/samples/item-models.ts +++ b/scripts/samples/item-models.ts @@ -34,7 +34,9 @@ try { outputDir: outputDir, apiMode: 'default', deliveryApiKey: deliveryApiKey, - filterByTypeCodenames: [] + filterByTypeCodenames: [], + generateObjects: true, + generateTypes: true }); } catch (error) { logError(error); From cdaae5a5c756985efdd99ed870b789297d1411e7 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 1 Oct 2024 16:04:33 +0200 Subject: [PATCH 153/183] chore(release): 8.0.0-3 --- CHANGELOG.md | 2 ++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c9826a..60d5dcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [8.0.0-3](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-2...v8.0.0-3) (2024-10-01) + ## [8.0.0-2](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-1...v8.0.0-2) (2024-09-16) ## [8.0.0-1](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-0...v8.0.0-1) (2024-09-16) diff --git a/package-lock.json b/package-lock.json index d07ebdf..39e7a06 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-2", + "version": "8.0.0-3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@kontent-ai/model-generator", - "version": "8.0.0-2", + "version": "8.0.0-3", "license": "MIT", "dependencies": { "@kontent-ai/management-sdk": "7.3.0", diff --git a/package.json b/package.json index bfb8a95..50f7d6a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-2", + "version": "8.0.0-3", "description": "This utility generates strongly-typed models based on Content Types in a Kontent.ai project. These models can be used with SDKs", "bin": { "kontent-generate": "./dist/es2022/lib/code/app.js" From b105a90c09ebcc3622960bf238146e9f8a0c12b3 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 2 Oct 2024 11:53:13 +0200 Subject: [PATCH 154/183] Adds mjs & mts file extension options, improves parsing functions & command option listings --- lib/cli/actions/delivery-action.ts | 2 +- lib/cli/actions/environment-action.ts | 2 +- lib/cli/actions/items-action.ts | 2 +- lib/cli/actions/migrate-action.ts | 2 +- lib/cli/arg.utils.ts | 42 ++++------ lib/cli/command.options.ts | 93 ++++++++++++++++++++++ lib/cli/commands.ts | 109 ++++---------------------- lib/core/core.models.ts | 2 +- 8 files changed, 130 insertions(+), 124 deletions(-) create mode 100644 lib/cli/command.options.ts diff --git a/lib/cli/actions/delivery-action.ts b/lib/cli/actions/delivery-action.ts index b4aa536..c805136 100644 --- a/lib/cli/actions/delivery-action.ts +++ b/lib/cli/actions/delivery-action.ts @@ -8,7 +8,7 @@ import { managementBaseUrlOption, moduleFileExtensionOption, outputDirOption -} from '../commands.js'; +} from '../command.options.js'; export async function deliveryActionAsync(cliFetcher: CliArgumentsFetcher): Promise { await generateDeliveryModelsAsync({ diff --git a/lib/cli/actions/environment-action.ts b/lib/cli/actions/environment-action.ts index f84c290..e89d4b2 100644 --- a/lib/cli/actions/environment-action.ts +++ b/lib/cli/actions/environment-action.ts @@ -9,7 +9,7 @@ import { managementBaseUrlOption, moduleFileExtensionOption, outputDirOption -} from '../commands.js'; +} from '../command.options.js'; export async function environmentActionAsync(cliFetcher: CliArgumentsFetcher): Promise { await generateEnvironmentModelsAsync({ diff --git a/lib/cli/actions/items-action.ts b/lib/cli/actions/items-action.ts index 405d87d..8cd4181 100644 --- a/lib/cli/actions/items-action.ts +++ b/lib/cli/actions/items-action.ts @@ -14,7 +14,7 @@ import { managementBaseUrlOption, moduleFileExtensionOption, outputDirOption -} from '../commands.js'; +} from '../command.options.js'; export async function itemsActionAsync(cliFetcher: CliArgumentsFetcher): Promise { await generateItemsAsync({ diff --git a/lib/cli/actions/migrate-action.ts b/lib/cli/actions/migrate-action.ts index 3be36c2..951d836 100644 --- a/lib/cli/actions/migrate-action.ts +++ b/lib/cli/actions/migrate-action.ts @@ -8,7 +8,7 @@ import { managementBaseUrlOption, moduleFileExtensionOption, outputDirOption -} from '../commands.js'; +} from '../command.options.js'; export async function migrateActionAsync(cliFetcher: CliArgumentsFetcher): Promise { await generateMigrationModelsAsync({ diff --git a/lib/cli/arg.utils.ts b/lib/cli/arg.utils.ts index d8d9318..931ceeb 100644 --- a/lib/cli/arg.utils.ts +++ b/lib/cli/arg.utils.ts @@ -2,33 +2,23 @@ import { defaultDeliveryApiMode, defaultModuleFileExtension } from '../config.js import { DeliveryApiMode, LiteralUnion, ModuleFileExtension } from '../core/core.models.js'; export function parseModuleFileExtension(moduleFileExtension: LiteralUnion | undefined): ModuleFileExtension { - if (moduleFileExtension === 'js') { - return 'js'; - } - - if (moduleFileExtension === 'ts') { - return 'ts'; - } - - if (moduleFileExtension === 'none') { - return 'none'; - } - - return defaultModuleFileExtension; + return moduleFileExtensionOptions[moduleFileExtension ?? defaultModuleFileExtension]; } export function parseDeliveryApiMode(apiMode: LiteralUnion | undefined): DeliveryApiMode { - if (apiMode === 'default') { - return 'default'; - } - - if (apiMode === 'preview') { - return 'preview'; - } - - if (apiMode === 'secure') { - return 'secure'; - } - - return defaultDeliveryApiMode; + return deliveryApiModeOptions[apiMode ?? defaultDeliveryApiMode]; } + +export const moduleFileExtensionOptions: Record, ModuleFileExtension> = { + js: 'js', + ts: 'ts', + mts: 'mts', + mjs: 'mjs', + none: 'none' +}; + +export const deliveryApiModeOptions: Record, DeliveryApiMode> = { + default: 'default', + preview: 'preview', + secure: 'secure' +}; diff --git a/lib/cli/command.options.ts b/lib/cli/command.options.ts new file mode 100644 index 0000000..7e6339f --- /dev/null +++ b/lib/cli/command.options.ts @@ -0,0 +1,93 @@ +import { deliveryApiModeOptions, moduleFileExtensionOptions } from './arg.utils.js'; +import { CommandOption } from './cli.models.js'; + +export const environmentIdOption: CommandOption = { + name: `environmentId`, + description: `Id of the environment`, + type: 'string', + isRequired: true +}; + +export const managementApiKeyOption: CommandOption = { + name: `apiKey`, + description: `Management API key`, + type: 'string', + isRequired: true +}; + +export const deliveryApiKeyOption: CommandOption = { + name: `apiKey`, + description: `Delivery API key`, + type: 'string', + isRequired: true +}; + +export const outputDirOption: CommandOption = { + name: `outputDir`, + description: `Relative directory path where directory will be created`, + type: 'string', + isRequired: false +}; + +export const addTimestampOption: CommandOption = { + name: `outputDir`, + description: `Indicates whether timestamp should be generated for every file`, + type: 'boolean', + isRequired: false +}; + +export const moduleFileExtensionOption: CommandOption = { + name: `moduleFileExtension`, + description: `Module resolution for imports. One of: ${Object.values(moduleFileExtensionOptions).join(', ')}`, + type: 'string', + isRequired: false +}; + +export const apiModeOption: CommandOption = { + name: `apiMode`, + description: `API mode for Delivery. ${Object.values(deliveryApiModeOptions).join(', ')}`, + type: 'string', + isRequired: false +}; + +export const contentTypesOption: CommandOption = { + name: `contentTypes`, + description: `CSV of content types to generate models for. If not provided, all items will be generated`, + type: 'string', + isRequired: false +}; + +export const isEnterpriseSubscriptionOption: CommandOption = { + name: `isEnterpriseSubscription`, + description: `Indicates if the subscription is Enterprise. If true, the generator will generate models for Enterprise features`, + type: 'boolean', + isRequired: false +}; + +export const managementBaseUrlOption: CommandOption = { + name: `baseUrl`, + description: `Base URL for Management API`, + type: 'string', + isRequired: false +}; + +export const deliveryBaseUrlOption: CommandOption = { + name: `deliveryBaseUrl`, + description: `Base URL for Delivery API`, + type: 'string', + isRequired: false +}; + +export const generateTypesOption: CommandOption = { + name: `generateTypes`, + description: `Indicates if Typescript types representing data are generated`, + type: 'boolean', + isRequired: false +}; + +export const generateObjectsOption: CommandOption = { + name: `generateTypes`, + description: `Indicates if objects (const variables) representing data are generated`, + type: 'boolean', + isRequired: false +}; diff --git a/lib/cli/commands.ts b/lib/cli/commands.ts index 64dcdd4..0e846eb 100644 --- a/lib/cli/commands.ts +++ b/lib/cli/commands.ts @@ -1,97 +1,20 @@ -import { CliAction, DeliveryApiMode, LibraryType, ModuleFileExtension } from '../core/core.models.js'; +import { CliAction, LibraryType } from '../core/core.models.js'; import { argumentsSetter } from './args/args-setter.js'; -import { CommandOption } from './cli.models.js'; - -export const environmentIdOption: CommandOption = { - name: `environmentId`, - description: `Id of the environment`, - type: 'string', - isRequired: true -}; - -export const managementApiKeyOption: CommandOption = { - name: `apiKey`, - description: `Management API key`, - type: 'string', - isRequired: true -}; - -export const deliveryApiKeyOption: CommandOption = { - name: `apiKey`, - description: `Delivery API key`, - type: 'string', - isRequired: true -}; - -export const outputDirOption: CommandOption = { - name: `outputDir`, - description: `Relative directory path where directory will be created`, - type: 'string', - isRequired: false -}; - -export const addTimestampOption: CommandOption = { - name: `outputDir`, - description: `Indicates whether timestamp should be generated for every file`, - type: 'boolean', - isRequired: false -}; - -export const moduleFileExtensionOption: CommandOption = { - name: `moduleFileExtension`, - description: `Module resolution for imports. Available options are: '${'js' satisfies ModuleFileExtension}', '${'ts' satisfies ModuleFileExtension}' or '${'none' satisfies ModuleFileExtension}' (no extension) }`, - type: 'string', - isRequired: false -}; - -export const apiModeOption: CommandOption = { - name: `apiMode`, - description: `API mode for Delivery. Options are '${'default' satisfies DeliveryApiMode}', '${'preview' satisfies DeliveryApiMode}' or '${'secure' satisfies DeliveryApiMode}'`, - type: 'string', - isRequired: false -}; - -export const contentTypesOption: CommandOption = { - name: `contentTypes`, - description: `CSV of content types to generate models for. If not provided, all items will be generated`, - type: 'string', - isRequired: false -}; - -export const isEnterpriseSubscriptionOption: CommandOption = { - name: `isEnterpriseSubscription`, - description: `Indicates if the subscription is Enterprise. If true, the generator will generate models for Enterprise features`, - type: 'boolean', - isRequired: false -}; - -export const managementBaseUrlOption: CommandOption = { - name: `baseUrl`, - description: `Base URL for Management API`, - type: 'string', - isRequired: false -}; - -export const deliveryBaseUrlOption: CommandOption = { - name: `deliveryBaseUrl`, - description: `Base URL for Delivery API`, - type: 'string', - isRequired: false -}; - -export const generateTypesOption: CommandOption = { - name: `generateTypes`, - description: `Indicates if Typescript types representing data are generated`, - type: 'boolean', - isRequired: false -}; - -export const generateObjectsOption: CommandOption = { - name: `generateTypes`, - description: `Indicates if objects (const variables) representing data are generated`, - type: 'boolean', - isRequired: false -}; +import { + addTimestampOption, + apiModeOption, + contentTypesOption, + deliveryApiKeyOption, + deliveryBaseUrlOption, + environmentIdOption, + generateObjectsOption, + generateTypesOption, + isEnterpriseSubscriptionOption, + managementApiKeyOption, + managementBaseUrlOption, + moduleFileExtensionOption, + outputDirOption +} from './command.options.js'; export const cliArgs = argumentsSetter() .withCommand({ diff --git a/lib/core/core.models.ts b/lib/core/core.models.ts index 8e2f5aa..7622323 100644 --- a/lib/core/core.models.ts +++ b/lib/core/core.models.ts @@ -10,7 +10,7 @@ import { export type CliAction = 'delivery-sdk' | 'migration-toolkit' | 'environment' | 'items'; export type LibraryType = '@kontent-ai/migration-toolkit' | '@kontent-ai/delivery-sdk'; -export type ModuleFileExtension = 'js' | 'ts' | 'none'; +export type ModuleFileExtension = 'js' | 'ts' | 'mjs' | 'mts' | 'none'; export type CaseType = 'camelCase' | 'pascalCase'; export type DeliveryApiMode = 'preview' | 'secure' | 'default'; export type GeneratorManagementClient = Readonly>; From 79f8acb9a7cbce7081208228139620973fec6079 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 2 Oct 2024 12:11:51 +0200 Subject: [PATCH 155/183] Removes tsconfig.es2022.json in favor of a single ts.config & updates outputDir and paths accordingly --- package.json | 11 +++++------ tsconfig.es2022.json | 10 ---------- tsconfig.json | 7 ++++--- 3 files changed, 9 insertions(+), 19 deletions(-) delete mode 100644 tsconfig.es2022.json diff --git a/package.json b/package.json index 50f7d6a..801d392 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "@kontent-ai/model-generator", "version": "8.0.0-3", - "description": "This utility generates strongly-typed models based on Content Types in a Kontent.ai project. These models can be used with SDKs", + "description": "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.", "bin": { - "kontent-generate": "./dist/es2022/lib/code/app.js" + "kontent-generate": "./dist/lib/code/app.js" }, "repository": { "type": "git", @@ -22,8 +22,8 @@ "Kontent Model Generator", "Kontent.ai strongly typed models" ], - "exports": "./dist/es2022/lib/public_api.js", - "types": "./dist/es2022/lib/public_api.d.ts", + "exports": "./dist/lib/public_api.js", + "types": "./dist/lib/public_api.d.ts", "type": "module", "scripts": { "release": "standard-version && npm run update:version", @@ -34,8 +34,7 @@ "prerelease:major": "standard-version --prerelease --release-as major", "prepublishOnly": "npm run build && npm run push:tags", "publish:beta": "npm publish --tag=next", - "build:es2022": "tsc --p tsconfig.es2022.json", - "build": "npm run clean && npm run build:es2022", + "build": "npm run clean && tsc --p tsconfig.json", "test:all": "npm run build", "sample:delivery": "tsx scripts/samples/delivery-models", "sample:environment": "tsx scripts/samples/environment-models", diff --git a/tsconfig.es2022.json b/tsconfig.es2022.json deleted file mode 100644 index 6d5b1db..0000000 --- a/tsconfig.es2022.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "importHelpers": true, - "target": "es2022", - "outDir": "dist/es2022", - "moduleResolution": "NodeNext", - "module": "NodeNext" - } -} diff --git a/tsconfig.json b/tsconfig.json index 7d21266..272085a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,14 +2,15 @@ "compileOnSave": true, "compilerOptions": { "outDir": "dist", - "sourceMap": true, - "declaration": true, + "target": "es2022", "moduleResolution": "NodeNext", "module": "NodeNext", + "importHelpers": true, + "sourceMap": true, + "declaration": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "allowSyntheticDefaultImports": true, - "target": "es2022", "strict": true, "strictNullChecks": true, "strictPropertyInitialization": true, From cafd2a234e7e73269a0d0032227cb9c58b132a26 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 2 Oct 2024 12:40:51 +0200 Subject: [PATCH 156/183] chore(release): 8.0.0-4 --- CHANGELOG.md | 2 ++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60d5dcf..e3ecde7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [8.0.0-4](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-3...v8.0.0-4) (2024-10-02) + ## [8.0.0-3](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-2...v8.0.0-3) (2024-10-01) ## [8.0.0-2](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-1...v8.0.0-2) (2024-09-16) diff --git a/package-lock.json b/package-lock.json index 39e7a06..970e3e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-3", + "version": "8.0.0-4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@kontent-ai/model-generator", - "version": "8.0.0-3", + "version": "8.0.0-4", "license": "MIT", "dependencies": { "@kontent-ai/management-sdk": "7.3.0", diff --git a/package.json b/package.json index 801d392..6e7e06e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-3", + "version": "8.0.0-4", "description": "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.", "bin": { "kontent-generate": "./dist/lib/code/app.js" From 1afb705902bce74c85d9afd78690985c46ae52bc Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 4 Oct 2024 15:05:20 +0200 Subject: [PATCH 157/183] Adds core type representing typed IContentItem to further improve typings on elements & generic content item --- lib/config.ts | 2 + .../delivery-content-type.generator.ts | 157 +++++++++++------- sample/delivery/content-types/actor.ts | 13 +- sample/delivery/content-types/movie.ts | 44 +++-- sample/delivery/system/core.type.ts | 31 ++++ sample/delivery/system/index.ts | 1 + 6 files changed, 150 insertions(+), 98 deletions(-) create mode 100644 sample/delivery/system/core.type.ts diff --git a/lib/config.ts b/lib/config.ts index 39cc327..9bf1613 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -44,6 +44,8 @@ export const deliveryConfig = { taxonomiesFolderName: `taxonomies`, systemTypesFolderName: 'system', coreCodenamesFilename: 'delivery.codenames', + coreTypeFilename: 'core.type', + coreContentTypeName: 'CoreContentType', sdkTypes: { contentItem: 'IContentItem', diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 9422344..950df88 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -81,18 +81,11 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato taxonomy: mapName(config.nameResolvers?.taxonomy, 'pascalCase') }; - const getSystemTypeImports = (): readonly string[] => { + const getContentTypeSystemImports = (): readonly string[] => { return [ importer.importType({ - filePathOrPackage: `../${deliveryConfig.systemTypesFolderName}/${deliveryConfig.coreCodenamesFilename}.ts`, - importValue: [ - sharedTypesConfig.collectionCodenames, - sharedTypesConfig.languageCodenames, - sharedTypesConfig.workflowCodenames, - sharedTypesConfig.workflowStepCodenames - ] - .map((m) => m) - .join(', ') + filePathOrPackage: `../${deliveryConfig.systemTypesFolderName}/${coreConfig.barrelExportFilename}`, + importValue: [deliveryConfig.coreContentTypeName].map((m) => m).join(', ') }) ]; }; @@ -198,7 +191,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato return { imports: sortAlphabetically( [ - ...getSystemTypeImports(), + ...getContentTypeSystemImports(), ...getReferencedTypeImports(data.contentType, data.flattenedElements), ...getReferencedTaxonomyImports(data.flattenedElements), ...getSnippetImports(snippets) @@ -239,15 +232,15 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato }; }; - const getDeliverySdkImports = ( + const getTypeDeliverySdkImports = ( typeOrSnippet: ContentTypeOrSnippet, flattenedElements: readonly FlattenedElement[] ): readonly string[] => { - const mainType = - typeOrSnippet instanceof ContentTypeModels.ContentType ? deliveryConfig.sdkTypes.contentItem : deliveryConfig.sdkTypes.snippet; - return sortAlphabetically( - [mainType, ...(flattenedElements.length ? [deliveryConfig.sdkTypes.elements] : [])], + [ + ...(typeOrSnippet instanceof ContentTypeSnippetModels.ContentTypeSnippet ? [deliveryConfig.sdkTypes.snippet] : []), + ...(flattenedElements.length ? [deliveryConfig.sdkTypes.elements] : []) + ], (importValue) => importValue ); }; @@ -270,7 +263,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato return ` ${importer.importType({ filePathOrPackage: deliveryConfig.npmPackageName, - importValue: `${getDeliverySdkImports(snippet, flattenedElements).join(', ')}` + importValue: `${getTypeDeliverySdkImports(snippet, flattenedElements).join(', ')}` })} ${importsResult.imports.join('\n')} @@ -308,7 +301,7 @@ ${getElementsCode(flattenedElements)}>; return ` ${importer.importType({ filePathOrPackage: deliveryConfig.npmPackageName, - importValue: `${getDeliverySdkImports(contentType, flattenedElements).join(', ')}` + importValue: `${getTypeDeliverySdkImports(contentType, flattenedElements).join(', ')}` })} ${importsResult.imports.join('\n')} @@ -323,14 +316,9 @@ ${wrapComment(` * Id: ${contentType.id} * Codename: ${contentType.codename} `)} -export type ${importsResult.typeName} = ${deliveryConfig.sdkTypes.contentItem}< +export type ${importsResult.typeName} = ${deliveryConfig.coreContentTypeName}< ${getElementsCode(flattenedElements)}${importsResult.contentTypeExtends ? ` ${importsResult.contentTypeExtends}` : ''}, -'${contentType.codename}', -${sharedTypesConfig.languageCodenames}, -${sharedTypesConfig.collectionCodenames}, -${sharedTypesConfig.workflowCodenames}, -${sharedTypesConfig.workflowStepCodenames}, -${nameOfTypeRepresentingAllElementCodenames}>; +'${contentType.codename}'>; `; }; @@ -391,12 +379,6 @@ ${nameOfTypeRepresentingAllElementCodenames}>; if (flattenedElements.length === 0) { return `export type ${typeName} = never`; } - - const el = flattenedElements.find((m) => m.codename === 'link__f25fb651_eea8_4a0a_8e39_ac5a0f97ed72'); - if (el) { - console.log(el); - } - return `export type ${typeName} = ${flattenedElements.map((element) => `'${element.codename}'`).join(' | ')};`; }; @@ -406,24 +388,27 @@ ${nameOfTypeRepresentingAllElementCodenames}>; .with({ type: 'text' }, () => 'TextElement') .with({ type: 'number' }, () => 'NumberElement') .with({ type: 'modular_content' }, (linkedItemsElement) => { - if (!linkedItemsElement.allowedContentTypes?.length) { - return 'LinkedItemsElement'; - } - return `LinkedItemsElement<${getLinkedItemsAllowedTypes(linkedItemsElement.allowedContentTypes ?? []).join(' | ')}>`; + return `LinkedItemsElement<${ + linkedItemsElement.allowedContentTypes?.length + ? getLinkedItemsAllowedTypes(linkedItemsElement.allowedContentTypes).join(' | ') + : deliveryConfig.coreContentTypeName + }>`; }) .with({ type: 'subpages' }, (linkedItemsElement) => { - if (!linkedItemsElement.allowedContentTypes?.length) { - return 'LinkedItemsElement'; - } - return `LinkedItemsElement<${getLinkedItemsAllowedTypes(linkedItemsElement.allowedContentTypes ?? []).join(' | ')}>`; + return `LinkedItemsElement<${ + linkedItemsElement.allowedContentTypes?.length + ? getLinkedItemsAllowedTypes(linkedItemsElement.allowedContentTypes).join(' | ') + : deliveryConfig.coreContentTypeName + }>`; }) .with({ type: 'asset' }, () => 'AssetsElement') .with({ type: 'date_time' }, () => 'DateTimeElement') .with({ type: 'rich_text' }, (richTextElement) => { - if (!richTextElement.allowedContentTypes?.length) { - return 'RichTextElement'; - } - return `RichTextElement<${getLinkedItemsAllowedTypes(richTextElement.allowedContentTypes ?? []).join(' | ')}>`; + return `RichTextElement<${ + richTextElement.allowedContentTypes?.length + ? getLinkedItemsAllowedTypes(richTextElement.allowedContentTypes).join(' | ') + : deliveryConfig.coreContentTypeName + }>`; }) .with({ type: 'multiple_choice' }, (multipleChoiceElement) => { if (!multipleChoiceElement.multipleChoiceOptions?.length) { @@ -451,6 +436,70 @@ ${nameOfTypeRepresentingAllElementCodenames}>; return types.map((type) => nameResolvers.contentType(type)); }; + const getCoreContentTypeFile = (): GeneratedFile => { + const sdkImports: string[] = [deliveryConfig.sdkTypes.contentItem, deliveryConfig.sdkTypes.contentItemElements]; + + const codenameImports: string[] = [ + sharedTypesConfig.contentTypeCodenames, + sharedTypesConfig.collectionCodenames, + sharedTypesConfig.languageCodenames, + sharedTypesConfig.workflowCodenames, + sharedTypesConfig.workflowStepCodenames + ]; + + const contentTypeGenericArgName: string = 'TContentTypeCodename'; + const elementsGenericArgName: string = 'TElements'; + + return { + filename: `${deliveryConfig.coreTypeFilename}.ts`, + text: ` + ${importer.importType({ + filePathOrPackage: deliveryConfig.npmPackageName, + importValue: `${sdkImports.join(', ')}` + })} + ${importer.importType({ + filePathOrPackage: `./${deliveryConfig.coreCodenamesFilename}.ts`, + importValue: `${codenameImports.join(', ')}` + })} + + ${wrapComment(`\n * Core content type used in favor of generic '${deliveryConfig.sdkTypes.contentItem}'\n`)} + export type ${deliveryConfig.coreContentTypeName}< + ${elementsGenericArgName} extends ${deliveryConfig.sdkTypes.contentItemElements} = ${deliveryConfig.sdkTypes.contentItemElements}, + ${contentTypeGenericArgName} extends ${sharedTypesConfig.contentTypeCodenames} = ${sharedTypesConfig.contentTypeCodenames} + > = ${deliveryConfig.sdkTypes.contentItem}< + ${elementsGenericArgName}, + ${contentTypeGenericArgName}, + ${sharedTypesConfig.languageCodenames}, + ${sharedTypesConfig.collectionCodenames}, + ${sharedTypesConfig.workflowCodenames}, + ${sharedTypesConfig.workflowStepCodenames} + >; + ` + }; + }; + + const getCodenamesFile = (): GeneratedFile => { + return { + filename: `${deliveryConfig.coreCodenamesFilename}.ts`, + text: ` + ${wrapComment(`\n * Type representing all languages\n`)} + ${getLanguageCodenamesType(config.environmentData.languages)} + + ${wrapComment(`\n * Type representing all content types\n`)} + ${getContentTypeCodenamesType(config.environmentData.types)} + + ${wrapComment(`\n * Type representing all collections\n`)} + ${getCollectionCodenamesType(config.environmentData.collections)} + + ${wrapComment(`\n * Type representing all workflows\n`)} + ${getWorkflowCodenamesType(config.environmentData.workflows)} + + ${wrapComment(`\n * Type representing all worksflow steps across all workflows\n`)} + ${getWorkflowStepCodenamesType(config.environmentData.workflows)} + ` + }; + }; + return { generateModels: (): { contentTypeFiles: GeneratedSet; @@ -470,27 +519,7 @@ ${nameOfTypeRepresentingAllElementCodenames}>; getSystemFiles(): GeneratedSet { return { folderName: deliveryConfig.systemTypesFolderName, - files: [ - { - filename: `${deliveryConfig.coreCodenamesFilename}.ts`, - text: ` - ${wrapComment(`\n * Type representing all languages\n`)} - ${getLanguageCodenamesType(config.environmentData.languages)} - - ${wrapComment(`\n * Type representing all content types\n`)} - ${getContentTypeCodenamesType(config.environmentData.types)} - - ${wrapComment(`\n * Type representing all collections\n`)} - ${getCollectionCodenamesType(config.environmentData.collections)} - - ${wrapComment(`\n * Type representing all workflows\n`)} - ${getWorkflowCodenamesType(config.environmentData.workflows)} - - ${wrapComment(`\n * Type representing all worksflow steps across all workflows\n`)} - ${getWorkflowStepCodenamesType(config.environmentData.workflows)} - ` - } - ] + files: [getCoreContentTypeFile(), getCodenamesFile()] }; } }; diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index 3d93e16..8458be0 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -13,8 +13,8 @@ * ------------------------------------------------------------------------------- **/ -import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; -import type { CollectionCodenames, LanguageCodenames, WorkflowCodenames, WorkflowStepCodenames } from '../system/delivery.codenames.js'; +import type { Elements } from '@kontent-ai/delivery-sdk'; +import type { CoreContentType } from '../system/index.js'; /** * Type representing all available element codenames for Actor @@ -27,7 +27,7 @@ export type ActorElementCodenames = 'url' | 'first_name' | 'last_name' | 'photo' * Id: 58099989-319f-495f-aa36-cb3710854e36 * Codename: actor */ -export type Actor = IContentItem< +export type Actor = CoreContentType< { /** * Url @@ -67,10 +67,5 @@ export type Actor = IContentItem< */ readonly photo: Elements.AssetsElement; }, - 'actor', - LanguageCodenames, - CollectionCodenames, - WorkflowCodenames, - WorkflowStepCodenames, - ActorElementCodenames + 'actor' >; diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 09273ad..14998bb 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -1,22 +1,21 @@ +/** + * This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- + * + * Project: Movie Database + * Environment: Production + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + * + * ------------------------------------------------------------------------------- + **/ -/** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Movie Database -* Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 -* -* ------------------------------------------------------------------------------- -**/ - -import type { Elements, IContentItem } from '@kontent-ai/delivery-sdk'; -import type { Actor } from './index.js'; -import type { CollectionCodenames, LanguageCodenames, WorkflowCodenames, WorkflowStepCodenames } from '../system/delivery.codenames.js'; +import type { Elements } from '@kontent-ai/delivery-sdk'; +import type { CoreContentType } from '../system/index.js'; import type { Releasecategory } from '../taxonomies/index.js'; +import type { Actor } from './index.js'; /** * Type representing all available element codenames for Movie @@ -38,7 +37,7 @@ export type MovieElementCodenames = * Id: b0c0f9c2-ffb6-4e62-bac9-34e14172dd8c * Codename: movie */ -export type Movie = IContentItem< +export type Movie = CoreContentType< { /** * Title @@ -57,7 +56,7 @@ export type Movie = IContentItem< * Codename: plot * Id: f7ee4f27-27fd-a19b-3c5c-102aae1c50ce */ - readonly plot: Elements.RichTextElement; + readonly plot: Elements.RichTextElement; /** * Released * @@ -124,10 +123,5 @@ export type Movie = IContentItem< */ readonly releasecategory: Elements.TaxonomyElement; }, - 'movie', - LanguageCodenames, - CollectionCodenames, - WorkflowCodenames, - WorkflowStepCodenames, - MovieElementCodenames + 'movie' >; diff --git a/sample/delivery/system/core.type.ts b/sample/delivery/system/core.type.ts new file mode 100644 index 0000000..70e918d --- /dev/null +++ b/sample/delivery/system/core.type.ts @@ -0,0 +1,31 @@ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ + +import type { IContentItem, IContentItemElements } from '@kontent-ai/delivery-sdk'; +import type { + ContentTypeCodenames, + CollectionCodenames, + LanguageCodenames, + WorkflowCodenames, + WorkflowStepCodenames +} from './delivery.codenames.js'; + +/** + * Core content type used in favor of generic 'IContentItem' + */ +export type CoreContentType< + TElements extends IContentItemElements = IContentItemElements, + TContentTypeCodename extends ContentTypeCodenames = ContentTypeCodenames +> = IContentItem; diff --git a/sample/delivery/system/index.ts b/sample/delivery/system/index.ts index f68040f..0e57cfc 100644 --- a/sample/delivery/system/index.ts +++ b/sample/delivery/system/index.ts @@ -13,4 +13,5 @@ * ------------------------------------------------------------------------------- **/ +export * from './core.type.js'; export * from './delivery.codenames.js'; From 3161fa6b0e648d272f7a2191d9f4d437f28c5a2c Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Fri, 4 Oct 2024 15:05:29 +0200 Subject: [PATCH 158/183] chore(release): 8.0.0-5 --- CHANGELOG.md | 2 ++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3ecde7..a85afa6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [8.0.0-5](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-4...v8.0.0-5) (2024-10-04) + ## [8.0.0-4](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-3...v8.0.0-4) (2024-10-02) ## [8.0.0-3](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-2...v8.0.0-3) (2024-10-01) diff --git a/package-lock.json b/package-lock.json index 970e3e1..e835444 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-4", + "version": "8.0.0-5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@kontent-ai/model-generator", - "version": "8.0.0-4", + "version": "8.0.0-5", "license": "MIT", "dependencies": { "@kontent-ai/management-sdk": "7.3.0", diff --git a/package.json b/package.json index 6e7e06e..e6088a7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-4", + "version": "8.0.0-5", "description": "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.", "bin": { "kontent-generate": "./dist/lib/code/app.js" From 56f72a721326dfed55e086c0677e44a71cd49e12 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 7 Oct 2024 15:25:09 +0200 Subject: [PATCH 159/183] Fixes incorrect option name --- lib/cli/command.options.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli/command.options.ts b/lib/cli/command.options.ts index 7e6339f..617a0c0 100644 --- a/lib/cli/command.options.ts +++ b/lib/cli/command.options.ts @@ -86,7 +86,7 @@ export const generateTypesOption: CommandOption = { }; export const generateObjectsOption: CommandOption = { - name: `generateTypes`, + name: `generateObjects`, description: `Indicates if objects (const variables) representing data are generated`, type: 'boolean', isRequired: false From c7d2c9f772adbcf3e6796a5aa890c2de681ada34 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 7 Oct 2024 15:25:13 +0200 Subject: [PATCH 160/183] Removes unused map --- lib/generators/delivery/delivery-content-type.generator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 950df88..2c02a82 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -85,7 +85,7 @@ export function deliveryContentTypeGenerator(config: DeliveryContentTypeGenerato return [ importer.importType({ filePathOrPackage: `../${deliveryConfig.systemTypesFolderName}/${coreConfig.barrelExportFilename}`, - importValue: [deliveryConfig.coreContentTypeName].map((m) => m).join(', ') + importValue: [deliveryConfig.coreContentTypeName].join(', ') }) ]; }; From 32a04b368638360cf22c5621422b2a1e09aac894 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 8 Oct 2024 11:53:34 +0200 Subject: [PATCH 161/183] udpates deps --- package-lock.json | 552 +++++++++++++++++++++++++++++++--------------- package.json | 12 +- 2 files changed, 379 insertions(+), 185 deletions(-) diff --git a/package-lock.json b/package-lock.json index e835444..a20cc8e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,28 +9,28 @@ "version": "8.0.0-5", "license": "MIT", "dependencies": { - "@kontent-ai/management-sdk": "7.3.0", - "@kontent-ai/migration-toolkit": "1.5.1", + "@kontent-ai/delivery-sdk": "15.2.0", + "@kontent-ai/management-sdk": "7.5.0", "chalk": "5.3.0", "prettier": "3.3.3", "ts-pattern": "5.4.0", "yargs": "17.7.2" }, "bin": { - "kontent-generate": "dist/es2022/lib/code/app.js" + "kontent-generate": "dist/lib/code/app.js" }, "devDependencies": { - "@eslint/js": "^9.11.1", - "@kontent-ai/delivery-sdk": "15.2.0", + "@eslint/js": "9.12.0", + "@kontent-ai/migration-toolkit": "2.0.0", "@types/eslint__js": "8.42.3", - "@types/node": "22.7.4", + "@types/node": "22.7.5", "@types/yargs": "17.0.33", "dotenv-cli": "7.4.2", - "eslint": "9.11.1", + "eslint": "9.12.0", "standard-version": "9.5.0", "tsx": "4.19.1", "typescript": "5.6.2", - "typescript-eslint": "8.8.0" + "typescript-eslint": "8.8.1" }, "engines": { "node": ">= 20" @@ -643,9 +643,9 @@ } }, "node_modules/@eslint/js": { - "version": "9.11.1", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.11.1.tgz", - "integrity": "sha512-/qu+TWz8WwPWc7/HcIJKi+c+MOm46GdVaSlTTQcaqaL53+GsoA6MxWp5PtTx48qbSP7ylM1Kn7nhvkugfJvRSA==", + "version": "9.12.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.12.0.tgz", + "integrity": "sha512-eohesHH8WFRUprDNyEREgqP6beG6htMeUYeCpkEgBCieCMme5r9zFWjzAJp//9S+Kub4rqE+jXe9Cp1a7IYIIA==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -672,6 +672,28 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "node_modules/@humanfs/core": { + "version": "0.19.0", + "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.0.tgz", + "integrity": "sha512-2cbWIHbZVEweE853g8jymffCA+NCMiuqeECeBBLm8dg2oFdjuGJhgN4UAbI+6v0CKbbhvtXA4qV8YR5Ji86nmw==", + "dev": true, + "engines": { + "node": ">=18.18.0" + } + }, + "node_modules/@humanfs/node": { + "version": "0.16.5", + "resolved": "https://registry.npmjs.org/@humanfs/node/-/node-0.16.5.tgz", + "integrity": "sha512-KSPA4umqSG4LHYRodq31VDwKAvaTF4xmVlzM8Aeh4PlU1JQ3IG0wiA8C25d3RQ9nJyM3mBHyI53K06VVL/oFFg==", + "dev": true, + "dependencies": { + "@humanfs/core": "^0.19.0", + "@humanwhocodes/retry": "^0.3.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, "node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", @@ -686,9 +708,9 @@ } }, "node_modules/@humanwhocodes/retry": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.3.0.tgz", - "integrity": "sha512-d2CGZR2o7fS6sWB7DG/3a95bGKQyHMACZ5aW8qGkkqQpUoZV6C0X7Pc7l4ZNMZkfNBf4VWNe9E1jRsf0G146Ew==", + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.3.1.tgz", + "integrity": "sha512-JBxkERygn7Bv/GbN5Rv8Ul6LVknS+5Bp6RgDC/O8gEBU/yeH5Ui5C/OlWrTb6qct7LjjfT6Re2NxB0ln0yYybA==", "dev": true, "engines": { "node": ">=18.18" @@ -711,6 +733,7 @@ "version": "0.0.7", "resolved": "https://registry.npmjs.org/@kontent-ai-consulting/tools-analytics/-/tools-analytics-0.0.7.tgz", "integrity": "sha512-grkW8hEe4vij3R5uZ0K4DuQiR1HvJhdPqoTF/z/q++8xA2X0X0orgRLbWNgyC9XYuSUiCbojmT64zBJf32RKkw==", + "dev": true, "dependencies": { "@kontent-ai/core-sdk": "10.7.0" }, @@ -722,6 +745,7 @@ "version": "10.7.0", "resolved": "https://registry.npmjs.org/@kontent-ai/core-sdk/-/core-sdk-10.7.0.tgz", "integrity": "sha512-NNS1jatzMzp+XBWNc45bcbZjTFTs4szAFJxKn9oj/4p4+ZXucqYXBs88KCUotXmCCcoeUiFAFn8aQUF2aiTM+Q==", + "dev": true, "dependencies": { "axios": "1.7.4" }, @@ -733,7 +757,6 @@ "version": "15.2.0", "resolved": "https://registry.npmjs.org/@kontent-ai/delivery-sdk/-/delivery-sdk-15.2.0.tgz", "integrity": "sha512-ozo7L9TWDlh3Zo3ZsIL9plj7r1QmrMKMLUz4JpTc5nyNF9ZYws3EUjydUpUvjKR7MYm9OeqQcCgiOTSvc9wwdQ==", - "dev": true, "dependencies": { "@kontent-ai/core-sdk": "10.8.0", "url-parse": "1.5.10", @@ -747,7 +770,6 @@ "version": "10.8.0", "resolved": "https://registry.npmjs.org/@kontent-ai/core-sdk/-/core-sdk-10.8.0.tgz", "integrity": "sha512-6o5kn+ANhJ7vCucWXunxy1qCSSDsN3F86zdLXzPnFaK/qOf4BJGnPda81Alvnt4N7n4e1m9J7uP0tm3tQ/W25Q==", - "dev": true, "dependencies": { "axios": "1.7.7" }, @@ -759,7 +781,6 @@ "version": "1.7.7", "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", - "dev": true, "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -767,9 +788,9 @@ } }, "node_modules/@kontent-ai/management-sdk": { - "version": "7.3.0", - "resolved": "https://registry.npmjs.org/@kontent-ai/management-sdk/-/management-sdk-7.3.0.tgz", - "integrity": "sha512-CUIP+ux6W5guOkCO0U+z0XPUyzFYio35cIHhwf+0/o5RntXM6ubYCdpl/kgna1tpexiTnYovtqc8mvcmFm6Cng==", + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/management-sdk/-/management-sdk-7.5.0.tgz", + "integrity": "sha512-/yYTg+els2qstXZbT2QqI2waNuwc3rhgJMy1F1fceQhXJh5wXuThp5O+KUfjGJEfVfzu7vg1cx4pm8R3G6YtkA==", "dependencies": { "@kontent-ai/core-sdk": "10.8.0", "mime": "3.0.0" @@ -800,23 +821,25 @@ } }, "node_modules/@kontent-ai/migration-toolkit": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/@kontent-ai/migration-toolkit/-/migration-toolkit-1.5.1.tgz", - "integrity": "sha512-gj7twSzCIiA8L4UF5CUBg/hHHcG8USnTOR+iJnFyd+YksK9fXqZLXpB9Js1UE6wCdBmBtEC9DzjCSEv2XLdFCg==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/migration-toolkit/-/migration-toolkit-2.0.0.tgz", + "integrity": "sha512-CnuZfKM/Y2or7jePLrVpZh7sT6lQgAgMJcA+GWfLb14noU5yk7GAYN511d1q1Mz6O32MX8U+6B0Q0zYWQ6ZKGg==", + "dev": true, "dependencies": { "@kontent-ai-consulting/tools-analytics": "0.0.7", - "@kontent-ai/management-sdk": "7.2.0", + "@kontent-ai/management-sdk": "7.4.0", "browser-or-node": "3.0.0", + "buffer": "6.0.3", "bytes": "3.1.2", "chalk": "5.3.0", "deep-equal": "2.2.3", "dotenv": "16.4.5", "jszip": "3.10.1", "mime": "4.0.4", - "ora": "8.0.1", + "ora": "8.1.0", "p-limit": "6.1.0", "prompts": "2.4.2", - "ts-pattern": "5.3.1", + "ts-pattern": "5.4.0", "yargs": "17.7.2", "zod": "3.23.8" }, @@ -827,12 +850,25 @@ "node": ">=20" } }, + "node_modules/@kontent-ai/migration-toolkit/node_modules/@kontent-ai/core-sdk": { + "version": "10.8.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/core-sdk/-/core-sdk-10.8.0.tgz", + "integrity": "sha512-6o5kn+ANhJ7vCucWXunxy1qCSSDsN3F86zdLXzPnFaK/qOf4BJGnPda81Alvnt4N7n4e1m9J7uP0tm3tQ/W25Q==", + "dev": true, + "dependencies": { + "axios": "1.7.7" + }, + "engines": { + "node": ">= 20" + } + }, "node_modules/@kontent-ai/migration-toolkit/node_modules/@kontent-ai/management-sdk": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@kontent-ai/management-sdk/-/management-sdk-7.2.0.tgz", - "integrity": "sha512-vfEzmQDrDdKj+4evxoCjBE/Cpr5FT1L7KdOjwISk5MSaQsUxl8hrBYL7UDo8ln/J5LIO/6aOwxJ7aY4yAwI9yw==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@kontent-ai/management-sdk/-/management-sdk-7.4.0.tgz", + "integrity": "sha512-/gKLaI2A69/sRKOmRCsQFhv/V+R/qRE5/hy7KTNUsXjtA39thVFCt5L6OsCsfAH0rxb5qYtlJM5qJ4KbgYdVfQ==", + "dev": true, "dependencies": { - "@kontent-ai/core-sdk": "10.7.0", + "@kontent-ai/core-sdk": "10.8.0", "mime": "3.0.0" }, "engines": { @@ -843,6 +879,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz", "integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==", + "dev": true, "bin": { "mime": "cli.js" }, @@ -850,10 +887,22 @@ "node": ">=10.0.0" } }, + "node_modules/@kontent-ai/migration-toolkit/node_modules/axios": { + "version": "1.7.7", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", + "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", + "dev": true, + "dependencies": { + "follow-redirects": "^1.15.6", + "form-data": "^4.0.0", + "proxy-from-env": "^1.1.0" + } + }, "node_modules/@kontent-ai/migration-toolkit/node_modules/mime": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/mime/-/mime-4.0.4.tgz", "integrity": "sha512-v8yqInVjhXyqP6+Kw4fV3ZzeMRqEW6FotRsKXjRS5VMTNIuXsdRoAvklpoRgSqXm6o9VNH4/C0mgedko9DdLsQ==", + "dev": true, "funding": [ "https://github.com/sponsors/broofa" ], @@ -864,11 +913,6 @@ "node": ">=16" } }, - "node_modules/@kontent-ai/migration-toolkit/node_modules/ts-pattern": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/ts-pattern/-/ts-pattern-5.3.1.tgz", - "integrity": "sha512-1RUMKa8jYQdNfmnK4jyzBK3/PS/tnjcZ1CW0v1vWDeYe5RBklc/nquw03MEoB66hVBm4BnlCfmOqDVxHyT1DpA==" - }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -942,9 +986,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.7.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.4.tgz", - "integrity": "sha512-y+NPi1rFzDs1NdQHHToqeiX2TIS79SWEAw9GYhkkx8bD0ChpfqC+n2j5OXOCpzfojBEBt6DnEnnG9MY0zk1XLg==", + "version": "22.7.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.5.tgz", + "integrity": "sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ==", "dev": true, "dependencies": { "undici-types": "~6.19.2" @@ -972,16 +1016,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.8.0.tgz", - "integrity": "sha512-wORFWjU30B2WJ/aXBfOm1LX9v9nyt9D3jsSOxC3cCaTQGCW5k4jNpmjFv3U7p/7s4yvdjHzwtv2Sd2dOyhjS0A==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.8.1.tgz", + "integrity": "sha512-xfvdgA8AP/vxHgtgU310+WBnLB4uJQ9XdyP17RebG26rLtDrQJV3ZYrcopX91GrHmMoH8bdSwMRh2a//TiJ1jQ==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "8.8.0", - "@typescript-eslint/type-utils": "8.8.0", - "@typescript-eslint/utils": "8.8.0", - "@typescript-eslint/visitor-keys": "8.8.0", + "@typescript-eslint/scope-manager": "8.8.1", + "@typescript-eslint/type-utils": "8.8.1", + "@typescript-eslint/utils": "8.8.1", + "@typescript-eslint/visitor-keys": "8.8.1", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", @@ -1005,15 +1049,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.8.0.tgz", - "integrity": "sha512-uEFUsgR+tl8GmzmLjRqz+VrDv4eoaMqMXW7ruXfgThaAShO9JTciKpEsB+TvnfFfbg5IpujgMXVV36gOJRLtZg==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.8.1.tgz", + "integrity": "sha512-hQUVn2Lij2NAxVFEdvIGxT9gP1tq2yM83m+by3whWFsWC+1y8pxxxHUFE1UqDu2VsGi2i6RLcv4QvouM84U+ow==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "8.8.0", - "@typescript-eslint/types": "8.8.0", - "@typescript-eslint/typescript-estree": "8.8.0", - "@typescript-eslint/visitor-keys": "8.8.0", + "@typescript-eslint/scope-manager": "8.8.1", + "@typescript-eslint/types": "8.8.1", + "@typescript-eslint/typescript-estree": "8.8.1", + "@typescript-eslint/visitor-keys": "8.8.1", "debug": "^4.3.4" }, "engines": { @@ -1033,13 +1077,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.8.0.tgz", - "integrity": "sha512-EL8eaGC6gx3jDd8GwEFEV091210U97J0jeEHrAYvIYosmEGet4wJ+g0SYmLu+oRiAwbSA5AVrt6DxLHfdd+bUg==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.8.1.tgz", + "integrity": "sha512-X4JdU+66Mazev/J0gfXlcC/dV6JI37h+93W9BRYXrSn0hrE64IoWgVkO9MSJgEzoWkxONgaQpICWg8vAN74wlA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.8.0", - "@typescript-eslint/visitor-keys": "8.8.0" + "@typescript-eslint/types": "8.8.1", + "@typescript-eslint/visitor-keys": "8.8.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1050,13 +1094,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.8.0.tgz", - "integrity": "sha512-IKwJSS7bCqyCeG4NVGxnOP6lLT9Okc3Zj8hLO96bpMkJab+10HIfJbMouLrlpyOr3yrQ1cA413YPFiGd1mW9/Q==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.8.1.tgz", + "integrity": "sha512-qSVnpcbLP8CALORf0za+vjLYj1Wp8HSoiI8zYU5tHxRVj30702Z1Yw4cLwfNKhTPWp5+P+k1pjmD5Zd1nhxiZA==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "8.8.0", - "@typescript-eslint/utils": "8.8.0", + "@typescript-eslint/typescript-estree": "8.8.1", + "@typescript-eslint/utils": "8.8.1", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -1074,9 +1118,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.8.0.tgz", - "integrity": "sha512-QJwc50hRCgBd/k12sTykOJbESe1RrzmX6COk8Y525C9l7oweZ+1lw9JiU56im7Amm8swlz00DRIlxMYLizr2Vw==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.8.1.tgz", + "integrity": "sha512-WCcTP4SDXzMd23N27u66zTKMuEevH4uzU8C9jf0RO4E04yVHgQgW+r+TeVTNnO1KIfrL8ebgVVYYMMO3+jC55Q==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1087,13 +1131,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.8.0.tgz", - "integrity": "sha512-ZaMJwc/0ckLz5DaAZ+pNLmHv8AMVGtfWxZe/x2JVEkD5LnmhWiQMMcYT7IY7gkdJuzJ9P14fRy28lUrlDSWYdw==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.8.1.tgz", + "integrity": "sha512-A5d1R9p+X+1js4JogdNilDuuq+EHZdsH9MjTVxXOdVFfTJXunKJR/v+fNNyO4TnoOn5HqobzfRlc70NC6HTcdg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.8.0", - "@typescript-eslint/visitor-keys": "8.8.0", + "@typescript-eslint/types": "8.8.1", + "@typescript-eslint/visitor-keys": "8.8.1", "debug": "^4.3.4", "fast-glob": "^3.3.2", "is-glob": "^4.0.3", @@ -1115,15 +1159,15 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.8.0.tgz", - "integrity": "sha512-QE2MgfOTem00qrlPgyByaCHay9yb1+9BjnMFnSFkUKQfu7adBXDTnCAivURnuPPAG/qiB+kzKkZKmKfaMT0zVg==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.8.1.tgz", + "integrity": "sha512-/QkNJDbV0bdL7H7d0/y0qBbV2HTtf0TIyjSDTvvmQEzeVx8jEImEbLuOA4EsvE8gIgqMitns0ifb5uQhMj8d9w==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "8.8.0", - "@typescript-eslint/types": "8.8.0", - "@typescript-eslint/typescript-estree": "8.8.0" + "@typescript-eslint/scope-manager": "8.8.1", + "@typescript-eslint/types": "8.8.1", + "@typescript-eslint/typescript-estree": "8.8.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1137,12 +1181,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.8.0.tgz", - "integrity": "sha512-8mq51Lx6Hpmd7HnA2fcHQo3YgfX1qbccxQOgZcb4tvasu//zXRaA1j5ZRFeCw/VRAdFi4mRM9DnZw0Nu0Q2d1g==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.8.1.tgz", + "integrity": "sha512-0/TdC3aeRAsW7MDvYRwEc1Uwm0TIBfzjPFgg60UU2Haj5qsCs9cc3zNgY71edqE3LbWfF/WoZQd3lJoDXFQpag==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.8.0", + "@typescript-eslint/types": "8.8.1", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -1228,6 +1272,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/array-buffer-byte-length/-/array-buffer-byte-length-1.0.1.tgz", "integrity": "sha512-ahC5W1xgou+KTXix4sAO8Ki12Q+jf4i0+tmk3sC+zgcynshkHxzpXdImBehiUYKKKDwvfFiJl1tZt6ewscS1Mg==", + "dev": true, "dependencies": { "call-bind": "^1.0.5", "is-array-buffer": "^3.0.4" @@ -1263,6 +1308,7 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", "integrity": "sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==", + "dev": true, "dependencies": { "possible-typed-array-names": "^1.0.0" }, @@ -1277,6 +1323,7 @@ "version": "1.7.4", "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.4.tgz", "integrity": "sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw==", + "dev": true, "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", @@ -1289,6 +1336,26 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, "node_modules/brace-expansion": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", @@ -1313,7 +1380,32 @@ "node_modules/browser-or-node": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/browser-or-node/-/browser-or-node-3.0.0.tgz", - "integrity": "sha512-iczIdVJzGEYhP5DqQxYM9Hh7Ztpqqi+CXZpSmX8ALFs9ecXkQIeqRyM6TfxEfMVpwhl3dSuDvxdzzo9sUOIVBQ==" + "integrity": "sha512-iczIdVJzGEYhP5DqQxYM9Hh7Ztpqqi+CXZpSmX8ALFs9ecXkQIeqRyM6TfxEfMVpwhl3dSuDvxdzzo9sUOIVBQ==", + "dev": true + }, + "node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } }, "node_modules/buffer-from": { "version": "1.1.2", @@ -1325,6 +1417,7 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "dev": true, "engines": { "node": ">= 0.8" } @@ -1333,6 +1426,7 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", + "dev": true, "dependencies": { "es-define-property": "^1.0.0", "es-errors": "^1.3.0", @@ -1394,14 +1488,15 @@ } }, "node_modules/cli-cursor": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-4.0.0.tgz", - "integrity": "sha512-VGtlMu3x/4DOtIUwEkRezxUZ2lBacNJCHash0N0WeZDBS+7Ux1dm3XWAgWYxLJFMMdOeXMHXorshEFhbMSGelg==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-5.0.0.tgz", + "integrity": "sha512-aCj4O5wKyszjMmDT4tZj93kxyydN/K5zPWSCe6/0AV/AA1pqe5ZBIw0a2ZfPQV7lL5/yb5HsUreJ6UFAF1tEQw==", + "dev": true, "dependencies": { - "restore-cursor": "^4.0.0" + "restore-cursor": "^5.0.0" }, "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -1411,6 +1506,7 @@ "version": "2.9.2", "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.2.tgz", "integrity": "sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==", + "dev": true, "engines": { "node": ">=6" }, @@ -1785,7 +1881,8 @@ "node_modules/core-util-is": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", - "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" + "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", + "dev": true }, "node_modules/cross-spawn": { "version": "7.0.3", @@ -1874,6 +1971,7 @@ "version": "2.2.3", "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-2.2.3.tgz", "integrity": "sha512-ZIwpnevOurS8bpT4192sqAowWM76JDKSHYzMLty3BZGSswgq6pBaH3DhCSW5xVAZICZyKdOBPjwww5wfgT/6PA==", + "dev": true, "dependencies": { "array-buffer-byte-length": "^1.0.0", "call-bind": "^1.0.5", @@ -1911,6 +2009,7 @@ "version": "1.1.4", "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", + "dev": true, "dependencies": { "es-define-property": "^1.0.0", "es-errors": "^1.3.0", @@ -1927,6 +2026,7 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz", "integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==", + "dev": true, "dependencies": { "define-data-property": "^1.0.1", "has-property-descriptors": "^1.0.0", @@ -1981,6 +2081,7 @@ "version": "16.4.5", "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "dev": true, "engines": { "node": ">=12" }, @@ -2109,9 +2210,10 @@ } }, "node_modules/emoji-regex": { - "version": "10.3.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.3.0.tgz", - "integrity": "sha512-QpLs9D9v9kArv4lfDEgg1X/gN5XLnf/A6l9cs8SPZLRZR3ZkY9+kwIQTxm+fsSej5UMYGE8fdoaZVIBlqG0XTw==" + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.4.0.tgz", + "integrity": "sha512-EC+0oUMY1Rqm4O6LLrgjtYDvcVYTy7chDnM4Q7030tP4Kwj3u/pR6gP9ygnp2CJMK5Gq+9Q2oqmrFJAz01DXjw==", + "dev": true }, "node_modules/error-ex": { "version": "1.3.2", @@ -2126,6 +2228,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", + "dev": true, "dependencies": { "get-intrinsic": "^1.2.4" }, @@ -2137,6 +2240,7 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "dev": true, "engines": { "node": ">= 0.4" } @@ -2145,6 +2249,7 @@ "version": "1.1.3", "resolved": "https://registry.npmjs.org/es-get-iterator/-/es-get-iterator-1.1.3.tgz", "integrity": "sha512-sPZmqHBe6JIiTfN5q2pEi//TwxmAFHwj/XEuYjTuse78i8KxaqMTTzxPoFKuzRpDpTJ+0NAbpfenkmH2rePtuw==", + "dev": true, "dependencies": { "call-bind": "^1.0.2", "get-intrinsic": "^1.1.3", @@ -2220,9 +2325,9 @@ } }, "node_modules/eslint": { - "version": "9.11.1", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.11.1.tgz", - "integrity": "sha512-MobhYKIoAO1s1e4VUrgx1l1Sk2JBR/Gqjjgw8+mfgoLE2xwsHur4gdfTxyTgShrhvdVFTaJSgMiQBl1jv/AWxg==", + "version": "9.12.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.12.0.tgz", + "integrity": "sha512-UVIOlTEWxwIopRL1wgSQYdnVDcEvs2wyaO6DGo5mXqe3r16IoCNWkR29iHhyaP4cICWjbgbmFUGAhh0GJRuGZw==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", @@ -2230,11 +2335,11 @@ "@eslint/config-array": "^0.18.0", "@eslint/core": "^0.6.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.11.1", + "@eslint/js": "9.12.0", "@eslint/plugin-kit": "^0.2.0", + "@humanfs/node": "^0.16.5", "@humanwhocodes/module-importer": "^1.0.1", - "@humanwhocodes/retry": "^0.3.0", - "@nodelib/fs.walk": "^1.2.8", + "@humanwhocodes/retry": "^0.3.1", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", @@ -2242,9 +2347,9 @@ "cross-spawn": "^7.0.2", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^8.0.2", - "eslint-visitor-keys": "^4.0.0", - "espree": "^10.1.0", + "eslint-scope": "^8.1.0", + "eslint-visitor-keys": "^4.1.0", + "espree": "^10.2.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -2254,13 +2359,11 @@ "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", - "is-path-inside": "^3.0.3", "json-stable-stringify-without-jsonify": "^1.0.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.3", - "strip-ansi": "^6.0.1", "text-table": "^0.2.0" }, "bin": { @@ -2282,9 +2385,9 @@ } }, "node_modules/eslint-scope": { - "version": "8.0.2", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.0.2.tgz", - "integrity": "sha512-6E4xmrTw5wtxnLA5wYL3WDfhZ/1bUBGOXV0zQvVRDOtrR8D0p6W7fs3JweNYhwRYeGvd/1CKX2se0/2s7Q/nJA==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.1.0.tgz", + "integrity": "sha512-14dSvlhaVhKKsa9Fx1l8A17s7ah7Ef7wCakJ10LYk6+GYmP9yDti2oq2SEwcyndt6knfcZyhyxwY3i9yL78EQw==", "dev": true, "dependencies": { "esrecurse": "^4.3.0", @@ -2336,9 +2439,9 @@ } }, "node_modules/eslint/node_modules/eslint-visitor-keys": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.0.0.tgz", - "integrity": "sha512-OtIRv/2GyiF6o/d8K7MYKKbXrOUBIK6SfkIRM4Z0dY3w+LiQ0vy3F57m0Z71bjbyeiWFiHJ8brqnmE6H6/jEuw==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.1.0.tgz", + "integrity": "sha512-Q7lok0mqMUSf5a/AdAZkA5a/gHcO6snwQClVNNvFKCAVlxXucdU8pKydU5ZVZjBx5xr37vGbFFWtLQYreLzrZg==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -2360,14 +2463,14 @@ } }, "node_modules/espree": { - "version": "10.1.0", - "resolved": "https://registry.npmjs.org/espree/-/espree-10.1.0.tgz", - "integrity": "sha512-M1M6CpiE6ffoigIOWYO9UDP8TMUw9kqb21tf+08IgDYjCsOvCuDt4jQcZmoYxx+w7zlKw9/N0KXfto+I8/FrXA==", + "version": "10.2.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-10.2.0.tgz", + "integrity": "sha512-upbkBJbckcCNBDBDXEbuhjbP68n+scUd3k/U2EkyM9nw+I/jPiL4cLF/Al06CF96wRltFda16sxDFrxsI1v0/g==", "dev": true, "dependencies": { "acorn": "^8.12.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.0.0" + "eslint-visitor-keys": "^4.1.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -2377,9 +2480,9 @@ } }, "node_modules/espree/node_modules/eslint-visitor-keys": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.0.0.tgz", - "integrity": "sha512-OtIRv/2GyiF6o/d8K7MYKKbXrOUBIK6SfkIRM4Z0dY3w+LiQ0vy3F57m0Z71bjbyeiWFiHJ8brqnmE6H6/jEuw==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.1.0.tgz", + "integrity": "sha512-Q7lok0mqMUSf5a/AdAZkA5a/gHcO6snwQClVNNvFKCAVlxXucdU8pKydU5ZVZjBx5xr37vGbFFWtLQYreLzrZg==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -2591,6 +2694,7 @@ "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", "integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==", + "dev": true, "dependencies": { "is-callable": "^1.1.3" } @@ -2626,6 +2730,7 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -2634,6 +2739,7 @@ "version": "1.2.3", "resolved": "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz", "integrity": "sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==", + "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -2650,6 +2756,7 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/get-east-asian-width/-/get-east-asian-width-1.2.0.tgz", "integrity": "sha512-2nk+7SIVb14QrgXFHcm84tD4bKQz0RxPuMT8Ag5KPOq7J5fEmAg0UbXdTOSHqNuHSU28k55qnceesxXRZGzKWA==", + "dev": true, "engines": { "node": ">=18" }, @@ -2661,6 +2768,7 @@ "version": "1.2.4", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", + "dev": true, "dependencies": { "es-errors": "^1.3.0", "function-bind": "^1.1.2", @@ -2858,6 +2966,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "dev": true, "dependencies": { "get-intrinsic": "^1.1.3" }, @@ -2911,6 +3020,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz", "integrity": "sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ==", + "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -2928,6 +3038,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", + "dev": true, "dependencies": { "es-define-property": "^1.0.0" }, @@ -2939,6 +3050,7 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -2950,6 +3062,7 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -2961,6 +3074,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "dev": true, "dependencies": { "has-symbols": "^1.0.3" }, @@ -2975,6 +3089,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "dev": true, "dependencies": { "function-bind": "^1.1.2" }, @@ -2994,6 +3109,26 @@ "node": ">=10" } }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, "node_modules/ignore": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", @@ -3006,7 +3141,8 @@ "node_modules/immediate": { "version": "3.0.6", "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz", - "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==" + "integrity": "sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==", + "dev": true }, "node_modules/import-fresh": { "version": "3.3.0", @@ -3045,7 +3181,8 @@ "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true }, "node_modules/ini": { "version": "1.3.8", @@ -3057,6 +3194,7 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.7.tgz", "integrity": "sha512-NGnrKwXzSms2qUUih/ILZ5JBqNTSa1+ZmP6flaIp6KmSElgE9qdndzS3cqjrDovwFdmwsGsLdeFgB6suw+1e9g==", + "dev": true, "dependencies": { "es-errors": "^1.3.0", "hasown": "^2.0.0", @@ -3070,6 +3208,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", + "dev": true, "dependencies": { "call-bind": "^1.0.2", "has-tostringtag": "^1.0.0" @@ -3085,6 +3224,7 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/is-array-buffer/-/is-array-buffer-3.0.4.tgz", "integrity": "sha512-wcjaerHw0ydZwfhiKbXJWLDY8A7yV7KhjQOpb83hGgGfId/aQa4TOvwyzn2PuswW2gPCYEL/nEAiSVpdOj1lXw==", + "dev": true, "dependencies": { "call-bind": "^1.0.2", "get-intrinsic": "^1.2.1" @@ -3106,6 +3246,7 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-bigint/-/is-bigint-1.0.4.tgz", "integrity": "sha512-zB9CruMamjym81i2JZ3UMn54PKGsQzsJeo6xvN3HJJ4CAsQNB6iRutp2To77OfCNuoxspsIhzaPoO1zyCEhFOg==", + "dev": true, "dependencies": { "has-bigints": "^1.0.1" }, @@ -3117,6 +3258,7 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.2.tgz", "integrity": "sha512-gDYaKHJmnj4aWxyj6YHyXVpdQawtVLHU5cb+eztPGczf6cjuTdwve5ZIEfgXqH4e57An1D1AKf8CZ3kYrQRqYA==", + "dev": true, "dependencies": { "call-bind": "^1.0.2", "has-tostringtag": "^1.0.0" @@ -3132,6 +3274,7 @@ "version": "1.2.7", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -3158,6 +3301,7 @@ "version": "1.0.5", "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.5.tgz", "integrity": "sha512-9YQaSxsAiSwcvS33MBk3wTCVnWK+HhF8VZR2jRxehM16QcVOdHqPn4VPHmRK4lSr38n9JriurInLcP90xsYNfQ==", + "dev": true, "dependencies": { "has-tostringtag": "^1.0.0" }, @@ -3201,6 +3345,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-2.0.0.tgz", "integrity": "sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==", + "dev": true, "engines": { "node": ">=12" }, @@ -3212,6 +3357,7 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/is-map/-/is-map-2.0.3.tgz", "integrity": "sha512-1Qed0/Hr2m+YqxnM09CjA2d/i6YZNfF6R2oRAOj36eUdS6qIV/huPJNSEpKbupewFs+ZsJlxsjjPbc0/afW6Lw==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -3232,6 +3378,7 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.0.7.tgz", "integrity": "sha512-k1U0IRzLMo7ZlYIfzRu23Oh6MiIFasgpb9X76eqfFZAqwH44UI4KTBvBYIZ1dSL9ZzChTB9ShHfLkR4pdW5krQ==", + "dev": true, "dependencies": { "has-tostringtag": "^1.0.0" }, @@ -3251,15 +3398,6 @@ "node": ">=8" } }, - "node_modules/is-path-inside": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", - "integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/is-plain-obj": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-1.1.0.tgz", @@ -3273,6 +3411,7 @@ "version": "1.1.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", "integrity": "sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==", + "dev": true, "dependencies": { "call-bind": "^1.0.2", "has-tostringtag": "^1.0.0" @@ -3288,6 +3427,7 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/is-set/-/is-set-2.0.3.tgz", "integrity": "sha512-iPAjerrse27/ygGLxw+EBR9agv9Y6uLeYVJMu+QNCoouJ1/1ri0mGrcWpfCqFZuzzx3WjtwxG098X+n4OuRkPg==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -3299,6 +3439,7 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/is-shared-array-buffer/-/is-shared-array-buffer-1.0.3.tgz", "integrity": "sha512-nA2hv5XIhLR3uVzDDfCIknerhx8XUKnstuOERPNNIinXG7v9u+ohXF67vxm4TPTEPU6lm61ZkwP3c9PCB97rhg==", + "dev": true, "dependencies": { "call-bind": "^1.0.7" }, @@ -3313,6 +3454,7 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.7.tgz", "integrity": "sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==", + "dev": true, "dependencies": { "has-tostringtag": "^1.0.0" }, @@ -3327,6 +3469,7 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.4.tgz", "integrity": "sha512-C/CPBqKWnvdcxqIARxyOh4v1UUEOCHpgDa0WYgpKDFMszcrPcffg5uhwSgPCLD2WWxmq6isisz87tzT01tuGhg==", + "dev": true, "dependencies": { "has-symbols": "^1.0.2" }, @@ -3350,9 +3493,10 @@ } }, "node_modules/is-unicode-supported": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-2.0.0.tgz", - "integrity": "sha512-FRdAyx5lusK1iHG0TWpVtk9+1i+GjrzRffhDg4ovQ7mcidMQ6mj+MhKPmvh7Xwyv5gIS06ns49CA7Sqg7lC22Q==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-2.1.0.tgz", + "integrity": "sha512-mE00Gnza5EEB3Ds0HfMyllZzbBrmLOX3vfWoj9A9PEnTfratQ/BcaJOuMhnkhjXvb2+FkY3VuHqtAGpTPmglFQ==", + "dev": true, "engines": { "node": ">=18" }, @@ -3364,6 +3508,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/is-weakmap/-/is-weakmap-2.0.2.tgz", "integrity": "sha512-K5pXYOm9wqY1RgjpL3YTkF39tni1XajUIkawTLUo9EZEVUFga5gSQJF8nNS7ZwJQ02y+1YCNYcMh+HIf1ZqE+w==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -3375,6 +3520,7 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/is-weakset/-/is-weakset-2.0.3.tgz", "integrity": "sha512-LvIm3/KWzS9oRFHugab7d+M/GcBXuXX5xZkzPmN+NxihdQlZUQ4dWuSV1xR/sq6upL1TJEDrfBgRepHFdBtSNQ==", + "dev": true, "dependencies": { "call-bind": "^1.0.7", "get-intrinsic": "^1.2.4" @@ -3389,7 +3535,8 @@ "node_modules/isarray": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", - "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==" + "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", + "dev": true }, "node_modules/isexe": { "version": "2.0.0", @@ -3480,6 +3627,7 @@ "version": "3.10.1", "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.10.1.tgz", "integrity": "sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==", + "dev": true, "dependencies": { "lie": "~3.3.0", "pako": "~1.0.2", @@ -3509,6 +3657,7 @@ "version": "3.0.3", "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", "integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==", + "dev": true, "engines": { "node": ">=6" } @@ -3530,6 +3679,7 @@ "version": "3.3.0", "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz", "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==", + "dev": true, "dependencies": { "immediate": "~3.0.5" } @@ -3601,6 +3751,7 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-6.0.0.tgz", "integrity": "sha512-i24m8rpwhmPIS4zscNzK6MSEhk0DUWa/8iYQWxhffV8jkI4Phvs3F+quL5xvS0gdQR0FyTCMMH33Y78dDTzzIw==", + "dev": true, "dependencies": { "chalk": "^5.3.0", "is-unicode-supported": "^1.3.0" @@ -3616,6 +3767,7 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-1.3.0.tgz", "integrity": "sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==", + "dev": true, "engines": { "node": ">=12" }, @@ -3871,12 +4023,16 @@ "node": ">= 0.6" } }, - "node_modules/mimic-fn": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", - "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", + "node_modules/mimic-function": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/mimic-function/-/mimic-function-5.0.1.tgz", + "integrity": "sha512-VP79XUPxV2CigYP3jWwAUFSku2aKqBH7uTAapFWCBqutsbmDo96KY5o8uh6U+/YSIn5OxJnXp73beVkpqMIGhA==", + "dev": true, "engines": { - "node": ">=6" + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/min-indent": { @@ -3972,6 +4128,7 @@ "version": "1.13.2", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", "integrity": "sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==", + "dev": true, "engines": { "node": ">= 0.4" }, @@ -3983,6 +4140,7 @@ "version": "1.1.6", "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.6.tgz", "integrity": "sha512-F8cZ+KfGlSGi09lJT7/Nd6KJZ9ygtvYC0/UYYLI9nmQKLMnydpB9yvbv9K1uSkEu7FU9vYPmVwLg328tX+ot3Q==", + "dev": true, "dependencies": { "call-bind": "^1.0.7", "define-properties": "^1.2.1" @@ -3998,6 +4156,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", + "dev": true, "engines": { "node": ">= 0.4" } @@ -4006,6 +4165,7 @@ "version": "4.1.5", "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.5.tgz", "integrity": "sha512-byy+U7gp+FVwmyzKPYhW2h5l3crpmGsxl7X2s8y43IgxvG4g3QZ6CffDtsNQy1WsmZpQbO+ybo0AlW7TY6DcBQ==", + "dev": true, "dependencies": { "call-bind": "^1.0.5", "define-properties": "^1.2.1", @@ -4020,14 +4180,15 @@ } }, "node_modules/onetime": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", - "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-7.0.0.tgz", + "integrity": "sha512-VXJjc87FScF88uafS3JllDgvAm+c/Slfz06lorj2uAY34rlUu0Nt+v8wreiImcrgAjjIHp1rXpTDlLOGw29WwQ==", + "dev": true, "dependencies": { - "mimic-fn": "^2.1.0" + "mimic-function": "^5.0.0" }, "engines": { - "node": ">=6" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -4051,18 +4212,19 @@ } }, "node_modules/ora": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/ora/-/ora-8.0.1.tgz", - "integrity": "sha512-ANIvzobt1rls2BDny5fWZ3ZVKyD6nscLvfFRpQgfWsythlcsVUC9kL0zq6j2Z5z9wwp1kd7wpsD/T9qNPVLCaQ==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/ora/-/ora-8.1.0.tgz", + "integrity": "sha512-GQEkNkH/GHOhPFXcqZs3IDahXEQcQxsSjEkK4KvEEST4t7eNzoMjxTzef+EZ+JluDEV+Raoi3WQ2CflnRdSVnQ==", + "dev": true, "dependencies": { "chalk": "^5.3.0", - "cli-cursor": "^4.0.0", + "cli-cursor": "^5.0.0", "cli-spinners": "^2.9.2", "is-interactive": "^2.0.0", "is-unicode-supported": "^2.0.0", "log-symbols": "^6.0.0", - "stdin-discarder": "^0.2.1", - "string-width": "^7.0.0", + "stdin-discarder": "^0.2.2", + "string-width": "^7.2.0", "strip-ansi": "^7.1.0" }, "engines": { @@ -4073,9 +4235,10 @@ } }, "node_modules/ora/node_modules/ansi-regex": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", - "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz", + "integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==", + "dev": true, "engines": { "node": ">=12" }, @@ -4087,6 +4250,7 @@ "version": "7.1.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, "dependencies": { "ansi-regex": "^6.0.1" }, @@ -4101,6 +4265,7 @@ "version": "6.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-6.1.0.tgz", "integrity": "sha512-H0jc0q1vOzlEk0TqAKXKZxdl7kX3OFUzCnNVUnq5Pc3DGo0kpeaMuPqxQn235HibwBEb0/pm9dgKTjXy66fBkg==", + "dev": true, "dependencies": { "yocto-queue": "^1.1.1" }, @@ -4165,7 +4330,8 @@ "node_modules/pako": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", - "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==" + "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==", + "dev": true }, "node_modules/parent-module": { "version": "1.0.1", @@ -4247,6 +4413,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz", "integrity": "sha512-d7Uw+eZoloe0EHDIYoe+bQ5WXnGMOpmiZFTuMWCwpjzzkL2nTjcKiAk4hh8TjnGye2TwWOk3UXucZ+3rbmBa8Q==", + "dev": true, "engines": { "node": ">= 0.4" } @@ -4277,12 +4444,14 @@ "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", + "dev": true }, "node_modules/prompts": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", "integrity": "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==", + "dev": true, "dependencies": { "kleur": "^3.0.3", "sisteransi": "^1.0.5" @@ -4319,8 +4488,7 @@ "node_modules/querystringify": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/querystringify/-/querystringify-2.2.0.tgz", - "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==", - "dev": true + "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==" }, "node_modules/queue-microtask": { "version": "1.2.3", @@ -4497,6 +4665,7 @@ "version": "2.3.8", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "dev": true, "dependencies": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -4510,7 +4679,8 @@ "node_modules/readable-stream/node_modules/isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", + "dev": true }, "node_modules/redent": { "version": "3.0.0", @@ -4529,6 +4699,7 @@ "version": "1.5.2", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz", "integrity": "sha512-NcDiDkTLuPR+++OCKB0nWafEmhg/Da8aUPLPMQbK+bxKKCm1/S5he+AqYa4PlMCVBalb4/yxIRub6qkEx5yJbw==", + "dev": true, "dependencies": { "call-bind": "^1.0.6", "define-properties": "^1.2.1", @@ -4553,8 +4724,7 @@ "node_modules/requires-port": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", - "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==", - "dev": true + "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==" }, "node_modules/resolve": { "version": "1.22.8", @@ -4592,15 +4762,16 @@ } }, "node_modules/restore-cursor": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-4.0.0.tgz", - "integrity": "sha512-I9fPXU9geO9bHOt9pHHOhOkYerIMsmVaWB0rA2AI9ERh/+x/i7MV5HKBNrg+ljO5eoPVgCcnFuRjJ9uH6I/3eg==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-5.1.0.tgz", + "integrity": "sha512-oMA2dcrw6u0YfxJQXm342bFKX/E4sG9rbTzO9ptUcR/e8A33cHuvStiYOwH7fszkZlZ1z/ta9AAoPk2F4qIOHA==", + "dev": true, "dependencies": { - "onetime": "^5.1.0", - "signal-exit": "^3.0.2" + "onetime": "^7.0.0", + "signal-exit": "^4.1.0" }, "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -4642,7 +4813,8 @@ "node_modules/safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "dev": true }, "node_modules/semver": { "version": "7.6.3", @@ -4660,6 +4832,7 @@ "version": "1.2.2", "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", + "dev": true, "dependencies": { "define-data-property": "^1.1.4", "es-errors": "^1.3.0", @@ -4676,6 +4849,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/set-function-name/-/set-function-name-2.0.2.tgz", "integrity": "sha512-7PGFlmtwsEADb0WYyvCMa1t+yke6daIG4Wirafur5kcf+MhUnPms1UeR0CKQdTZD81yESwMHbtn+TR+dMviakQ==", + "dev": true, "dependencies": { "define-data-property": "^1.1.4", "es-errors": "^1.3.0", @@ -4689,7 +4863,8 @@ "node_modules/setimmediate": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", - "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==" + "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==", + "dev": true }, "node_modules/shebang-command": { "version": "2.0.0", @@ -4716,6 +4891,7 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==", + "dev": true, "dependencies": { "call-bind": "^1.0.7", "es-errors": "^1.3.0", @@ -4730,14 +4906,22 @@ } }, "node_modules/signal-exit": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", - "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "dev": true, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } }, "node_modules/sisteransi": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", - "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==" + "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==", + "dev": true }, "node_modules/source-map": { "version": "0.6.1", @@ -4967,6 +5151,7 @@ "version": "0.2.2", "resolved": "https://registry.npmjs.org/stdin-discarder/-/stdin-discarder-0.2.2.tgz", "integrity": "sha512-UhDfHmA92YAlNnCfhmq0VeNL5bDbiZGg7sZ2IvPsXubGkiNa9EC+tUTsjBRsYUAz87btI6/1wf4XoVvQ3uRnmQ==", + "dev": true, "engines": { "node": ">=18" }, @@ -4978,6 +5163,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/stop-iteration-iterator/-/stop-iteration-iterator-1.0.0.tgz", "integrity": "sha512-iCGQj+0l0HOdZ2AEeBADlsRC+vsnDsZsbdSiH1yNSjcfKM7fdpCMfqAL/dwF5BLiw/XhRft/Wax6zQbhq2BcjQ==", + "dev": true, "dependencies": { "internal-slot": "^1.0.4" }, @@ -4989,6 +5175,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "dev": true, "dependencies": { "safe-buffer": "~5.1.0" } @@ -4997,6 +5184,7 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", "integrity": "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==", + "dev": true, "dependencies": { "emoji-regex": "^10.3.0", "get-east-asian-width": "^1.0.0", @@ -5010,9 +5198,10 @@ } }, "node_modules/string-width/node_modules/ansi-regex": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", - "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz", + "integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==", + "dev": true, "engines": { "node": ">=12" }, @@ -5024,6 +5213,7 @@ "version": "7.1.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, "dependencies": { "ansi-regex": "^6.0.1" }, @@ -5254,14 +5444,14 @@ } }, "node_modules/typescript-eslint": { - "version": "8.8.0", - "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.8.0.tgz", - "integrity": "sha512-BjIT/VwJ8+0rVO01ZQ2ZVnjE1svFBiRczcpr1t1Yxt7sT25VSbPfrJtDsQ8uQTy2pilX5nI9gwxhUyLULNentw==", + "version": "8.8.1", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.8.1.tgz", + "integrity": "sha512-R0dsXFt6t4SAFjUSKFjMh4pXDtq04SsFKCVGDP3ZOzNP7itF0jBcZYU4fMsZr4y7O7V7Nc751dDeESbe4PbQMQ==", "dev": true, "dependencies": { - "@typescript-eslint/eslint-plugin": "8.8.0", - "@typescript-eslint/parser": "8.8.0", - "@typescript-eslint/utils": "8.8.0" + "@typescript-eslint/eslint-plugin": "8.8.1", + "@typescript-eslint/parser": "8.8.1", + "@typescript-eslint/utils": "8.8.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -5308,7 +5498,6 @@ "version": "1.5.10", "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz", "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", - "dev": true, "dependencies": { "querystringify": "^2.1.1", "requires-port": "^1.0.0" @@ -5317,13 +5506,13 @@ "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", + "dev": true }, "node_modules/uuid": { "version": "10.0.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==", - "dev": true, "funding": [ "https://github.com/sponsors/broofa", "https://github.com/sponsors/ctavan" @@ -5361,6 +5550,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz", "integrity": "sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==", + "dev": true, "dependencies": { "is-bigint": "^1.0.1", "is-boolean-object": "^1.1.0", @@ -5376,6 +5566,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/which-collection/-/which-collection-1.0.2.tgz", "integrity": "sha512-K4jVyjnBdgvc86Y6BkaLZEN933SwYOuBFkdmBu9ZfkcAbdVbpITnDmjvZ/aQjRXQrv5EPkTnD1s39GiiqbngCw==", + "dev": true, "dependencies": { "is-map": "^2.0.3", "is-set": "^2.0.3", @@ -5393,6 +5584,7 @@ "version": "1.1.15", "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.15.tgz", "integrity": "sha512-oV0jmFtUky6CXfkqehVvBP/LSWJ2sy4vWMioiENyJLePrBO/yKyV9OyJySfAKosh+RYkIl5zJCNZ8/4JncrpdA==", + "dev": true, "dependencies": { "available-typed-arrays": "^1.0.7", "call-bind": "^1.0.7", @@ -5535,6 +5727,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.1.1.tgz", "integrity": "sha512-b4JR1PFR10y1mKjhHY9LaGo6tmrgjit7hxVIeAmyMw3jegXR4dhYqLaQF5zMXZxY7tLpMyJeLjr1C4rLmkVe8g==", + "dev": true, "engines": { "node": ">=12.20" }, @@ -5546,6 +5739,7 @@ "version": "3.23.8", "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", + "dev": true, "funding": { "url": "https://github.com/sponsors/colinhacks" } diff --git a/package.json b/package.json index e6088a7..577bde8 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "update:version": "tsx ./scripts/update-version.ts" }, "dependencies": { - "@kontent-ai/management-sdk": "7.3.0", + "@kontent-ai/management-sdk": "7.5.0", "@kontent-ai/delivery-sdk": "15.2.0", "chalk": "5.3.0", "prettier": "3.3.3", @@ -57,16 +57,16 @@ "yargs": "17.7.2" }, "devDependencies": { - "@eslint/js": "9.11.1", - "@kontent-ai/migration-toolkit": "1.5.1", + "@eslint/js": "9.12.0", + "@kontent-ai/migration-toolkit": "2.0.0", "@types/eslint__js": "8.42.3", - "@types/node": "22.7.4", + "@types/node": "22.7.5", "@types/yargs": "17.0.33", "dotenv-cli": "7.4.2", - "eslint": "9.11.1", + "eslint": "9.12.0", "standard-version": "9.5.0", "tsx": "4.19.1", "typescript": "5.6.2", - "typescript-eslint": "8.8.0" + "typescript-eslint": "8.8.1" } } From 0b5a646e373b4349854aafa82aa62da8f911071c Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 8 Oct 2024 12:08:39 +0200 Subject: [PATCH 162/183] Adds tracking headers --- lib/config.ts | 5 ++++- lib/fetch/delivery-kontent-fetcher.ts | 9 ++++++++- lib/fetch/management-kontent-fetcher.ts | 4 +++- lib/meta/metadata.ts | 8 +++++--- scripts/update-version.ts | 1 + 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/config.ts b/lib/config.ts index 9bf1613..cf33b67 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -1,10 +1,13 @@ import { DeliveryApiMode, ModuleFileExtension } from './core/core.models.js'; +import { libMetadata } from './meta/metadata.js'; export const defaultModuleFileExtension: ModuleFileExtension = 'js'; export const defaultDeliveryApiMode: DeliveryApiMode = 'default'; export const coreConfig = { - barrelExportFilename: 'index.ts' + barrelExportFilename: 'index.ts', + kontentTrackingHeaderName: 'X-KC-SOURCE', + kontentTrackingHeaderValue: `${libMetadata.name};${libMetadata.version}` } as const; export const sharedTypesConfig = { diff --git a/lib/fetch/delivery-kontent-fetcher.ts b/lib/fetch/delivery-kontent-fetcher.ts index 83ab126..b3554d7 100644 --- a/lib/fetch/delivery-kontent-fetcher.ts +++ b/lib/fetch/delivery-kontent-fetcher.ts @@ -1,6 +1,7 @@ import { HttpService } from '@kontent-ai/core-sdk'; import { createDeliveryClient, IContentItem, ItemsFeedQuery } from '@kontent-ai/delivery-sdk'; import chalk from 'chalk'; +import { coreConfig } from '../config.js'; import { DeliveryApiMode, GeneratorDeliveryClient } from '../core/core.models.js'; import { sortAlphabetically } from '../core/core.utils.js'; @@ -16,7 +17,13 @@ export function deliveryKontentFetcher(config: KontentFetcherConfig) { environmentId: config.environmentId, defaultQueryConfig: { usePreviewMode: config.apiMode === 'preview', - useSecuredMode: config.apiMode === 'secure' + useSecuredMode: config.apiMode === 'secure', + customHeaders: [ + { + header: coreConfig.kontentTrackingHeaderName, + value: coreConfig.kontentTrackingHeaderValue + } + ] }, secureApiKey: config.apiMode === 'secure' ? config.apiKey : undefined, previewApiKey: config.apiMode === 'preview' ? config.apiKey : undefined, diff --git a/lib/fetch/management-kontent-fetcher.ts b/lib/fetch/management-kontent-fetcher.ts index cef3151..81b48a6 100644 --- a/lib/fetch/management-kontent-fetcher.ts +++ b/lib/fetch/management-kontent-fetcher.ts @@ -14,6 +14,7 @@ import { WorkflowModels } from '@kontent-ai/management-sdk'; import chalk from 'chalk'; +import { coreConfig } from '../config.js'; import { toSafeComment } from '../core/comment.utils.js'; import { GeneratorManagementClient } from '../core/core.models.js'; @@ -28,7 +29,8 @@ export function managementKontentFetcher(config: KontentFetcherConfig) { environmentId: config.environmentId, apiKey: config.apiKey, baseUrl: config.baseUrl, - httpService: new HttpService({ logErrorsToConsole: false }) + httpService: new HttpService({ logErrorsToConsole: false }), + headers: [{ header: coreConfig.kontentTrackingHeaderName, value: coreConfig.kontentTrackingHeaderValue }] }); return { diff --git a/lib/meta/metadata.ts b/lib/meta/metadata.ts index 21c3b7a..b229297 100644 --- a/lib/meta/metadata.ts +++ b/lib/meta/metadata.ts @@ -1,5 +1,7 @@ + export const libMetadata = { - name: '@kontent-ai/model-generator', - timestamp: 'Mon, 16 Sep 2024 09:31:58 GMT', - version: '8.0.0-0' + host: 'npmjs.com', + name: '@kontent-ai/model-generator', + timestamp: 'Tue, 08 Oct 2024 10:03:49 GMT', + version: '8.0.0-5' }; diff --git a/scripts/update-version.ts b/scripts/update-version.ts index e6606b2..7ee72f4 100644 --- a/scripts/update-version.ts +++ b/scripts/update-version.ts @@ -14,6 +14,7 @@ function createVersionFile(date: Date, filePath: string, propertyName: string): const src = ` export const ${propertyName} = { + host: 'npmjs.com', name: '${name}', timestamp: '${date.toUTCString()}', version: '${version}' From a5c527dbb285474985617d9e5b0299efacf654ab Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 8 Oct 2024 12:18:50 +0200 Subject: [PATCH 163/183] chore(release): 8.0.0-6 --- CHANGELOG.md | 2 ++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a85afa6..fb0b066 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [8.0.0-6](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-5...v8.0.0-6) (2024-10-08) + ## [8.0.0-5](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-4...v8.0.0-5) (2024-10-04) ## [8.0.0-4](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-3...v8.0.0-4) (2024-10-02) diff --git a/package-lock.json b/package-lock.json index a20cc8e..562e62c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-5", + "version": "8.0.0-6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@kontent-ai/model-generator", - "version": "8.0.0-5", + "version": "8.0.0-6", "license": "MIT", "dependencies": { "@kontent-ai/delivery-sdk": "15.2.0", diff --git a/package.json b/package.json index 577bde8..314af80 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-5", + "version": "8.0.0-6", "description": "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.", "bin": { "kontent-generate": "./dist/lib/code/app.js" From 91dc01219c92fd3ee11dd54b0a2017d2b9c0c3aa Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 29 Oct 2024 16:14:53 +0100 Subject: [PATCH 164/183] Generates type representing all possible element codenames --- lib/config.ts | 3 +- .../delivery-content-type.generator.ts | 8 +++-- .../shared/type-codename.generator.ts | 25 +++++++++++++++- .../delivery/content-type-snippets/index.ts | 2 +- sample/delivery/content-types/actor.ts | 2 +- sample/delivery/content-types/index.ts | 2 +- sample/delivery/content-types/movie.ts | 29 ++++++++++--------- sample/delivery/index.ts | 2 +- sample/delivery/system/core.type.ts | 2 +- sample/delivery/system/delivery.codenames.ts | 20 ++++++++++++- sample/delivery/system/index.ts | 2 +- sample/delivery/taxonomies/index.ts | 2 +- sample/delivery/taxonomies/movietype.ts | 2 +- sample/delivery/taxonomies/releasecategory.ts | 2 +- 14 files changed, 75 insertions(+), 28 deletions(-) diff --git a/lib/config.ts b/lib/config.ts index cf33b67..b1092cc 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -15,7 +15,8 @@ export const sharedTypesConfig = { collectionCodenames: 'CollectionCodenames', workflowCodenames: 'WorkflowCodenames', workflowStepCodenames: 'WorkflowStepCodenames', - contentTypeCodenames: 'ContentTypeCodenames' + contentTypeCodenames: 'ContentTypeCodenames', + elementCodenames: 'ElementCodenames' } as const; export const migrationConfig = { diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 2c02a82..758d224 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -27,6 +27,7 @@ import { import { getCollectionCodenamesType, getContentTypeCodenamesType, + getElementCodenamesType, getLanguageCodenamesType, getWorkflowCodenamesType, getWorkflowStepCodenamesType @@ -437,9 +438,9 @@ ${getElementsCode(flattenedElements)}${importsResult.contentTypeExtends ? ` ${im }; const getCoreContentTypeFile = (): GeneratedFile => { - const sdkImports: string[] = [deliveryConfig.sdkTypes.contentItem, deliveryConfig.sdkTypes.contentItemElements]; + const sdkImports: readonly string[] = [deliveryConfig.sdkTypes.contentItem, deliveryConfig.sdkTypes.contentItemElements]; - const codenameImports: string[] = [ + const codenameImports: readonly string[] = [ sharedTypesConfig.contentTypeCodenames, sharedTypesConfig.collectionCodenames, sharedTypesConfig.languageCodenames, @@ -496,6 +497,9 @@ ${getElementsCode(flattenedElements)}${importsResult.contentTypeExtends ? ` ${im ${wrapComment(`\n * Type representing all worksflow steps across all workflows\n`)} ${getWorkflowStepCodenamesType(config.environmentData.workflows)} + + ${wrapComment(`\n * Type representing all element codenames across all content types\n`)} + ${getElementCodenamesType(config.environmentData.types, config.environmentData.snippets)} ` }; }; diff --git a/lib/generators/shared/type-codename.generator.ts b/lib/generators/shared/type-codename.generator.ts index 3593ecf..c788167 100644 --- a/lib/generators/shared/type-codename.generator.ts +++ b/lib/generators/shared/type-codename.generator.ts @@ -1,4 +1,6 @@ -import { CollectionModels, ContentTypeModels, LanguageModels, WorkflowModels } from '@kontent-ai/management-sdk'; +import { CollectionModels, ContentTypeModels, ContentTypeSnippetModels, LanguageModels, WorkflowModels } from '@kontent-ai/management-sdk'; +import { isNotUndefined } from '@kontent-ai/migration-toolkit'; +import { match, P } from 'ts-pattern'; import { sharedTypesConfig } from '../../config.js'; import { ObjectWithCodename } from '../../core/core.models.js'; import { uniqueFilter } from '../../core/core.utils.js'; @@ -26,6 +28,27 @@ export function getWorkflowStepCodenamesType(workflows: readonly Readonly[], + snippets: readonly Readonly[] +): string { + return getTypeWithCodenames( + sharedTypesConfig.elementCodenames, + [...types, ...snippets].flatMap((type) => + type.elements + .map((element) => + match(element) + .returnType() + .with({ codename: P.nonNullable }, (elementWithCodename) => { + return elementWithCodename; + }) + .otherwise(() => undefined) + ) + .filter(isNotUndefined) + ) + ); +} + function getTypeWithCodenames(typeName: string, items: readonly ObjectWithCodename[]): string { return `export type ${typeName} = ${items .map((item) => `'${item.codename}'`) diff --git a/sample/delivery/content-type-snippets/index.ts b/sample/delivery/content-type-snippets/index.ts index 0f798e7..634fd05 100644 --- a/sample/delivery/content-type-snippets/index.ts +++ b/sample/delivery/content-type-snippets/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index 8458be0..ef6042d 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/delivery/content-types/index.ts b/sample/delivery/content-types/index.ts index c05bf8f..b33a70c 100644 --- a/sample/delivery/content-types/index.ts +++ b/sample/delivery/content-types/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 14998bb..657b442 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -1,21 +1,22 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ import type { Elements } from '@kontent-ai/delivery-sdk'; +import type { Actor } from './index.js'; import type { CoreContentType } from '../system/index.js'; import type { Releasecategory } from '../taxonomies/index.js'; -import type { Actor } from './index.js'; /** * Type representing all available element codenames for Movie diff --git a/sample/delivery/index.ts b/sample/delivery/index.ts index 05f9c38..a93bf4e 100644 --- a/sample/delivery/index.ts +++ b/sample/delivery/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/delivery/system/core.type.ts b/sample/delivery/system/core.type.ts index 70e918d..c5faf99 100644 --- a/sample/delivery/system/core.type.ts +++ b/sample/delivery/system/core.type.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/delivery/system/delivery.codenames.ts b/sample/delivery/system/delivery.codenames.ts index 4419167..7b563d5 100644 --- a/sample/delivery/system/delivery.codenames.ts +++ b/sample/delivery/system/delivery.codenames.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * @@ -37,3 +37,21 @@ export type WorkflowCodenames = 'default'; * Type representing all worksflow steps across all workflows */ export type WorkflowStepCodenames = 'draft' | 'review' | 'ready_to_publish' | 'published' | 'archived' | 'scheduled'; + +/** + * Type representing all element codenames across all content types + */ +export type ElementCodenames = + | 'url' + | 'first_name' + | 'last_name' + | 'photo' + | 'title' + | 'plot' + | 'released' + | 'length' + | 'poster' + | 'category' + | 'stars' + | 'seoname' + | 'releasecategory'; diff --git a/sample/delivery/system/index.ts b/sample/delivery/system/index.ts index 0e57cfc..b169583 100644 --- a/sample/delivery/system/index.ts +++ b/sample/delivery/system/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/delivery/taxonomies/index.ts b/sample/delivery/taxonomies/index.ts index 823ef58..392c718 100644 --- a/sample/delivery/taxonomies/index.ts +++ b/sample/delivery/taxonomies/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/delivery/taxonomies/movietype.ts b/sample/delivery/taxonomies/movietype.ts index 5d70baf..79bc94d 100644 --- a/sample/delivery/taxonomies/movietype.ts +++ b/sample/delivery/taxonomies/movietype.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/delivery/taxonomies/releasecategory.ts b/sample/delivery/taxonomies/releasecategory.ts index ab76cad..0c79cfa 100644 --- a/sample/delivery/taxonomies/releasecategory.ts +++ b/sample/delivery/taxonomies/releasecategory.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * From 80d7a558d2bce2efea93144563d2245b8a31b78e Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 29 Oct 2024 16:15:29 +0100 Subject: [PATCH 165/183] chore(release): 8.0.0-7 --- CHANGELOG.md | 2 ++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb0b066..514f03f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [8.0.0-7](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-6...v8.0.0-7) (2024-10-29) + ## [8.0.0-6](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-5...v8.0.0-6) (2024-10-08) ## [8.0.0-5](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-4...v8.0.0-5) (2024-10-04) diff --git a/package-lock.json b/package-lock.json index 562e62c..f60a059 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-6", + "version": "8.0.0-7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@kontent-ai/model-generator", - "version": "8.0.0-6", + "version": "8.0.0-7", "license": "MIT", "dependencies": { "@kontent-ai/delivery-sdk": "15.2.0", diff --git a/package.json b/package.json index 314af80..1bdb80c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-6", + "version": "8.0.0-7", "description": "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.", "bin": { "kontent-generate": "./dist/lib/code/app.js" From d25edd87e4a08bcb3ba43226c8cf46dd9c72c736 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 30 Oct 2024 08:58:46 +0100 Subject: [PATCH 166/183] Uses proper import for isNotUndefined --- lib/generators/shared/type-codename.generator.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/generators/shared/type-codename.generator.ts b/lib/generators/shared/type-codename.generator.ts index c788167..803ea0b 100644 --- a/lib/generators/shared/type-codename.generator.ts +++ b/lib/generators/shared/type-codename.generator.ts @@ -1,9 +1,8 @@ import { CollectionModels, ContentTypeModels, ContentTypeSnippetModels, LanguageModels, WorkflowModels } from '@kontent-ai/management-sdk'; -import { isNotUndefined } from '@kontent-ai/migration-toolkit'; import { match, P } from 'ts-pattern'; import { sharedTypesConfig } from '../../config.js'; import { ObjectWithCodename } from '../../core/core.models.js'; -import { uniqueFilter } from '../../core/core.utils.js'; +import { isNotUndefined, uniqueFilter } from '../../core/core.utils.js'; export function getLanguageCodenamesType(languages: readonly Readonly[]): string { return getTypeWithCodenames(sharedTypesConfig.languageCodenames, languages); From 9ac746880414750fe158cb427e5137ecba0fb8cc Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 30 Oct 2024 08:59:11 +0100 Subject: [PATCH 167/183] chore(release): 8.0.0-8 --- CHANGELOG.md | 2 ++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 514f03f..14e5735 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [8.0.0-8](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-7...v8.0.0-8) (2024-10-30) + ## [8.0.0-7](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-6...v8.0.0-7) (2024-10-29) ## [8.0.0-6](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-5...v8.0.0-6) (2024-10-08) diff --git a/package-lock.json b/package-lock.json index f60a059..24b18a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-7", + "version": "8.0.0-8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@kontent-ai/model-generator", - "version": "8.0.0-7", + "version": "8.0.0-8", "license": "MIT", "dependencies": { "@kontent-ai/delivery-sdk": "15.2.0", diff --git a/package.json b/package.json index 1bdb80c..fa198b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-7", + "version": "8.0.0-8", "description": "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.", "bin": { "kontent-generate": "./dist/lib/code/app.js" From 8bffb3d9eaa8c9d5f0f19a6046e488298ac91365 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 11 Nov 2024 08:41:05 +0100 Subject: [PATCH 168/183] updates deps & regenerates models --- package-lock.json | 323 +++++++++----------- package.json | 18 +- sample/delivery/index.ts | 27 +- sample/environment/assetFolders.ts | 2 +- sample/environment/collections.ts | 2 +- sample/environment/contentTypeSnippets.ts | 2 +- sample/environment/contentTypes.ts | 2 +- sample/environment/index.ts | 2 +- sample/environment/languages.ts | 2 +- sample/environment/roles.ts | 2 +- sample/environment/taxonomies.ts | 2 +- sample/environment/webhooks.ts | 2 +- sample/environment/workflows.ts | 2 +- sample/migration/content-types/actor.ts | 2 +- sample/migration/content-types/index.ts | 2 +- sample/migration/content-types/movie.ts | 2 +- sample/migration/environment/environment.ts | 2 +- sample/migration/environment/index.ts | 2 +- sample/migration/index.ts | 2 +- sample/migration/migration.ts | 2 +- 20 files changed, 183 insertions(+), 219 deletions(-) diff --git a/package-lock.json b/package-lock.json index 24b18a6..796b1d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,27 +10,27 @@ "license": "MIT", "dependencies": { "@kontent-ai/delivery-sdk": "15.2.0", - "@kontent-ai/management-sdk": "7.5.0", + "@kontent-ai/management-sdk": "7.5.1", "chalk": "5.3.0", "prettier": "3.3.3", - "ts-pattern": "5.4.0", + "ts-pattern": "5.5.0", "yargs": "17.7.2" }, "bin": { "kontent-generate": "dist/lib/code/app.js" }, "devDependencies": { - "@eslint/js": "9.12.0", - "@kontent-ai/migration-toolkit": "2.0.0", + "@eslint/js": "9.14.0", + "@kontent-ai/migration-toolkit": "2.2.2", "@types/eslint__js": "8.42.3", - "@types/node": "22.7.5", + "@types/node": "22.9.0", "@types/yargs": "17.0.33", "dotenv-cli": "7.4.2", - "eslint": "9.12.0", + "eslint": "9.14.0", "standard-version": "9.5.0", - "tsx": "4.19.1", - "typescript": "5.6.2", - "typescript-eslint": "8.8.1" + "tsx": "4.19.2", + "typescript": "5.6.3", + "typescript-eslint": "8.13.0" }, "engines": { "node": ">= 20" @@ -544,9 +544,9 @@ } }, "node_modules/@eslint-community/regexpp": { - "version": "4.11.0", - "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.11.0.tgz", - "integrity": "sha512-G/M/tIiMrTAxEWRfLfQJMmGNX28IxBg4PBz8XqQhqUHLFI6TL2htpIB1iQCj144V5ee/JaKyT9/WZ0MGZWfA7A==", + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.12.1.tgz", + "integrity": "sha512-CCZCDJuduB9OUkFkY2IgppNZMi2lBQgD2qzwXkEia16cge2pijY/aXi96CJMquDMn3nJdlPV1A5KrJEXwfLNzQ==", "dev": true, "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" @@ -589,9 +589,9 @@ } }, "node_modules/@eslint/core": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.6.0.tgz", - "integrity": "sha512-8I2Q8ykA4J0x0o7cg67FPVnehcqWTBehu/lmY+bolPFHGjh49YzGBMXTvpqVgEbBdvNCSxj6iFgiIyHzf03lzg==", + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@eslint/core/-/core-0.7.0.tgz", + "integrity": "sha512-xp5Jirz5DyPYlPiKat8jaq0EmYvDXKKpzTbxXMpT9eqlRJkRKIz9AGMdlvYjih+im+QlhWrpvVjl8IPC/lHlUw==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -643,9 +643,9 @@ } }, "node_modules/@eslint/js": { - "version": "9.12.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.12.0.tgz", - "integrity": "sha512-eohesHH8WFRUprDNyEREgqP6beG6htMeUYeCpkEgBCieCMme5r9zFWjzAJp//9S+Kub4rqE+jXe9Cp1a7IYIIA==", + "version": "9.14.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-9.14.0.tgz", + "integrity": "sha512-pFoEtFWCPyDOl+C6Ift+wC7Ro89otjigCf5vcuWqWgqNSQbRrpjSvdeE6ofLz4dHmyxD5f7gIdGT4+p36L6Twg==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -673,27 +673,40 @@ } }, "node_modules/@humanfs/core": { - "version": "0.19.0", - "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.0.tgz", - "integrity": "sha512-2cbWIHbZVEweE853g8jymffCA+NCMiuqeECeBBLm8dg2oFdjuGJhgN4UAbI+6v0CKbbhvtXA4qV8YR5Ji86nmw==", + "version": "0.19.1", + "resolved": "https://registry.npmjs.org/@humanfs/core/-/core-0.19.1.tgz", + "integrity": "sha512-5DyQ4+1JEUzejeK1JGICcideyfUbGixgS9jNgex5nqkW+cY7WZhxBigmieN5Qnw9ZosSNVC9KQKyb+GUaGyKUA==", "dev": true, "engines": { "node": ">=18.18.0" } }, "node_modules/@humanfs/node": { - "version": "0.16.5", - "resolved": "https://registry.npmjs.org/@humanfs/node/-/node-0.16.5.tgz", - "integrity": "sha512-KSPA4umqSG4LHYRodq31VDwKAvaTF4xmVlzM8Aeh4PlU1JQ3IG0wiA8C25d3RQ9nJyM3mBHyI53K06VVL/oFFg==", + "version": "0.16.6", + "resolved": "https://registry.npmjs.org/@humanfs/node/-/node-0.16.6.tgz", + "integrity": "sha512-YuI2ZHQL78Q5HbhDiBA1X4LmYdXCKCMQIfw0pw7piHJwyREFebJUvrQN4cMssyES6x+vfUbx1CIpaQUKYdQZOw==", "dev": true, "dependencies": { - "@humanfs/core": "^0.19.0", + "@humanfs/core": "^0.19.1", "@humanwhocodes/retry": "^0.3.0" }, "engines": { "node": ">=18.18.0" } }, + "node_modules/@humanfs/node/node_modules/@humanwhocodes/retry": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.3.1.tgz", + "integrity": "sha512-JBxkERygn7Bv/GbN5Rv8Ul6LVknS+5Bp6RgDC/O8gEBU/yeH5Ui5C/OlWrTb6qct7LjjfT6Re2NxB0ln0yYybA==", + "dev": true, + "engines": { + "node": ">=18.18" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, "node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", @@ -708,9 +721,9 @@ } }, "node_modules/@humanwhocodes/retry": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.3.1.tgz", - "integrity": "sha512-JBxkERygn7Bv/GbN5Rv8Ul6LVknS+5Bp6RgDC/O8gEBU/yeH5Ui5C/OlWrTb6qct7LjjfT6Re2NxB0ln0yYybA==", + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/retry/-/retry-0.4.1.tgz", + "integrity": "sha512-c7hNEllBlenFTHBky65mhq8WD2kbN9Q6gk0bTk8lSBvc554jpXSkST1iePudpt7+A/AQvuHs9EMqjHDXMY1lrA==", "dev": true, "engines": { "node": ">=18.18" @@ -788,9 +801,9 @@ } }, "node_modules/@kontent-ai/management-sdk": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/@kontent-ai/management-sdk/-/management-sdk-7.5.0.tgz", - "integrity": "sha512-/yYTg+els2qstXZbT2QqI2waNuwc3rhgJMy1F1fceQhXJh5wXuThp5O+KUfjGJEfVfzu7vg1cx4pm8R3G6YtkA==", + "version": "7.5.1", + "resolved": "https://registry.npmjs.org/@kontent-ai/management-sdk/-/management-sdk-7.5.1.tgz", + "integrity": "sha512-sx7cwRq3kqamKOm3hNk5nZN5b/B1d+OiPBz9mJRJKG9Oz8ovaQsnKPxVDvvBS50fA5B+iiClXZtV0cWq/Hf2cA==", "dependencies": { "@kontent-ai/core-sdk": "10.8.0", "mime": "3.0.0" @@ -821,13 +834,13 @@ } }, "node_modules/@kontent-ai/migration-toolkit": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@kontent-ai/migration-toolkit/-/migration-toolkit-2.0.0.tgz", - "integrity": "sha512-CnuZfKM/Y2or7jePLrVpZh7sT6lQgAgMJcA+GWfLb14noU5yk7GAYN511d1q1Mz6O32MX8U+6B0Q0zYWQ6ZKGg==", + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/@kontent-ai/migration-toolkit/-/migration-toolkit-2.2.2.tgz", + "integrity": "sha512-+dj4pm2JYFSkiEyO8x56/0pGBYBFJSBMrDCk2PrAbEreoUB8LQWhTEibuBKkkQLwt0kdnMRspHCBxzZhPCXQKQ==", "dev": true, "dependencies": { "@kontent-ai-consulting/tools-analytics": "0.0.7", - "@kontent-ai/management-sdk": "7.4.0", + "@kontent-ai/management-sdk": "7.5.1", "browser-or-node": "3.0.0", "buffer": "6.0.3", "bytes": "3.1.2", @@ -839,7 +852,7 @@ "ora": "8.1.0", "p-limit": "6.1.0", "prompts": "2.4.2", - "ts-pattern": "5.4.0", + "ts-pattern": "5.5.0", "yargs": "17.7.2", "zod": "3.23.8" }, @@ -850,54 +863,6 @@ "node": ">=20" } }, - "node_modules/@kontent-ai/migration-toolkit/node_modules/@kontent-ai/core-sdk": { - "version": "10.8.0", - "resolved": "https://registry.npmjs.org/@kontent-ai/core-sdk/-/core-sdk-10.8.0.tgz", - "integrity": "sha512-6o5kn+ANhJ7vCucWXunxy1qCSSDsN3F86zdLXzPnFaK/qOf4BJGnPda81Alvnt4N7n4e1m9J7uP0tm3tQ/W25Q==", - "dev": true, - "dependencies": { - "axios": "1.7.7" - }, - "engines": { - "node": ">= 20" - } - }, - "node_modules/@kontent-ai/migration-toolkit/node_modules/@kontent-ai/management-sdk": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/@kontent-ai/management-sdk/-/management-sdk-7.4.0.tgz", - "integrity": "sha512-/gKLaI2A69/sRKOmRCsQFhv/V+R/qRE5/hy7KTNUsXjtA39thVFCt5L6OsCsfAH0rxb5qYtlJM5qJ4KbgYdVfQ==", - "dev": true, - "dependencies": { - "@kontent-ai/core-sdk": "10.8.0", - "mime": "3.0.0" - }, - "engines": { - "node": ">= 20" - } - }, - "node_modules/@kontent-ai/migration-toolkit/node_modules/@kontent-ai/management-sdk/node_modules/mime": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz", - "integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==", - "dev": true, - "bin": { - "mime": "cli.js" - }, - "engines": { - "node": ">=10.0.0" - } - }, - "node_modules/@kontent-ai/migration-toolkit/node_modules/axios": { - "version": "1.7.7", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.7.tgz", - "integrity": "sha512-S4kL7XrjgBmvdGut0sN3yJxqYzrDOnivkBiN0OFs6hLiUam3UPvswUo0kqGyhqUZGEOytHyumEdXsAkgCOUf3Q==", - "dev": true, - "dependencies": { - "follow-redirects": "^1.15.6", - "form-data": "^4.0.0", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/@kontent-ai/migration-toolkit/node_modules/mime": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/mime/-/mime-4.0.4.tgz", @@ -986,12 +951,12 @@ "dev": true }, "node_modules/@types/node": { - "version": "22.7.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.7.5.tgz", - "integrity": "sha512-jML7s2NAzMWc//QSJ1a3prpk78cOPchGvXJsC3C6R6PSMoooztvRVQEz89gmBTBY1SPMaqo5teB4uNHPdetShQ==", + "version": "22.9.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.9.0.tgz", + "integrity": "sha512-vuyHg81vvWA1Z1ELfvLko2c8f34gyA0zaic0+Rllc5lbCnbSyuvb2Oxpm6TAUAC/2xZN3QGqxBNggD1nNR2AfQ==", "dev": true, "dependencies": { - "undici-types": "~6.19.2" + "undici-types": "~6.19.8" } }, "node_modules/@types/normalize-package-data": { @@ -1016,16 +981,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.8.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.8.1.tgz", - "integrity": "sha512-xfvdgA8AP/vxHgtgU310+WBnLB4uJQ9XdyP17RebG26rLtDrQJV3ZYrcopX91GrHmMoH8bdSwMRh2a//TiJ1jQ==", + "version": "8.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.13.0.tgz", + "integrity": "sha512-nQtBLiZYMUPkclSeC3id+x4uVd1SGtHuElTxL++SfP47jR0zfkZBJHc+gL4qPsgTuypz0k8Y2GheaDYn6Gy3rg==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "8.8.1", - "@typescript-eslint/type-utils": "8.8.1", - "@typescript-eslint/utils": "8.8.1", - "@typescript-eslint/visitor-keys": "8.8.1", + "@typescript-eslint/scope-manager": "8.13.0", + "@typescript-eslint/type-utils": "8.13.0", + "@typescript-eslint/utils": "8.13.0", + "@typescript-eslint/visitor-keys": "8.13.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", @@ -1049,15 +1014,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.8.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.8.1.tgz", - "integrity": "sha512-hQUVn2Lij2NAxVFEdvIGxT9gP1tq2yM83m+by3whWFsWC+1y8pxxxHUFE1UqDu2VsGi2i6RLcv4QvouM84U+ow==", + "version": "8.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.13.0.tgz", + "integrity": "sha512-w0xp+xGg8u/nONcGw1UXAr6cjCPU1w0XVyBs6Zqaj5eLmxkKQAByTdV/uGgNN5tVvN/kKpoQlP2cL7R+ajZZIQ==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "8.8.1", - "@typescript-eslint/types": "8.8.1", - "@typescript-eslint/typescript-estree": "8.8.1", - "@typescript-eslint/visitor-keys": "8.8.1", + "@typescript-eslint/scope-manager": "8.13.0", + "@typescript-eslint/types": "8.13.0", + "@typescript-eslint/typescript-estree": "8.13.0", + "@typescript-eslint/visitor-keys": "8.13.0", "debug": "^4.3.4" }, "engines": { @@ -1077,13 +1042,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.8.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.8.1.tgz", - "integrity": "sha512-X4JdU+66Mazev/J0gfXlcC/dV6JI37h+93W9BRYXrSn0hrE64IoWgVkO9MSJgEzoWkxONgaQpICWg8vAN74wlA==", + "version": "8.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.13.0.tgz", + "integrity": "sha512-XsGWww0odcUT0gJoBZ1DeulY1+jkaHUciUq4jKNv4cpInbvvrtDoyBH9rE/n2V29wQJPk8iCH1wipra9BhmiMA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.8.1", - "@typescript-eslint/visitor-keys": "8.8.1" + "@typescript-eslint/types": "8.13.0", + "@typescript-eslint/visitor-keys": "8.13.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1094,13 +1059,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.8.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.8.1.tgz", - "integrity": "sha512-qSVnpcbLP8CALORf0za+vjLYj1Wp8HSoiI8zYU5tHxRVj30702Z1Yw4cLwfNKhTPWp5+P+k1pjmD5Zd1nhxiZA==", + "version": "8.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.13.0.tgz", + "integrity": "sha512-Rqnn6xXTR316fP4D2pohZenJnp+NwQ1mo7/JM+J1LWZENSLkJI8ID8QNtlvFeb0HnFSK94D6q0cnMX6SbE5/vA==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "8.8.1", - "@typescript-eslint/utils": "8.8.1", + "@typescript-eslint/typescript-estree": "8.13.0", + "@typescript-eslint/utils": "8.13.0", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -1118,9 +1083,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "8.8.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.8.1.tgz", - "integrity": "sha512-WCcTP4SDXzMd23N27u66zTKMuEevH4uzU8C9jf0RO4E04yVHgQgW+r+TeVTNnO1KIfrL8ebgVVYYMMO3+jC55Q==", + "version": "8.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.13.0.tgz", + "integrity": "sha512-4cyFErJetFLckcThRUFdReWJjVsPCqyBlJTi6IDEpc1GWCIIZRFxVppjWLIMcQhNGhdWJJRYFHpHoDWvMlDzng==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1131,13 +1096,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.8.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.8.1.tgz", - "integrity": "sha512-A5d1R9p+X+1js4JogdNilDuuq+EHZdsH9MjTVxXOdVFfTJXunKJR/v+fNNyO4TnoOn5HqobzfRlc70NC6HTcdg==", + "version": "8.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.13.0.tgz", + "integrity": "sha512-v7SCIGmVsRK2Cy/LTLGN22uea6SaUIlpBcO/gnMGT/7zPtxp90bphcGf4fyrCQl3ZtiBKqVTG32hb668oIYy1g==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.8.1", - "@typescript-eslint/visitor-keys": "8.8.1", + "@typescript-eslint/types": "8.13.0", + "@typescript-eslint/visitor-keys": "8.13.0", "debug": "^4.3.4", "fast-glob": "^3.3.2", "is-glob": "^4.0.3", @@ -1159,15 +1124,15 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "8.8.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.8.1.tgz", - "integrity": "sha512-/QkNJDbV0bdL7H7d0/y0qBbV2HTtf0TIyjSDTvvmQEzeVx8jEImEbLuOA4EsvE8gIgqMitns0ifb5uQhMj8d9w==", + "version": "8.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.13.0.tgz", + "integrity": "sha512-A1EeYOND6Uv250nybnLZapeXpYMl8tkzYUxqmoKAWnI4sei3ihf2XdZVd+vVOmHGcp3t+P7yRrNsyyiXTvShFQ==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "8.8.1", - "@typescript-eslint/types": "8.8.1", - "@typescript-eslint/typescript-estree": "8.8.1" + "@typescript-eslint/scope-manager": "8.13.0", + "@typescript-eslint/types": "8.13.0", + "@typescript-eslint/typescript-estree": "8.13.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -1181,12 +1146,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.8.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.8.1.tgz", - "integrity": "sha512-0/TdC3aeRAsW7MDvYRwEc1Uwm0TIBfzjPFgg60UU2Haj5qsCs9cc3zNgY71edqE3LbWfF/WoZQd3lJoDXFQpag==", + "version": "8.13.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.13.0.tgz", + "integrity": "sha512-7N/+lztJqH4Mrf0lb10R/CbI1EaAMMGyF5y0oJvFoAhafwgiRA7TXyd8TFn8FC8k5y2dTsYogg238qavRGNnlw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "8.8.1", + "@typescript-eslint/types": "8.13.0", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -1198,9 +1163,9 @@ } }, "node_modules/acorn": { - "version": "8.12.1", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", - "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", + "version": "8.14.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz", + "integrity": "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==", "dev": true, "bin": { "acorn": "bin/acorn" @@ -2325,21 +2290,21 @@ } }, "node_modules/eslint": { - "version": "9.12.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.12.0.tgz", - "integrity": "sha512-UVIOlTEWxwIopRL1wgSQYdnVDcEvs2wyaO6DGo5mXqe3r16IoCNWkR29iHhyaP4cICWjbgbmFUGAhh0GJRuGZw==", + "version": "9.14.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-9.14.0.tgz", + "integrity": "sha512-c2FHsVBr87lnUtjP4Yhvk4yEhKrQavGafRA/Se1ouse8PfbfC/Qh9Mxa00yWsZRlqeUB9raXip0aiiUZkgnr9g==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", - "@eslint-community/regexpp": "^4.11.0", + "@eslint-community/regexpp": "^4.12.1", "@eslint/config-array": "^0.18.0", - "@eslint/core": "^0.6.0", + "@eslint/core": "^0.7.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.12.0", + "@eslint/js": "9.14.0", "@eslint/plugin-kit": "^0.2.0", - "@humanfs/node": "^0.16.5", + "@humanfs/node": "^0.16.6", "@humanwhocodes/module-importer": "^1.0.1", - "@humanwhocodes/retry": "^0.3.1", + "@humanwhocodes/retry": "^0.4.0", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", @@ -2347,9 +2312,9 @@ "cross-spawn": "^7.0.2", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^8.1.0", - "eslint-visitor-keys": "^4.1.0", - "espree": "^10.2.0", + "eslint-scope": "^8.2.0", + "eslint-visitor-keys": "^4.2.0", + "espree": "^10.3.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -2385,9 +2350,9 @@ } }, "node_modules/eslint-scope": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.1.0.tgz", - "integrity": "sha512-14dSvlhaVhKKsa9Fx1l8A17s7ah7Ef7wCakJ10LYk6+GYmP9yDti2oq2SEwcyndt6knfcZyhyxwY3i9yL78EQw==", + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-8.2.0.tgz", + "integrity": "sha512-PHlWUfG6lvPc3yvP5A4PNyBL1W8fkDUccmI21JUu/+GKZBoH/W5u6usENXUrWFRsyoW5ACUjFGgAFQp5gUlb/A==", "dev": true, "dependencies": { "esrecurse": "^4.3.0", @@ -2439,9 +2404,9 @@ } }, "node_modules/eslint/node_modules/eslint-visitor-keys": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.1.0.tgz", - "integrity": "sha512-Q7lok0mqMUSf5a/AdAZkA5a/gHcO6snwQClVNNvFKCAVlxXucdU8pKydU5ZVZjBx5xr37vGbFFWtLQYreLzrZg==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.0.tgz", + "integrity": "sha512-UyLnSehNt62FFhSwjZlHmeokpRK59rcz29j+F1/aDgbkbRTk7wIc9XzdoasMUbRNKDM0qQt/+BJ4BrpFeABemw==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -2463,14 +2428,14 @@ } }, "node_modules/espree": { - "version": "10.2.0", - "resolved": "https://registry.npmjs.org/espree/-/espree-10.2.0.tgz", - "integrity": "sha512-upbkBJbckcCNBDBDXEbuhjbP68n+scUd3k/U2EkyM9nw+I/jPiL4cLF/Al06CF96wRltFda16sxDFrxsI1v0/g==", + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/espree/-/espree-10.3.0.tgz", + "integrity": "sha512-0QYC8b24HWY8zjRnDTL6RiHfDbAWn63qb4LMj1Z4b076A4une81+z03Kg7l7mn/48PUTqoLptSXez8oknU8Clg==", "dev": true, "dependencies": { - "acorn": "^8.12.0", + "acorn": "^8.14.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.1.0" + "eslint-visitor-keys": "^4.2.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -2480,9 +2445,9 @@ } }, "node_modules/espree/node_modules/eslint-visitor-keys": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.1.0.tgz", - "integrity": "sha512-Q7lok0mqMUSf5a/AdAZkA5a/gHcO6snwQClVNNvFKCAVlxXucdU8pKydU5ZVZjBx5xr37vGbFFWtLQYreLzrZg==", + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.0.tgz", + "integrity": "sha512-UyLnSehNt62FFhSwjZlHmeokpRK59rcz29j+F1/aDgbkbRTk7wIc9XzdoasMUbRNKDM0qQt/+BJ4BrpFeABemw==", "dev": true, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -5365,9 +5330,9 @@ } }, "node_modules/ts-api-utils": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.3.0.tgz", - "integrity": "sha512-UQMIo7pb8WRomKR1/+MFVLTroIvDVtMX3K6OUir8ynLyzB8Jeriont2bTAtmNPa1ekAgN7YPDyf6V+ygrdU+eQ==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.4.0.tgz", + "integrity": "sha512-032cPxaEKwM+GT3vA5JXNzIaizx388rhsSW79vGRNGXfRRAdEAn2mvk36PvK5HnOchyWZ7afLEXqYCvPCrzuzQ==", "dev": true, "engines": { "node": ">=16" @@ -5377,14 +5342,14 @@ } }, "node_modules/ts-pattern": { - "version": "5.4.0", - "resolved": "https://registry.npmjs.org/ts-pattern/-/ts-pattern-5.4.0.tgz", - "integrity": "sha512-hgfOMfjlrARCnYtGD/xEAkFHDXuSyuqjzFSltyQCbN689uNvoQL20TVN2XFcLMjfNuwSsQGU+xtH6MrjIwhwUg==" + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/ts-pattern/-/ts-pattern-5.5.0.tgz", + "integrity": "sha512-jqbIpTsa/KKTJYWgPNsFNbLVpwCgzXfFJ1ukNn4I8hMwyQzHMJnk/BqWzggB0xpkILuKzaO/aMYhS0SkaJyKXg==" }, "node_modules/tsx": { - "version": "4.19.1", - "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.19.1.tgz", - "integrity": "sha512-0flMz1lh74BR4wOvBjuh9olbnwqCPc35OOlfyzHba0Dc+QNUeWX/Gq2YTbnwcWPO3BMd8fkzRVrHcsR+a7z7rA==", + "version": "4.19.2", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.19.2.tgz", + "integrity": "sha512-pOUl6Vo2LUq/bSa8S5q7b91cgNSjctn9ugq/+Mvow99qW6x/UZYwzxy/3NmqoT66eHYfCVvFvACC58UBPFf28g==", "dev": true, "dependencies": { "esbuild": "~0.23.0", @@ -5431,9 +5396,9 @@ "dev": true }, "node_modules/typescript": { - "version": "5.6.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz", - "integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==", + "version": "5.6.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz", + "integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -5444,14 +5409,14 @@ } }, "node_modules/typescript-eslint": { - "version": "8.8.1", - "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.8.1.tgz", - "integrity": "sha512-R0dsXFt6t4SAFjUSKFjMh4pXDtq04SsFKCVGDP3ZOzNP7itF0jBcZYU4fMsZr4y7O7V7Nc751dDeESbe4PbQMQ==", + "version": "8.13.0", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.13.0.tgz", + "integrity": "sha512-vIMpDRJrQd70au2G8w34mPps0ezFSPMEX4pXkTzUkrNbRX+36ais2ksGWN0esZL+ZMaFJEneOBHzCgSqle7DHw==", "dev": true, "dependencies": { - "@typescript-eslint/eslint-plugin": "8.8.1", - "@typescript-eslint/parser": "8.8.1", - "@typescript-eslint/utils": "8.8.1" + "@typescript-eslint/eslint-plugin": "8.13.0", + "@typescript-eslint/parser": "8.13.0", + "@typescript-eslint/utils": "8.13.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -5480,9 +5445,9 @@ } }, "node_modules/undici-types": { - "version": "6.19.6", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.6.tgz", - "integrity": "sha512-e/vggGopEfTKSvj4ihnOLTsqhrKRN3LeO6qSN/GxohhuRv8qH9bNQ4B8W7e/vFL+0XTnmHPB4/kegunZGA4Org==", + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", "dev": true }, "node_modules/uri-js": { diff --git a/package.json b/package.json index fa198b2..28308cd 100644 --- a/package.json +++ b/package.json @@ -49,24 +49,24 @@ "update:version": "tsx ./scripts/update-version.ts" }, "dependencies": { - "@kontent-ai/management-sdk": "7.5.0", + "@kontent-ai/management-sdk": "7.5.1", "@kontent-ai/delivery-sdk": "15.2.0", "chalk": "5.3.0", "prettier": "3.3.3", - "ts-pattern": "5.4.0", + "ts-pattern": "5.5.0", "yargs": "17.7.2" }, "devDependencies": { - "@eslint/js": "9.12.0", - "@kontent-ai/migration-toolkit": "2.0.0", + "@eslint/js": "9.14.0", + "@kontent-ai/migration-toolkit": "2.2.2", "@types/eslint__js": "8.42.3", - "@types/node": "22.7.5", + "@types/node": "22.9.0", "@types/yargs": "17.0.33", "dotenv-cli": "7.4.2", - "eslint": "9.12.0", + "eslint": "9.14.0", "standard-version": "9.5.0", - "tsx": "4.19.1", - "typescript": "5.6.2", - "typescript-eslint": "8.8.1" + "tsx": "4.19.2", + "typescript": "5.6.3", + "typescript-eslint": "8.13.0" } } diff --git a/sample/delivery/index.ts b/sample/delivery/index.ts index a93bf4e..b223413 100644 --- a/sample/delivery/index.ts +++ b/sample/delivery/index.ts @@ -1,17 +1,16 @@ - -/** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. -* -* (c) Kontent.ai -* -* ------------------------------------------------------------------------------- -* -* Project: Movie Database -* Environment: Production -* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 -* -* ------------------------------------------------------------------------------- -**/ +/** + * This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. + * + * (c) Kontent.ai + * + * ------------------------------------------------------------------------------- + * + * Project: Movie Database + * Environment: Production + * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 + * + * ------------------------------------------------------------------------------- + **/ export * from './content-type-snippets/index.js'; export * from './content-types/index.js'; diff --git a/sample/environment/assetFolders.ts b/sample/environment/assetFolders.ts index 156c402..8db2c78 100644 --- a/sample/environment/assetFolders.ts +++ b/sample/environment/assetFolders.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/environment/collections.ts b/sample/environment/collections.ts index e1c4057..1ba9775 100644 --- a/sample/environment/collections.ts +++ b/sample/environment/collections.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/environment/contentTypeSnippets.ts b/sample/environment/contentTypeSnippets.ts index 7c6cbba..131b2fa 100644 --- a/sample/environment/contentTypeSnippets.ts +++ b/sample/environment/contentTypeSnippets.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/environment/contentTypes.ts b/sample/environment/contentTypes.ts index 4ce7cb4..0a562e3 100644 --- a/sample/environment/contentTypes.ts +++ b/sample/environment/contentTypes.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/environment/index.ts b/sample/environment/index.ts index b536195..495b6fa 100644 --- a/sample/environment/index.ts +++ b/sample/environment/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/environment/languages.ts b/sample/environment/languages.ts index ea2742c..577ed8f 100644 --- a/sample/environment/languages.ts +++ b/sample/environment/languages.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/environment/roles.ts b/sample/environment/roles.ts index 0450265..a72d3f5 100644 --- a/sample/environment/roles.ts +++ b/sample/environment/roles.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/environment/taxonomies.ts b/sample/environment/taxonomies.ts index 79ad7da..341710b 100644 --- a/sample/environment/taxonomies.ts +++ b/sample/environment/taxonomies.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/environment/webhooks.ts b/sample/environment/webhooks.ts index ffa2841..36125f6 100644 --- a/sample/environment/webhooks.ts +++ b/sample/environment/webhooks.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/environment/workflows.ts b/sample/environment/workflows.ts index 47eefcf..62af032 100644 --- a/sample/environment/workflows.ts +++ b/sample/environment/workflows.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/migration/content-types/actor.ts b/sample/migration/content-types/actor.ts index e39f60f..ff6654e 100644 --- a/sample/migration/content-types/actor.ts +++ b/sample/migration/content-types/actor.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/migration/content-types/index.ts b/sample/migration/content-types/index.ts index c05bf8f..b33a70c 100644 --- a/sample/migration/content-types/index.ts +++ b/sample/migration/content-types/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/migration/content-types/movie.ts b/sample/migration/content-types/movie.ts index 506f899..11797de 100644 --- a/sample/migration/content-types/movie.ts +++ b/sample/migration/content-types/movie.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/migration/environment/environment.ts b/sample/migration/environment/environment.ts index 4419167..3591bd6 100644 --- a/sample/migration/environment/environment.ts +++ b/sample/migration/environment/environment.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/migration/environment/index.ts b/sample/migration/environment/index.ts index ad44f85..6bb7831 100644 --- a/sample/migration/environment/index.ts +++ b/sample/migration/environment/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/migration/index.ts b/sample/migration/index.ts index 945a217..b4d2a1c 100644 --- a/sample/migration/index.ts +++ b/sample/migration/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/migration/migration.ts b/sample/migration/migration.ts index 1f9e0bb..564b14d 100644 --- a/sample/migration/migration.ts +++ b/sample/migration/migration.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * From c601a00d7268ae04f6cd4c2bbb331a96eafc044a Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 11 Nov 2024 10:38:32 +0100 Subject: [PATCH 169/183] Generates type guards for delivery models --- lib/config.ts | 1 + lib/core/resolvers.ts | 21 +++++++---- .../delivery-content-type.generator.ts | 28 +++++++++------ .../delivery/delivery-type-guard.generator.ts | 28 +++++++++++++++ sample/delivery/content-types/actor.ts | 17 ++++++--- sample/delivery/content-types/movie.ts | 35 +++++++++++-------- sample/delivery/index.ts | 27 +++++++------- 7 files changed, 108 insertions(+), 49 deletions(-) create mode 100644 lib/generators/delivery/delivery-type-guard.generator.ts diff --git a/lib/config.ts b/lib/config.ts index b1092cc..cd2e984 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -46,6 +46,7 @@ export const deliveryConfig = { contentTypesFolderName: `content-types`, contentTypeSnippetsFolderName: `content-type-snippets`, taxonomiesFolderName: `taxonomies`, + typeGuardsFileName: 'delivery.type-guards', systemTypesFolderName: 'system', coreCodenamesFilename: 'delivery.codenames', coreTypeFilename: 'core.type', diff --git a/lib/core/resolvers.ts b/lib/core/resolvers.ts index 467af59..16691c8 100644 --- a/lib/core/resolvers.ts +++ b/lib/core/resolvers.ts @@ -33,13 +33,22 @@ export function mapFilename(resolver: FilenameReso }; } -export function mapName(resolver: NameResolver, defaultCase: CaseType): MapObjectToName { +export function mapName( + resolver: NameResolver, + defaultCase: CaseType, + options?: { + prefix?: string; + } +): MapObjectToName { return (item) => { - return match(resolver) - .returnType() - .with(P.instanceOf(Function), (resolver) => resolver(item)) - .with(undefined, () => resolveCase(item.name, defaultCase)) - .otherwise((resolverType) => resolveCase(item.name, resolverType)); + return ( + `${options?.prefix ? options.prefix : ''}` + + match(resolver) + .returnType() + .with(P.instanceOf(Function), (resolver) => resolver(item)) + .with(undefined, () => resolveCase(item.name, defaultCase)) + .otherwise((resolverType) => resolveCase(item.name, resolverType)) + ); }; } diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index 758d224..b014306 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -32,6 +32,7 @@ import { getWorkflowCodenamesType, getWorkflowStepCodenamesType } from '../shared/type-codename.generator.js'; +import { deliveryTypeGuardGenerator } from './delivery-type-guard.generator.js'; interface ExtractImportsResult { readonly typeName: string; @@ -268,11 +269,6 @@ ${importer.importType({ })} ${importsResult.imports.join('\n')} -${wrapComment(` -* Type representing all available element codenames for ${snippet.name} -`)} -${getContentTypeElementCodenamesType(nameOfTypeRepresentingAllElementCodenames, flattenedElements)} - ${wrapComment(` * ${snippet.name} * @@ -281,6 +277,11 @@ ${wrapComment(` `)} export type ${importsResult.typeName} = ${deliveryConfig.sdkTypes.snippet}<${nameOfTypeRepresentingAllElementCodenames}, ${getElementsCode(flattenedElements)}>; + +${wrapComment(` +* Type representing all available element codenames for ${snippet.name} +`)} +${getContentTypeElementCodenamesType(nameOfTypeRepresentingAllElementCodenames, flattenedElements)} `; }; @@ -306,11 +307,6 @@ ${importer.importType({ })} ${importsResult.imports.join('\n')} -${wrapComment(` -* Type representing all available element codenames for ${contentType.name} -`)} -${getContentTypeElementCodenamesType(nameOfTypeRepresentingAllElementCodenames, flattenedElements)} - ${wrapComment(` * ${contentType.name} * @@ -319,7 +315,17 @@ ${wrapComment(` `)} export type ${importsResult.typeName} = ${deliveryConfig.coreContentTypeName}< ${getElementsCode(flattenedElements)}${importsResult.contentTypeExtends ? ` ${importsResult.contentTypeExtends}` : ''}, -'${contentType.codename}'>; +'${contentType.codename}'> + +${wrapComment(` +* Type representing all available element codenames for ${contentType.name} +`)} +${getContentTypeElementCodenamesType(nameOfTypeRepresentingAllElementCodenames, flattenedElements)}; + +${wrapComment(` +* Type guard for ${contentType.name} +`)} +${deliveryTypeGuardGenerator(config).getTypeGuardFunction(contentType)}; `; }; diff --git a/lib/generators/delivery/delivery-type-guard.generator.ts b/lib/generators/delivery/delivery-type-guard.generator.ts new file mode 100644 index 0000000..e88f4c5 --- /dev/null +++ b/lib/generators/delivery/delivery-type-guard.generator.ts @@ -0,0 +1,28 @@ +import { ContentTypeModels } from '@kontent-ai/management-sdk'; +import { deliveryConfig } from '../../config.js'; +import { ContentTypeNameResolver, mapName } from '../../core/resolvers.js'; + +export interface DeliveryTypeGuardGeneratorConfig { + readonly nameResolvers?: { + readonly contentType?: ContentTypeNameResolver; + }; +} + +export function deliveryTypeGuardGenerator(config: DeliveryTypeGuardGeneratorConfig) { + const nameResolvers = { + typeGuardFunctionName: mapName(config.nameResolvers?.contentType, 'pascalCase', { + prefix: 'is' + }), + typeName: mapName(config.nameResolvers?.contentType, 'pascalCase') + }; + + const getTypeGuardFunction = (contentType: Readonly): string => { + return `export function ${nameResolvers.typeGuardFunctionName(contentType)}(item: ${deliveryConfig.coreContentTypeName}): item is ${nameResolvers.typeName(contentType)} { + return item.system.type === '${contentType.codename}'; + }`; + }; + + return { + getTypeGuardFunction + }; +} diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index ef6042d..aeef488 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -16,11 +16,6 @@ import type { Elements } from '@kontent-ai/delivery-sdk'; import type { CoreContentType } from '../system/index.js'; -/** - * Type representing all available element codenames for Actor - */ -export type ActorElementCodenames = 'url' | 'first_name' | 'last_name' | 'photo'; - /** * Actor * @@ -69,3 +64,15 @@ export type Actor = CoreContentType< }, 'actor' >; + +/** + * Type representing all available element codenames for Actor + */ +export type ActorElementCodenames = 'url' | 'first_name' | 'last_name' | 'photo'; + +/** + * Type guard for Actor + */ +export function isActor(item: CoreContentType): item is Actor { + return item.system.type === 'actor'; +} diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 657b442..c0058dd 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -18,20 +18,6 @@ import type { Actor } from './index.js'; import type { CoreContentType } from '../system/index.js'; import type { Releasecategory } from '../taxonomies/index.js'; -/** - * Type representing all available element codenames for Movie - */ -export type MovieElementCodenames = - | 'title' - | 'plot' - | 'released' - | 'length' - | 'poster' - | 'category' - | 'stars' - | 'seoname' - | 'releasecategory'; - /** * Movie * @@ -126,3 +112,24 @@ export type Movie = CoreContentType< }, 'movie' >; + +/** + * Type representing all available element codenames for Movie + */ +export type MovieElementCodenames = + | 'title' + | 'plot' + | 'released' + | 'length' + | 'poster' + | 'category' + | 'stars' + | 'seoname' + | 'releasecategory'; + +/** + * Type guard for Movie + */ +export function isMovie(item: CoreContentType): item is Movie { + return item.system.type === 'movie'; +} diff --git a/sample/delivery/index.ts b/sample/delivery/index.ts index b223413..a93bf4e 100644 --- a/sample/delivery/index.ts +++ b/sample/delivery/index.ts @@ -1,16 +1,17 @@ -/** - * This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. - * - * (c) Kontent.ai - * - * ------------------------------------------------------------------------------- - * - * Project: Movie Database - * Environment: Production - * Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 - * - * ------------------------------------------------------------------------------- - **/ + +/** +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. +* +* (c) Kontent.ai +* +* ------------------------------------------------------------------------------- +* +* Project: Movie Database +* Environment: Production +* Id: da5abe9f-fdad-4168-97cd-b3464be2ccb9 +* +* ------------------------------------------------------------------------------- +**/ export * from './content-type-snippets/index.js'; export * from './content-types/index.js'; From 4c58a6ae5c6660f170e533973ff0039dc1bdebcf Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 11 Nov 2024 11:17:40 +0100 Subject: [PATCH 170/183] fixes command path --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 28308cd..63f663f 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "8.0.0-8", "description": "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.", "bin": { - "kontent-generate": "./dist/lib/code/app.js" + "kontent-generate": "./dist/lib/cli/app.js" }, "repository": { "type": "git", From 8f6d4c2c99f98181e4800655cad198b6fd462702 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 11 Nov 2024 11:18:57 +0100 Subject: [PATCH 171/183] chore(release): 8.0.0-9 --- CHANGELOG.md | 2 ++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14e5735..f0a0bcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [8.0.0-9](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-8...v8.0.0-9) (2024-11-11) + ## [8.0.0-8](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-7...v8.0.0-8) (2024-10-30) ## [8.0.0-7](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-6...v8.0.0-7) (2024-10-29) diff --git a/package-lock.json b/package-lock.json index 796b1d6..0da2251 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-8", + "version": "8.0.0-9", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@kontent-ai/model-generator", - "version": "8.0.0-8", + "version": "8.0.0-9", "license": "MIT", "dependencies": { "@kontent-ai/delivery-sdk": "15.2.0", diff --git a/package.json b/package.json index 63f663f..fe51ca7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-8", + "version": "8.0.0-9", "description": "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.", "bin": { "kontent-generate": "./dist/lib/cli/app.js" From 70cd7e603bb52b2c89a0b23e0d89b0bc5ee98522 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 11 Nov 2024 12:48:51 +0100 Subject: [PATCH 172/183] Fixes & simplifies toCamelCase function --- lib/core/core.utils.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/core/core.utils.ts b/lib/core/core.utils.ts index 1030588..fc29a68 100644 --- a/lib/core/core.utils.ts +++ b/lib/core/core.utils.ts @@ -33,16 +33,9 @@ export function toPascalCase(text: string): string { } export function toCamelCase(text: string): string { - return prefixWithUnderscoreWhenStartsWithNonAlpha( - toSafeStringCode( - text - .replace(/(?:^\w|\b\w)/g, (word, index) => { - return index === 0 ? word.toLowerCase() : word.toUpperCase(); - }) - .replace(/\s+/g, '') - ) - ); + return toPascalCase(text).replace(/^\w/, (s) => s.toLowerCase()); } + export function toGuidelinesComment(guidelines: string): string { return removeLineEndings(guidelines); } From 5bdb89ce9d3949166808fc095107e23550003abf Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 11 Nov 2024 12:54:18 +0100 Subject: [PATCH 173/183] Use codename for property name by default instead of converting to camelCase when not necessary --- lib/generators/environment/environment.generator.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generators/environment/environment.generator.ts b/lib/generators/environment/environment.generator.ts index c698997..addbea2 100644 --- a/lib/generators/environment/environment.generator.ts +++ b/lib/generators/environment/environment.generator.ts @@ -230,7 +230,7 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { ${wrapComment(` * ${option.name} `)} - ${toSafePropertyName(option.codename ?? option.name)}: { + ${option.codename ? option.codename : toSafePropertyName(option.name)}: { name: '${toSafePropertyValue(option.name)}', id: '${option.id}', codename: ${getStringOrUndefined(option.codename)}, @@ -284,7 +284,7 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { ${wrapComment(` * ${role.name} `)} - ${toSafePropertyName(role.codename ?? role.name)}: { + ${role.codename ? role.codename : toSafePropertyName(role.name)}: { codename: ${getStringOrUndefined(role.codename)}, id: '${role.id}', name: '${toSafePropertyValue(role.name)}' From 861713d8d3e530412d438e87fe24e3df8f852a08 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 11 Nov 2024 12:54:23 +0100 Subject: [PATCH 174/183] updates samples --- sample/items/codenames/actor.codenames.ts | 2 +- sample/items/codenames/index.ts | 2 +- sample/items/codenames/movie.codenames.ts | 2 +- sample/items/index.ts | 2 +- sample/items/items/actor.items.ts | 2 +- sample/items/items/index.ts | 2 +- sample/items/items/movie.items.ts | 2 +- scripts/samples/delivery-models.ts | 3 ++- 8 files changed, 9 insertions(+), 8 deletions(-) diff --git a/sample/items/codenames/actor.codenames.ts b/sample/items/codenames/actor.codenames.ts index daf932e..6c77904 100644 --- a/sample/items/codenames/actor.codenames.ts +++ b/sample/items/codenames/actor.codenames.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/items/codenames/index.ts b/sample/items/codenames/index.ts index ac86f7f..c78ebd3 100644 --- a/sample/items/codenames/index.ts +++ b/sample/items/codenames/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/items/codenames/movie.codenames.ts b/sample/items/codenames/movie.codenames.ts index c11a52b..2019a57 100644 --- a/sample/items/codenames/movie.codenames.ts +++ b/sample/items/codenames/movie.codenames.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/items/index.ts b/sample/items/index.ts index b219167..f010fde 100644 --- a/sample/items/index.ts +++ b/sample/items/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/items/items/actor.items.ts b/sample/items/items/actor.items.ts index ac17ee1..359481b 100644 --- a/sample/items/items/actor.items.ts +++ b/sample/items/items/actor.items.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/items/items/index.ts b/sample/items/items/index.ts index 4ba9dc6..1872a9a 100644 --- a/sample/items/items/index.ts +++ b/sample/items/items/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/sample/items/items/movie.items.ts b/sample/items/items/movie.items.ts index a0d0dfd..d0f7417 100644 --- a/sample/items/items/movie.items.ts +++ b/sample/items/items/movie.items.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-0'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. * * (c) Kontent.ai * diff --git a/scripts/samples/delivery-models.ts b/scripts/samples/delivery-models.ts index 6af7a8f..f814f82 100644 --- a/scripts/samples/delivery-models.ts +++ b/scripts/samples/delivery-models.ts @@ -30,7 +30,8 @@ try { environmentId: environmentId, apiKey: apiKey, moduleFileExtension: moduleFileExtension, - outputDir: outputDir + outputDir: outputDir, + fileResolvers: { contentType: 'camelCase', snippet: 'camelCase', taxonomy: 'camelCase' } }); } catch (error) { logError(error); From 612be4809939eadedd0b341504f441858194042f Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 11 Nov 2024 13:32:17 +0100 Subject: [PATCH 175/183] use toSafePropertyName for role codename as it may contain dashes --- lib/generators/environment/environment.generator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/environment/environment.generator.ts b/lib/generators/environment/environment.generator.ts index addbea2..17a3884 100644 --- a/lib/generators/environment/environment.generator.ts +++ b/lib/generators/environment/environment.generator.ts @@ -284,7 +284,7 @@ export function environmentGenerator(config: ProjectGeneratorConfig) { ${wrapComment(` * ${role.name} `)} - ${role.codename ? role.codename : toSafePropertyName(role.name)}: { + ${toSafePropertyName(role.codename ?? role.name)}: { codename: ${getStringOrUndefined(role.codename)}, id: '${role.id}', name: '${toSafePropertyValue(role.name)}' From 4ea6f854446a01e83e890b37387ae6aacc0a3561 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 11 Nov 2024 13:32:25 +0100 Subject: [PATCH 176/183] chore(release): 8.0.0-10 --- CHANGELOG.md | 2 ++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0a0bcf..14387f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [8.0.0-10](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-9...v8.0.0-10) (2024-11-11) + ## [8.0.0-9](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-8...v8.0.0-9) (2024-11-11) ## [8.0.0-8](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-7...v8.0.0-8) (2024-10-30) diff --git a/package-lock.json b/package-lock.json index 0da2251..a27fca1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-9", + "version": "8.0.0-10", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@kontent-ai/model-generator", - "version": "8.0.0-9", + "version": "8.0.0-10", "license": "MIT", "dependencies": { "@kontent-ai/delivery-sdk": "15.2.0", diff --git a/package.json b/package.json index fe51ca7..dd748d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-9", + "version": "8.0.0-10", "description": "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.", "bin": { "kontent-generate": "./dist/lib/cli/app.js" From ee06e1514f54014e87ac5bdbf23cf55bf595da91 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 11 Nov 2024 13:38:59 +0100 Subject: [PATCH 177/183] Adds update version scripts to release scripts --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index dd748d0..a0bb628 100644 --- a/package.json +++ b/package.json @@ -29,9 +29,9 @@ "release": "standard-version && npm run update:version", "release:major": "standard-version --release-as major && npm run update:version", "release:major:beta": "standard-version --prerelease --release-as major && npm run update:version", - "release:beta": "standard-version --prerelease", - "prerelease:standard": "standard-version --prerelease", - "prerelease:major": "standard-version --prerelease --release-as major", + "release:beta": "standard-version --prerelease && npm run update:version", + "prerelease:standard": "standard-version --prerelease && npm run update:version", + "prerelease:major": "standard-version --prerelease --release-as major && npm run update:version", "prepublishOnly": "npm run build && npm run push:tags", "publish:beta": "npm publish --tag=next", "build": "npm run clean && tsc --p tsconfig.json", From 57b7df1734ed4fc8525bda0d1fa266df4695024c Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 11 Nov 2024 13:52:32 +0100 Subject: [PATCH 178/183] Adds undefined | null to typeguard arg --- lib/generators/delivery/delivery-type-guard.generator.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generators/delivery/delivery-type-guard.generator.ts b/lib/generators/delivery/delivery-type-guard.generator.ts index e88f4c5..d0ab963 100644 --- a/lib/generators/delivery/delivery-type-guard.generator.ts +++ b/lib/generators/delivery/delivery-type-guard.generator.ts @@ -17,8 +17,8 @@ export function deliveryTypeGuardGenerator(config: DeliveryTypeGuardGeneratorCon }; const getTypeGuardFunction = (contentType: Readonly): string => { - return `export function ${nameResolvers.typeGuardFunctionName(contentType)}(item: ${deliveryConfig.coreContentTypeName}): item is ${nameResolvers.typeName(contentType)} { - return item.system.type === '${contentType.codename}'; + return `export function ${nameResolvers.typeGuardFunctionName(contentType)}(item: ${deliveryConfig.coreContentTypeName} | undefined | null): item is ${nameResolvers.typeName(contentType)} { + return item?.system?.type === '${contentType.codename}'; }`; }; From 5c39700e9cdbfd070b3f5f8f44a837ce9f8fa835 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 11 Nov 2024 13:52:39 +0100 Subject: [PATCH 179/183] updates sample --- sample/delivery/content-types/actor.ts | 4 ++-- sample/delivery/content-types/movie.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index aeef488..fde05da 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -73,6 +73,6 @@ export type ActorElementCodenames = 'url' | 'first_name' | 'last_name' | 'photo' /** * Type guard for Actor */ -export function isActor(item: CoreContentType): item is Actor { - return item.system.type === 'actor'; +export function isActor(item: CoreContentType | undefined | null): item is Actor { + return item?.system?.type === 'actor'; } diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index c0058dd..0e45036 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -130,6 +130,6 @@ export type MovieElementCodenames = /** * Type guard for Movie */ -export function isMovie(item: CoreContentType): item is Movie { - return item.system.type === 'movie'; +export function isMovie(item: CoreContentType | undefined | null): item is Movie { + return item?.system?.type === 'movie'; } From 2a3ffbd6fda89613fa7975a218bf4b03eda26ccd Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 11 Nov 2024 13:52:44 +0100 Subject: [PATCH 180/183] chore(release): 8.0.0-11 --- CHANGELOG.md | 2 ++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14387f0..a179ea8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [8.0.0-11](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-10...v8.0.0-11) (2024-11-11) + ## [8.0.0-10](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-9...v8.0.0-10) (2024-11-11) ## [8.0.0-9](https://github.com/kontent-ai/model-generator-js/compare/v8.0.0-8...v8.0.0-9) (2024-11-11) diff --git a/package-lock.json b/package-lock.json index a27fca1..6dd3f16 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-10", + "version": "8.0.0-11", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@kontent-ai/model-generator", - "version": "8.0.0-10", + "version": "8.0.0-11", "license": "MIT", "dependencies": { "@kontent-ai/delivery-sdk": "15.2.0", diff --git a/package.json b/package.json index a0bb628..5f8d3dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kontent-ai/model-generator", - "version": "8.0.0-10", + "version": "8.0.0-11", "description": "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.", "bin": { "kontent-generate": "./dist/lib/cli/app.js" From aa13cdcd5cf1cfbc41a244a012679a0db9db0cc5 Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Mon, 11 Nov 2024 13:52:51 +0100 Subject: [PATCH 181/183] Update metadata.ts --- lib/meta/metadata.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/meta/metadata.ts b/lib/meta/metadata.ts index b229297..0cc9331 100644 --- a/lib/meta/metadata.ts +++ b/lib/meta/metadata.ts @@ -2,6 +2,6 @@ export const libMetadata = { host: 'npmjs.com', name: '@kontent-ai/model-generator', - timestamp: 'Tue, 08 Oct 2024 10:03:49 GMT', - version: '8.0.0-5' + timestamp: 'Mon, 11 Nov 2024 12:52:45 GMT', + version: '8.0.0-11' }; From b4492efb613e260e3744edf75e540c6dea9257fd Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Tue, 12 Nov 2024 15:22:16 +0100 Subject: [PATCH 182/183] Adds codename of type to type guard comment --- lib/generators/delivery/delivery-content-type.generator.ts | 2 ++ sample/delivery/content-type-snippets/index.ts | 2 +- sample/delivery/content-types/actor.ts | 4 +++- sample/delivery/content-types/index.ts | 2 +- sample/delivery/content-types/movie.ts | 4 +++- sample/delivery/index.ts | 2 +- sample/delivery/system/core.type.ts | 2 +- sample/delivery/system/delivery.codenames.ts | 2 +- sample/delivery/system/index.ts | 2 +- sample/delivery/taxonomies/index.ts | 2 +- sample/delivery/taxonomies/movietype.ts | 2 +- sample/delivery/taxonomies/releasecategory.ts | 2 +- 12 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/generators/delivery/delivery-content-type.generator.ts b/lib/generators/delivery/delivery-content-type.generator.ts index b014306..8ab78d9 100644 --- a/lib/generators/delivery/delivery-content-type.generator.ts +++ b/lib/generators/delivery/delivery-content-type.generator.ts @@ -324,6 +324,8 @@ ${getContentTypeElementCodenamesType(nameOfTypeRepresentingAllElementCodenames, ${wrapComment(` * Type guard for ${contentType.name} +* +* Codename: ${contentType.codename} `)} ${deliveryTypeGuardGenerator(config).getTypeGuardFunction(contentType)}; `; diff --git a/sample/delivery/content-type-snippets/index.ts b/sample/delivery/content-type-snippets/index.ts index 634fd05..bdf84f5 100644 --- a/sample/delivery/content-type-snippets/index.ts +++ b/sample/delivery/content-type-snippets/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-11'. * * (c) Kontent.ai * diff --git a/sample/delivery/content-types/actor.ts b/sample/delivery/content-types/actor.ts index fde05da..a5970ce 100644 --- a/sample/delivery/content-types/actor.ts +++ b/sample/delivery/content-types/actor.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-11'. * * (c) Kontent.ai * @@ -72,6 +72,8 @@ export type ActorElementCodenames = 'url' | 'first_name' | 'last_name' | 'photo' /** * Type guard for Actor + * + * Codename: actor */ export function isActor(item: CoreContentType | undefined | null): item is Actor { return item?.system?.type === 'actor'; diff --git a/sample/delivery/content-types/index.ts b/sample/delivery/content-types/index.ts index b33a70c..722c9f7 100644 --- a/sample/delivery/content-types/index.ts +++ b/sample/delivery/content-types/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-11'. * * (c) Kontent.ai * diff --git a/sample/delivery/content-types/movie.ts b/sample/delivery/content-types/movie.ts index 0e45036..84f25b6 100644 --- a/sample/delivery/content-types/movie.ts +++ b/sample/delivery/content-types/movie.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-11'. * * (c) Kontent.ai * @@ -129,6 +129,8 @@ export type MovieElementCodenames = /** * Type guard for Movie + * + * Codename: movie */ export function isMovie(item: CoreContentType | undefined | null): item is Movie { return item?.system?.type === 'movie'; diff --git a/sample/delivery/index.ts b/sample/delivery/index.ts index a93bf4e..9c44e97 100644 --- a/sample/delivery/index.ts +++ b/sample/delivery/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-11'. * * (c) Kontent.ai * diff --git a/sample/delivery/system/core.type.ts b/sample/delivery/system/core.type.ts index c5faf99..83ca6cb 100644 --- a/sample/delivery/system/core.type.ts +++ b/sample/delivery/system/core.type.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-11'. * * (c) Kontent.ai * diff --git a/sample/delivery/system/delivery.codenames.ts b/sample/delivery/system/delivery.codenames.ts index 7b563d5..d7f880a 100644 --- a/sample/delivery/system/delivery.codenames.ts +++ b/sample/delivery/system/delivery.codenames.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-11'. * * (c) Kontent.ai * diff --git a/sample/delivery/system/index.ts b/sample/delivery/system/index.ts index b169583..918478d 100644 --- a/sample/delivery/system/index.ts +++ b/sample/delivery/system/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-11'. * * (c) Kontent.ai * diff --git a/sample/delivery/taxonomies/index.ts b/sample/delivery/taxonomies/index.ts index 392c718..6bffe90 100644 --- a/sample/delivery/taxonomies/index.ts +++ b/sample/delivery/taxonomies/index.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-11'. * * (c) Kontent.ai * diff --git a/sample/delivery/taxonomies/movietype.ts b/sample/delivery/taxonomies/movietype.ts index 79bc94d..1c976f8 100644 --- a/sample/delivery/taxonomies/movietype.ts +++ b/sample/delivery/taxonomies/movietype.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-11'. * * (c) Kontent.ai * diff --git a/sample/delivery/taxonomies/releasecategory.ts b/sample/delivery/taxonomies/releasecategory.ts index 0c79cfa..8fa20d8 100644 --- a/sample/delivery/taxonomies/releasecategory.ts +++ b/sample/delivery/taxonomies/releasecategory.ts @@ -1,6 +1,6 @@ /** -* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-5'. +* This file has been auto-generated by '@kontent-ai/model-generator@8.0.0-11'. * * (c) Kontent.ai * From 1a978d301fd476dd30037f0555b4cf5aaaec3c1e Mon Sep 17 00:00:00 2001 From: Richard Sustek Date: Wed, 13 Nov 2024 10:40:35 +0100 Subject: [PATCH 183/183] Simplifies `mapName` function --- lib/core/resolvers.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/core/resolvers.ts b/lib/core/resolvers.ts index 16691c8..0984588 100644 --- a/lib/core/resolvers.ts +++ b/lib/core/resolvers.ts @@ -40,16 +40,13 @@ export function mapName( prefix?: string; } ): MapObjectToName { - return (item) => { - return ( - `${options?.prefix ? options.prefix : ''}` + - match(resolver) - .returnType() - .with(P.instanceOf(Function), (resolver) => resolver(item)) - .with(undefined, () => resolveCase(item.name, defaultCase)) - .otherwise((resolverType) => resolveCase(item.name, resolverType)) - ); - }; + return (item) => + (options?.prefix ? options.prefix : '') + + match(resolver) + .returnType() + .with(P.instanceOf(Function), (resolver) => resolver(item)) + .with(undefined, () => resolveCase(item.name, defaultCase)) + .otherwise((resolverType) => resolveCase(item.name, resolverType)); } function addExtensionToFilename(filename: string, addExtension: boolean): string {