1
+ import { Preprocessors } from "./BlockParser" ;
1
2
import {
2
- Options ,
3
- ResolvedConfiguration ,
4
- } from "./options" ;
5
-
6
- import { OutputMode } from "./OutputMode" ;
7
-
3
+ OutputMode ,
4
+ } from "./OutputMode" ;
8
5
import {
9
6
filesystemImporter ,
10
7
Importer ,
11
8
ImporterData ,
12
9
} from "./importing" ;
10
+ import {
11
+ Configuration ,
12
+ ConfigurationObjectKeys ,
13
+ ConfigurationSimpleKeys ,
14
+ Options ,
15
+ ResolvedConfiguration ,
16
+ } from "./options" ;
13
17
14
- import { Preprocessors } from "./BlockParser" ;
15
-
18
+ const CONFIG_OBJECT_KEYS : Array < ConfigurationObjectKeys > = [
19
+ "importerData" ,
20
+ "preprocessors" ,
21
+ ] ;
22
+ const CONFIG_SIMPLE_KEYS : Array < ConfigurationSimpleKeys > = [
23
+ "outputMode" ,
24
+ "importer" ,
25
+ "rootDir" ,
26
+ "disablePreprocessChaining" ,
27
+ "maxConcurrentCompiles" ,
28
+ ] ;
16
29
const DEFAULTS : ResolvedConfiguration = {
17
30
outputMode : OutputMode . BEM ,
18
31
importer : filesystemImporter ,
@@ -28,18 +41,25 @@ const DEFAULTS: ResolvedConfiguration = {
28
41
* passed.
29
42
*/
30
43
class OptionsReader implements ResolvedConfiguration {
31
- private _opts : ResolvedConfiguration ;
44
+ private _opts : Configuration ;
32
45
33
- constructor ( options : Options = { } , defaults : Options = { } ) {
46
+ constructor ( options ? : Options , defaults ? : Options ) {
34
47
this . _opts = { ...DEFAULTS } ;
35
- for ( let k of Object . keys ( defaults ) ) {
36
- if ( defaults [ k ] !== undefined ) {
37
- this . _opts [ k ] = defaults [ k ] ;
48
+ this . setAll ( defaults ) ;
49
+ this . setAll ( options ) ;
50
+ }
51
+ private setAll ( opts : Options | undefined ) {
52
+ if ( opts === undefined ) return ;
53
+ for ( let k of CONFIG_SIMPLE_KEYS ) {
54
+ let v = opts [ k ] ;
55
+ if ( v !== undefined ) {
56
+ this . _opts [ k ] = v ;
38
57
}
39
58
}
40
- for ( let k of Object . keys ( options ) ) {
41
- if ( options [ k ] !== undefined ) {
42
- this . _opts [ k ] = options [ k ] ;
59
+ for ( let k of CONFIG_OBJECT_KEYS ) {
60
+ let v = opts [ k ] ;
61
+ if ( v !== undefined ) {
62
+ this . _opts [ k ] = { ...v } ;
43
63
}
44
64
}
45
65
}
0 commit comments