11import * as fs from "fs" ;
22import * as path from "path" ;
33
4+ type FontawesomeConfig = {
5+ /* used regular icons without `fa-` prefix*/
6+ regular : string [ ] ;
7+ /* used solid icons without `fa-` prefix*/
8+ solid : string [ ] ;
9+ /* used brands icons without `fa-` prefix*/
10+ brands : string [ ] ;
11+ } ;
12+
13+ type FileObject = { name : string ; isDirectory : boolean } ;
14+
415const iconSet = {
516 solid : parseIcons ( "solid" ) ,
617 regular : parseIcons ( "regular" ) ,
@@ -39,20 +50,13 @@ const modules2 = {
3950 stacked : [ "stack" , "stack-1x" , "stack-2x" , "inverse" ] ,
4051} ;
4152
42- /**
43- * fontawesome icon config
44- * @typedef {Object } FontawesomeConfig
45- * @property {string[] } solid - used solid icons without `fa-` prefix
46- * @property {string[] } brands - used brands icons without `fa-` prefix
47- */
48-
4953/**
5054 * Detect used fontawesome icons in the directories `src/**` and `static/**{.html|.css}`
5155 * @param {boolean } debug - Enable debug output
5256 * @returns {FontawesomeConfig } - used icons
5357 */
5458
55- export function getFontawesomeConfig ( debug = false ) {
59+ export function getFontawesomeConfig ( debug = false ) : FontawesomeConfig {
5660 const time = Date . now ( ) ;
5761 const srcFiles = findAllFiles (
5862 "./src" ,
@@ -66,7 +70,7 @@ export function getFontawesomeConfig(debug = false) {
6670 ) ;
6771
6872 const allFiles = [ ...srcFiles , ...staticFiles ] ;
69- const usedClassesSet = new Set ( ) ;
73+ const usedClassesSet : Set < string > = new Set ( ) ;
7074
7175 const regex = / \b f a - [ a - z 0 - 9 - ] + \b / g;
7276
@@ -130,12 +134,15 @@ if (import.meta.url.endsWith(process.argv[1])) {
130134 getFontawesomeConfig ( true ) ;
131135}
132136
133- function toFileAndDir ( dir , file ) {
137+ function toFileAndDir ( dir , file ) : FileObject {
134138 const name = path . join ( dir , file ) ;
135139 return { name, isDirectory : fs . statSync ( name ) . isDirectory ( ) } ;
136140}
137141
138- function findAllFiles ( dir , filter = ( filename ) => true ) {
142+ function findAllFiles (
143+ dir : string ,
144+ filter : ( filename : string ) => boolean = ( _it ) : boolean => true
145+ ) : string [ ] {
139146 return fs
140147 . readdirSync ( dir )
141148 . map ( ( it ) => toFileAndDir ( dir , it ) )
@@ -147,11 +154,12 @@ function findAllFiles(dir, filter = (filename) => true) {
147154 } , [ ] ) ;
148155}
149156
150- function parseIcons ( iconSet ) {
151- const file = fs
157+ function parseIcons ( iconSet : string ) : string [ ] {
158+ const file : string | null = fs
152159 . readFileSync ( `node_modules/@fortawesome/fontawesome-free/js/${ iconSet } .js` )
153160 . toString ( ) ;
161+
154162 return file
155- . match ( / \ "( .* ) \" \ : \[ .* \] , / g)
156- . map ( ( it ) => it . substring ( 1 , it . indexOf ( ":" ) - 1 ) ) ;
163+ ? .match ( / " ( .* ) " : \[ .* \] , / g)
164+ ? .map ( ( it ) => it . substring ( 1 , it . indexOf ( ":" ) - 1 ) ) as string [ ] ;
157165}
0 commit comments