@@ -12,12 +12,25 @@ export interface ExtractedData {
12
12
path : string ;
13
13
}
14
14
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
+ */
16
21
function readFileContent ( filePath : string ) : string {
17
22
return fs . readFileSync ( filePath , 'utf8' ) ;
18
23
}
19
24
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
+ */
21
34
function processFiles < T extends ExtractedData > (
22
35
files : FileInfo [ ] ,
23
36
extractorFn : ( content : string ) => string [ ] ,
@@ -40,7 +53,12 @@ function processFiles<T extends ExtractedData>(
40
53
. filter ( ( item ) : item is T => item !== null && item . data . length > 0 ) ;
41
54
}
42
55
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
+ */
44
62
export function processTemplateFilesToExtractClasses ( templateFiles : FileInfo [ ] ) : ExtractedData [ ] {
45
63
return processFiles < ExtractedData > (
46
64
templateFiles ,
@@ -49,7 +67,12 @@ export function processTemplateFilesToExtractClasses(templateFiles: FileInfo[]):
49
67
) ;
50
68
}
51
69
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
+ */
53
76
export function processCssFilesToExtractClasses ( cssFiles : FileInfo [ ] ) : ExtractedData [ ] {
54
77
return processFiles < ExtractedData > (
55
78
cssFiles ,
@@ -58,18 +81,36 @@ export function processCssFilesToExtractClasses(cssFiles: FileInfo[]): Extracted
58
81
) ;
59
82
}
60
83
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
+ */
62
91
function writeDataToFile ( data : ExtractedData [ ] , fileName : string , uncssTempDir : string ) : void {
63
92
const outputPath = path . join ( uncssTempDir , fileName ) ;
64
93
fs . writeFileSync ( outputPath , JSON . stringify ( data , null , 2 ) ) ;
65
94
}
66
95
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
+ */
68
103
export function writeTemplateClassesToFile ( templateClasses : ExtractedData [ ] , fileName : string , uncssTempDir : string ) : void {
69
104
writeDataToFile ( templateClasses , fileName , uncssTempDir ) ;
70
105
}
71
106
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
+ */
73
114
export function writeCssSelectorsToFile ( cssSelectors : ExtractedData [ ] , fileName : string , uncssTempDir : string ) : void {
74
115
writeDataToFile ( cssSelectors , fileName , uncssTempDir ) ;
75
116
}
0 commit comments