npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

theme-json-generator

v0.3.0

Published

Generate WordPress theme.json from your tailwind.config with Webpack.

Downloads

11

Readme

Theme JSON for Developers

A Webpack plugin for programmatically generating WordPress theme.json with JavaScript from tailwind.config or another configuration file.

Core Concepts

  • Use Webpack and JavaScript functions to programmatically generate JSON files.
  • Reduce duplicate code by re-using the Tailwind variables you're already to create the theme.json options.
  • JSON is difficult to work with, writing JSON as JavaScript is much more efficient and allows for using variables and functions.

Getting Started

To begin, you'll need to install theme-json-generator.

npm install theme-json-generator --save-dev

Then add the plugin to your webpack config like so:

// webpack.config.js
const { ThemeJsonPlugin } = require( 'theme-json-generator' );

module.exports = {
 plugins: [
  new ThemeJsonPlugin( {
   from: './src/theme.config.js',
   to: './theme.json',
  } ),
 ],
};

Config Parameters

| Option | Description | Default | Type | |------- |----------------------------------------------------------------------------------------------------- |------------------- |---------- | | from | Relative path to the config JS file used to generate theme.json. | theme.config.js | string | | to | Relative path to the generated JSON file. If the file does not exist it will be created at runtime. | theme.json | string |

Note: Do not use absolute filepaths using NodeJS path module in theto or from options. These should be relative file paths based on the location of the originating script.

theme.config.js

theme.config.js is the JavaScript file used for compiling theme.json.

This file is essentially as JavaScript version of theme.json where functions and variables are used to build out the contents of the json file.

In the code example below, Tailwind config values are passed into the theme.config and are used to generate the theme.json options.

 // theme.config.js
 const {transform} = require('theme-json-generator'); // Plugin helper for transforming data.
 const {theme} = require('../tailwind.config.js'); // Import Tailwind config.

 module.exports = {
    settings: {
       layout: {
          contentSize: theme.extend.screens.desktop || '',
       },
       typography: {
          lineHeight: false,
          textDecoration: false,
          textTransform: false,
          dropCap: false,
          fontSizes: [],
          fontFamilies: [],
       },
       color: {
          palette: transform('palette', theme.extend.colors),
       },
       blocks: {
          'core/button': {
             color: {
                background: true,
                text: true,
                gradients: [],
                palette: transform('palette', theme.extend.colors),
             },
          },
          'core/pullquote': {
             border: {
                radius: false,
                style: false,
                color: false,
                width: false,
             },
             typography: {
                fontSizes: [],
             },
          },
          'core/buttons': {
             layout: {},
             typography: {
                fontSizes: [],
             },
          },
          'core/heading': {
             color: {
                text: true,
                background: true,
                palette: transform('palette', theme.extend.colors, [
                   'blue',
                   'teal',
                   'cyan',
                   'black',
                ]),
                link: false,
             },
          },
       },
    },
    styles: {
       typography: {
          fontFamily: theme.extend.fontFamily.sans.toString(),
          fontSize: theme.extend.fontSize.base,
          lineHeight: '1.5',
       },
       elements: {
          link: {
             color: {
                text: theme.extend.colors.blue,
             },
             typography: {
                textDecoration: 'none',
             },
             ':hover': {
                color: {
                   text: theme.extend.colors.black,
                },
             },
             ':focus': {
                color: {
                   text: theme.extend.colors.black,
                },
             },
          },
          cite: {
             typography: {
                fontSize: theme.extend.fontSize['14'],
                fontStyle: 'normal',
                fontWeight: '800',
                textTransform: 'uppercase',
             },
          },
       },
       blocks: {
          'core/quote': {
             typography: {
                fontSize: theme.extend.fontSize['20'],
                fontWeight: '400',
             },
             color: {
                text: theme.extend.colors.text,
                background: theme.extend.colors.bkg,
             },
             spacing: {
                padding: {
                   top: theme.spacing[5],
                   right: theme.spacing[5],
                   bottom: theme.spacing[5],
                   left: theme.spacing[5],
                },
                margin: {
                   bottom: theme.spacing[5],
                },
             },
          },
          'core/heading': {
             typography: {
                fontWeight: '700',
             },
             color: {
                text: theme.extend.colors.heading,
             },
             spacing: {
                margin: {
                   bottom: theme.spacing[3],
                },
             },
          },
          'core/paragraph': {
             typography: {
                lineHeight: '1.5',
             },
             color: {
                text: theme.extend.colors.text,
             },
             spacing: {
                margin: {
                   top: '0',
                   bottom: theme.spacing[5],
                },
             },
          },
       },
    },
 };