This repository has been archived by the owner on Mar 16, 2021. It is now read-only.
forked from NathanJAdams/json-schema-to-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.ts
84 lines (77 loc) · 1.49 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
76
77
78
79
80
81
82
83
84
import { PartialDeep } from './types';
enum UntypedType {
ANY = 'any',
NEVER = 'never',
UNDEFINED = 'undefined',
UNKNOWN = 'unknown'
}
enum OptionalFieldPattern {
QUESTION = 'fieldName?',
PIPE_UNDEFINED = 'Type | undefined'
}
interface AllOptions {
files: {
cwd?: string;
source: {
dir: string;
encoding: BufferEncoding;
recursive: boolean;
};
destination: {
dir: string;
preClean: boolean;
indexFiles: boolean;
};
};
ts: {
optionalFields: OptionalFieldPattern;
untyped: UntypedType;
};
}
type Options = PartialDeep<AllOptions>;
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
}
};
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
}
};
};
export {
OptionalFieldPattern,
UntypedType,
AllOptions,
Options,
DEFAULT_OPTIONS,
createOptions
};