@@ -12,12 +12,25 @@ export interface ExtractedData {
1212 path : string ;
1313}
1414
15- // Generic function to read file content
15+ /**
16+ * Reads the content of a file
17+ *
18+ * @param {string } filePath - The path to the file
19+ * @returns {string } The content of the file
20+ */
1621function readFileContent ( filePath : string ) : string {
1722 return fs . readFileSync ( filePath , 'utf8' ) ;
1823}
1924
20- // Generic function to process files
25+ /**
26+ * Processes files using the provided extractor function and data processor
27+ *
28+ * @template T
29+ * @param {FileInfo[] } files - Array of file information objects
30+ * @param {(content: string) => string[] } extractorFn - Function to extract data from file content
31+ * @param {(data: string[]) => T['data'] } dataProcessor - Function to process extracted data
32+ * @returns {T[] } Array of processed data objects
33+ */
2134function processFiles < T extends ExtractedData > (
2235 files : FileInfo [ ] ,
2336 extractorFn : ( content : string ) => string [ ] ,
@@ -40,7 +53,12 @@ function processFiles<T extends ExtractedData>(
4053 . filter ( ( item ) : item is T => item !== null && item . data . length > 0 ) ;
4154}
4255
43- // Process template files
56+ /**
57+ * Processes template files to extract classes
58+ *
59+ * @param {FileInfo[] } templateFiles - Array of template file information objects
60+ * @returns {ExtractedData[] } Array of extracted class data
61+ */
4462export function processTemplateFilesToExtractClasses ( templateFiles : FileInfo [ ] ) : ExtractedData [ ] {
4563 return processFiles < ExtractedData > (
4664 templateFiles ,
@@ -49,7 +67,12 @@ export function processTemplateFilesToExtractClasses(templateFiles: FileInfo[]):
4967 ) ;
5068}
5169
52- // Process CSS files
70+ /**
71+ * Processes CSS files to extract classes
72+ *
73+ * @param {FileInfo[] } cssFiles - Array of CSS file information objects
74+ * @returns {ExtractedData[] } Array of extracted CSS selector data
75+ */
5376export function processCssFilesToExtractClasses ( cssFiles : FileInfo [ ] ) : ExtractedData [ ] {
5477 return processFiles < ExtractedData > (
5578 cssFiles ,
@@ -58,18 +81,36 @@ export function processCssFilesToExtractClasses(cssFiles: FileInfo[]): Extracted
5881 ) ;
5982}
6083
61- // Generic function to write data to file
84+ /**
85+ * Writes data to a file in the specified directory
86+ *
87+ * @param {ExtractedData[] } data - Array of extracted data objects
88+ * @param {string } fileName - Name of the output file
89+ * @param {string } uncssTempDir - Path to the temporary directory
90+ */
6291function writeDataToFile ( data : ExtractedData [ ] , fileName : string , uncssTempDir : string ) : void {
6392 const outputPath = path . join ( uncssTempDir , fileName ) ;
6493 fs . writeFileSync ( outputPath , JSON . stringify ( data , null , 2 ) ) ;
6594}
6695
67- // Write template classes to file
96+ /**
97+ * Writes extracted template classes to a file
98+ *
99+ * @param {ExtractedData[] } templateClasses - Array of extracted template class data
100+ * @param {string } fileName - Name of the output file
101+ * @param {string } uncssTempDir - Path to the temporary directory
102+ */
68103export function writeTemplateClassesToFile ( templateClasses : ExtractedData [ ] , fileName : string , uncssTempDir : string ) : void {
69104 writeDataToFile ( templateClasses , fileName , uncssTempDir ) ;
70105}
71106
72- // Write CSS selectors to file
107+ /**
108+ * Writes extracted CSS selectors to a file
109+ *
110+ * @param {ExtractedData[] } cssSelectors - Array of extracted CSS selector data
111+ * @param {string } fileName - Name of the output file
112+ * @param {string } uncssTempDir - Path to the temporary directory
113+ */
73114export function writeCssSelectorsToFile ( cssSelectors : ExtractedData [ ] , fileName : string , uncssTempDir : string ) : void {
74115 writeDataToFile ( cssSelectors , fileName , uncssTempDir ) ;
75116}
0 commit comments