-
Notifications
You must be signed in to change notification settings - Fork 3
/
options.ts
75 lines (69 loc) · 1.42 KB
/
options.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { PartialDeep } from './types';
export enum UntypedType {
ANY = 'any',
NEVER = 'never',
UNDEFINED = 'undefined',
UNKNOWN = 'unknown'
}
export enum OptionalFieldPattern {
QUESTION = 'fieldName?',
PIPE_UNDEFINED = 'Type | undefined'
}
export type AllOptions = {
files: {
cwd?: string;
source: {
dir: string;
encoding: BufferEncoding;
recursive: boolean;
};
destination: {
dir: string;
preClean: boolean;
indexFiles: boolean;
};
};
ts: {
optionalFields: OptionalFieldPattern;
untyped: UntypedType;
};
}
export type Options = PartialDeep<AllOptions>;
export const DEFAULT_OPTIONS: AllOptions = {
files: {
source: {
dir: 'src/schemas',
encoding: 'utf-8',
recursive: true
},
destination: {
dir: 'src/generated',
preClean: false,
indexFiles: true
}
},
ts: {
optionalFields: OptionalFieldPattern.QUESTION,
untyped: UntypedType.UNKNOWN
}
};
export const createOptions = (options: PartialDeep<AllOptions>): AllOptions => {
return {
files: {
...DEFAULT_OPTIONS.files,
...options.files,
source: {
...DEFAULT_OPTIONS.files.source,
...options.files?.source
},
destination: {
...DEFAULT_OPTIONS.files.destination,
...options.files?.destination
}
},
ts: {
...DEFAULT_OPTIONS.ts,
...options.ts
}
};
};