@@ -8,36 +8,56 @@ import picomatch from 'picomatch'
8
8
import type { Expression , PrivateName } from '@babel/types'
9
9
import type { OptionsResolved } from './options'
10
10
11
+ /**
12
+ * Represents the scan options for the enum.
13
+ */
11
14
export type ScanOptions = Pick <
12
15
OptionsResolved ,
13
16
'scanDir' | 'scanMode' | 'scanPattern'
14
17
>
15
18
19
+ /**
20
+ * Represents a member of an enum.
21
+ */
16
22
export interface EnumMember {
17
23
readonly name : string
18
24
readonly value : string | number
19
25
}
20
26
27
+ /**
28
+ * Represents a declaration of an enum.
29
+ */
21
30
export interface EnumDeclaration {
22
31
readonly id : string
23
32
readonly range : readonly [ start : number , end : number ]
24
33
readonly members : ReadonlyArray < EnumMember >
25
34
}
26
35
36
+ /**
37
+ * Represents the data of all enums.
38
+ */
27
39
export interface EnumData {
28
40
readonly declarations : {
29
41
readonly [ file : string ] : ReadonlyArray < EnumDeclaration >
30
42
}
31
43
readonly defines : { readonly [ id_key : `${string } .${string } `] : string }
32
44
}
33
45
46
+ /**
47
+ * Evaluates a JavaScript expression and returns the result.
48
+ * @param exp - The expression to evaluate.
49
+ * @returns The evaluated result.
50
+ */
34
51
function evaluate ( exp : string ) : string | number {
35
52
return new Function ( `return ${ exp } ` ) ( )
36
53
}
37
54
38
- // this is called in the build script entry once
39
- // so the data can be shared across concurrent Rollup processes
40
- export function scanEnums ( options : ScanOptions ) {
55
+ /**
56
+ * Scans the specified directory for enums based on the provided options.
57
+ * @param options - The scan options for the enum.
58
+ * @returns The data of all enums found.
59
+ */
60
+ export function scanEnums ( options : ScanOptions ) : EnumData {
41
61
const declarations : { [ file : string ] : EnumDeclaration [ ] } =
42
62
Object . create ( null )
43
63
@@ -184,6 +204,11 @@ export function scanEnums(options: ScanOptions) {
184
204
return enumData
185
205
}
186
206
207
+ /**
208
+ * Scans the specified directory for files based on the provided options.
209
+ * @param options - The scan options for the files.
210
+ * @returns The list of files found.
211
+ */
187
212
export function scanFiles ( options : ScanOptions ) : string [ ] {
188
213
if ( options . scanMode === 'fs' ) {
189
214
return fg . sync ( options . scanPattern , {
0 commit comments