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

@lfantom/design-tokens-poc

v1.0.0

Published

An example to show how to automate build files that match folders

Downloads

2

Readme

design-tokens-poc

Deisgn tokens concept using Style Dictionary

Automatically generate separate build files that match your folder structure

This example shows how you can manage what tokens are generated and how they are organized. This is useful when you want to generate a 1:1 relationship between build files and token categories.

Common use cases include:

  • Each token category as its own Sass partial (_colors.scss)
  • Separate component files (button.css, input.css, etc)
  • Tree shaking (only import what you need)

Running the example

First of all, set up the required dependencies running the command npm install in your local CLI environment (if you prefer to use yarn, update the commands accordingly).

At this point, you can run npm run build. This command will generate the output file in the build folder.

How does it work

The "build" command processes the JSON files in the tokens folder. The index.js file adds each folder, allowing you to map through them in config.js. The script goes through each folder and generates a file for each folder and populates it with tokens that match the filter.

# tokens/color/base.json
{
   "color": {
       "red": {
            "value": "#FF0000"
        }
   }
}
# tokens/size/base.json
{
   "size": {
       "small": {
            "value": "2px"
        }
   }
}

Because the folder name matches the category, the output would automatically generate separate color and size files.

What to look at

Open the config.js file and see how the script first looks within the tokens directory to map through each folder. The destination then outputs a file that would match the name, and fill that file with the tokens that match the filter criteria.

     files: core.map((tokenCategory) => {
        return {
          destination: `${tokenCategory}.css`,
          format: "css/variables",
          filter: function (token) {
            console.log({ tokenCategory });
            console.log(token);
            return token.filePath.includes(tokenCategory);
          },
        };
      }),

Now each new folder that gets added will automatically generate a corresponding file filled with tokens that match the category!

Token structure

Core and Semantic tokens

  • Category
  • Subcategory
  • Item
  • Sub-item
  • Variant
  • Size

e.g text-body-size-sm

Component tokens

  • Item
  • Sub-item
  • Variant
  • Category
  • Subcategory
  • Size

e.g button-primary-text-color