55import path from "node:path" ;
66import { fileURLToPath } from "node:url" ;
77import { existsSync , mkdirSync , rmSync } from "node:fs" ;
8- import { readdir , readFile , writeFile } from "node:fs/promises" ;
8+ import { readdir , writeFile } from "node:fs/promises" ;
99import { createRequire } from "node:module" ;
10- import { createHash } from "node:crypto" ;
1110import { far } from "@fortawesome/free-regular-svg-icons" ;
1211import { fas } from "@fortawesome/free-solid-svg-icons" ;
1312import { fab } from "@fortawesome/free-brands-svg-icons" ;
@@ -42,11 +41,6 @@ const tasks = [];
4241 default : [ ] ,
4342 } ;
4443
45- const ranges = { } ;
46- const allSvg = [ ] ;
47- const iconsWithPath = [ ] ;
48- let cursor = - 2 ;
49-
5044 tasks . push (
5145 ( async ( ) => {
5246 const list = await readdir ( legacyEasyOpsIconsPath , {
@@ -71,62 +65,19 @@ const tasks = [];
7165 }
7266 } else if ( ext === ".svg" ) {
7367 allIcons [ item . name ] . push ( iconName ) ;
74- iconsWithPath . push ( [
75- item . name ,
76- path . join ( legacyEasyOpsIconsPath , item . name , icon ) ,
77- ] ) ;
7868 }
7969 }
8070 } else if ( item . name . endsWith ( ".svg" ) ) {
8171 const iconName = item . name . substring ( 0 , item . name . length - 4 ) ;
8272 allIcons . default . push ( iconName ) ;
83- iconsWithPath . push ( [
84- "default" ,
85- path . join ( legacyEasyOpsIconsPath , item . name ) ,
86- ] ) ;
8773 }
8874 } )
8975 ) ;
9076
91- const hashes = [ ] ;
92-
93- // Have to be sequential
94- for ( const [ category , iconPath ] of iconsWithPath ) {
95- const svg = await readFile ( iconPath ) ;
96- allSvg . push ( svg ) ;
97-
98- let groupRanges = ranges [ category ] ;
99- if ( ! _ . has ( ranges , category ) ) {
100- groupRanges = ranges [ category ] = [ ] ;
101- }
102- cursor += svg . length + 1 ;
103- groupRanges . push ( cursor ) ;
104-
105- const sha1 = createHash ( "sha1" ) ;
106- sha1 . update ( svg ) ;
107- hashes . push ( sha1 . digest ( "hex" ) . substring ( 0 , 8 ) ) ;
108- }
109-
110- // Let final hash to be irrelevant to the order of icons
111- hashes . sort ( ) ;
112- const sha1 = createHash ( "sha1" ) ;
113- sha1 . update ( hashes . join ( "" ) ) ;
114- ranges . _hash = sha1 . digest ( "hex" ) . substring ( 0 , 8 ) ;
115-
116- await Promise . all ( [
117- writeFile (
118- path . resolve ( newEasyOpsIconsPath , "icons.json" ) ,
119- JSON . stringify ( allIcons )
120- ) ,
121- writeFile (
122- path . resolve ( newEasyOpsIconsPath , "ranges.json" ) ,
123- JSON . stringify ( ranges )
124- ) ,
125- writeFile (
126- path . resolve ( newEasyOpsIconsPath , `all.${ ranges . _hash } .svg` ) ,
127- allSvg . join ( "\n" )
128- ) ,
129- ] ) ;
77+ await writeFile (
78+ path . resolve ( newEasyOpsIconsPath , "icons.json" ) ,
79+ JSON . stringify ( allIcons )
80+ ) ;
13081 } ) ( )
13182 ) ;
13283}
@@ -152,14 +103,8 @@ const tasks = [];
152103 allIcons [ category ] = [ ] ;
153104 }
154105
155- const ranges = { } ;
156- const allJson = [ ] ;
157- let cursor = - 2 ;
158-
159106 tasks . push (
160107 ( async ( ) => {
161- const hashes = [ ] ;
162-
163108 await Promise . all (
164109 Object . entries ( iconCategories ) . map ( async ( [ category , pack ] ) => {
165110 const aliasMap = ( aliasMapByCategory [ category ] = { } ) ;
@@ -174,20 +119,6 @@ const tasks = [];
174119 aliasMap [ alias ] = item . iconName ;
175120 }
176121 const content = JSON . stringify ( item ) ;
177-
178- let groupRanges = ranges [ category ] ;
179- if ( ! _ . has ( ranges , category ) ) {
180- groupRanges = ranges [ category ] = [ ] ;
181- }
182- cursor += content . length + 1 ;
183- groupRanges . push ( cursor ) ;
184-
185- allJson . push ( content ) ;
186-
187- const sha1 = createHash ( "sha1" ) ;
188- sha1 . update ( content ) ;
189- hashes . push ( sha1 . digest ( "hex" ) . substring ( 0 , 8 ) ) ;
190-
191122 return writeFile (
192123 path . resolve ( generatedDir , `${ category } /${ item . iconName } .json` ) ,
193124 content
@@ -197,11 +128,6 @@ const tasks = [];
197128 } )
198129 ) ;
199130
200- hashes . sort ( ) ;
201- const sha1 = createHash ( "sha1" ) ;
202- sha1 . update ( hashes . join ( "" ) ) ;
203- ranges . _hash = sha1 . digest ( "hex" ) . substring ( 0 , 8 ) ;
204-
205131 await Promise . all ( [
206132 writeFile (
207133 path . resolve ( generatedDir , "alias.json" ) ,
@@ -211,14 +137,6 @@ const tasks = [];
211137 path . resolve ( generatedDir , "icons.json" ) ,
212138 JSON . stringify ( allIcons )
213139 ) ,
214- writeFile (
215- path . resolve ( generatedDir , "ranges.json" ) ,
216- JSON . stringify ( ranges )
217- ) ,
218- writeFile (
219- path . resolve ( generatedDir , `all.${ ranges . _hash } .json` ) ,
220- allJson . join ( "\n" )
221- ) ,
222140 ] ) ;
223141 } ) ( )
224142 ) ;
@@ -240,14 +158,8 @@ const tasks = [];
240158 allIcons [ theme ] = [ ] ;
241159 }
242160
243- const ranges = { } ;
244- const allSvg = [ ] ;
245- let cursor = - 2 ;
246-
247161 tasks . push (
248162 ( async ( ) => {
249- const hashes = [ ] ;
250-
251163 await Promise . all (
252164 Object . values ( antdIcons ) . map ( ( icon ) => {
253165 if ( ! themes . includes ( icon . theme ) ) {
@@ -262,45 +174,17 @@ const tasks = [];
262174 } ,
263175 } ) ;
264176
265- let groupRanges = ranges [ icon . theme ] ;
266- if ( ! _ . has ( ranges , icon . theme ) ) {
267- groupRanges = ranges [ icon . theme ] = [ ] ;
268- }
269- cursor += svg . length + 1 ;
270- groupRanges . push ( cursor ) ;
271-
272- allSvg . push ( svg ) ;
273-
274- const sha1 = createHash ( "sha1" ) ;
275- sha1 . update ( svg ) ;
276- hashes . push ( sha1 . digest ( "hex" ) . substring ( 0 , 8 ) ) ;
277-
278177 return writeFile (
279178 path . resolve ( generatedDir , icon . theme , `${ icon . name } .svg` ) ,
280179 svg
281180 ) ;
282181 } )
283182 ) ;
284183
285- hashes . sort ( ) ;
286- const sha1 = createHash ( "sha1" ) ;
287- sha1 . update ( hashes . join ( "" ) ) ;
288- ranges . _hash = sha1 . digest ( "hex" ) . substring ( 0 , 8 ) ;
289-
290- await Promise . all ( [
291- writeFile (
292- path . resolve ( generatedDir , "icons.json" ) ,
293- JSON . stringify ( allIcons )
294- ) ,
295- writeFile (
296- path . resolve ( generatedDir , "ranges.json" ) ,
297- JSON . stringify ( ranges )
298- ) ,
299- writeFile (
300- path . resolve ( generatedDir , `all.${ ranges . _hash } .svg` ) ,
301- allSvg . join ( "\n" )
302- ) ,
303- ] ) ;
184+ await writeFile (
185+ path . resolve ( generatedDir , "icons.json" ) ,
186+ JSON . stringify ( allIcons )
187+ ) ;
304188 } ) ( )
305189 ) ;
306190}
@@ -322,10 +206,7 @@ const tasks = [];
322206 [ defaultCategory ] : [ ] ,
323207 } ;
324208
325- const ranges = { } ;
326- const allSvg = [ ] ;
327209 const iconsWithPath = [ ] ;
328- let cursor = - 2 ;
329210
330211 tasks . push (
331212 ( async ( ) => {
@@ -341,45 +222,10 @@ const tasks = [];
341222 }
342223 }
343224
344- const hashes = [ ] ;
345-
346- // Have to be sequential
347- for ( const [ category , iconPath ] of iconsWithPath ) {
348- const svg = await readFile ( iconPath ) ;
349- allSvg . push ( svg ) ;
350-
351- let groupRanges = ranges [ category ] ;
352- if ( ! _ . has ( ranges , category ) ) {
353- groupRanges = ranges [ category ] = [ ] ;
354- }
355- cursor += svg . length + 1 ;
356- groupRanges . push ( cursor ) ;
357-
358- const sha1 = createHash ( "sha1" ) ;
359- sha1 . update ( svg ) ;
360- hashes . push ( sha1 . digest ( "hex" ) . substring ( 0 , 8 ) ) ;
361- }
362-
363- // Let final hash to be irrelevant to the order of icons
364- hashes . sort ( ) ;
365- const sha1 = createHash ( "sha1" ) ;
366- sha1 . update ( hashes . join ( "" ) ) ;
367- ranges . _hash = sha1 . digest ( "hex" ) . substring ( 0 , 8 ) ;
368-
369- await Promise . all ( [
370- writeFile (
371- path . resolve ( generatedDir , "icons.json" ) ,
372- JSON . stringify ( allIcons )
373- ) ,
374- writeFile (
375- path . resolve ( generatedDir , "ranges.json" ) ,
376- JSON . stringify ( ranges )
377- ) ,
378- writeFile (
379- path . resolve ( generatedDir , `all.${ ranges . _hash } .svg` ) ,
380- allSvg . join ( "\n" )
381- ) ,
382- ] ) ;
225+ await writeFile (
226+ path . resolve ( generatedDir , "icons.json" ) ,
227+ JSON . stringify ( allIcons )
228+ ) ;
383229 } ) ( )
384230 ) ;
385231}
0 commit comments