Skip to content

Commit

Permalink
fix(schema): add option to exclude default page schema from dereference
Browse files Browse the repository at this point in the history
  • Loading branch information
julrich committed Sep 24, 2024
1 parent 344fb56 commit d9aff4f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/commands/schema/dereference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const dereference = new Command('dereference')
'--cms-path <path>',
chalkTemplate`relative path from project root to your cms specific components directory, default {bold ./src/components}`
)
.option(
'--load-page-schema',
chalkTemplate`load default page schema, default {bold true}`
)
.option(
'--rc-only',
chalkTemplate`only read configuration from {bold .schema-dereferencerc.json}, skip prompts`,
Expand All @@ -31,6 +35,7 @@ const dereference = new Command('dereference')
runTask(
options.componentsPath,
options.cmsPath,
options.loadPageSchema,
options.rcOnly,
options.revert,
options.cleanup,
Expand Down
3 changes: 2 additions & 1 deletion src/tasks/schema/dereference-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const {
const run = async (
componentsPath: string = 'src/components',
cmsPath: string,
loadPageSchema: boolean = true,
rcOnly: boolean,
isRevert: boolean,
shouldCleanup: boolean,
Expand All @@ -56,7 +57,7 @@ const run = async (
globs.push(`${callingPath}/${cmsPath}/**/*.schema.json`);
}
const customSchemaPaths = await fg(globs);
const dereffed = await schemaDereferenceSchemas(globs);
const dereffed = await schemaDereferenceSchemas(globs, loadPageSchema);

logger.info(
chalkTemplate`dereffed {bold ${
Expand Down
9 changes: 7 additions & 2 deletions src/util/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ const renderImportName = (schemaId: string) =>
export default (logger: winston.Logger): SchemaUtil => {
const subCmdLogger = logger.child({ utility: true });

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

const dereffedSchemas = await dereference(customSchemaIds, ajv);
Expand Down
3 changes: 2 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ interface SchemaUtil {
mergeAllOf: boolean
) => Promise<Record<string, string>>;
dereferenceSchemas: (
schemaGlobs: string[]
schemaGlobs: string[],
loadPageSchema: boolean
) => Promise<Record<string, JSONSchema.Interface>>;
toStoryblok: (
schemaGlobs: string[],
Expand Down

0 comments on commit d9aff4f

Please sign in to comment.