-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokens.js
63 lines (59 loc) · 1.53 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
const { registerTransforms } = require('@tokens-studio/sd-transforms');
const StyleDictionary = require('style-dictionary');
/**
* Register a custom transformation to preserve tokens references as token strings.
*/
StyleDictionary.registerTransform({
name: 'cfa-uswds-theme/tokens',
type: 'value',
transitive: true,
matcher: token => {
return typeof token.original.value === 'string' &&
token.original.value.includes('{')
},
transformer: token => {
return token.original.value
.replace('{', '\'').replace('}', '\'');
}
});
/**
* Configure and register Tokens Studio transformations
*/
registerTransforms(StyleDictionary, {
excludeParentKeys: true,
casing: 'kebab'
});
/**
* Style Dictionary extend
*/
const theme = StyleDictionary.extend({
source: ['src/tokens/index.json'],
platforms: {
scss: {
transforms: [
'cfa-uswds-theme/tokens',
'content/quote',
'ts/descriptionToComment',
'ts/size/px',
'ts/opacity',
'ts/size/lineheight',
'ts/typography/fontWeight',
'ts/resolveMath',
'ts/size/css/letterspacing',
'ts/typography/css/fontFamily',
'ts/typography/css/shorthand',
'ts/border/css/shorthand',
'ts/shadow/css/shorthand',
'ts/color/css/hexrgba',
'ts/color/modifiers',
'name/cti/kebab',
],
buildPath: 'packages/',
files: [{
destination: 'cfa-uswds-theme/_tokens.scss',
format: 'scss/variables'
}]
}
}
});
theme.buildAllPlatforms();