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