style-dictionary
Version:
Style once, use everywhere. A build system for creating cross-platform styles.
74 lines (66 loc) • 2 kB
JavaScript
import StyleDictionary from 'style-dictionary';
import { formats, transformGroups } from 'style-dictionary/enums';
const { androidColors, androidDimens, androidFontDimens, iosMacros, scssVariables } = formats;
const { web } = transformGroups;
// HAVE THE STYLE DICTIONARY CONFIG DYNAMICALLY GENERATED
function getStyleDictionaryConfig(brand, platform) {
return {
source: [
`tokens/brands/${brand}/*.json`,
'tokens/globals/**/*.json',
`tokens/platforms/${platform}/*.json`,
],
platforms: {
web: {
transformGroup: web,
buildPath: `build/web/${brand}/`,
files: [
{
destination: 'tokens.scss',
format: scssVariables,
},
],
},
android: {
transformGroup: 'android',
buildPath: `build/android/${brand}/`,
files: [
{
destination: 'tokens.colors.xml',
format: androidColors,
},
{
destination: 'tokens.dimens.xml',
format: androidDimens,
},
{
destination: 'tokens.font_dimens.xml',
format: androidFontDimens,
},
],
},
ios: {
transformGroup: 'ios',
buildPath: `build/ios/${brand}/`,
files: [
{
destination: 'tokens.h',
format: iosMacros,
},
],
},
},
};
}
console.log('Build started...');
// PROCESS THE DESIGN TOKENS FOR THE DIFFEREN BRANDS AND PLATFORMS
['brand-1', 'brand-2', 'brand-3'].map(function (brand) {
['web', 'ios', 'android'].map(function (platform) {
console.log('\n==============================================');
console.log(`\nProcessing: [${platform}] [${brand}]`);
const sd = new StyleDictionary(getStyleDictionaryConfig(brand, platform));
sd.buildPlatform(platform);
});
});
console.log('\n==============================================');
console.log('\nBuild completed!');