1
1
import { CodeWithSourceMap } from './metadata' ;
2
2
3
3
export interface StyleTransformer {
4
- ( style : string , url ?: string ) : CodeWithSourceMap ;
4
+ ( code : string , url ?: string ) : CodeWithSourceMap ;
5
5
}
6
6
7
7
export interface TemplateTransformer {
8
- ( template : string , url ?: string ) : CodeWithSourceMap ;
8
+ ( code : string , url ?: string ) : CodeWithSourceMap ;
9
9
}
10
10
11
11
export interface UrlResolver {
@@ -14,9 +14,11 @@ export interface UrlResolver {
14
14
15
15
export const LogLevel = { Debug : 0b111 , Error : 0b001 , Info : 0b011 , None : 0 } ;
16
16
17
+ type ValueOf < T > = T [ keyof T ] ;
18
+
17
19
export interface Config {
18
20
interpolation : [ string , string ] ;
19
- logLevel : number ;
21
+ logLevel : ValueOf < typeof LogLevel > ;
20
22
predefinedDirectives : DirectiveDeclaration [ ] ;
21
23
resolveUrl : UrlResolver ;
22
24
transformStyle : StyleTransformer ;
@@ -33,10 +35,17 @@ export interface DirectiveDeclaration {
33
35
selector : string ;
34
36
}
35
37
38
+ const CSS_FILE_EXTENSION = '.css' ;
39
+ const HTML_FILE_EXTENSION = '.html' ;
40
+ const SVG_FILE_EXTENSION = '.svg' ;
36
41
let BUILD_TYPE = '<%= BUILD_TYPE %>' ;
37
42
38
- const transform = ( code : string , extension : '.css' | '.html' , url ?: string ) : { code : string ; url ?: string } => {
39
- return { code : ! url || url . endsWith ( extension ) ? code : '' , url } ;
43
+ type FileExtension = typeof CSS_FILE_EXTENSION | typeof HTML_FILE_EXTENSION | typeof SVG_FILE_EXTENSION ;
44
+
45
+ const transform = ( code : string , fileExtensions : ReadonlyArray < FileExtension > , url ?: string ) : { code : string ; url ?: string } => {
46
+ const parsedCode = ! url || fileExtensions . some ( fileExtension => url . endsWith ( fileExtension ) ) ? code : '' ;
47
+
48
+ return { code : parsedCode , url } ;
40
49
} ;
41
50
42
51
export const Config : Config = {
@@ -71,13 +80,11 @@ export const Config: Config = {
71
80
{ selector : 'md-select' , exportAs : 'mdSelect' }
72
81
] ,
73
82
74
- resolveUrl ( url : string | null ) {
75
- return url ;
76
- } ,
83
+ resolveUrl : ( url : string | null ) => url ,
77
84
78
- transformStyle : ( code : string , url ?: string ) => transform ( code , '.css' , url ) ,
85
+ transformStyle : ( code : string , url ?: string ) => transform ( code , [ CSS_FILE_EXTENSION ] , url ) ,
79
86
80
- transformTemplate : ( code : string , url ?: string ) => transform ( code , '.html' , url )
87
+ transformTemplate : ( code : string , url ?: string ) => transform ( code , [ HTML_FILE_EXTENSION , SVG_FILE_EXTENSION ] , url )
81
88
} ;
82
89
83
90
try {
0 commit comments