A build system for creating cross-platform styles.
aff6646: Allow passing a custom FileSystem Volume to your Style-Dictionary instances, to ensure input/output files are read/written from/to that specific volume. Useful in case you want multiple Style-Dictionary instances that are isolated from one another in terms of inputs/outputs.
import { Volume } from 'memfs';
// You will need a bundler for memfs in browser...
// Or use as a prebundled fork:
import memfs from '@bundled-es-modules/memfs';
const { Volume } = memfs;
const vol = new Volume();
const sd = new StyleDictionary(
{
tokens: {
colors: {
red: {
value: '#FF0000',
type: 'color',
},
},
},
platforms: {
css: {
transformGroup: 'css',
files: [
{
destination: 'variables.css',
format: 'css/variables',
},
],
},
},
},
{ volume: vol },
);
await sd.buildAllPlatforms();
vol.readFileSync('/variables.css');
/**
* :root {
* --colors-red: #FF0000;
* }
*/
This also works when using extend:
const extendedSd = await sd.extend(cfg, { volume: vol });
79bb201: BREAKING: Logging has been redesigned a fair bit and is more configurable now.
Before:
{
"log": "error" // 'error' | 'warn' -> 'warn' is the default value
}
After:
{
"log": {
"warnings": "error", // 'error' | 'warn' -> 'warn' is the default value
"verbosity": "verbose" // 'default' | 'verbose' | 'silent' -> 'default' is the default value
}
}
Log is now and object and the old "log" option is now "warnings".
This configures whether the following five warnings will be thrown as errors instead of being logged as warnings:
Verbosity configures whether the following warnings/errors should display in a verbose manner:
And it also configures whether success/neutral logs should be logged at all. Using "silent" (or --silent in the CLI) means no logs are shown apart from fatal errors.
bcb5ef3: Remove reliance on CTI token structure across transforms, actions and formats.
Breaking changes:
attributes.category
as the token type indicator.name/cti/casing
to just name/casing
. name/ti/camel
and name/ti/constant
have been removed. For example name/cti/kebab
transform is now name/kebab
.content/icon
has been renamed to html/icon
since it targets HTML entity strings, not just any icon content.font/objC/literal
, font/swift/literal
and font/flutter/literal
have been removed in favor of font/objC/literal
, font/swift/literal
and font/flutter/literal
, as they do he exact same transformations.typescript/module-declarations
format to be updated with current DesignToken type interface.Before:
{
"color": {
"red": {
"value": "#FF0000"
}
}
}
After:
{
"color": {
// <-- this no longer needs to be "color" in order for the tokens inside this group to be considered of type "color"
"red": {
"value": "#FF0000",
"type": "color"
}
}
}
502dbd1: BREAKING: All of our hooks, parsers, preprocessors, transforms, formats, actions, fileHeaders and filters, support async functions as well now. This means that the formatHelpers -> fileHeader helper method is now asynchronous, to support async fileheader functions.
import StyleDictionary from 'style-dictionary';
const { fileHeader } = StyleDictionary.formatHelpers;
StyleDictionary.registerFormat({
name: 'custom/css',
// this can be async now, usually it is if you use fileHeader format helper, since that now always returns a Promise
formatter: async function ({ dictionary, file, options }) {
const { outputReferences } = options;
return (
// this helper is now async! because the user-passed file.fileHeader might be an async function
(await fileHeader({ file })) +
':root {\n' +
formattedVariables({ format: 'css', dictionary, outputReferences }) +
'\n}\n'
);
},
});
typeW3CDelegate
utility function to typeDtcgDelegate
, as using "W3C" is highly discouraged when the standard isn't a W3C standard yet.