-
Notifications
You must be signed in to change notification settings - Fork 2
/
sd.config.js
57 lines (51 loc) · 1.57 KB
/
sd.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import StyleDictionary from 'style-dictionary';
const baseTokens = ['colors', 'typography', 'spacing', 'radii'];
const tokenFilter = (cat) => (token) => token.attributes.category === cat;
const generateFilesArr = (tokensCategories) => {
return tokensCategories.map((cat) => ({
filter: tokenFilter(cat),
destination: `${cat}/src/_${cat}.js`,
format: 'cssLiterals',
}));
};
export default {
source: ['**/*.tokens.js'],
format: {
cssLiterals: (opts) => {
const { dictionary, file } = opts;
let output = StyleDictionary.formatHelpers.fileHeader(file);
output += `import { css } from 'lit';\n\n`;
dictionary.allTokens.forEach((token) => {
const { path, value } = token;
const [, ..._path] = path;
const name = _path.reduce((acc, str, index) => {
// converts to camelCase
const _str =
index === 0 ? str : str.charAt(0).toUpperCase() + str.slice(1);
return acc.concat(_str);
}, '');
output += `export const ${name} = css\`${value}\`;\n`;
});
return output;
},
},
platforms: {
css: {
transformGroup: 'css',
prefix: 'simba',
buildPath: 'tokens/',
files: [
{
filter: (token) => baseTokens.includes(token.attributes.category),
destination: 'tokens.css',
format: 'css/variables',
},
],
},
js: {
transformGroup: 'js',
buildPath: '',
files: generateFilesArr([...baseTokens, 'button']),
},
},
};