Skip to content

Conversation

@kellymears
Copy link
Contributor

@kellymears kellymears commented Mar 5, 2022

This PR

  • generates theme.json from bud.config.js
  • sets theme.json palette from tailwind.config.js

See: updated @roots/sage documentation on theme.json support

TODOs

@github-actions github-actions bot added the build label Mar 5, 2022
@kellymears kellymears requested a review from retlehs March 5, 2022 06:31
@retlehs retlehs changed the title feat: bud 5.5.0 config features feat: generate theme.json from bud.config.js Mar 5, 2022
@retlehs

This comment was marked as resolved.

@retlehs retlehs modified the milestones: 10.1.0, 10.2.0 Mar 5, 2022
@kellymears

This comment was marked as resolved.

@joshuafredrickson
Copy link
Contributor

I'm running into this when using a callback with themeJson:

bud.config.js:

    .themeJson((theme) => {
      theme.set("typography.customFontSize", true);
      return theme;
    })

This nests a duplicate settings object inside settings > respository and doesn't set the customFontSize. Resulting theme.json:

{
  "__generated__": "⚠️ This file is generated. Do not edit.",
  "$schema": "https://schemas.wp.org/trunk/theme.json",
  "version": 2,
  "settings": {
    "ident": "container",
    "repository": {
      "path": "/site/wp-content/themes/sage-10/theme.json",
      "settings": {
        "color": {
          "custom": false,
          "customGradient": false
        },
        "custom": {
          "spacing": {},
          "typography": {
            "font-size": {},
            "line-height": {}
          }
        },
        "spacing": {
          "padding": true,
          "units": [
            "px",
            "%",
            "em",
            "rem",
            "vw",
            "vh"
          ]
        },
        "typography": {
          "customFontSize": false,
          "dropCap": false
        }
      }
    }
  }
}

It all works if I use standard json with themeJson, but then I have to set the entire json vs using the handy defaults already available.

@retlehs retlehs removed this from the 10.2.0 milestone Jul 10, 2022
@kellymears
Copy link
Contributor Author

kellymears commented Jul 28, 2022

this would obviously need to be updated, but I'm thinking we can revisit now.

This:

  app.wpjson
    .settings((theme) => theme.set("typography.customFontSize", true))
    .enable();

Yields the expected result:

{
  "__generated__": "⚠️ This file is generated. Do not edit.",
  "$schema": "https://schemas.wp.org/trunk/theme.json",
  "version": 2,
  "settings": {
    "color": {
      "custom": false,
      "customGradient": false
    },
    "custom": {
      "spacing": {},
      "typography": {
        "font-size": {},
        "line-height": {}
      }
    },
    "spacing": {
      "padding": true,
      "units": [
        "px",
        "%",
        "em",
        "rem",
        "vw",
        "vh"
      ]
    },
    "typography": {
      "customFontSize": true,
      "dropCap": false
    }
  }
}

setOption, and the tailwind helpers all seem OK too:

app.wpjson.useTailwindColors().enable()
  app.wpjson
    .setOption("settings", (settings) => ({
      ...settings,
      typography: {
        ...(settings?.typography ?? {}),
        customFontSize: true,
      },
    }))
    .enable();

Tested w/ 6.3.5

@joshuafredrickson
Copy link
Contributor

I've added this into a new site build and in my limited time with it so far, I agree this is in a place where it's working as expected. 👍

@codepuncher
Copy link

Same here! All working for me. Great feature.

@github-actions github-actions bot removed the build label Sep 22, 2022
@retlehs retlehs marked this pull request as draft September 23, 2022 20:49
@retlehs retlehs added this to the 10.3.0 milestone Sep 23, 2022
@github-actions github-actions bot removed the build label Sep 24, 2022
@retlehs retlehs marked this pull request as ready for review September 24, 2022 15:25
@abombelli
Copy link

abombelli commented Nov 7, 2022

The script does not include the global styles node at the right position.

The generated theme.json looks like this:

{
  "__generated__": "⚠️ This file is generated. Do not edit.",
  "$schema": "https://schemas.wp.org/trunk/theme.json",
  "version": 2,
  "settings": {
    "appearanceTools": false,
    "color": {
      "custom": false,
      "customGradient": false,
      "defaultPalette": false,
      "defaultGradients": false
    },
    "custom": {
      "spacing": {},
      "typography": {
        "font-size": {},
        "line-height": {}
      }
    },
    "spacing": {
      "padding": true,
      "units": [
        "px",
        "%",
        "em",
        "rem",
        "vw",
        "vh"
      ]
    },
    "typography": {
      "customFontSize": false,
      "fontWeight": false,
      "letterSpacing": false,
      "lineHeight": false,
      "textDecoration": false,
      "textTransform": false,
      "dropCap": false,
      "fontSizes": [],
      "fontFamilies": [
        {
          "fontFamily": "'Frutiger Next', sans-serif",
          "slug": "base",
          "name": "Frutiger Next",
          "fontFace": [
            {
              "fontFamily": "Frutiger Next",
              "fontWeight": "300",
              "fontStyle": "normal",
              "fontStretch": "normal",
              "src": [
                "file:./public/fonts/FrutigerNextLight_normal_normal.e764ad.woff2"
              ]
            }
          ]
        }
      ]
    },
    "layout": {
      "contentSize": "900px",
      "wideSize": "calc(900px + 10vw)"
    },
    "blocks": {
      "core/site-title": {
        "typography": {
          "fontFamilies": [
            {
              "fontFamily": "Helvetica Neue, Helvetica, Arial, sans-serif",
              "slug": "helvetica-arial",
              "name": "Helvetica or Arial"
            }
          ]
        }
      },
      "core/paragraph": {
        "color": {},
        "custom": {},
        "layout": {},
        "spacing": {},
        "typography": {
          "customFontSize": false
        }
      }
    },
    "styles": {
      "elements": {
        "h1": {
          "typography": {
            "fontFamily": "var(--wp--preset--font-family--base)",
            "fontWeight": "500"
          }
        }
      },
      "typography": {
        "fontFamily": "var(--wp--preset--font-family--base)",
        "fontWeight": "300"
      }
    }
  }
}

But the styles node a t the end should be placed outside the settings node:

{
  "__generated__": "⚠️ This file is generated. Do not edit.",
  "$schema": "https://schemas.wp.org/trunk/theme.json",
  "version": 2,
  "settings": {
    "appearanceTools": false,
    "color": {
      "custom": false,
      "customGradient": false,
      "defaultPalette": false,
      "defaultGradients": false
    },
    "custom": {
      "spacing": {},
      "typography": {
        "font-size": {},
        "line-height": {}
      }
    },
    "spacing": {
      "padding": true,
      "units": [
        "px",
        "%",
        "em",
        "rem",
        "vw",
        "vh"
      ]
    },
    "typography": {
      "customFontSize": false,
      "fontWeight": false,
      "letterSpacing": false,
      "lineHeight": false,
      "textDecoration": false,
      "textTransform": false,
      "dropCap": false,
      "fontSizes": [],
      "fontFamilies": [
        {
          "fontFamily": "'Frutiger Next', sans-serif",
          "slug": "base",
          "name": "Frutiger Next",
          "fontFace": [
            {
              "fontFamily": "Frutiger Next",
              "fontWeight": "300",
              "fontStyle": "normal",
              "fontStretch": "normal",
              "src": [
                "file:./public/fonts/FrutigerNextLight_normal_normal.e764ad.woff2"
              ]
            }
          ]
        }
      ]
    },
    "layout": {
      "contentSize": "900px",
      "wideSize": "calc(900px + 10vw)"
    },
    "blocks": {
      "core/site-title": {
        "typography": {
          "fontFamilies": [
            {
              "fontFamily": "Helvetica Neue, Helvetica, Arial, sans-serif",
              "slug": "helvetica-arial",
              "name": "Helvetica or Arial"
            }
          ]
        }
      },
      "core/paragraph": {
        "color": {},
        "custom": {},
        "layout": {},
        "spacing": {},
        "typography": {
          "customFontSize": false
        }
      }
    }
  },
  "styles": {
    "elements": {
      "h1": {
        "typography": {
          "fontFamily": "var(--wp--preset--font-family--base)",
          "fontWeight": "500"
        }
      }
    },
    "typography": {
      "fontFamily": "var(--wp--preset--font-family--base)",
      "fontWeight": "300"
    }
  }
}

This is the setup in bud.config.mjs


/**
     * Generate WordPress `theme.json`
     *
     * @note This overwrites `theme.json` on every build.
     */
    .wpjson
      .settings({
        appearanceTools: false,
        color: {
          custom: false,
          customGradient: false,
          defaultPalette: false,
          defaultGradients: false,
        },
        custom: {
          spacing: {},
          typography: {
            'font-size': {},
            'line-height': {},
          },
        },
        spacing: {
          padding: true,
          units: ['px', '%', 'em', 'rem', 'vw', 'vh'],
        },
        typography: {
          customFontSize: false,
          fontWeight: false,
          letterSpacing: false,
          lineHeight: false,
          textDecoration: false,
          textTransform: false,
          dropCap: false,
          fontSizes: [],
          fontFamilies: [
            {
              fontFamily: "'Frutiger Next', sans-serif",
              slug: "base",
              name: "Frutiger Next",
              "fontFace": [
                {
                  "fontFamily": "Frutiger Next",
                  "fontWeight": "300",
                  "fontStyle": "normal",
                  "fontStretch": "normal",
                  "src": [ "file:./public/fonts/FrutigerNextLight.woff2" ]
                }
              ]
            },
          ],
        },
        layout: {
          contentSize: '900px',
          wideSize: 'calc(900px + 10vw)'
        } ,
        blocks: {
          "core/site-title": {
            "typography": {
              "fontFamilies": [
                {
                  "fontFamily": "Helvetica Neue, Helvetica, Arial, sans-serif",
                  "slug": "helvetica-arial",
                  "name": "Helvetica or Arial"
                }
              ]
            }
          },
            'core/paragraph': {
                color: {},
                custom: {},
                layout: {},
                spacing: {},
                typography: {
                  customFontSize: false
                }
            }
        },
      styles: {
        elements: {
          h1: {
              typography: {
                  fontFamily: "var(--wp--preset--font-family--base)",
                  fontWeight: "500"
              }
          }
        },
        typography: {
              fontFamily: "var(--wp--preset--font-family--base)",
              fontWeight: "300"
        }
      },
    })

Or am I missing something?

UPDATE: Solved using .setOption('styles', { })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants