@@ -5,18 +5,11 @@ import { getProjectRoot } from "../tools/getProjectRoot";
55import { generateTypographyTsCode } from "./typography" ;
66import { generateSpacingTsCode } from "./spacing" ;
77import { generateClassNamesTsCode } from "./classNames" ;
8+ import { collectIcons } from "./icons" ;
89import * as fs from "fs" ;
9- import { readFile } from "fs/promises" ;
10- import {
11- join as pathJoin ,
12- basename as pathBasename ,
13- relative as pathRelative ,
14- dirname as pathDirname
15- } from "path" ;
16- import { crawl } from "../tools/crawl" ;
17- import { id } from "tsafe/id" ;
10+ import { join as pathJoin , basename as pathBasename , relative as pathRelative } from "path" ;
1811
19- export async function main ( ) {
12+ ( async ( ) => {
2013 const projectRoot = getProjectRoot ( ) ;
2114
2215 const dsfrDistDirPath = pathJoin ( projectRoot , "dsfr" ) ;
@@ -124,71 +117,4 @@ export async function main() {
124117 "utf8"
125118 )
126119 ) ;
127- }
128-
129- export type Icon = Icon . Dsfr | Icon . Remixicon ;
130-
131- export namespace Icon {
132- export type Common = {
133- iconId : string ;
134- } ;
135-
136- export type Dsfr = Common & {
137- prefix : "fr-icon-" ;
138- category : string ;
139- } ;
140-
141- export type Remixicon = Common & {
142- prefix : "ri-" ;
143- rawSvgCode : string ;
144- } ;
145- }
146-
147- export async function collectIcons ( params : {
148- dsfrDistDirPath : string ;
149- remixiconDirPath : string ;
150- } ) : Promise < Icon [ ] > {
151- const { dsfrDistDirPath, remixiconDirPath } = params ;
152-
153- return (
154- await Promise . all ( [
155- ( async ( ) => {
156- const iconDirPath = pathJoin ( remixiconDirPath , "icons" ) ;
157-
158- return Promise . all (
159- ( await crawl ( { "dirPath" : iconDirPath } ) )
160- . filter ( filePath => filePath . endsWith ( ".svg" ) )
161- . map ( async svgFilePath =>
162- id < Icon . Remixicon > ( {
163- "prefix" : "ri-" ,
164- "iconId" : pathBasename ( svgFilePath ) . replace ( / \. s v g $ / , "" ) ,
165- "rawSvgCode" : (
166- await readFile ( pathJoin ( iconDirPath , svgFilePath ) )
167- ) . toString ( "utf8" )
168- } )
169- )
170- ) ;
171- } ) ( ) ,
172- ( async ( ) =>
173- (
174- await crawl ( {
175- "dirPath" : pathJoin ( dsfrDistDirPath , "icons" ) ,
176- "getDoCrawlInDir" : ( { relativeDirPath } ) =>
177- pathBasename ( relativeDirPath ) !== "remixicon"
178- } )
179- )
180- . filter ( filePath => filePath . endsWith ( ".svg" ) )
181- . map ( svgFilePath =>
182- id < Icon . Dsfr > ( {
183- "prefix" : "fr-icon-" ,
184- "category" : pathBasename ( pathDirname ( svgFilePath ) ) ,
185- "iconId" : pathBasename ( svgFilePath ) . replace ( / \. s v g $ / , "" )
186- } )
187- ) ) ( )
188- ] )
189- ) . flat ( ) ;
190- }
191-
192- if ( require . main === module ) {
193- main ( ) ;
194- }
120+ } ) ( ) ;
0 commit comments