Skip to content

Commit

Permalink
feat: Add support for tokens in toml files
Browse files Browse the repository at this point in the history
  • Loading branch information
xitij2000 committed May 10, 2024
1 parent f5a5c05 commit 331d991
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 7 deletions.
26 changes: 20 additions & 6 deletions lib/build-tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ async function buildTokensCommand(commandArgs) {
};

const alias = {
'build-dir': 'b',
themes: 't',
"build-dir": "b",

Check failure on line 22 in lib/build-tokens.js

View workflow job for this annotation

GitHub Actions / tests

Strings must use singlequote

Check failure on line 22 in lib/build-tokens.js

View workflow job for this annotation

GitHub Actions / tests

Strings must use singlequote
themes: "t",

Check failure on line 23 in lib/build-tokens.js

View workflow job for this annotation

GitHub Actions / tests

Strings must use singlequote
};

const {
Expand All @@ -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"),

Check failure on line 35 in lib/build-tokens.js

View workflow job for this annotation

GitHub Actions / tests

Strings must use singlequote
path.resolve(__dirname, "../tokens/src/core/**/*.toml"),

Check failure on line 36 in lib/build-tokens.js

View workflow job for this annotation

GitHub Actions / tests

Strings must use singlequote
],
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`,

Check failure on line 82 in lib/build-tokens.js

View workflow job for this annotation

GitHub Actions / tests

Expected indentation of 8 spaces but found 10
`${tokensSource}/themes/${themeVariant}/**/*.toml`,

Check failure on line 83 in lib/build-tokens.js

View workflow job for this annotation

GitHub Actions / tests

Expected indentation of 8 spaces but found 10
]

Check failure on line 84 in lib/build-tokens.js

View workflow job for this annotation

GitHub Actions / tests

Expected indentation of 6 spaces but found 8
: [],
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
9 changes: 9 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,14 @@ StyleDictionary.registerFilter({
matcher: token => token?.isSource === true,
});


Check failure on line 220 in tokens/style-dictionary.js

View workflow job for this annotation

GitHub Actions / tests

More than 1 blank line not allowed
StyleDictionary.registerParser({
pattern: /\.toml$/,
parse: ({contents, filePath}) => {

Check failure on line 223 in tokens/style-dictionary.js

View workflow job for this annotation

GitHub Actions / tests

A space is required after '{'
return toml.load(contents);
}
})

module.exports = {
StyleDictionary,
createCustomCSSVariables,
Expand Down

0 comments on commit 331d991

Please sign in to comment.