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

figmasset-export

v0.0.5

Published

Simplifies exporting a number of assets from Figma to disk.

Downloads

47

Readme

Figmasset-export

Simplifies exporting a number of assets from Figma to disk.

One use case for this is when a project that uses FigmassetJS, leaves the iterative design phase and moves into production. You can simply export all assets into a static image directory, and replace the FigmassetJS code with the snippet given below.

Usage

index.js --file <filekey> --frame <node ID or name> --out myassets [more
options]

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]
  --file     File key                                        [string] [required]
  --frame    Node id or name of frame containing assets       [array] [required]
  --token    Figma personal access token (or set FIGMA_TOKEN)           [string]
  --out      Directory to write outputs             [string] [default: "assets"]
  --scale    Scales at which to export: 2 for @2x       [array] [default: [1,2]]

Examples:
  index.js --file BESGFwgYIJRhho324d26tnHd26t --frame 3:5 --frame pins --scale
  1 2 --out public/pins

The --frame option can reference either the node ID ("3:5", found in the URL) of the frame, or its name (found in the Layers sidebar).

Guide

In Figma, arrange your assets as top-level children under one or more frames. That is, your Layers sidebar should look something like this:

# myframe
  # mycircle
  # myrectangle
# myotherframe
  # myexclamation
    - dot
    - straight bit
# other frame I don't care about
  # junk

(The top-level children under each frame don't have to themselves be frames - they can be any type.)

Get the file key from the URL. Given a URL like https://www.figma.com/file/ABC123/Untitled?node-id=0%3A1, "ABC123" is your file key.

In this scenario, you can export your assets like this:

figmasset-export --file ABC123 --frame myframe myotherframe --scale 1 2 --out assets

This will produce these files:

assets@1x/
  assets.json
  mycircle.png
  myrectangle.png
  myexclamation.png
assets@2x/
  assets.json
  mycircle.png
  myrectangle.png
  myexclamation.png

Load assets as icons into Mapbox GL JS or Maplibre GL JS

You can use the generated assets.json files to load the assets as icons into a Map* GL JS map, as follows:

async function loadAssets(map) {
    const assets = (await fetch('myicons/assets.json').then(r => r.json)).data;
    for (const asset of assets) {
        map.loadImage(`myicons/${asset.fileName}`, (error, image) => {
            this.map.addImage(asset.id, image, { pixelRatio: asset.scale })
        });
    }
}

Generate a Mapbox GL or Maplibre GL spritesheet

It is easy to combine figmasset-export with mbsprite to turn a set of icons into a spritesheet:

figmasset-export --file ABC123 --frame myframe myotherframe --frame pins --scale 1 2 --out assets
npx mbsprite bundle sprite assets@1x assets@2x