-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.ts
78 lines (63 loc) · 1.32 KB
/
main.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
import "reflect-metadata"
import { plainToClass } from "class-transformer"
import {
ArrayNotEmpty,
IsDefined,
IsIn,
IsNotEmptyObject,
IsString,
MaxLength,
validate,
} from "class-validator"
export async function validateLayout(
content: Record<string, unknown>
): Promise<boolean> {
const layout = plainToClass(Layout, content)
const errors = await validate(layout)
if (errors.length) {
console.log(errors.map((e) => e.toString()).join(", "))
}
return !errors.length
}
export class Layout {
@IsString()
name: string
@IsString()
version: string
@IsString()
language: string
//@IsString()
//@IsIn(["Thai"])
//language: "Thai"
@ArrayNotEmpty()
@IsIn(
["Base", "Shift", "AltGr", "Command", "Option", "Control", "ShiftAltGr"],
{
each: true,
}
)
layers: Array<
"Base" | "Shift" | "AltGr" | "Command" | "Option" | "Control" | "ShiftAltGr"
>
@IsDefined()
@IsNotEmptyObject()
keys: Record<string, string[]>
@IsDefined()
os: OSAttributes
@IsString()
license: string
}
interface OSAttributes {
windows: WindowsAttributes
}
export class WindowsAttributes {
@IsString()
company: string
@IsString()
localeId: string
@IsString()
@MaxLength(8, {
message: "Installer name cannot be longer than 8 characters",
})
installerName: string
}