From 39206a8f74a7cb3e592e71185061d123c82f3149 Mon Sep 17 00:00:00 2001 From: Jonas Ulrich | ruhmesmeile GmbH Date: Tue, 8 Jul 2025 15:53:06 +0200 Subject: [PATCH 1/6] feat(schema): adjust layer ordering --- package.json | 24 ++++++------ src/commands/cms/stackbit.ts | 15 +++---- src/commands/cms/staticcms.ts | 15 +++---- src/commands/cms/storyblok.ts | 15 +++---- src/commands/cms/uniform.ts | 15 +++---- src/commands/schema/defaults.ts | 15 +++---- src/commands/schema/dereference.ts | 15 +++---- src/commands/schema/layer.ts | 15 +++---- src/commands/schema/types.ts | 13 +++++-- src/tasks/cms/stackbit-task.ts | 17 ++++---- src/tasks/cms/staticcms-task.ts | 17 ++++---- src/tasks/cms/storyblok-task.ts | 17 ++++---- src/tasks/cms/uniform-task.ts | 19 +++++---- src/tasks/schema/defaults-task.ts | 17 ++++---- src/tasks/schema/dereference-task.ts | 17 ++++---- src/tasks/schema/layer-task.ts | 16 ++++---- src/tasks/schema/types-task.ts | 16 +++++--- src/util/schema.ts | 28 ++++++++++---- types/index.d.ts | 24 ++++++++---- yarn.lock | 58 ++++++++++++++-------------- 20 files changed, 225 insertions(+), 163 deletions(-) diff --git a/package.json b/package.json index fc0d479..388f5b7 100644 --- a/package.json +++ b/package.json @@ -101,12 +101,12 @@ "@commitlint/config-conventional": "^16.2.1", "@kickstartds/eslint-config": "^1.2.0", "@kickstartds/style-dictionary": "^4.0.2", - "@kickstartds/jsonschema-utils": "^3.6.1", - "@kickstartds/jsonschema2staticcms": "^2.9.35", - "@kickstartds/jsonschema2stackbit": "^1.7.4", - "@kickstartds/jsonschema2storyblok": "^1.6.5", - "@kickstartds/jsonschema2types": "^1.2.3", - "@kickstartds/jsonschema2uniform": "^1.4.22", + "@kickstartds/jsonschema-utils": "^3.7.0", + "@kickstartds/jsonschema2staticcms": "^2.9.37", + "@kickstartds/jsonschema2stackbit": "^1.7.6", + "@kickstartds/jsonschema2storyblok": "^1.6.7", + "@kickstartds/jsonschema2types": "^1.2.5", + "@kickstartds/jsonschema2uniform": "^1.4.24", "@stackbit/types": "^0.10.14", "@types/byline": "^4.2.33", "@types/dockerode": "^3.3.9", @@ -135,11 +135,11 @@ "peerDependencies": { "@kickstartds/core": "^4.0.2", "@kickstartds/style-dictionary": "^4.0.2", - "@kickstartds/jsonschema-utils": "^3.6.1", - "@kickstartds/jsonschema2staticcms": "^2.9.35", - "@kickstartds/jsonschema2stackbit": "^1.7.4", - "@kickstartds/jsonschema2storyblok": "^1.6.5", - "@kickstartds/jsonschema2types": "^1.2.3", - "@kickstartds/jsonschema2uniform": "^1.4.22" + "@kickstartds/jsonschema-utils": "^3.7.0", + "@kickstartds/jsonschema2staticcms": "^2.9.37", + "@kickstartds/jsonschema2stackbit": "^1.7.6", + "@kickstartds/jsonschema2storyblok": "^1.6.7", + "@kickstartds/jsonschema2types": "^1.2.5", + "@kickstartds/jsonschema2uniform": "^1.4.24" } } diff --git a/src/commands/cms/stackbit.ts b/src/commands/cms/stackbit.ts index dff8939..3401bb4 100644 --- a/src/commands/cms/stackbit.ts +++ b/src/commands/cms/stackbit.ts @@ -7,13 +7,14 @@ const stackbit = new Command('stackbit') chalkTemplate`Generates {bold Stackbit} configuration from your {bold JSON Schema} component definitions` ) .option( - '--components-path ', - chalkTemplate`relative path from project root to your components directory, default {bold ./src/components}`, - 'src/components' + '--schema-paths ', + chalkTemplate`paths to your JSON Schema component definitions, default {bold ./src/components}`, + ['src/components'] ) .option( - '--cms-path ', - chalkTemplate`relative path from project root to your cms specific components directory, default {bold ./src/components}` + '--layer-order ', + chalkTemplate`order of layers in processing, default {bold ['cms', 'schema']}`, + ['cms', 'schema'] ) .option( '--configuration-path ', @@ -67,8 +68,8 @@ const stackbit = new Command('stackbit') .action((options) => import('./../../tasks/cms/stackbit-task.js').then((runTask) => { runTask.default( - options.componentsPath, - options.cmsPath, + options.schemaPaths, + options.layerOrder, options.configurationPath, options.updateConfig, options.templates, diff --git a/src/commands/cms/staticcms.ts b/src/commands/cms/staticcms.ts index c1d8a13..b4b51d3 100644 --- a/src/commands/cms/staticcms.ts +++ b/src/commands/cms/staticcms.ts @@ -7,13 +7,14 @@ const staticcms = new Command('staticcms') chalkTemplate`Generates {bold Static CMS} configuration from your {bold JSON Schema} component definitions` ) .option( - '--components-path ', - chalkTemplate`relative path from project root to your components directory, default {bold ./src/components}`, - 'src/components' + '--schema-paths ', + chalkTemplate`paths to your JSON Schema component definitions, default {bold ./src/components}`, + ['src/components'] ) .option( - '--cms-path ', - chalkTemplate`relative path from project root to your cms specific components directory, default {bold ./src/components}` + '--layer-order ', + chalkTemplate`order of layers in processing, default {bold ['cms', 'schema']}`, + ['cms', 'schema'] ) .option( '--configuration-path ', @@ -69,8 +70,8 @@ const staticcms = new Command('staticcms') .option('--debug', 'show debugging output', false) .action((options) => { runTask( - options.componentsPath, - options.cmsPath, + options.schemaPaths, + options.layerOrder, options.configurationPath, options.updateConfig, options.templates, diff --git a/src/commands/cms/storyblok.ts b/src/commands/cms/storyblok.ts index 46f55bb..51d6f3d 100644 --- a/src/commands/cms/storyblok.ts +++ b/src/commands/cms/storyblok.ts @@ -7,13 +7,14 @@ const storyblok = new Command('storyblok') chalkTemplate`Generates {bold Storyblok} configuration from your {bold JSON Schema} component definitions` ) .option( - '--components-path ', - chalkTemplate`relative path from project root to your components directory, default {bold ./src/components}`, - 'src/components' + '--schema-paths ', + chalkTemplate`paths to your JSON Schema component definitions, default {bold ./src/components}`, + ['src/components'] ) .option( - '--cms-path ', - chalkTemplate`relative path from project root to your cms specific components directory, default {bold ./src/components}` + '--layer-order ', + chalkTemplate`order of layers in processing, default {bold ['cms', 'schema']}`, + ['cms', 'schema'] ) .option( '--configuration-path ', @@ -66,8 +67,8 @@ const storyblok = new Command('storyblok') .option('--debug', 'show debugging output', false) .action((options) => { runTask( - options.componentsPath, - options.cmsPath, + options.schemaPaths, + options.layerOrder, options.configurationPath, options.updateConfig, options.templates, diff --git a/src/commands/cms/uniform.ts b/src/commands/cms/uniform.ts index b9ac45e..6a0e636 100644 --- a/src/commands/cms/uniform.ts +++ b/src/commands/cms/uniform.ts @@ -7,13 +7,14 @@ const uniform = new Command('uniform') chalkTemplate`Generates {bold Uniform} configuration from your {bold JSON Schema} component definitions` ) .option( - '--components-path ', - chalkTemplate`relative path from project root to your components directory, default {bold ./src/components}`, - 'src/components' + '--schema-paths ', + chalkTemplate`paths to your JSON Schema component definitions, default {bold ./src/components}`, + ['src/components'] ) .option( - '--cms-path ', - chalkTemplate`relative path from project root to your cms specific components directory, default {bold ./src/components}` + '--layer-order ', + chalkTemplate`order of layers in processing, default {bold ['cms', 'schema']}`, + ['cms', 'schema'] ) .option( '--configuration-path ', @@ -44,8 +45,8 @@ const uniform = new Command('uniform') .option('--debug', 'show debugging output', false) .action((options) => { runTask( - options.componentsPath, - options.cmsPath, + options.schemaPaths, + options.layerOrder, options.configurationPath, options.templates, options.globals, diff --git a/src/commands/schema/defaults.ts b/src/commands/schema/defaults.ts index 71401ba..438f769 100644 --- a/src/commands/schema/defaults.ts +++ b/src/commands/schema/defaults.ts @@ -7,13 +7,14 @@ const defaults = new Command('defaults') chalkTemplate`Creates default objects for {bold JSON Schema} component definitions` ) .option( - '--components-path ', - chalkTemplate`relative path from project root to your components directory, default {bold ./src/components}`, - 'src/components' + '--schema-paths ', + chalkTemplate`paths to your JSON Schema component definitions, default {bold ./src/components}`, + ['src/components'] ) .option( - '--cms-path ', - chalkTemplate`relative path from project root to your cms specific components directory, default {bold ./src/components}` + '--layer-order ', + chalkTemplate`order of layers in processing, default {bold ['cms', 'schema']}`, + ['cms', 'schema'] ) .option( '--no-default-page-schema', @@ -38,8 +39,8 @@ const defaults = new Command('defaults') .option('--debug', 'show debugging output', false) .action((options) => { runTask( - options.componentsPath, - options.cmsPath, + options.schemaPaths, + options.layerOrder, options.defaultPageSchema, options.layerKickstartdsComponents, options.rcOnly, diff --git a/src/commands/schema/dereference.ts b/src/commands/schema/dereference.ts index e3689d8..ed47d00 100644 --- a/src/commands/schema/dereference.ts +++ b/src/commands/schema/dereference.ts @@ -7,13 +7,14 @@ const dereference = new Command('dereference') chalkTemplate`Dereferences {bold JSON Schema} component definitions, (mainly) inlining all $ref references in the process` ) .option( - '--components-path ', - chalkTemplate`relative path from project root to your components directory, default {bold ./src/components}`, - 'src/components' + '--schema-paths ', + chalkTemplate`paths to your JSON Schema component definitions, default {bold ./src/components}`, + ['src/components'] ) .option( - '--cms-path ', - chalkTemplate`relative path from project root to your cms specific components directory, default {bold ./src/components}` + '--layer-order ', + chalkTemplate`order of layers in processing, default {bold ['cms', 'schema']}`, + ['cms', 'schema'] ) .option( '--no-default-page-schema', @@ -38,8 +39,8 @@ const dereference = new Command('dereference') .option('--debug', 'show debugging output', false) .action((options) => { runTask( - options.componentsPath, - options.cmsPath, + options.schemaPaths, + options.layerOrder, options.defaultPageSchema, options.layerKickstartdsComponents, options.rcOnly, diff --git a/src/commands/schema/layer.ts b/src/commands/schema/layer.ts index d795785..fe8bc51 100644 --- a/src/commands/schema/layer.ts +++ b/src/commands/schema/layer.ts @@ -7,13 +7,14 @@ const types = new Command('layer') chalkTemplate`Layers kickstartDS {bold TypeScript} type definitions using your {bold JSON Schema} component definitions` ) .option( - '--components-path ', - chalkTemplate`relative path from project root to your components directory, default {bold ./src/components}`, - 'src/components' + '--schema-paths ', + chalkTemplate`paths to your JSON Schema component definitions, default {bold ./src/components}`, + ['src/components'] ) .option( - '--cms-path ', - chalkTemplate`relative path from project root to your cms specific components directory, default {bold ./src/components}` + '--layer-order ', + chalkTemplate`order of layers in processing, default {bold ['cms', 'schema']}`, + ['cms', 'schema'] ) .option( '--types-path ', @@ -48,8 +49,8 @@ const types = new Command('layer') .option('--debug', 'show debugging output', false) .action((options) => { runTask( - options.componentsPath, - options.cmsPath, + options.schemaPaths, + options.layerOrder, options.typesPath, options.mergeSchemas, options.defaultPageSchema, diff --git a/src/commands/schema/types.ts b/src/commands/schema/types.ts index a32b09d..f408c77 100644 --- a/src/commands/schema/types.ts +++ b/src/commands/schema/types.ts @@ -12,8 +12,14 @@ const types = new Command('types') 'src/components' ) .option( - '--cms-path ', - chalkTemplate`relative path from project root to your cms specific components directory, default {bold ./src/components}` + '--schema-paths ', + chalkTemplate`paths to your JSON Schema component definitions, default {bold ./src/components}`, + ['src/components'] + ) + .option( + '--layer-order ', + chalkTemplate`order of layers in processing, default {bold ['cms', 'schema']}`, + ['cms', 'schema'] ) .option( '--merge-schemas', @@ -49,7 +55,8 @@ const types = new Command('types') .action((options) => { runTask( options.componentsPath, - options.cmsPath, + options.schemaPaths, + options.layerOrder, options.mergeSchemas, options.defaultPageSchema, options.layerKickstartdsComponents, diff --git a/src/tasks/cms/stackbit-task.ts b/src/tasks/cms/stackbit-task.ts index 17a7d85..88ddfeb 100644 --- a/src/tasks/cms/stackbit-task.ts +++ b/src/tasks/cms/stackbit-task.ts @@ -34,8 +34,8 @@ const { } = taskUtilSchema; const run = async ( - componentsPath: string = 'src/components', - cmsPath: string, + schemaPaths: string[] = ['src/components'], + layerOrder: string[] = ['cms', 'schema'], configurationPath: string = 'src/cms', updateConfig: boolean = true, templates: string[] = ['page', 'blog-post'], @@ -75,16 +75,19 @@ const run = async ( const stackbit = async (logger: winston.Logger): Promise => { logger.info(chalkTemplate`running the {bold stackbit} subtask`); - const customSchemaGlob = `${callingPath}/${componentsPath}/**/*.(schema|definitions|interface).json`; - const globs = [customSchemaGlob]; - if (cmsPath) { - globs.push(`${callingPath}/${cmsPath}/**/*.schema.json`); + const globs = []; + for (const schemaPath of schemaPaths) { + globs.push( + `${callingPath}/${schemaPath}/**/*.(schema|definitions|interface).json` + ); } + const elements = await schemaToStackbit( globs, templates, globals, - components + components, + [...layerOrder, 'kickstartds'] ); shell.mkdir('-p', `${shell.pwd()}/${configurationPath}/`); diff --git a/src/tasks/cms/staticcms-task.ts b/src/tasks/cms/staticcms-task.ts index 4d94f7c..778e56f 100644 --- a/src/tasks/cms/staticcms-task.ts +++ b/src/tasks/cms/staticcms-task.ts @@ -35,8 +35,8 @@ const { } = taskUtilSchema; const run = async ( - componentsPath: string = 'src/components', - cmsPath: string, + schemaPaths: string[] = ['src/components'], + layerOrder: string[] = ['cms', 'schema'], configurationPath: string = 'src/cms', updateConfig: boolean = true, templates: string[] = ['page', 'blog-post'], @@ -73,16 +73,19 @@ const run = async ( const staticcms = async (logger: winston.Logger): Promise => { logger.info(chalkTemplate`running the {bold staticcms} subtask`); - const customSchemaGlob = `${callingPath}/${componentsPath}/**/*.(schema|definitions|interface).json`; - const globs = [customSchemaGlob]; - if (cmsPath) { - globs.push(`${callingPath}/${cmsPath}/**/*.schema.json`); + const globs = []; + for (const schemaPath of schemaPaths) { + globs.push( + `${callingPath}/${schemaPath}/**/*.(schema|definitions|interface).json` + ); } + const elements = await schemaToStaticcms( globs, templates, globals, - components + components, + [...layerOrder, 'kickstartds'] ); shell.mkdir('-p', `${shell.pwd()}/${configurationPath}/`); diff --git a/src/tasks/cms/storyblok-task.ts b/src/tasks/cms/storyblok-task.ts index d4b7fb6..e445dca 100644 --- a/src/tasks/cms/storyblok-task.ts +++ b/src/tasks/cms/storyblok-task.ts @@ -34,8 +34,8 @@ const { } = taskUtilSchema; const run = async ( - componentsPath: string = 'src/components', - cmsPath: string, + schemaPaths: string[] = ['src/components'], + layerOrder: string[] = ['cms', 'schema'], configurationPath: string = 'src/cms', updateConfig: boolean = true, templates: string[] = ['page', 'blog-post', 'blog-overview', 'settings'], @@ -72,16 +72,19 @@ const run = async ( const storyblok = async (logger: winston.Logger): Promise => { logger.info(chalkTemplate`running the {bold storyblok} subtask`); - const customSchemaGlob = `${callingPath}/${componentsPath}/**/*.(schema|definitions|interface).json`; - const globs = [customSchemaGlob]; - if (cmsPath) { - globs.push(`${callingPath}/${cmsPath}/**/*.schema.json`); + const globs = []; + for (const schemaPath of schemaPaths) { + globs.push( + `${callingPath}/${schemaPath}/**/*.(schema|definitions|interface).json` + ); } + const elements = await schemaToStoryblok( globs, templates, globals, - components + components, + [...layerOrder, 'kickstartds'] ); shell.mkdir('-p', `${shell.pwd()}/${configurationPath}/`); diff --git a/src/tasks/cms/uniform-task.ts b/src/tasks/cms/uniform-task.ts index a605265..6a36afb 100644 --- a/src/tasks/cms/uniform-task.ts +++ b/src/tasks/cms/uniform-task.ts @@ -29,8 +29,8 @@ const { } = taskUtilSchema; const run = async ( - componentsPath: string = 'src/components', - cmsPath: string, + schemaPaths: string[] = ['src/components'], + layerOrder: string[] = ['cms', 'schema'], configurationPath: string = 'src/cms', templates: string[] = ['page', 'blog-post', 'blog-overview', 'settings'], globals: string[] = ['header', 'footer', 'seo'], @@ -53,16 +53,21 @@ const run = async ( const uniform = async (logger: winston.Logger): Promise => { logger.info(chalkTemplate`running the {bold uniform} subtask`); - const customSchemaGlob = `${callingPath}/${componentsPath}/**/*.(schema|definitions).json`; - const globs = [customSchemaGlob]; - if (cmsPath) { - globs.push(`${callingPath}/${cmsPath}/**/*.schema.json`); + const globs = []; + for (const schemaPath of schemaPaths) { + globs.push( + `${callingPath}/${schemaPath}/**/*.(schema|definitions|interface).json` + ); } + const { components: uniformComponents, templates: uniformTemplates, globals: uniformGlobals, - } = await schemaToUniform(globs, templates, globals); + } = await schemaToUniform(globs, templates, globals, [ + ...layerOrder, + 'kickstartds', + ]); shell.mkdir('-p', `${shell.pwd()}/${configurationPath}/`); diff --git a/src/tasks/schema/defaults-task.ts b/src/tasks/schema/defaults-task.ts index 4f5124d..6500f01 100644 --- a/src/tasks/schema/defaults-task.ts +++ b/src/tasks/schema/defaults-task.ts @@ -30,8 +30,8 @@ const { } = taskUtilSchema; const run = async ( - componentsPath: string = 'src/components', - cmsPath: string, + schemaPaths: string[] = ['src/components'], + layerOrder: string[] = ['cms', 'schema'], defaultPageSchema: boolean = true, layerKickstartdsComponents: boolean = true, rcOnly: boolean, @@ -53,16 +53,19 @@ const run = async ( const defaults = async (logger: winston.Logger): Promise => { logger.info(chalkTemplate`running the {bold defaults} subtask`); - const customSchemaGlob = `${callingPath}/${componentsPath}/**/*.schema.json`; - const globs = [customSchemaGlob]; - if (cmsPath) { - globs.push(`${callingPath}/${cmsPath}/**/*.schema.json`); + const globs = []; + for (const schemaPath of schemaPaths) { + globs.push( + `${callingPath}/${schemaPath}/**/*.(schema|definitions|interface).json` + ); } + const customSchemaPaths = await fg(globs); const defaults = await schemaCreateDefaultObjects( globs, defaultPageSchema, - layerKickstartdsComponents + layerKickstartdsComponents, + [...layerOrder, 'kickstartds'] ); logger.info( diff --git a/src/tasks/schema/dereference-task.ts b/src/tasks/schema/dereference-task.ts index 08092cf..37f8f12 100644 --- a/src/tasks/schema/dereference-task.ts +++ b/src/tasks/schema/dereference-task.ts @@ -29,8 +29,8 @@ const { } = taskUtilSchema; const run = async ( - componentsPath: string = 'src/components', - cmsPath: string, + schemaPaths: string[] = ['src/components'], + layerOrder: string[] = ['cms', 'schema'], defaultPageSchema: boolean = true, layerKickstartdsComponents: boolean = true, rcOnly: boolean, @@ -52,16 +52,19 @@ const run = async ( const dereference = async (logger: winston.Logger): Promise => { logger.info(chalkTemplate`running the {bold dereference} subtask`); - const customSchemaGlob = `${callingPath}/${componentsPath}/**/*.schema.json`; - const globs = [customSchemaGlob]; - if (cmsPath) { - globs.push(`${callingPath}/${cmsPath}/**/*.schema.json`); + const globs = []; + for (const schemaPath of schemaPaths) { + globs.push( + `${callingPath}/${schemaPath}/**/*.(schema|definitions|interface).json` + ); } + const customSchemaPaths = await fg(globs); const dereffed = await schemaDereferenceSchemas( globs, defaultPageSchema, - layerKickstartdsComponents + layerKickstartdsComponents, + [...layerOrder, 'kickstartds'] ); logger.info( diff --git a/src/tasks/schema/layer-task.ts b/src/tasks/schema/layer-task.ts index 89f77e2..f7710bb 100644 --- a/src/tasks/schema/layer-task.ts +++ b/src/tasks/schema/layer-task.ts @@ -31,8 +31,8 @@ const { } = taskUtilSchema; const run = async ( - componentsPath: string = 'src/components', - cmsPath: string, + schemaPaths: string[] = ['src/components'], + layerOrder: string[] = ['cms', 'schema'], typesPath: string = 'src/types', mergeSchemas: boolean, defaultPageSchema: boolean = true, @@ -56,17 +56,19 @@ const run = async ( const layer = async (logger: winston.Logger): Promise => { logger.info(chalkTemplate`running the {bold layer} subtask`); - const customSchemaGlob = `${callingPath}/${componentsPath}/**/*.(schema|definitions).json`; - const globs = [customSchemaGlob]; - if (cmsPath) { - globs.push(`${callingPath}/${cmsPath}/**/*.schema.json`); + const globs = []; + for (const schemaPath of schemaPaths) { + globs.push( + `${callingPath}/${schemaPath}/**/*.(schema|definitions|interface).json` + ); } const layeredTypes = await schemaLayerComponentPropTypes( globs, mergeSchemas, defaultPageSchema, - layerKickstartdsComponents + layerKickstartdsComponents, + [...layerOrder, 'kickstartds'] ); shell.mkdir('-p', `${shell.pwd()}/${typesPath}/`); diff --git a/src/tasks/schema/types-task.ts b/src/tasks/schema/types-task.ts index 8835813..c750782 100644 --- a/src/tasks/schema/types-task.ts +++ b/src/tasks/schema/types-task.ts @@ -31,7 +31,8 @@ const { const run = async ( componentsPath: string = 'src/components', - cmsPath: string, + schemaPaths: string[] = ['src/components'], + layerOrder: string[] = ['cms', 'schema'], mergeSchemas: boolean, defaultPageSchema: boolean = true, layerKickstartdsComponents: boolean = true, @@ -55,11 +56,13 @@ const run = async ( const types = async (logger: winston.Logger): Promise => { logger.info(chalkTemplate`running the {bold types} subtask`); - const customSchemaGlob = `${callingPath}/${componentsPath}/**/*.schema.json`; - const globs = [customSchemaGlob]; - if (cmsPath) { - globs.push(`${callingPath}/${cmsPath}/**/*.schema.json`); + const globs = []; + for (const schemaPath of schemaPaths) { + globs.push( + `${callingPath}/${schemaPath}/**/*.(schema|definitions|interface).json` + ); } + const customSchemaPaths = await fg(globs); const types = await schemaGenerateComponentPropTypes( globs, @@ -67,7 +70,8 @@ const run = async ( defaultPageSchema, layerKickstartdsComponents, typeNaming, - componentsPath + componentsPath, + [...layerOrder, 'kickstartds'] ); await Promise.all( diff --git a/src/util/schema.ts b/src/util/schema.ts index fb4f39b..4bef84f 100644 --- a/src/util/schema.ts +++ b/src/util/schema.ts @@ -89,7 +89,8 @@ export default (logger: winston.Logger): SchemaUtil => { defaultPageSchema = true, layerKickstartdsComponents = true, typeNaming = 'title', - componentsPath = 'src/components' + componentsPath = 'src/components', + layerOrder: string[] ) => { subCmdLogger.info( chalkTemplate`generating component prop types for component schemas` @@ -101,6 +102,7 @@ export default (logger: winston.Logger): SchemaUtil => { mergeAllOf: mergeAllOf, loadPageSchema: defaultPageSchema, layerRefs: layerKickstartdsComponents, + layerOrder, }); const customSchemaIds = getCustomSchemaIds(schemaIds); @@ -146,7 +148,8 @@ export default (logger: winston.Logger): SchemaUtil => { schemaGlobs: string[], mergeAllOf: boolean, defaultPageSchema = true, - layerKickstartdsComponents = true + layerKickstartdsComponents = true, + layerOrder: string[] ) => { subCmdLogger.info( chalkTemplate`layering component prop types for component schemas` @@ -158,6 +161,7 @@ export default (logger: winston.Logger): SchemaUtil => { mergeAllOf: mergeAllOf, loadPageSchema: defaultPageSchema, layerRefs: layerKickstartdsComponents, + layerOrder, }); const kdsSchemaIds = schemaIds.filter((schemaId) => schemaId.includes('schema.kickstartds.com') @@ -220,12 +224,14 @@ ${convertedTs[schemaId]} const createDefaultObjects = async ( schemaGlobs: string[], defaultPageSchema = true, - layerKickstartdsComponents = true + layerKickstartdsComponents = true, + layerOrder: string[] ) => { const ajv = getSchemaRegistry(); const schemaIds = await processSchemaGlobs(schemaGlobs, ajv, { loadPageSchema: defaultPageSchema, layerRefs: layerKickstartdsComponents, + layerOrder, }); const kdsSchemaIds = schemaIds.filter((schemaId) => schemaId.includes('schema.kickstartds.com') @@ -269,11 +275,13 @@ export default defaults;`; schemaGlobs: string[], templates: string[], globals: string[], - components: string[] + components: string[], + layerOrder: string[] ) => { const ajv = getSchemaRegistry(); const schemaIds = await processSchemaGlobs(schemaGlobs, ajv, { hideCmsFields: true, + layerOrder, }); const customSchemaIds = getCustomSchemaIds(schemaIds); @@ -308,11 +316,13 @@ export default defaults;`; const toUniform = async ( schemaGlobs: string[], templates: string[], - globals: string[] + globals: string[], + layerOrder: string[] ) => { const ajv = getSchemaRegistry(); const schemaIds = await processSchemaGlobs(schemaGlobs, ajv, { hideCmsFields: true, + layerOrder, }); const customSchemaIds = getCustomSchemaIds(schemaIds); @@ -341,11 +351,13 @@ export default defaults;`; schemaGlobs: string[], templates: string[], globals: string[], - components: string[] + components: string[], + layerOrder: string[] ) => { const ajv = getSchemaRegistry(); const schemaIds = await processSchemaGlobs(schemaGlobs, ajv, { hideCmsFields: true, + layerOrder, }); const customSchemaIds = getCustomSchemaIds(schemaIds); @@ -382,11 +394,13 @@ export default defaults;`; const toStaticcms = async ( schemaGlobs: string[], templates: string[], - globals: string[] + globals: string[], + layerOrder: string[] ) => { const ajv = getSchemaRegistry(); const schemaIds = await processSchemaGlobs(schemaGlobs, ajv, { hideCmsFields: true, + layerOrder, }); const customSchemaIds = getCustomSchemaIds(schemaIds); diff --git a/types/index.d.ts b/types/index.d.ts index 8587011..d1a48a1 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -219,29 +219,34 @@ interface SchemaUtil { defaultPageSchema: boolean, layerRefs: boolean, typeNaming: string, - componentsPath: string + componentsPath: string, + layerOrder: string[] ) => Promise>; layerComponentPropTypes: ( schemaGlobs: string[], mergeAllOf: boolean, defaultPageSchema: boolean, - layerRefs: boolean + layerRefs: boolean, + layerOrder: string[] ) => Promise>; dereferenceSchemas: ( schemaGlobs: string[], defaultPageSchema: boolean, - layerRefs: boolean + layerRefs: boolean, + layerOrder: string[] ) => Promise>; createDefaultObjects: ( schemaGlobs: string[], defaultPageSchema: boolean, - layerRefs: boolean + layerRefs: boolean, + layerOrder: string[] ) => Promise>; toStoryblok: ( schemaGlobs: string[], templates: string[], globals: string[], - components: string[] + components: string[], + layerOrder: string[] ) => Promise>; toStoryblokConfig: ( elements: CMSResult @@ -249,13 +254,15 @@ interface SchemaUtil { toUniform: ( schemaGlobs: string[], templates: string[], - globals: string[] + globals: string[], + layerOrder: string[] ) => Promise>; toStackbit: ( schemaGlobs: string[], templates: string[], globals: string[], - components: string[] + components: string[], + layerOrder: string[] ) => Promise>; toStackbitConfig: ( elements: CMSResult @@ -264,7 +271,8 @@ interface SchemaUtil { schemaGlobs: string[], templates: string[], globals: string[], - components: string[] + components: string[], + layerOrder: string[] ) => Promise>; toStaticcmsConfig: ( elements: CMSResult, diff --git a/yarn.lock b/yarn.lock index 580a5a2..d34568e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -921,10 +921,10 @@ mkdirp "^1.0.4" prettier "^2.6.2" -"@kickstartds/jsonschema-utils@3.6.1", "@kickstartds/jsonschema-utils@^3.6.1": - version "3.6.1" - resolved "https://registry.npmjs.org/@kickstartds/jsonschema-utils/-/jsonschema-utils-3.6.1.tgz#b692e56bfeae8c8bf8961ba3f86e358a811da198" - integrity sha512-Ke5adEzH0s5XXYJmBLGIIGBXAl0rWHaiOoFE0LmZUD1S8rTgS7VN5hoW6OWj35uXcWRVwC0sdkPFnKsVCxM+rQ== +"@kickstartds/jsonschema-utils@3.7.0", "@kickstartds/jsonschema-utils@^3.7.0": + version "3.7.0" + resolved "https://registry.npmjs.org/@kickstartds/jsonschema-utils/-/jsonschema-utils-3.7.0.tgz#95ffd90cc808d6ea5010436b6e3327f170e637bf" + integrity sha512-fgzLDl6ALF81Oi4e3Jw8a+NyspTfyqmierdde3sOWHrmP+me1j7D3I9if4qeXVx5vTsw5tbEKQpbow2GWSNnww== dependencies: "@bcherny/json-schema-ref-parser" "10.0.5-fork" "@kickstartds/cambria" "1.0.5" @@ -936,52 +936,52 @@ json-schema-traverse "^1.0.0" jsonpointer "~5.0.1" -"@kickstartds/jsonschema2stackbit@^1.7.4": - version "1.7.4" - resolved "https://registry.npmjs.org/@kickstartds/jsonschema2stackbit/-/jsonschema2stackbit-1.7.4.tgz#bd43e7932c4b8e207e85af40b82caa52f3efccfb" - integrity sha512-IKZCckXqOZeAj3xvm01t0KNOdxCA/kdlkaT1keXIzHglzvBEACu5JjaGaU0/OfswVJ8tfUOh9rqEb3RsIfN0Lg== +"@kickstartds/jsonschema2stackbit@^1.7.6": + version "1.7.6" + resolved "https://registry.npmjs.org/@kickstartds/jsonschema2stackbit/-/jsonschema2stackbit-1.7.6.tgz#730975e3bde05cc3e56cd53ec60429f65942c93e" + integrity sha512-UyXuUZe00G5rDUloTmSgPxXmSUKOrC8BiRObH8hi0c2opfLk6lKxCcviTTQHurgQir9oVv6G3DOAGy130Zgy7A== dependencies: - "@kickstartds/jsonschema-utils" "3.6.1" + "@kickstartds/jsonschema-utils" "3.7.0" ajv "^8.12.0" object-traversal "^1.0.1" pluralize-esm "~9.0.5" -"@kickstartds/jsonschema2staticcms@^2.9.35": - version "2.9.35" - resolved "https://registry.npmjs.org/@kickstartds/jsonschema2staticcms/-/jsonschema2staticcms-2.9.35.tgz#0872a8a7d441cb88230fc88a6b573f4477261200" - integrity sha512-uJUZXVVl+ZPwYgNfFwAW6lHQcmjyyttDMpC6CS9WE1Y3CyBMANT12UKkfrLbfEcj8LJNlUdS/mJBOoF8moT8Yw== +"@kickstartds/jsonschema2staticcms@^2.9.37": + version "2.9.37" + resolved "https://registry.npmjs.org/@kickstartds/jsonschema2staticcms/-/jsonschema2staticcms-2.9.37.tgz#024cb5d3af98f5d508a68937337a3c1346f5cc63" + integrity sha512-SvSTlChxKJk0SkdV9bILshaYMjJ90zyBO0HRPDTOISxFiDGPNOowXpJPIXugOTVzIpesZbtOiBI0AszVGdbpLw== dependencies: - "@kickstartds/jsonschema-utils" "3.6.1" + "@kickstartds/jsonschema-utils" "3.7.0" ajv "^8.12.0" object-traversal "^1.0.1" pluralize "^8.0.0" -"@kickstartds/jsonschema2storyblok@^1.6.5": - version "1.6.5" - resolved "https://registry.npmjs.org/@kickstartds/jsonschema2storyblok/-/jsonschema2storyblok-1.6.5.tgz#f8e376df999a732d4bfb6a270a01afbe2cfba16f" - integrity sha512-h+AHseOHkiU95LZ+qxlw2d66yJm/nH4iU+mXgG9QGsRZrQjchFmEgGtj2/xXMJWl9d0ZCsWDuTBfr9/R8jE0dQ== +"@kickstartds/jsonschema2storyblok@^1.6.7": + version "1.6.7" + resolved "https://registry.npmjs.org/@kickstartds/jsonschema2storyblok/-/jsonschema2storyblok-1.6.7.tgz#90314bfb873aefae508975f103985befc564324d" + integrity sha512-IGOVt7VK7dEw7epnXc8qWM1WZ+ezuDZ0+EwmQ7oWxmbzCFmbCRjB4vmjLvDoU6WUQDdBP/oLUfV0tO9bBxgUDA== dependencies: - "@kickstartds/jsonschema-utils" "3.6.1" + "@kickstartds/jsonschema-utils" "3.7.0" ajv "^8.12.0" object-traversal "^1.0.1" uuid "~9.0.0" -"@kickstartds/jsonschema2types@^1.2.3": - version "1.2.3" - resolved "https://registry.npmjs.org/@kickstartds/jsonschema2types/-/jsonschema2types-1.2.3.tgz#a4580b772648682d1c07c37af5be7aabf38ee891" - integrity sha512-Dp41eGa4jkyahkB0NPYroixStSP/+f/01r5FuDIxdJK3ljU7FWTJGuYPNcToPN0gZxSHgaWASirFrAKUD5TgUg== +"@kickstartds/jsonschema2types@^1.2.5": + version "1.2.5" + resolved "https://registry.npmjs.org/@kickstartds/jsonschema2types/-/jsonschema2types-1.2.5.tgz#6ad9feee3a8b66f61293c34a213a7b3f63467c42" + integrity sha512-JItd6ZKK6FsW4vS1EFoQRdElyi99EXAZgsWs1tZEXdo1pzm77aYuCvPgXzeTE0qvRyyjoikTYJO5Z2ocah4s0A== dependencies: "@kickstartds/json-schema-to-typescript" "~13.1.20" - "@kickstartds/jsonschema-utils" "3.6.1" + "@kickstartds/jsonschema-utils" "3.7.0" ajv "^8.12.0" object-traversal "^1.0.1" -"@kickstartds/jsonschema2uniform@^1.4.22": - version "1.4.22" - resolved "https://registry.npmjs.org/@kickstartds/jsonschema2uniform/-/jsonschema2uniform-1.4.22.tgz#59c14e21f1b720add603ee457fc1a30c751f6737" - integrity sha512-SuPgC+PN2IaOJq7zugyXne2zUyJ5e4TLyClbYMBQAxrWnboRDEc8QzcxR7Pf9WyHuAKaO8w2F35c5tEN8hAWAA== +"@kickstartds/jsonschema2uniform@^1.4.24": + version "1.4.24" + resolved "https://registry.npmjs.org/@kickstartds/jsonschema2uniform/-/jsonschema2uniform-1.4.24.tgz#957a976dca7c500e8063c179d1ba5343f3432e29" + integrity sha512-RKkCpRMst3D+PBPwPiQhEBxyhknhdCMKUvEUpLJACEfzcQhKIa+61gzavymgNaVf7RUKGY8yOQ+NKsIdYk58qQ== dependencies: - "@kickstartds/jsonschema-utils" "3.6.1" + "@kickstartds/jsonschema-utils" "3.7.0" ajv "^8.12.0" change-case "^5.0.2" From df4d00ff39413af0c926b1cb76f46017c9b0dc04 Mon Sep 17 00:00:00 2001 From: Jonas Ulrich | ruhmesmeile GmbH Date: Tue, 8 Jul 2025 16:59:18 +0200 Subject: [PATCH 2/6] fix(schema): bug in dereferencing --- src/util/schema.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/schema.ts b/src/util/schema.ts index 4bef84f..09549f1 100644 --- a/src/util/schema.ts +++ b/src/util/schema.ts @@ -31,12 +31,14 @@ export default (logger: winston.Logger): SchemaUtil => { const dereferenceSchemas = async ( schemaGlobs: string[], defaultPageSchema = true, - layerKickstartdsComponents = true + layerKickstartdsComponents = true, + layerOrder: string[] ) => { const ajv = getSchemaRegistry(); const schemaIds = await processSchemaGlobs(schemaGlobs, ajv, { loadPageSchema: defaultPageSchema, layerRefs: layerKickstartdsComponents, + layerOrder, }); const customSchemaIds = getCustomSchemaIds(schemaIds); From 0ae0820fafe346d66ad87e43349a4cd39747cd10 Mon Sep 17 00:00:00 2001 From: Jonas Ulrich | ruhmesmeile GmbH Date: Thu, 24 Jul 2025 16:30:54 +0200 Subject: [PATCH 3/6] fix(schema): update schema related tasks to use layer order --- package.json | 24 +++++++++---------- src/util/schema.ts | 16 +++++++------ yarn.lock | 58 +++++++++++++++++++++++----------------------- 3 files changed, 50 insertions(+), 48 deletions(-) diff --git a/package.json b/package.json index 388f5b7..5f2c844 100644 --- a/package.json +++ b/package.json @@ -101,12 +101,12 @@ "@commitlint/config-conventional": "^16.2.1", "@kickstartds/eslint-config": "^1.2.0", "@kickstartds/style-dictionary": "^4.0.2", - "@kickstartds/jsonschema-utils": "^3.7.0", - "@kickstartds/jsonschema2staticcms": "^2.9.37", - "@kickstartds/jsonschema2stackbit": "^1.7.6", - "@kickstartds/jsonschema2storyblok": "^1.6.7", - "@kickstartds/jsonschema2types": "^1.2.5", - "@kickstartds/jsonschema2uniform": "^1.4.24", + "@kickstartds/jsonschema-utils": "^3.8.0", + "@kickstartds/jsonschema2staticcms": "^2.9.38", + "@kickstartds/jsonschema2stackbit": "^1.7.7", + "@kickstartds/jsonschema2storyblok": "^1.6.8", + "@kickstartds/jsonschema2types": "^1.2.6", + "@kickstartds/jsonschema2uniform": "^1.4.25", "@stackbit/types": "^0.10.14", "@types/byline": "^4.2.33", "@types/dockerode": "^3.3.9", @@ -135,11 +135,11 @@ "peerDependencies": { "@kickstartds/core": "^4.0.2", "@kickstartds/style-dictionary": "^4.0.2", - "@kickstartds/jsonschema-utils": "^3.7.0", - "@kickstartds/jsonschema2staticcms": "^2.9.37", - "@kickstartds/jsonschema2stackbit": "^1.7.6", - "@kickstartds/jsonschema2storyblok": "^1.6.7", - "@kickstartds/jsonschema2types": "^1.2.5", - "@kickstartds/jsonschema2uniform": "^1.4.24" + "@kickstartds/jsonschema-utils": "^3.8.0", + "@kickstartds/jsonschema2staticcms": "^2.9.38", + "@kickstartds/jsonschema2stackbit": "^1.7.7", + "@kickstartds/jsonschema2storyblok": "^1.6.8", + "@kickstartds/jsonschema2types": "^1.2.6", + "@kickstartds/jsonschema2uniform": "^1.4.25" } } diff --git a/src/util/schema.ts b/src/util/schema.ts index 09549f1..69037e3 100644 --- a/src/util/schema.ts +++ b/src/util/schema.ts @@ -173,12 +173,14 @@ export default (logger: winston.Logger): SchemaUtil => { (schemaId) => !customSchemaIds.includes(schemaId) ); const layeredSchemaIds = customSchemaIds.filter((schemaId) => - kdsSchemaIds.some((kdsSchemaId) => shouldLayer(schemaId, kdsSchemaId)) + kdsSchemaIds.some((kdsSchemaId) => + shouldLayer(schemaId, kdsSchemaId, layerOrder) + ) ); const renderImportStatement = (schemaId: string) => { - const layeredId = isLayering(schemaId, kdsSchemaIds) - ? layeredSchemaId(schemaId, kdsSchemaIds) + const layeredId = isLayering(schemaId, kdsSchemaIds, layerOrder) + ? layeredSchemaId(schemaId, kdsSchemaIds, layerOrder) : schemaId; // TODO remove, this is a hack needed because of "broken" conventions // in this case of automatic interface schema generation @@ -205,8 +207,8 @@ export default (logger: winston.Logger): SchemaUtil => { ajv ); for (const schemaId of Object.keys(convertedTs)) { - const layeredId = isLayering(schemaId, kdsSchemaIds) - ? layeredSchemaId(schemaId, kdsSchemaIds) + const layeredId = isLayering(schemaId, kdsSchemaIds, layerOrder) + ? layeredSchemaId(schemaId, kdsSchemaIds, layerOrder) : schemaId; const content = `declare module "@kickstartds/${getSchemaModule( @@ -246,8 +248,8 @@ ${convertedTs[schemaId]} } const getImportName = (schemaId: string) => { - const layeredId = isLayering(schemaId, kdsSchemaIds) - ? layeredSchemaId(schemaId, kdsSchemaIds) + const layeredId = isLayering(schemaId, kdsSchemaIds, layerOrder) + ? layeredSchemaId(schemaId, kdsSchemaIds, layerOrder) : schemaId; return `${pascalCase(getSchemaName(layeredId))}Props`; }; diff --git a/yarn.lock b/yarn.lock index d34568e..7bbeadf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -921,10 +921,10 @@ mkdirp "^1.0.4" prettier "^2.6.2" -"@kickstartds/jsonschema-utils@3.7.0", "@kickstartds/jsonschema-utils@^3.7.0": - version "3.7.0" - resolved "https://registry.npmjs.org/@kickstartds/jsonschema-utils/-/jsonschema-utils-3.7.0.tgz#95ffd90cc808d6ea5010436b6e3327f170e637bf" - integrity sha512-fgzLDl6ALF81Oi4e3Jw8a+NyspTfyqmierdde3sOWHrmP+me1j7D3I9if4qeXVx5vTsw5tbEKQpbow2GWSNnww== +"@kickstartds/jsonschema-utils@3.8.0", "@kickstartds/jsonschema-utils@^3.8.0": + version "3.8.0" + resolved "https://registry.npmjs.org/@kickstartds/jsonschema-utils/-/jsonschema-utils-3.8.0.tgz#dbb8bcf10042a7e33292172bef1733b4c01718d7" + integrity sha512-hW5jv/3jjz5+DsbGf0dZo/NeoyLdbgrT4ccdCYz4s+in+cITpvAZAbYlFjOaPgH7MQGhs3KK3ShQ7LSK4OHuEA== dependencies: "@bcherny/json-schema-ref-parser" "10.0.5-fork" "@kickstartds/cambria" "1.0.5" @@ -936,52 +936,52 @@ json-schema-traverse "^1.0.0" jsonpointer "~5.0.1" -"@kickstartds/jsonschema2stackbit@^1.7.6": - version "1.7.6" - resolved "https://registry.npmjs.org/@kickstartds/jsonschema2stackbit/-/jsonschema2stackbit-1.7.6.tgz#730975e3bde05cc3e56cd53ec60429f65942c93e" - integrity sha512-UyXuUZe00G5rDUloTmSgPxXmSUKOrC8BiRObH8hi0c2opfLk6lKxCcviTTQHurgQir9oVv6G3DOAGy130Zgy7A== +"@kickstartds/jsonschema2stackbit@^1.7.7": + version "1.7.7" + resolved "https://registry.npmjs.org/@kickstartds/jsonschema2stackbit/-/jsonschema2stackbit-1.7.7.tgz#f66df859c7451bc2312c87de51eea4637e78c641" + integrity sha512-sq2SeFGaACGo2QwcAOwUtLpRT8uhy8/Lm1AM5ZdT6tTC9Cv5b48ijunMWiN+n3cc2woBy/elDURb2RbxOcBjbw== dependencies: - "@kickstartds/jsonschema-utils" "3.7.0" + "@kickstartds/jsonschema-utils" "3.8.0" ajv "^8.12.0" object-traversal "^1.0.1" pluralize-esm "~9.0.5" -"@kickstartds/jsonschema2staticcms@^2.9.37": - version "2.9.37" - resolved "https://registry.npmjs.org/@kickstartds/jsonschema2staticcms/-/jsonschema2staticcms-2.9.37.tgz#024cb5d3af98f5d508a68937337a3c1346f5cc63" - integrity sha512-SvSTlChxKJk0SkdV9bILshaYMjJ90zyBO0HRPDTOISxFiDGPNOowXpJPIXugOTVzIpesZbtOiBI0AszVGdbpLw== +"@kickstartds/jsonschema2staticcms@^2.9.38": + version "2.9.38" + resolved "https://registry.npmjs.org/@kickstartds/jsonschema2staticcms/-/jsonschema2staticcms-2.9.38.tgz#7d4a8199acc0bc4439d49a8be0e8a4807dbf0e1f" + integrity sha512-TcfedPtt3Ul1b5dJ2gXyAR2iLgeeYRobHHtrEXfyfbQQFOww3ZA+xxO32FTWgiDRm9cMrsINRmsZJ31f1e7YLA== dependencies: - "@kickstartds/jsonschema-utils" "3.7.0" + "@kickstartds/jsonschema-utils" "3.8.0" ajv "^8.12.0" object-traversal "^1.0.1" pluralize "^8.0.0" -"@kickstartds/jsonschema2storyblok@^1.6.7": - version "1.6.7" - resolved "https://registry.npmjs.org/@kickstartds/jsonschema2storyblok/-/jsonschema2storyblok-1.6.7.tgz#90314bfb873aefae508975f103985befc564324d" - integrity sha512-IGOVt7VK7dEw7epnXc8qWM1WZ+ezuDZ0+EwmQ7oWxmbzCFmbCRjB4vmjLvDoU6WUQDdBP/oLUfV0tO9bBxgUDA== +"@kickstartds/jsonschema2storyblok@^1.6.8": + version "1.6.8" + resolved "https://registry.npmjs.org/@kickstartds/jsonschema2storyblok/-/jsonschema2storyblok-1.6.8.tgz#0c0cd052628ef0fe7813a5cbd68134f157005940" + integrity sha512-3c9f88+eN6Qun37WXIU1zLHvetI+dG5FIbivXcK8ZFXy2MUX76flMrhASZtxJWjzzmrripp/8rUXaVsmUTL20Q== dependencies: - "@kickstartds/jsonschema-utils" "3.7.0" + "@kickstartds/jsonschema-utils" "3.8.0" ajv "^8.12.0" object-traversal "^1.0.1" uuid "~9.0.0" -"@kickstartds/jsonschema2types@^1.2.5": - version "1.2.5" - resolved "https://registry.npmjs.org/@kickstartds/jsonschema2types/-/jsonschema2types-1.2.5.tgz#6ad9feee3a8b66f61293c34a213a7b3f63467c42" - integrity sha512-JItd6ZKK6FsW4vS1EFoQRdElyi99EXAZgsWs1tZEXdo1pzm77aYuCvPgXzeTE0qvRyyjoikTYJO5Z2ocah4s0A== +"@kickstartds/jsonschema2types@^1.2.6": + version "1.2.6" + resolved "https://registry.npmjs.org/@kickstartds/jsonschema2types/-/jsonschema2types-1.2.6.tgz#eac239ad47b17df1df31d0889bd7565a6b61cfc5" + integrity sha512-Jp3PEY95KHp6BUZ0a6qg5nuhL5c24ZswSqFqmUVbAFTOhBsqjhI9PqhZu5xHy8/SM0MpsJQhjPgL7IldzwhkAA== dependencies: "@kickstartds/json-schema-to-typescript" "~13.1.20" - "@kickstartds/jsonschema-utils" "3.7.0" + "@kickstartds/jsonschema-utils" "3.8.0" ajv "^8.12.0" object-traversal "^1.0.1" -"@kickstartds/jsonschema2uniform@^1.4.24": - version "1.4.24" - resolved "https://registry.npmjs.org/@kickstartds/jsonschema2uniform/-/jsonschema2uniform-1.4.24.tgz#957a976dca7c500e8063c179d1ba5343f3432e29" - integrity sha512-RKkCpRMst3D+PBPwPiQhEBxyhknhdCMKUvEUpLJACEfzcQhKIa+61gzavymgNaVf7RUKGY8yOQ+NKsIdYk58qQ== +"@kickstartds/jsonschema2uniform@^1.4.25": + version "1.4.25" + resolved "https://registry.npmjs.org/@kickstartds/jsonschema2uniform/-/jsonschema2uniform-1.4.25.tgz#87ef3de6b2e31f33a285329f2fd95a324b1f1d48" + integrity sha512-OiMDXzlGonBoYBwRQ1w6+4yT9hkXbZhMfpVYcGR3S4swWMiCBQ4X0Zm/d23U7WKr6NbvEFYK0PzyN+LQlKx8DA== dependencies: - "@kickstartds/jsonschema-utils" "3.7.0" + "@kickstartds/jsonschema-utils" "3.8.0" ajv "^8.12.0" change-case "^5.0.2" From eb6446f7915bbfad496b87e16f0ec9ceaeb2e070 Mon Sep 17 00:00:00 2001 From: Jonas Ulrich | ruhmesmeile GmbH Date: Mon, 28 Jul 2025 15:32:03 +0200 Subject: [PATCH 4/6] fix(schema): adjust type generation --- package.json | 24 +++++++++---------- src/util/schema.ts | 18 ++++++++++++-- yarn.lock | 58 +++++++++++++++++++++++----------------------- 3 files changed, 57 insertions(+), 43 deletions(-) diff --git a/package.json b/package.json index 5f2c844..03f1b26 100644 --- a/package.json +++ b/package.json @@ -101,12 +101,12 @@ "@commitlint/config-conventional": "^16.2.1", "@kickstartds/eslint-config": "^1.2.0", "@kickstartds/style-dictionary": "^4.0.2", - "@kickstartds/jsonschema-utils": "^3.8.0", - "@kickstartds/jsonschema2staticcms": "^2.9.38", - "@kickstartds/jsonschema2stackbit": "^1.7.7", - "@kickstartds/jsonschema2storyblok": "^1.6.8", - "@kickstartds/jsonschema2types": "^1.2.6", - "@kickstartds/jsonschema2uniform": "^1.4.25", + "@kickstartds/jsonschema-utils": "^3.8.1", + "@kickstartds/jsonschema2staticcms": "^2.9.39", + "@kickstartds/jsonschema2stackbit": "^1.7.8", + "@kickstartds/jsonschema2storyblok": "^1.6.9", + "@kickstartds/jsonschema2types": "^1.2.7", + "@kickstartds/jsonschema2uniform": "^1.4.26", "@stackbit/types": "^0.10.14", "@types/byline": "^4.2.33", "@types/dockerode": "^3.3.9", @@ -135,11 +135,11 @@ "peerDependencies": { "@kickstartds/core": "^4.0.2", "@kickstartds/style-dictionary": "^4.0.2", - "@kickstartds/jsonschema-utils": "^3.8.0", - "@kickstartds/jsonschema2staticcms": "^2.9.38", - "@kickstartds/jsonschema2stackbit": "^1.7.7", - "@kickstartds/jsonschema2storyblok": "^1.6.8", - "@kickstartds/jsonschema2types": "^1.2.6", - "@kickstartds/jsonschema2uniform": "^1.4.25" + "@kickstartds/jsonschema-utils": "^3.8.1", + "@kickstartds/jsonschema2staticcms": "^2.9.39", + "@kickstartds/jsonschema2stackbit": "^1.7.8", + "@kickstartds/jsonschema2storyblok": "^1.6.9", + "@kickstartds/jsonschema2types": "^1.2.7", + "@kickstartds/jsonschema2uniform": "^1.4.26" } } diff --git a/src/util/schema.ts b/src/util/schema.ts index 69037e3..d0eb8fe 100644 --- a/src/util/schema.ts +++ b/src/util/schema.ts @@ -14,6 +14,8 @@ import { getSchemaDefaults, IClassifierResult, processSchemaGlobs, + getTopLayerSchemas, + getSchemasForIds, } from '@kickstartds/jsonschema-utils'; import type { IStoryblokBlock } from '@kickstartds/jsonschema2storyblok'; import type { IStaticCmsField } from '@kickstartds/jsonschema2staticcms'; @@ -106,7 +108,19 @@ export default (logger: winston.Logger): SchemaUtil => { layerRefs: layerKickstartdsComponents, layerOrder, }); - const customSchemaIds = getCustomSchemaIds(schemaIds); + const schemas = getSchemasForIds(schemaIds, ajv); + const topLayerSchemas = getTopLayerSchemas(schemas, layerOrder); + const topLayerSchemaIds = []; + for (const schema of topLayerSchemas) { + if (schema.$id) { + topLayerSchemaIds.push(schema.$id); + } else { + subCmdLogger.warn( + chalkTemplate`Schema ${schema.title} has no $id, skipping` + ); + } + } + // const customSchemaIds = getCustomSchemaIds(schemaIds); const renderImportStatement = (schemaId: string) => schemaId.includes('schema.kickstartds.com') @@ -135,7 +149,7 @@ export default (logger: winston.Logger): SchemaUtil => { const convertedTs = await ( await import('@kickstartds/jsonschema2types') ).createTypes( - customSchemaIds, + topLayerSchemaIds, renderImportName, renderImportStatement, ajv, diff --git a/yarn.lock b/yarn.lock index 7bbeadf..17f3813 100644 --- a/yarn.lock +++ b/yarn.lock @@ -921,10 +921,10 @@ mkdirp "^1.0.4" prettier "^2.6.2" -"@kickstartds/jsonschema-utils@3.8.0", "@kickstartds/jsonschema-utils@^3.8.0": - version "3.8.0" - resolved "https://registry.npmjs.org/@kickstartds/jsonschema-utils/-/jsonschema-utils-3.8.0.tgz#dbb8bcf10042a7e33292172bef1733b4c01718d7" - integrity sha512-hW5jv/3jjz5+DsbGf0dZo/NeoyLdbgrT4ccdCYz4s+in+cITpvAZAbYlFjOaPgH7MQGhs3KK3ShQ7LSK4OHuEA== +"@kickstartds/jsonschema-utils@3.8.1", "@kickstartds/jsonschema-utils@^3.8.1": + version "3.8.1" + resolved "https://registry.npmjs.org/@kickstartds/jsonschema-utils/-/jsonschema-utils-3.8.1.tgz#4f568c7bd6865b8cb0f774d8263a190f8107d7e3" + integrity sha512-3ZdI2ZscE2yvgDN5XfiZMupRlFpU3+lGIBo7aG47YTYw58arBM/ES83Y9aS2FatWWKVEW8G+vIBmvWgn9R4y3w== dependencies: "@bcherny/json-schema-ref-parser" "10.0.5-fork" "@kickstartds/cambria" "1.0.5" @@ -936,52 +936,52 @@ json-schema-traverse "^1.0.0" jsonpointer "~5.0.1" -"@kickstartds/jsonschema2stackbit@^1.7.7": - version "1.7.7" - resolved "https://registry.npmjs.org/@kickstartds/jsonschema2stackbit/-/jsonschema2stackbit-1.7.7.tgz#f66df859c7451bc2312c87de51eea4637e78c641" - integrity sha512-sq2SeFGaACGo2QwcAOwUtLpRT8uhy8/Lm1AM5ZdT6tTC9Cv5b48ijunMWiN+n3cc2woBy/elDURb2RbxOcBjbw== +"@kickstartds/jsonschema2stackbit@^1.7.8": + version "1.7.8" + resolved "https://registry.npmjs.org/@kickstartds/jsonschema2stackbit/-/jsonschema2stackbit-1.7.8.tgz#0988792b650a2859d5832292d9cbfd231b682295" + integrity sha512-hyg0SrF+HsxhURBVxpLcJt+YwlPXTstPM+l/ZLHWlG8YW4pSn5NlW7rRdx2ebATbldVwqmQ670pR0RyFF/nPrg== dependencies: - "@kickstartds/jsonschema-utils" "3.8.0" + "@kickstartds/jsonschema-utils" "3.8.1" ajv "^8.12.0" object-traversal "^1.0.1" pluralize-esm "~9.0.5" -"@kickstartds/jsonschema2staticcms@^2.9.38": - version "2.9.38" - resolved "https://registry.npmjs.org/@kickstartds/jsonschema2staticcms/-/jsonschema2staticcms-2.9.38.tgz#7d4a8199acc0bc4439d49a8be0e8a4807dbf0e1f" - integrity sha512-TcfedPtt3Ul1b5dJ2gXyAR2iLgeeYRobHHtrEXfyfbQQFOww3ZA+xxO32FTWgiDRm9cMrsINRmsZJ31f1e7YLA== +"@kickstartds/jsonschema2staticcms@^2.9.39": + version "2.9.39" + resolved "https://registry.npmjs.org/@kickstartds/jsonschema2staticcms/-/jsonschema2staticcms-2.9.39.tgz#f50f3f61eab7f6d84d1eab71dd0cb8429bb5b115" + integrity sha512-2E44xeNES95pEU9g/1Ym8+yfXZbLT6zTIqBuPCc6E5rIxRtMCUEB4my+kBr6yTvO6tsJ6IdZHF1NNct+kKuNOw== dependencies: - "@kickstartds/jsonschema-utils" "3.8.0" + "@kickstartds/jsonschema-utils" "3.8.1" ajv "^8.12.0" object-traversal "^1.0.1" pluralize "^8.0.0" -"@kickstartds/jsonschema2storyblok@^1.6.8": - version "1.6.8" - resolved "https://registry.npmjs.org/@kickstartds/jsonschema2storyblok/-/jsonschema2storyblok-1.6.8.tgz#0c0cd052628ef0fe7813a5cbd68134f157005940" - integrity sha512-3c9f88+eN6Qun37WXIU1zLHvetI+dG5FIbivXcK8ZFXy2MUX76flMrhASZtxJWjzzmrripp/8rUXaVsmUTL20Q== +"@kickstartds/jsonschema2storyblok@^1.6.9": + version "1.6.9" + resolved "https://registry.npmjs.org/@kickstartds/jsonschema2storyblok/-/jsonschema2storyblok-1.6.9.tgz#877bd469f98d5625ba4f7390531c9032d3637797" + integrity sha512-AnMCBxCfG06rp7yV0bp7oOUSbgiv+iYNf1pLWKOWSJ0Qzz8wFRWK1wxozHwZ2OCB7rPsx34bJzCabwpAtg6UHQ== dependencies: - "@kickstartds/jsonschema-utils" "3.8.0" + "@kickstartds/jsonschema-utils" "3.8.1" ajv "^8.12.0" object-traversal "^1.0.1" uuid "~9.0.0" -"@kickstartds/jsonschema2types@^1.2.6": - version "1.2.6" - resolved "https://registry.npmjs.org/@kickstartds/jsonschema2types/-/jsonschema2types-1.2.6.tgz#eac239ad47b17df1df31d0889bd7565a6b61cfc5" - integrity sha512-Jp3PEY95KHp6BUZ0a6qg5nuhL5c24ZswSqFqmUVbAFTOhBsqjhI9PqhZu5xHy8/SM0MpsJQhjPgL7IldzwhkAA== +"@kickstartds/jsonschema2types@^1.2.7": + version "1.2.7" + resolved "https://registry.npmjs.org/@kickstartds/jsonschema2types/-/jsonschema2types-1.2.7.tgz#31753adcb79cd2c8a73a57f3195c94bc623dc8a4" + integrity sha512-f3yNQWFzGLZf2Jgnr4OyBJl8+ldgo/WmnSJML1OZ8QJ1bcj8cwaHhNxHWNCHRhExguIwReHLq6HKJUaADlkmuw== dependencies: "@kickstartds/json-schema-to-typescript" "~13.1.20" - "@kickstartds/jsonschema-utils" "3.8.0" + "@kickstartds/jsonschema-utils" "3.8.1" ajv "^8.12.0" object-traversal "^1.0.1" -"@kickstartds/jsonschema2uniform@^1.4.25": - version "1.4.25" - resolved "https://registry.npmjs.org/@kickstartds/jsonschema2uniform/-/jsonschema2uniform-1.4.25.tgz#87ef3de6b2e31f33a285329f2fd95a324b1f1d48" - integrity sha512-OiMDXzlGonBoYBwRQ1w6+4yT9hkXbZhMfpVYcGR3S4swWMiCBQ4X0Zm/d23U7WKr6NbvEFYK0PzyN+LQlKx8DA== +"@kickstartds/jsonschema2uniform@^1.4.26": + version "1.4.26" + resolved "https://registry.npmjs.org/@kickstartds/jsonschema2uniform/-/jsonschema2uniform-1.4.26.tgz#255d7d1b05fe8ef62e307a8dc81a0533c1748617" + integrity sha512-C3l+HEofAulRHHX8KKW+dYMvteUptxgbyRrAuhmCGEuBAUYwVWmtIyC1RftvGs4syf8eSiOJvWbXORNIx0RYkw== dependencies: - "@kickstartds/jsonschema-utils" "3.8.0" + "@kickstartds/jsonschema-utils" "3.8.1" ajv "^8.12.0" change-case "^5.0.2" From c157fd93f8b4ddecf9689861356d04bb36f35a47 Mon Sep 17 00:00:00 2001 From: Jonas Ulrich | ruhmesmeile GmbH Date: Wed, 30 Jul 2025 16:47:13 +0200 Subject: [PATCH 5/6] fix(schema): update layering --- src/tasks/schema/defaults-task.ts | 8 ++----- src/tasks/schema/dereference-task.ts | 9 +++---- src/tasks/schema/types-task.ts | 8 ++----- src/util/schema.ts | 35 ++++++++++++++++++++++++---- 4 files changed, 38 insertions(+), 22 deletions(-) diff --git a/src/tasks/schema/defaults-task.ts b/src/tasks/schema/defaults-task.ts index 6500f01..80765e3 100644 --- a/src/tasks/schema/defaults-task.ts +++ b/src/tasks/schema/defaults-task.ts @@ -80,13 +80,9 @@ const run = async ( (schemaPath) => schemaPath.endsWith( `/${schemaId.split('/').pop()}` || 'NO MATCH' - ) && - (schemaId.startsWith('http://cms.') - ? !schemaPath.includes('node_modules') - : true) + ) && !schemaPath.includes('node_modules') ); - if (!schemaPath) - throw new Error("Couldn't find matching schema path for schema $id"); + if (!schemaPath) return true; const base = basename(schemaPath, '.json'); const dir = dirname(schemaPath); diff --git a/src/tasks/schema/dereference-task.ts b/src/tasks/schema/dereference-task.ts index 37f8f12..99f29a5 100644 --- a/src/tasks/schema/dereference-task.ts +++ b/src/tasks/schema/dereference-task.ts @@ -5,6 +5,7 @@ import chalkTemplate from 'chalk-template'; import createTask from '../task.js'; import { StepFunction } from '../../../types/index.js'; import fsExtra from 'fs-extra'; +import { getTopLayerSchemas } from '@kickstartds/jsonschema-utils'; const writeFile = fsExtra.writeFile; @@ -79,13 +80,9 @@ const run = async ( (schemaPath) => schemaPath.endsWith( `/${schemaId.split('/').pop()}` || 'NO MATCH' - ) && - (schemaId.startsWith('http://cms.') - ? !schemaPath.includes('node_modules') - : true) + ) && !schemaPath.includes('node_modules') ); - if (!schemaPath) - throw new Error("Couldn't find matching schema path for schema $id"); + if (!schemaPath) return true; const base = basename(schemaPath, '.json'); const dir = dirname(schemaPath); diff --git a/src/tasks/schema/types-task.ts b/src/tasks/schema/types-task.ts index c750782..97aee27 100644 --- a/src/tasks/schema/types-task.ts +++ b/src/tasks/schema/types-task.ts @@ -80,13 +80,9 @@ const run = async ( (schemaPath) => schemaPath.endsWith( `/${schemaId.split('/').pop()}` || 'NO MATCH' - ) && - (schemaId.startsWith('http://cms.') - ? !schemaPath.includes('node_modules') - : true) + ) && !schemaPath.includes('node_modules') ); - if (!schemaPath) - throw new Error("Couldn't find matching schema path for schema $id"); + if (!schemaPath) return true; const base = basename(schemaPath, '.json'); const dir = dirname(schemaPath); diff --git a/src/util/schema.ts b/src/util/schema.ts index d0eb8fe..d6003d0 100644 --- a/src/util/schema.ts +++ b/src/util/schema.ts @@ -41,10 +41,23 @@ export default (logger: winston.Logger): SchemaUtil => { loadPageSchema: defaultPageSchema, layerRefs: layerKickstartdsComponents, layerOrder, + typeResolution: false, }); const customSchemaIds = getCustomSchemaIds(schemaIds); + const customSchemas = getSchemasForIds(customSchemaIds, ajv); + const topLayerSchemas = getTopLayerSchemas(customSchemas, layerOrder); + const topLayerSchemaIds = []; + for (const schema of topLayerSchemas) { + if (schema.$id) { + topLayerSchemaIds.push(schema.$id); + } else { + subCmdLogger.warn( + chalkTemplate`Schema ${schema.title} has no $id, skipping` + ); + } + } - const dereffedSchemas = await dereference(customSchemaIds, ajv); + const dereffedSchemas = await dereference(topLayerSchemaIds, ajv); subCmdLogger.info( chalkTemplate`dereferencing {bold ${ @@ -108,7 +121,8 @@ export default (logger: winston.Logger): SchemaUtil => { layerRefs: layerKickstartdsComponents, layerOrder, }); - const schemas = getSchemasForIds(schemaIds, ajv); + const customSchemaIds = getCustomSchemaIds(schemaIds); + const schemas = getSchemasForIds(customSchemaIds, ajv); const topLayerSchemas = getTopLayerSchemas(schemas, layerOrder); const topLayerSchemaIds = []; for (const schema of topLayerSchemas) { @@ -120,7 +134,6 @@ export default (logger: winston.Logger): SchemaUtil => { ); } } - // const customSchemaIds = getCustomSchemaIds(schemaIds); const renderImportStatement = (schemaId: string) => schemaId.includes('schema.kickstartds.com') @@ -250,11 +263,24 @@ ${convertedTs[schemaId]} loadPageSchema: defaultPageSchema, layerRefs: layerKickstartdsComponents, layerOrder, + typeResolution: false, }); const kdsSchemaIds = schemaIds.filter((schemaId) => schemaId.includes('schema.kickstartds.com') ); const customSchemaIds = getCustomSchemaIds(schemaIds); + const customSchemas = getSchemasForIds(customSchemaIds, ajv); + const topLayerSchemas = getTopLayerSchemas(customSchemas, layerOrder); + const topLayerSchemaIds = []; + for (const schema of topLayerSchemas) { + if (schema.$id) { + topLayerSchemaIds.push(schema.$id); + } else { + subCmdLogger.warn( + chalkTemplate`Schema ${schema.title} has no $id, skipping` + ); + } + } const defaultObjects: Record = {}; for (const schemaId of customSchemaIds) { @@ -268,7 +294,7 @@ ${convertedTs[schemaId]} return `${pascalCase(getSchemaName(layeredId))}Props`; }; - for (const schemaId of Object.keys(defaultObjects)) { + for (const schemaId of topLayerSchemaIds) { defaultObjects[schemaId] = `import { DeepPartial } from "../helpers"; import { ${getImportName(schemaId)} } from "./${getImportName(schemaId)}"; @@ -298,6 +324,7 @@ export default defaults;`; ) => { const ajv = getSchemaRegistry(); const schemaIds = await processSchemaGlobs(schemaGlobs, ajv, { + typeResolution: false, hideCmsFields: true, layerOrder, }); From 61bc03591585592e486a456f379c3493bfe59aac Mon Sep 17 00:00:00 2001 From: Jonas Ulrich | ruhmesmeile GmbH Date: Wed, 30 Jul 2025 17:22:31 +0200 Subject: [PATCH 6/6] fix(schema): bug in schema default objects --- src/util/schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/schema.ts b/src/util/schema.ts index d6003d0..8f3825e 100644 --- a/src/util/schema.ts +++ b/src/util/schema.ts @@ -283,7 +283,7 @@ ${convertedTs[schemaId]} } const defaultObjects: Record = {}; - for (const schemaId of customSchemaIds) { + for (const schemaId of topLayerSchemaIds) { defaultObjects[schemaId] = await getSchemaDefaults(schemaId, ajv); }