-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.ts
32 lines (30 loc) · 846 Bytes
/
config.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
import { Module } from "./module.ts";
export type Config = {
modules: Module[];
aliases: {
[name: string]: string;
};
};
export function validateConfig(config: Config) {
if (typeof config !== "object") {
throw new Error(`config type must be 'object'. actual: '${typeof config}'`);
}
if (!Array.isArray(config.modules)) {
throw new Error(
`version type must be Array. actual: '${typeof config.modules}'`,
);
}
config.modules.forEach((mod, i) => {
if (!mod.protocol || !mod.path || !mod.files) {
throw new Error(
`module format is invalid. index: ${i}, protocol: ${mod.protocol}, path: ${mod.path}`,
);
}
});
if (typeof config.aliases !== "object") {
throw new Error(
`config.aliases type must be 'object'. actual: '${typeof config
.aliases}'`,
);
}
}