File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,14 +19,27 @@ function traverseDir(dir) {
1919 const regex = / c l a s s N a m e \( [ " ' ` ] ( .* ?) [ " ' ` ] \) / g;
2020 let match ;
2121 while ( ( match = regex . exec ( content ) ) !== null ) {
22- collected . add ( "ste-" + match [ 1 ] . replaceAll ( " " , "-" ) ) ;
22+ collected . add ( {
23+ className : "ste-" + match [ 1 ] . replaceAll ( " " , "-" ) ,
24+ features : [
25+ dir . split ( "/features/" ) [ 1 ] . split ( "/" ) [ 0 ] . replaceAll ( ".js" , "" ) ,
26+ ] ,
27+ } ) ;
2328 }
2429 }
2530 }
2631}
2732
2833traverseDir ( rootDir ) ;
2934
30- // Write results
31- fs . writeFileSync ( outputFile , JSON . stringify ( [ ...collected ] , null , 2 ) ) ;
32- console . log ( `✅ Extracted ${ collected . size } class names to ${ outputFile } ` ) ;
35+ const mergedFeatures = Object . values (
36+ [ ...collected ] . reduce ( ( acc , item ) => {
37+ if ( ! acc [ item . className ] ) {
38+ acc [ item . className ] = { className : item . className , features : new Set ( ) } ;
39+ }
40+ item . features . forEach ( f => acc [ item . className ] . features . add ( f ) ) ;
41+ return acc ;
42+ } , { } )
43+ ) . map ( obj => ( { className : obj . className , features : [ ...obj . features ] } ) ) ;
44+
45+ fs . writeFileSync ( outputFile , JSON . stringify ( mergedFeatures , null , 2 ) ) ;
Original file line number Diff line number Diff line change 88
99jobs :
1010 extract :
11+ if : github.repository == 'STForScratch/ScratchTools'
1112 runs-on : ubuntu-latest
1213
1314 steps :
You can’t perform that action at this time.
0 commit comments