Skip to content

Commit

Permalink
Merge pull request #57 from kickstartDS/feature/add-layering-options
Browse files Browse the repository at this point in the history
Add ref layering option switch to schema tasks
  • Loading branch information
julrich authored Nov 13, 2024
2 parents 5fc799f + 0686385 commit b8bd084
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/commands/schema/dereference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const dereference = new Command('dereference')
'--no-default-page-schema',
chalkTemplate`disable load of default page schema, default {bold false}`
)
.option(
'--layer-kickstartds-components',
chalkTemplate`whether kickstartDS base components should be layered`,
true
)
.option(
'--rc-only',
chalkTemplate`only read configuration from {bold .schema-dereferencerc.json}, skip prompts`,
Expand All @@ -36,6 +41,7 @@ const dereference = new Command('dereference')
options.componentsPath,
options.cmsPath,
options.defaultPageSchema,
options.layerKickstartdsComponents,
options.rcOnly,
options.revert,
options.cleanup,
Expand Down
6 changes: 6 additions & 0 deletions src/commands/schema/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ const types = new Command('layer')
'--no-default-page-schema',
chalkTemplate`disable load of default page schema, default {bold false}`
)
.option(
'--layer-kickstartds-components',
chalkTemplate`whether kickstartDS base components should be layered`,
true
)
.option(
'--rc-only',
chalkTemplate`only read configuration from {bold .schema-typesrc.json}, skip prompts`,
Expand All @@ -48,6 +53,7 @@ const types = new Command('layer')
options.typesPath,
options.mergeSchemas,
options.defaultPageSchema,
options.layerKickstartdsComponents,
options.rcOnly,
options.revert,
options.cleanup,
Expand Down
6 changes: 6 additions & 0 deletions src/commands/schema/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const types = new Command('types')
'--no-default-page-schema',
chalkTemplate`disable load of default page schema, default {bold false}`
)
.option(
'--layer-kickstartds-components',
chalkTemplate`whether kickstartDS base components should be layered`,
true
)
.option(
'--rc-only',
chalkTemplate`only read configuration from {bold .schema-typesrc.json}, skip prompts`,
Expand All @@ -42,6 +47,7 @@ const types = new Command('types')
options.cmsPath,
options.mergeSchemas,
options.defaultPageSchema,
options.layerKickstartdsComponents,
options.rcOnly,
options.revert,
options.cleanup,
Expand Down
7 changes: 6 additions & 1 deletion src/tasks/schema/dereference-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const run = async (
componentsPath: string = 'src/components',
cmsPath: string,
defaultPageSchema: boolean = true,
layerKickstartdsComponents: boolean = true,
rcOnly: boolean,
isRevert: boolean,
shouldCleanup: boolean,
Expand All @@ -57,7 +58,11 @@ const run = async (
globs.push(`${callingPath}/${cmsPath}/**/*.schema.json`);
}
const customSchemaPaths = await fg(globs);
const dereffed = await schemaDereferenceSchemas(globs, defaultPageSchema);
const dereffed = await schemaDereferenceSchemas(
globs,
defaultPageSchema,
layerKickstartdsComponents
);

logger.info(
chalkTemplate`dereffed {bold ${
Expand Down
4 changes: 3 additions & 1 deletion src/tasks/schema/layer-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const run = async (
typesPath: string = 'src/types',
mergeSchemas: boolean,
defaultPageSchema: boolean = true,
layerKickstartdsComponents: boolean = true,
rcOnly: boolean,
isRevert: boolean,
shouldCleanup: boolean,
Expand Down Expand Up @@ -64,7 +65,8 @@ const run = async (
const layeredTypes = await schemaLayerComponentPropTypes(
globs,
mergeSchemas,
defaultPageSchema
defaultPageSchema,
layerKickstartdsComponents
);

shell.mkdir('-p', `${shell.pwd()}/${typesPath}/`);
Expand Down
2 changes: 2 additions & 0 deletions src/tasks/schema/types-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const run = async (
cmsPath: string,
mergeSchemas: boolean,
defaultPageSchema: boolean = true,
layerKickstartdsComponents: boolean = true,
rcOnly: boolean,
isRevert: boolean,
shouldCleanup: boolean,
Expand Down Expand Up @@ -63,6 +64,7 @@ const run = async (
globs,
mergeSchemas,
defaultPageSchema,
layerKickstartdsComponents,
componentsPath
);

Expand Down
10 changes: 8 additions & 2 deletions src/util/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ export default (logger: winston.Logger): SchemaUtil => {

const dereferenceSchemas = async (
schemaGlobs: string[],
defaultPageSchema = true
defaultPageSchema = true,
layerKickstartdsComponents = true
) => {
const ajv = getSchemaRegistry();
const schemaIds = await processSchemaGlobs(schemaGlobs, ajv, {
loadPageSchema: defaultPageSchema,
layerRefs: layerKickstartdsComponents,
});
const customSchemaIds = getCustomSchemaIds(schemaIds);

Expand Down Expand Up @@ -82,6 +84,7 @@ export default (logger: winston.Logger): SchemaUtil => {
schemaGlobs: string[],
mergeAllOf: boolean,
defaultPageSchema = true,
layerKickstartdsComponents = true,
componentsPath = 'src/components'
) => {
subCmdLogger.info(
Expand All @@ -93,6 +96,7 @@ export default (logger: winston.Logger): SchemaUtil => {
typeResolution: false,
mergeAllOf: mergeAllOf,
loadPageSchema: defaultPageSchema,
layerRefs: layerKickstartdsComponents,
});
const customSchemaIds = getCustomSchemaIds(schemaIds);

Expand Down Expand Up @@ -132,7 +136,8 @@ export default (logger: winston.Logger): SchemaUtil => {
const layerComponentPropTypes = async (
schemaGlobs: string[],
mergeAllOf: boolean,
defaultPageSchema = true
defaultPageSchema = true,
layerKickstartdsComponents = true
) => {
subCmdLogger.info(
chalkTemplate`layering component prop types for component schemas`
Expand All @@ -143,6 +148,7 @@ export default (logger: winston.Logger): SchemaUtil => {
typeResolution: false,
mergeAllOf: mergeAllOf,
loadPageSchema: defaultPageSchema,
layerRefs: layerKickstartdsComponents,
});
const kdsSchemaIds = schemaIds.filter((schemaId) =>
schemaId.includes('schema.kickstartds.com')
Expand Down
7 changes: 5 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,19 @@ interface SchemaUtil {
schemaGlobs: string[],
mergeAllOf: boolean,
defaultPageSchema: boolean,
layerRefs: boolean,
componentsPath: string
) => Promise<Record<string, string>>;
layerComponentPropTypes: (
schemaGlobs: string[],
mergeAllOf: boolean,
defaultPageSchema: boolean
defaultPageSchema: boolean,
layerRefs: boolean
) => Promise<Record<string, string>>;
dereferenceSchemas: (
schemaGlobs: string[],
defaultPageSchema: boolean
defaultPageSchema: boolean,
layerRefs: boolean
) => Promise<Record<string, JSONSchema.Interface>>;
toStoryblok: (
schemaGlobs: string[],
Expand Down

0 comments on commit b8bd084

Please sign in to comment.