@@ -305,6 +305,85 @@ const tasks = [];
305305 ) ;
306306}
307307
308+ {
309+ // --- Lucide Icons start ---
310+ const lucideIconsPath = path . resolve (
311+ require . resolve ( "lucide-static/package.json" ) ,
312+ "../icons"
313+ ) ;
314+ const generatedDir = path . resolve ( __dirname , "../src/lucide-icon/generated" ) ;
315+ if ( existsSync ( generatedDir ) ) {
316+ rmSync ( generatedDir , { recursive : true , force : true } ) ;
317+ }
318+ mkdirSync ( generatedDir ) ;
319+
320+ const defaultCategory = "default" ;
321+ const allIcons = {
322+ [ defaultCategory ] : [ ] ,
323+ } ;
324+
325+ const ranges = { } ;
326+ const allSvg = [ ] ;
327+ const iconsWithPath = [ ] ;
328+ let cursor = - 2 ;
329+
330+ tasks . push (
331+ ( async ( ) => {
332+ const icons = await readdir ( lucideIconsPath ) ;
333+ for ( const icon of icons ) {
334+ const [ _m , iconName , ext ] = icon . match ( / ^ ( .* ?) ( \. [ ^ . ] + ) ? $ / ) ;
335+ if ( ext === ".svg" ) {
336+ allIcons [ defaultCategory ] . push ( iconName ) ;
337+ iconsWithPath . push ( [
338+ defaultCategory ,
339+ path . join ( lucideIconsPath , icon ) ,
340+ ] ) ;
341+ }
342+ }
343+
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+ ] ) ;
383+ } ) ( )
384+ ) ;
385+ }
386+
308387Promise . all ( tasks ) . then (
309388 ( ) => {
310389 console . log ( "Generate icon files done!" ) ;
0 commit comments