@@ -5,6 +5,7 @@ const writeToFile = require('./lib/writeToFile');
5
5
6
6
const usedPrimitive = { } ;
7
7
const usedSemantic = { } ;
8
+ const semanticColorNames = [ ] ;
8
9
9
10
const files = {
10
11
primitive : '01 Primitive.value.json' ,
@@ -46,6 +47,7 @@ const convertPrimitivesJsonToCss = jsonFile => {
46
47
const convertContextJsonToCss = jsonFile => {
47
48
const jsonContent = JSON . parse ( fs . readFileSync ( jsonFile , 'utf8' ) ) ;
48
49
const cssLines = [ ] ;
50
+ const saveColors = semanticColorNames . length === 0 ;
49
51
50
52
const processColorTokens = ( obj , prefix = '' ) => {
51
53
for ( const [ key , value ] of Object . entries ( obj ) ) {
@@ -64,6 +66,7 @@ const convertContextJsonToCss = jsonFile => {
64
66
: value . $value ;
65
67
cssLines . push ( `${ cssVarName } : ${ cssVarValue } ;` ) ;
66
68
usedSemantic [ cssVarValue ] = true ;
69
+ if ( saveColors ) semanticColorNames . push ( cssVarName ) ;
67
70
} else if ( typeof value === 'object' ) {
68
71
processColorTokens ( value , `${ prefix } ${ key } -` ) ;
69
72
}
@@ -80,7 +83,6 @@ const convertContextJsonToCss = jsonFile => {
80
83
const convertSemanticJsonToCss = (
81
84
jsonFile ,
82
85
contextJsonFile ,
83
- contextAccentJsonFile ,
84
86
isStorybook = false ,
85
87
) => {
86
88
const jsonContent = JSON . parse ( fs . readFileSync ( jsonFile , 'utf8' ) ) ;
@@ -141,16 +143,18 @@ function generateSemanticColors() {
141
143
cssContent += `\n\n// Context accent \n.ffe-accent-mode {\n${ convertContextJsonToCss ( filePath ( files . contextAccent ) ) . join ( '\n' ) } }\n` ;
142
144
cssContent += `\n\n// Context \n:root,\n:host {\n${ convertContextJsonToCss ( filePath ( files . context ) ) . join ( '\n' ) } }\n` ;
143
145
cssContent += `\n\n${ convertSemanticJsonToCss ( filePath ( files . semanticLight ) ) } ` ;
144
- cssContent += `\n\n${ convertSemanticJsonToCss ( filePath ( files . semanticDark ) , filePath ( files . context ) , filePath ( files . contextAccent ) ) } ` ;
146
+ cssContent += `\n\n${ convertSemanticJsonToCss ( filePath ( files . semanticDark ) , filePath ( files . context ) ) } ` ;
145
147
cssContent += `\n\n${ convertPrimitivesJsonToCss ( filePath ( files . primitive ) ) } ` ;
146
148
147
149
writeToFile ( 'less/colors-semantic.less' ) ( cssContent ) ;
148
150
writeToFile ( 'css/colors-semantic.css' ) ( cssContent ) ;
151
+ writeToFile ( 'gen-src/semantic-color-names.json' ) (
152
+ JSON . stringify ( { colors : semanticColorNames } ) ,
153
+ ) ;
149
154
150
155
const storybookCssContent = convertSemanticJsonToCss (
151
156
filePath ( files . semanticDark ) ,
152
157
filePath ( files . context ) ,
153
- filePath ( files . contextAccent ) ,
154
158
true ,
155
159
) ;
156
160
writeToFile ( 'less/colors-semantic-storybook.less' ) ( storybookCssContent ) ;
0 commit comments