-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtokens.js
92 lines (86 loc) · 2.4 KB
/
tokens.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* A helper function to convert our base variables
* into formats that are useful (CSS, JS)
*/
const theo = require('theo');
const fs = require('fs');
const formatTheme = require('./custom-token-formats/theme.js');
const formatCustomPropertiesAsAnObject = require('./custom-token-formats/custom-properties-as-an-object');
const formatCSSHelpersColors = require('./custom-token-formats/css-helper-colors');
const formatCSSHelpersHoverColors = require('./custom-token-formats/css-helper-hover-colors');
const formatCSSHelpersFills = require('./custom-token-formats/css-helper-fills');
const formatsRequired = [
{
format: 'custom-properties.css',
fileName: 'tokens.css',
},
{
format: 'custom-properties-as-an-object',
fileName: 'tokens.css.js',
},
{
format: 'common.js',
fileName: 'tokens.js',
},
{
format: 'module.js',
fileName: 'tokens.module.js',
},
{
format: 'json',
fileName: 'tokens.json',
},
{
format: 'theme.js',
fileName: 'tokens.theme.js',
},
{
format: 'scss',
fileName: 'tokens.scss',
},
{
format: 'css-helpers/colors',
fileName: 'kalo-ui-colors.css',
},
{
format: 'css-helpers/hover-colors',
fileName: 'kalo-ui-hover-colors.css',
},
{
format: 'css-helpers/fills',
fileName: 'kalo-ui-fills.css',
},
];
theo.registerFormat('theme.js', formatTheme);
theo.registerFormat(
'custom-properties-as-an-object',
formatCustomPropertiesAsAnObject
);
theo.registerFormat('css-helpers/colors', formatCSSHelpersColors);
theo.registerFormat('css-helpers/hover-colors', formatCSSHelpersHoverColors);
theo.registerFormat('css-helpers/fills', formatCSSHelpersFills);
const writeToNewFile = (name, contents) => {
try {
fs.writeFileSync(`./src/design-tokens/${name}`, contents);
console.log(`Writing tokens to ./src/design-tokens/${name}`); // eslint-disable-line no-console
} catch (e) {
console.log('Cannot write file ', e); // eslint-disable-line no-console
}
};
theo.registerTransform('web', ['color/hex']);
formatsRequired.map(format => {
return theo
.convert({
transform: {
type: 'web',
file: './config/design-tokens/tokens.yml',
},
format: {
type: format.format,
},
})
.then(vars => {
writeToNewFile(format.fileName, vars);
})
.catch(error => console.log(`Something went wrong: ${error}`)); // eslint-disable-line no-console
});