@@ -2,15 +2,23 @@ import { ComponentsInfo, ComponentsImportMap, Options } from './types'
2
2
3
3
export class Context {
4
4
importMap : ComponentsImportMap = { }
5
- components : ComponentsInfo [ ] = [ ]
6
5
_searchingPromise ?: Promise < any >
7
6
7
+ private _components : ComponentsInfo [ ] = [ ]
8
8
private importMapPromises : Record < string , [ ( null | Promise < string [ ] > ) , ( null | ( ( result : string [ ] ) => void ) ) ] > = { }
9
9
10
10
constructor (
11
11
public readonly options : Options ,
12
12
) { }
13
13
14
+ get components ( ) {
15
+ return this . _components
16
+ }
17
+
18
+ set components ( components : ComponentsInfo [ ] ) {
19
+ this . _components = components . map ( ( [ name , path ] ) => [ capitalize ( camelize ( name ) ) , path ] )
20
+ }
21
+
14
22
async getImportMap ( key : string ) {
15
23
if ( this . importMap [ key ] )
16
24
return this . importMap [ key ]
@@ -27,8 +35,17 @@ export class Context {
27
35
}
28
36
29
37
setImportMap ( key : string , names : string [ ] ) {
30
- this . importMap [ key ] = names
38
+ const casedNames = names . map ( name => capitalize ( camelize ( name ) ) )
39
+ this . importMap [ key ] = casedNames
31
40
if ( this . importMapPromises [ key ] )
32
- this . importMapPromises [ key ] [ 1 ] ?.( names )
41
+ this . importMapPromises [ key ] [ 1 ] ?.( casedNames )
33
42
}
34
43
}
44
+
45
+ function camelize ( str : string ) {
46
+ return str . replace ( / - ( \w ) / g, ( _ , c ) => ( c ? c . toUpperCase ( ) : '' ) )
47
+ }
48
+
49
+ function capitalize ( str : string ) {
50
+ return str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 )
51
+ }
0 commit comments