Skip to content

Commit

Permalink
feat: Add support for tokens in toml files (#3047)
Browse files Browse the repository at this point in the history
  • Loading branch information
xitij2000 authored Jun 17, 2024
1 parent 05e9096 commit 3ba1adc
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 5 deletions.
22 changes: 18 additions & 4 deletions lib/build-tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ async function buildTokensCommand(commandArgs) {
} = minimist(commandArgs, { alias, default: defaultParams, boolean: 'source-tokens-only' });

const coreConfig = {
include: [path.resolve(__dirname, '../tokens/src/core/**/*.json')],
source: tokensSource ? [`${tokensSource}/core/**/*.json`] : [],
include: [
path.resolve(__dirname, '../tokens/src/core/**/*.json'),
path.resolve(__dirname, '../tokens/src/core/**/*.toml'),
],
source: tokensSource
? [`${tokensSource}/core/**/*.json`, `${tokensSource}/core/**/*.toml`]
: [],
platforms: {
css: {
prefix: 'pgn',
Expand Down Expand Up @@ -67,8 +72,17 @@ async function buildTokensCommand(commandArgs) {

const getStyleDictionaryConfig = (themeVariant) => ({
...coreConfig,
include: [...coreConfig.include, path.resolve(__dirname, `../tokens/src/themes/${themeVariant}/**/*.json`)],
source: tokensSource ? [`${tokensSource}/themes/${themeVariant}/**/*.json`] : [],
include: [
...coreConfig.include,
path.resolve(__dirname, `../tokens/src/themes/${themeVariant}/**/*.json`),
path.resolve(__dirname, `../tokens/src/themes/${themeVariant}/**/*.toml`),
],
source: tokensSource
? [
`${tokensSource}/themes/${themeVariant}/**/*.json`,
`${tokensSource}/themes/${themeVariant}/**/*.toml`,
]
: [],
transform: {
'color/sass-color-functions': {
...StyleDictionary.transform['color/sass-color-functions'],
Expand Down
66 changes: 65 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"file-selector": "^0.6.0",
"glob": "^8.0.3",
"inquirer": "^8.2.5",
"js-toml": "^1.0.0",
"lodash.uniqby": "^4.7.0",
"log-update": "^4.0.0",
"mailto-link": "^2.0.0",
Expand Down
6 changes: 6 additions & 0 deletions tokens/style-dictionary.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* This module creates and exports custom StyleDictionary instance for Paragon.
*/
const toml = require('js-toml');
const StyleDictionary = require('style-dictionary');
const chroma = require('chroma-js');
const { colorYiq, darken, lighten } = require('./sass-helpers');
Expand Down Expand Up @@ -216,6 +217,11 @@ StyleDictionary.registerFilter({
matcher: token => token?.isSource === true,
});

StyleDictionary.registerParser({
pattern: /\.toml$/,
parse: ({ contents }) => toml.load(contents),
});

module.exports = {
StyleDictionary,
createCustomCSSVariables,
Expand Down

0 comments on commit 3ba1adc

Please sign in to comment.