/
repl-init.ts
42 lines (34 loc) 路 1.04 KB
/
repl-init.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
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
import * as dotenv from "./dotenv/mod.ts";
import * as runtime from "./standards/runtime.ts";
import * as mod from "./mod.ts";
// TODO(@eser) get dependency injection container entries instead of this
await (async () => {
const env = await dotenv.load();
const kv = await runtime.current.openKv();
const variables: Record<string, unknown> = {
...mod,
env,
kv,
};
const vars = () => {
console.log(
"\n%cpredefined variables\n--------------------",
"font-weight: bold",
);
console.log(
"- " +
Object.keys(variables).map((x, i) =>
x.padEnd(20, " ") + (i % 3 === 2 ? "\n" : "")
).join("- "),
);
console.log();
};
variables["vars"] = vars;
for (const [key, value] of Object.entries(variables)) {
// @ts-ignore globalThis type check
globalThis[key] = value;
}
console.log(`%ccool REPL, version ${mod.metadata.version}`, "color: #00ff00");
vars();
})();