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: updating to Style Dictionary v4 #3186

Open
wants to merge 11 commits into
base: alpha
Choose a base branch
from
Open
16 changes: 9 additions & 7 deletions lib/build-tokens.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path');
const minimist = require('minimist');
const { StyleDictionary, colorTransform, createCustomCSSVariables } = require('../tokens/style-dictionary');
const { initializeStyleDictionary, createCustomCSSVariables, colorTransform } = require('../tokens/style-dictionary');
const { createIndexCssFile } = require('../tokens/utils');

/**
Expand All @@ -13,6 +13,8 @@ const { createIndexCssFile } = require('../tokens/utils');
* @param {string|string[]} [commandArgs.themes=['light']] - The themes (variants) for which to build tokens.
*/
async function buildTokensCommand(commandArgs) {
const StyleDictionary = await initializeStyleDictionary();

const defaultParams = {
themes: ['light'],
'build-dir': './build/',
Expand Down Expand Up @@ -62,7 +64,7 @@ async function buildTokensCommand(commandArgs) {
},
},
],
transforms: StyleDictionary.transformGroup.css.filter(item => item !== 'size/rem').concat('color/sass-color-functions', 'str-replace'),
transforms: StyleDictionary.hooks.transformGroups.css.filter(item => item !== 'size/rem').concat('color/sass-color-functions', 'str-replace'),
options: {
fileHeader: 'customFileHeader',
},
Expand All @@ -85,8 +87,8 @@ async function buildTokensCommand(commandArgs) {
: [],
transform: {
'color/sass-color-functions': {
...StyleDictionary.transform['color/sass-color-functions'],
transformer: (token) => colorTransform(token, themeVariant),
...StyleDictionary.hooks.transforms['color/sass-color-functions'],
transform: (token) => colorTransform(token, themeVariant),
},
},
format: {
Expand Down Expand Up @@ -120,12 +122,12 @@ async function buildTokensCommand(commandArgs) {
},
});

StyleDictionary.extend(coreConfig).buildAllPlatforms();
new StyleDictionary(coreConfig).buildAllPlatforms();
createIndexCssFile({ buildDir, isTheme: false });

themes.forEach((themeVariant) => {
themes.forEach(async (themeVariant) => {
const config = getStyleDictionaryConfig(themeVariant);
StyleDictionary.extend(config).buildAllPlatforms();
new StyleDictionary(config).buildAllPlatforms();
createIndexCssFile({ buildDir, isTheme: true, themeVariant });
});
}
Expand Down
Loading
Loading