@@ -8,22 +8,19 @@ import { generateClassNamesTsCode } from "./classNames";
8
8
import * as fs from "fs" ;
9
9
import { join as pathJoin , basename as pathBasename , relative as pathRelative } from "path" ;
10
10
import type { Icon } from "../../bin/only-include-used-icons" ;
11
- import { pathOfIconsJson } from "../../bin/only-include-used-icons" ;
12
11
13
- export function cssToTs ( ) {
14
- const projectRoot = getProjectRoot ( ) ;
15
-
16
- const dsfrDistDirPath = pathJoin ( projectRoot , "dsfr" ) ;
17
-
18
- const rawCssCode = fs . readFileSync ( pathJoin ( dsfrDistDirPath , "dsfr.css" ) ) . toString ( "utf8" ) ;
19
-
20
- const generatedDirPath = pathJoin ( projectRoot , "src" , "lib" , "generatedFromCss" ) ;
12
+ export function cssToTs ( params : {
13
+ rawDsfrCssCode : string ;
14
+ generatedDirPath : string ;
15
+ icons : Icon [ ] ;
16
+ } ) {
17
+ const { rawDsfrCssCode, generatedDirPath, icons } = params ;
21
18
22
19
fs . mkdirSync ( generatedDirPath , { "recursive" : true } ) ;
23
20
24
21
const warningMessage = [
25
22
`// This file is generated automatically by ${ pathRelative (
26
- projectRoot ,
23
+ getProjectRoot ( ) ,
27
24
__filename
28
25
) } , please don't edit.`
29
26
] . join ( "\n" ) ;
@@ -36,7 +33,7 @@ export function cssToTs() {
36
33
[
37
34
warningMessage ,
38
35
`` ,
39
- generateGetColorOptionsTsCode ( rawCssCode ) ,
36
+ generateGetColorOptionsTsCode ( rawDsfrCssCode ) ,
40
37
`` ,
41
38
`export type ColorOptions = ReturnType<typeof getColorOptions>;` ,
42
39
``
@@ -55,7 +52,7 @@ export function cssToTs() {
55
52
""
56
53
) } ";`,
57
54
`` ,
58
- generateGetColorDecisionsTsCode ( rawCssCode ) ,
55
+ generateGetColorDecisionsTsCode ( rawDsfrCssCode ) ,
59
56
`` ,
60
57
`export type ColorDecisions = ReturnType<typeof getColorDecisions>;` ,
61
58
``
@@ -66,7 +63,10 @@ export function cssToTs() {
66
63
67
64
fs . writeFileSync (
68
65
pathJoin ( generatedDirPath , "breakpoints.ts" ) ,
69
- Buffer . from ( [ warningMessage , `` , generateBreakpointsTsCode ( rawCssCode ) ] . join ( "\n" ) , "utf8" )
66
+ Buffer . from (
67
+ [ warningMessage , `` , generateBreakpointsTsCode ( rawDsfrCssCode ) ] . join ( "\n" ) ,
68
+ "utf8"
69
+ )
70
70
) ;
71
71
72
72
fs . writeFileSync (
@@ -76,7 +76,7 @@ export function cssToTs() {
76
76
warningMessage ,
77
77
`import { breakpoints } from "../breakpoints";` ,
78
78
`` ,
79
- generateTypographyTsCode ( rawCssCode ) ,
79
+ generateTypographyTsCode ( rawDsfrCssCode ) ,
80
80
``
81
81
] . join ( "\n" ) ,
82
82
"utf8"
@@ -85,7 +85,10 @@ export function cssToTs() {
85
85
86
86
fs . writeFileSync (
87
87
pathJoin ( generatedDirPath , "spacing.ts" ) ,
88
- Buffer . from ( [ warningMessage , `` , generateSpacingTsCode ( rawCssCode ) , `` ] . join ( "\n" ) , "utf8" )
88
+ Buffer . from (
89
+ [ warningMessage , `` , generateSpacingTsCode ( rawDsfrCssCode ) , `` ] . join ( "\n" ) ,
90
+ "utf8"
91
+ )
89
92
) ;
90
93
91
94
fs . writeFileSync (
@@ -95,23 +98,13 @@ export function cssToTs() {
95
98
warningMessage ,
96
99
`` ,
97
100
generateClassNamesTsCode ( {
98
- rawCssCode,
99
- ...( ( ) => {
100
- const icons : Icon [ ] = JSON . parse (
101
- fs
102
- . readFileSync ( pathJoin ( dsfrDistDirPath , pathOfIconsJson ) )
103
- . toString ( "utf8" )
104
- ) ;
105
-
106
- return {
107
- "dsfrIconClassNames" : icons
108
- . filter ( ( { prefix } ) => prefix === "fr-icon-" )
109
- . map ( ( { iconId, prefix } ) => `${ prefix } ${ iconId } ` ) ,
110
- "remixiconClassNames" : icons
111
- . filter ( ( { prefix } ) => prefix === "ri-" )
112
- . map ( ( { iconId, prefix } ) => `${ prefix } ${ iconId } ` )
113
- } ;
114
- } ) ( )
101
+ "rawCssCode" : rawDsfrCssCode ,
102
+ "dsfrIconClassNames" : icons
103
+ . filter ( ( { prefix } ) => prefix === "fr-icon-" )
104
+ . map ( ( { iconId, prefix } ) => `${ prefix } ${ iconId } ` ) ,
105
+ "remixiconClassNames" : icons
106
+ . filter ( ( { prefix } ) => prefix === "ri-" )
107
+ . map ( ( { iconId, prefix } ) => `${ prefix } ${ iconId } ` )
115
108
} ) ,
116
109
``
117
110
] . join ( "\n" ) ,
0 commit comments