1
+ require ( '../packages/tokens-builder/build' ) ;
1
2
const fs = require ( 'fs/promises' ) ;
2
3
const path = require ( 'path' ) ;
3
4
const StyleDictionary = require ( 'style-dictionary' ) ;
4
5
const { formatHelpers } = require ( 'style-dictionary' ) ;
5
- require ( '../packages/tokens-builder/build ' ) ;
6
+ const { applyCustomTransformations } = require ( '../packages/tokens-builder/formats/utils ' ) ;
6
7
7
8
const TOKEN_FILE_EXT = 'json5' ;
8
9
const BASE_PATH = 'packages/design-tokens/web' ;
9
10
10
- // Original console.log function
11
- const originalLog = console . log ;
12
-
13
- console . log = ( message ) => {
14
- /*
15
- Light/dark token names are in the same file but under different selectors
16
- But Style-Dictionary expects 1 unique token per file, or it will throw warn
17
- So, console output is overwritten to prevent unnecessary errors message
18
- */
19
- if ( ! message . includes ( 'token collisions' ) ) {
20
- originalLog ( message ) ;
21
- }
22
- } ;
23
-
24
11
const sdConfig = {
25
12
source : [ `${ BASE_PATH } /properties/**/*.json5` , `${ BASE_PATH } /components/**/*.json5` ] ,
26
13
platforms : {
27
14
css : {
28
15
buildPath : `dist/design-tokens/web/components/styles/` ,
29
16
transformGroup : 'kbq/css' ,
30
- filter : ( token ) =>
31
- ! [ 'light' , 'dark' , 'font' , 'size' , 'typography' , 'md-typography' , 'palette' ] . includes (
32
- token . attributes . category
33
- )
17
+ filter : ( token ) => ! [ 'font' , 'size' , 'typography' , 'md-typography' ] . includes ( token . attributes . category ) ,
18
+ options : {
19
+ outputReferences : true
20
+ }
34
21
}
35
22
}
36
23
} ;
@@ -45,9 +32,14 @@ StyleDictionary.registerFormat({
45
32
formatter : function ( { dictionary, options = { } } ) {
46
33
const { outputReferences, selector = ':root' , darkThemeSelector = '.kbq-dark' } = options ;
47
34
35
+ const allTokens = applyCustomTransformations ( dictionary ) ;
36
+
48
37
dictionary . allTokens . forEach ( ( token ) => {
49
38
token . name = token . name . replace ( / ( l i g h t | d a r k ) - / , '' ) ;
50
39
} ) ;
40
+ dictionary . allTokens = dictionary . allProperties = allTokens . filter (
41
+ ( token ) => ! [ 'light' , 'dark' ] . includes ( token . attributes . category )
42
+ ) ;
51
43
52
44
// formatting function expects dictionary as input, so here initialize a copy to work with different tokens
53
45
const baseDictionary = { ...dictionary } ;
@@ -82,7 +74,9 @@ const main = async () => {
82
74
destination : `${ path . basename ( currentValue , `.${ TOKEN_FILE_EXT } ` ) } .css` ,
83
75
filter : ( token ) =>
84
76
token . attributes . category ?. includes ( path . basename ( currentValue , `.${ TOKEN_FILE_EXT } ` ) ) ||
85
- path . basename ( currentValue , `.${ TOKEN_FILE_EXT } ` ) . includes ( token . attributes . category ) ,
77
+ path . basename ( currentValue , `.${ TOKEN_FILE_EXT } ` ) . includes ( token . attributes . category ) ||
78
+ // give access to light/dark/palette tokens to resolve reference manually
79
+ [ 'light' , 'dark' , 'palette' ] . includes ( token . attributes . category ) ,
86
80
format : 'kbq-css/component' ,
87
81
prefix : 'kbq'
88
82
} ) ) ;
0 commit comments