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

@primer/figma-theme

v0.1.0

Published

Generate development-ready theme JSON files from Figma Styles

Downloads

1

Readme

@primer/figma-theme

Generate a JSON representation of style colors from a Figma file. Forked from jxnblk/figma-theme, which was created by Brent Jackson.

Installation

@primer/figma-theme requires Node.js 11.0 or higher.

To use the command-line API, you may want to install the package globally:

# with npm
npm i -g @primer/figma-theme

# with yarn
yarn global add @primer/figma-theme

If you plan on using the package as part of another Node.js project, you can install it to your dependencies:

# with npm
npm i @primer/figma-theme

# with yarn
yarn add @primer/figma-theme

If you've installed the package as a local dependency, you can run the binary with:

./node_modules/.bin/figma-theme

Basic usage

The CLI can parse JSON created from the Figma API and outputs JSON data to standard output.

Local files

To parse a JSON file created from the Figma API, pass the filename of the JSON file to the command:

figma-theme my-figma-export.json

You can also use - to specify stdin as the source for the JSON data:

./my-export-script.sh | figma-theme -

Download from the Figma API

If you specify your Figma personal access token via an environment variable or a .env file, the CLI can contact the Figma API and export the file for you:

# using an environment variable
FIGMA_TOKEN=asdf1234 figma-theme ...

# using a .env file
echo "FIGMA_TOKEN=asdf1234" > .env
figma-theme ...

To specify which file to export, use the --fetch option to specify a Figma file ID:

FIGMA_TOKEN=asdf1234 figma-theme --fetch xRlnI4wD4TEQGzOERdUfJz

To identify the Figma file ID, look at the part of the URL after /file/. For example, in the URL:

https://www.figma.com/file/abcdef123456/My-Figma-File

the ID is abcdef123456.

Figma styles

The styles in your Figma file must adhere to the following rules:

  • Create a nested structure by using / in your style names, e.g. functional / text / primary (spaces are optional)
  • Your style names must not contain a period
  • Every style you want to be a part of your theme must be used in the file; if a style is unused, its color will be null

Options

Options are passed as CLI flags.

  • --out <file>: redirect output to the given file
  • --pretty: format the JSON output to be more human readable
  • --metadata: include additional metadata for each style
  • --fetch <file_id>: fetch the specified Figma document from the Figma API

For a full list of options, run figma-theme --help.

Example

$ figma-theme --pretty test/fixtures/figma-file.json

{
  "functional": {
    "fill": {
      "red": "#ff0000",
      "blue": "#0085ff",
      "blue-alpha": "rgba(0,133,255,0.7)",
      "gray": null,
    }
  },
  "borders": {
    "green": "#007521",
    "orange": "#ff7a00",
    "black-fade-30": "rgba(0,0,0,0.3)",
  }
}

Local development

To develop locally, clone the repository and install the dependencies with Yarn.

# install dependencies
yarn install

# run tests
yarn test

# run the CLI
./node_modules/.bin/ts-node ./src/cli-boot.ts --help
# OR
yarn cli --help