Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for tokens in toml files #3047

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -66,6 +66,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
Loading