forked from wrtnlabs/agentica
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestGlobal.ts
More file actions
39 lines (34 loc) · 1.01 KB
/
TestGlobal.ts
File metadata and controls
39 lines (34 loc) · 1.01 KB
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
import dotenv from "dotenv";
import dotenvExpand from "dotenv-expand";
import { Singleton } from "tstl";
import typia from "typia";
export class TestGlobal {
public static readonly ROOT: string =
__filename.substring(__filename.length - 2) === "js"
? `${__dirname}/../..`
: `${__dirname}/..`;
public static get env(): IEnvironments {
return environments.get();
}
public static getArguments(type: string): string[] {
const from: number = process.argv.indexOf(`--${type}`) + 1;
if (from === 0) return [];
const to: number = process.argv
.slice(from)
.findIndex((str) => str.startsWith("--"), from);
return process.argv.slice(
from,
to === -1 ? process.argv.length : to + from,
);
}
}
interface IEnvironments {
CHATGPT_API_KEY?: string;
CHATGPT_BASE_URL?: string;
CHATGPT_OPTIONS?: string;
}
const environments = new Singleton(() => {
const env = dotenv.config();
dotenvExpand.expand(env);
return typia.assert<IEnvironments>(process.env);
});