Skip to content

Commit

Permalink
Generate gutenberg types
Browse files Browse the repository at this point in the history
  • Loading branch information
nygrenh committed Oct 11, 2024
1 parent ac6a3b0 commit abbcfd0
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 2,515 deletions.
13 changes: 10 additions & 3 deletions services/cms/scripts/extractGutenbergAttributeTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,18 @@ async function main() {
res = res.concat(
block.deprecated?.map((deprecated, n) => {
const blockName = sanitizeNames(block.name)
let required: string[] = []
if (deprecated.attributes !== null && deprecated.attributes !== undefined) {
required = Object.entries(deprecated.attributes)
.filter(([_key, value]) => (value as { default: unknown }).default !== undefined)
.map(([key, _value]) => key)
}
return {
title: blockName.replace("Attributes", `Deprecated${n + 1}Attributes`),
type: "object" as JSONSchemaTypeName,
properties: fixProperties(deprecated.attributes),
additionalProperties: false,
required: Object.entries(deprecated.attributes)
.filter(([_key, value]) => (value as { default: unknown }).default !== undefined)
.map(([key, _value]) => key),
required: required,
deprecated: true,
}
}),
Expand Down Expand Up @@ -238,6 +242,9 @@ import type { StringWithHTML } from "."
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function fixProperties(properties: { readonly [x: string]: any }) {
const res = { ...properties }
if (properties === null || properties === undefined) {
return properties
}
for (const [_key, value] of Object.entries(properties)) {
if (value.type === "rich-text") {
value.tsType = "StringWithHTML"
Expand Down
Loading

0 comments on commit abbcfd0

Please sign in to comment.