@@ -2,42 +2,69 @@ import XLSX from 'xlsx';
22import fs from 'fs' ;
33
44const convertExcelToJson = ( ) => {
5- const workbook = XLSX . readFile ( './public/tools.xlsx' ) ; // Replace with your Excel file path
6- const sheetName = workbook . SheetNames [ 0 ] ; // Assuming first sheet contains the data
5+ const workbook = XLSX . readFile ( './public/tools.xlsx' ) ;
6+ const sheetName = workbook . SheetNames [ 0 ] ;
77 const worksheet = workbook . Sheets [ sheetName ] ;
88
9- // Define the structure of each row
109 const jsonData = XLSX . utils . sheet_to_json ( worksheet , { defval : "" } ) ;
1110
1211 const categoriesMap = { } ;
12+ const toolsDir = './public/tools' ;
13+
14+ // Ensure tools directory exists
15+ if ( ! fs . existsSync ( toolsDir ) ) {
16+ fs . mkdirSync ( toolsDir , { recursive : true } ) ;
17+ }
1318
1419 jsonData . forEach ( ( row ) => {
1520 const category = row . category || "Uncategorized" ;
21+ const categoryId = category . toLowerCase ( ) . replace ( / [ ^ a - z 0 - 9 ] / g, '_' ) ;
1622
1723 if ( ! categoriesMap [ category ] ) {
18- categoriesMap [ category ] = { category, tools : [ ] } ;
24+ categoriesMap [ category ] = {
25+ id : categoryId ,
26+ category,
27+ tools : [ ]
28+ } ;
1929 }
2030
2131 const install = { } ;
22-
23- // Map the package managers and installation commands dynamically
2432 [ 'choco' , 'winget' , 'scoop' , 'apt' , 'dnf' , 'pacman' , 'homebrew' ] . forEach ( pkg => {
2533 if ( row [ pkg ] ) {
2634 install [ pkg ] = row [ pkg ] ;
2735 }
2836 } ) ;
2937
3038 categoriesMap [ category ] . tools . push ( {
39+ id : row . name . toLowerCase ( ) . replace ( / [ ^ a - z 0 - 9 ] / g, '_' ) ,
3140 name : row . name ,
3241 iconsrc : row . iconsrc ,
3342 install,
3443 } ) ;
3544 } ) ;
3645
37- // Write the JSON data to a file
46+ const categoryList = [ ] ;
47+
48+ // Write individual category files and build manifest
49+ Object . values ( categoriesMap ) . forEach ( categoryData => {
50+ const fileName = `${ categoryData . id } .json` ;
51+ fs . writeFileSync ( `${ toolsDir } /${ fileName } ` , JSON . stringify ( categoryData , null , 2 ) ) ;
52+
53+ categoryList . push ( {
54+ id : categoryData . id ,
55+ name : categoryData . category ,
56+ file : `/tools/${ fileName } ` ,
57+ count : categoryData . tools . length
58+ } ) ;
59+ } ) ;
60+
61+ // Write manifest file
62+ fs . writeFileSync ( './public/tools/manifest.json' , JSON . stringify ( categoryList , null , 2 ) ) ;
63+
64+ // Keep tools.json for backward compatibility (optional but recommended for now)
3865 fs . writeFileSync ( './public/tools.json' , JSON . stringify ( Object . values ( categoriesMap ) , null , 2 ) ) ;
3966
40- console . log ( "Excel file has been converted to JSON." ) ;
67+ console . log ( `Successfully sharded ${ jsonData . length } tools into ${ categoryList . length } categories.` ) ;
4168} ;
4269
4370convertExcelToJson ( ) ;
0 commit comments