Skip to content

Commit

Permalink
Merge pull request #54 from kickstartDS/fix/add-option-to-toggle-defa…
Browse files Browse the repository at this point in the history
…ult-page

Add option to toggle default page
  • Loading branch information
julrich authored Oct 4, 2024
2 parents c1b0a57 + dc35b8a commit 15a8a48
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 11 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# v3.1.0 (Tue Aug 20 2024)

#### 🚀 Enhancement

- Add cms layering capabilities [#52](https://github.com/kickstartDS/cli/pull/52) ([@julrich](https://github.com/julrich))

#### 🐛 Bug Fix


#### Authors: 1

- Jonas Ulrich ([@julrich](https://github.com/julrich))

---

# v3.0.0 (Fri Apr 12 2024)

#### 💥 Breaking Change
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kickstartds",
"version": "3.0.0",
"version": "3.1.0",
"description": "kickstartDS CLI utility",
"keywords": [],
"license": "(MIT OR Apache-2.0)",
Expand Down
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(
'--no-default-page-schema',
chalkTemplate`disable load of default page schema, default {bold false}`
)
.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.defaultPageSchema,
options.rcOnly,
options.revert,
options.cleanup,
Expand Down
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
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,
defaultPageSchema: 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, defaultPageSchema);

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 @@ -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
17 changes: 13 additions & 4 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[],
defaultPageSchema = true
) => {
const ajv = getSchemaRegistry();
const schemaIds = await processSchemaGlobs(schemaGlobs, ajv);
const schemaIds = await processSchemaGlobs(schemaGlobs, ajv, {
loadPageSchema: defaultPageSchema,
});
const customSchemaIds = getCustomSchemaIds(schemaIds);

const dereffedSchemas = await dereference(customSchemaIds, ajv);
Expand Down Expand Up @@ -76,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 @@ -86,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 @@ -116,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 @@ -126,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
9 changes: 6 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,17 @@ 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[]
schemaGlobs: string[],
defaultPageSchema: boolean
) => Promise<Record<string, JSONSchema.Interface>>;
toStoryblok: (
schemaGlobs: string[],
Expand Down

0 comments on commit 15a8a48

Please sign in to comment.