Skip to content

Commit

Permalink
fix(schema): add page exclusion option to other schema related tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
julrich committed Sep 24, 2024
1 parent 38509dd commit dc35b8a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/commands/schema/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const types = new Command('layer')
chalkTemplate`merge allOf declarations in processed {bold JSON Schemas} / {bold component APIs}, default {bold false}`,
false
)
.option(
'--no-default-page-schema',
chalkTemplate`disable load of default page schema, default {bold false}`
)
.option(
'--rc-only',
chalkTemplate`only read configuration from {bold .schema-typesrc.json}, skip prompts`,
Expand All @@ -43,6 +47,7 @@ const types = new Command('layer')
options.cmsPath,
options.typesPath,
options.mergeSchemas,
options.defaultPageSchema,
options.rcOnly,
options.revert,
options.cleanup,
Expand Down
5 changes: 5 additions & 0 deletions src/commands/schema/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const types = new Command('types')
chalkTemplate`merge allOf declarations in processed {bold JSON Schemas} / {bold component APIs}, default {bold false}`,
false
)
.option(
'--no-default-page-schema',
chalkTemplate`disable load of default page schema, default {bold false}`
)
.option(
'--rc-only',
chalkTemplate`only read configuration from {bold .schema-typesrc.json}, skip prompts`,
Expand All @@ -37,6 +41,7 @@ const types = new Command('types')
options.componentsPath,
options.cmsPath,
options.mergeSchemas,
options.defaultPageSchema,
options.rcOnly,
options.revert,
options.cleanup,
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 @@ -35,6 +35,7 @@ const run = async (
cmsPath: string,
typesPath: string = 'src/types',
mergeSchemas: boolean,
defaultPageSchema: boolean = true,
rcOnly: boolean,
isRevert: boolean,
shouldCleanup: boolean,
Expand Down Expand Up @@ -62,7 +63,8 @@ const run = async (

const layeredTypes = await schemaLayerComponentPropTypes(
globs,
mergeSchemas
mergeSchemas,
defaultPageSchema
);

shell.mkdir('-p', `${shell.pwd()}/${typesPath}/`);
Expand Down
7 changes: 6 additions & 1 deletion src/tasks/schema/types-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const run = async (
componentsPath: string = 'src/components',
cmsPath: string,
mergeSchemas: boolean,
defaultPageSchema: boolean = true,
rcOnly: boolean,
isRevert: boolean,
shouldCleanup: boolean,
Expand All @@ -58,7 +59,11 @@ const run = async (
globs.push(`${callingPath}/${cmsPath}/**/*.schema.json`);
}
const customSchemaPaths = await fg(globs);
const types = await schemaGenerateComponentPropTypes(globs, mergeSchemas);
const types = await schemaGenerateComponentPropTypes(
globs,
mergeSchemas,
defaultPageSchema
);

await Promise.all(
Object.keys(types).map(async (schemaId) => {
Expand Down
8 changes: 6 additions & 2 deletions src/util/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ export default (logger: winston.Logger): SchemaUtil => {

const generateComponentPropTypes = async (
schemaGlobs: string[],
mergeAllOf: boolean
mergeAllOf: boolean,
defaultPageSchema = true
) => {
subCmdLogger.info(
chalkTemplate`generating component prop types for component schemas`
Expand All @@ -91,6 +92,7 @@ export default (logger: winston.Logger): SchemaUtil => {
const schemaIds = await processSchemaGlobs(schemaGlobs, ajv, {
typeResolution: false,
mergeAllOf: mergeAllOf,
loadPageSchema: defaultPageSchema,
});
const customSchemaIds = getCustomSchemaIds(schemaIds);

Expand Down Expand Up @@ -121,7 +123,8 @@ export default (logger: winston.Logger): SchemaUtil => {

const layerComponentPropTypes = async (
schemaGlobs: string[],
mergeAllOf: boolean
mergeAllOf: boolean,
defaultPageSchema = true
) => {
subCmdLogger.info(
chalkTemplate`layering component prop types for component schemas`
Expand All @@ -131,6 +134,7 @@ export default (logger: winston.Logger): SchemaUtil => {
const schemaIds = await processSchemaGlobs(schemaGlobs, ajv, {
typeResolution: false,
mergeAllOf: mergeAllOf,
loadPageSchema: defaultPageSchema,
});
const kdsSchemaIds = schemaIds.filter((schemaId) =>
schemaId.includes('schema.kickstartds.com')
Expand Down
6 changes: 4 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,13 @@ interface SchemaUtil {
helper: {
generateComponentPropTypes: (
schemaGlobs: string[],
mergeAllOf: boolean
mergeAllOf: boolean,
defaultPageSchema: boolean
) => Promise<Record<string, string>>;
layerComponentPropTypes: (
schemaGlobs: string[],
mergeAllOf: boolean
mergeAllOf: boolean,
defaultPageSchema: boolean
) => Promise<Record<string, string>>;
dereferenceSchemas: (
schemaGlobs: string[],
Expand Down

0 comments on commit dc35b8a

Please sign in to comment.