-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.ts
62 lines (56 loc) · 1.48 KB
/
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
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
import { extend, config as target } from "@rotorsoft/eventually";
import * as fs from "node:fs";
import { z } from "zod";
type Package = {
name: string;
version: string;
description: string;
author: {
name: string;
email: string;
};
license: string;
dependencies: Record<string, string>;
};
const getPackage = (): Package => {
const pkg = fs.readFileSync("package.json");
return JSON.parse(pkg.toString()) as Package;
};
/**
* OpenAPI spec options
* @default SwaggerUI
*/
const OAS_UIS = ["SwaggerUI", "Rapidoc", "Redoc"] as const;
export type OAS_UI = (typeof OAS_UIS)[number];
/**
* Configuration zod schema
*/
const Schema = z.object({
service: z.string().min(1),
version: z.string().min(1),
description: z.string().min(1),
author: z.object({ name: z.string().min(1), email: z.string() }),
license: z.string().min(1),
dependencies: z.record(z.string()),
port: z.number().int().min(1000).max(65535),
oas_ui: z.enum(OAS_UIS)
});
export type Config = z.infer<typeof Schema>;
const { PORT, OAS_UI } = process.env;
const pkg = getPackage();
const parts = pkg.name.split("/");
const service = parts.at(-1) || "";
export const config = extend(
{
service,
version: pkg.version,
description: pkg.description,
author: { name: pkg.author?.name, email: pkg.author?.email },
license: pkg.license,
dependencies: pkg.dependencies,
port: parseInt(PORT || "3000") || 3000,
oas_ui: (OAS_UI as OAS_UI) || "SwaggerUI"
},
Schema,
target()
);