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

gulp-theo

v2.0.1

Published

Gulp-theo is a plugin that transforms and formats Design Tokens

Downloads

1,458

Readme

gulp-theo

Build Status NPM version

Theo is a gulp plugin for transforming and formatting Design Tokens with Theo.

Install

npm install theo gulp-theo --save-dev

Usage

Here is a simple example with one file (props.yml) that gets transformed into its Sass (SCSS) equivalent:

# design/props.yml
global:
  category: 'web'
  type: 'color'
props:
  foo:
    value: '#ff0000'
  baz:
    value: '#0000ff'
// gulpfile.js
const gulp = require('gulp')
const theo = require('gulp-theo')

// Transform design/props.yml to dist/props.scss:
gulp.task('tokens:scss', () =>
  gulp.src('design/props.yml')
    .pipe(theo({
      transform: { type: 'web' },
      format: { type: 'scss' }
    }))
    .pipe(gulp.dest('dist'))
)

Running gulp run tokens:scss outputs:

// dist/props.scss
$foo: rgb(255, 0, 0);
$baz: rgb(0, 0, 255);

Advanced Usage

In this example (available in the /example folder), gulp-theo generates multiple files, transformed using a custom format (array.js).

# tokens/_aliases.yml
aliases:
  red: 'rgb(255, 0, 0)'
  blue: 'rgb(0, 0, 255)'
# tokens/_colors.yml
global:
  category: 'web'
  type: 'color'
imports:
  - _aliases.yml
props:
  brand:
    value: '{!blue}'
    comment: 'ACME Inc. brand color.'
  primary:
    value: '{!red}'
    comment: 'Use the primary color on call-to-action buttons. e.g. "Save", "Log In"…'
# tokens/_mobile-overrides.yml
global:
  category: 'web'
  type: 'mobile'
props:
  large:
    value: '3rem'
# tokens/_sizes.yml
global:
  category: 'web'
  type: 'size'
imports:
  - _aliases.yml
props:
  medium:
    value: '1rem'
  large:
    value: '2rem'
# tokens/default.yml
imports:
  - _colors.yml
  - _sizes.yml
# tokens/mobile.yml
imports:
  - _colors.yml
  - _sizes.yml
  - _mobile-overrides.yml
// gulpfile.js
const gulp = require('gulp')
const gulpTheo = require('gulp-theo')
const theo = require('theo')

theo.registerFormat('array.js', `
  // Source: {{stem meta.file}}
  module.exports = [
    {{#each props as |prop|}}
      {{#if prop.comment}}// {{{prop.comment}}}{{/if}}
      ['{{camelcase prop.name}}', '{{prop.value}}'],
    {{/each}}
  ]
`)

gulp.task('tokens:array', () =>
  gulp.src([
    // Look for yml files
    'tokens/*.yml',
    // Exclude partials (files prefixed with _)
    '!tokens/_*'
  ])
  .pipe(gulpTheo(
    {
      transform: {
        type: 'web'
      },
      format: {
        type: 'array.js'
      }
    }
  ))
  .pipe(gulp.dest('dist'))
)

Running gulp tokens:array will output:

// dist/default.array.js

// Source: default
module.exports = [
  // ACME Inc. brand color.
  ['brand', 'rgb(0, 0, 255)'],
  // Use the primary color on call-to-action buttons. e.g. "Save", "Log In"…
  ['primary', 'rgb(255, 0, 0)'],
  ['medium', '1rem'],  
  ['large', '2rem'],
]
// dist/mobile.array.js

// Source: mobile
module.exports = [
  // ACME Inc. brand color.
  ['brand', 'rgb(0, 0, 255)'],
  // Use the primary color on call-to-action buttons. e.g. "Save", "Log In"…
  ['primary', 'rgb(255, 0, 0)'],
  ['medium', '1rem'],  
  ['large', '3rem'],
]

Another example is available at https://github.com/salesforce-ux/theo-example.

For any other options, refer to Theo’s documentation.