forked from johnlindquist/kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
58 lines (48 loc) · 1.13 KB
/
index.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
import { homedir } from "os"
import path from "path"
import { URL } from "url"
let kitRun = async (
command: string,
..._args: string[]
) => {
process.env.KIT =
process.env.KIT ||
path.dirname(new URL(import.meta.url).pathname)
process.env.KNODE =
process.env.KNODE || path.resolve(homedir(), ".knode")
await import("./api/global.js")
await import("./api/kit.js")
await import("./api/lib.js")
await import("./target/terminal.js")
return await global.run(command, ..._args)
}
export * from "./api/kit.js"
export * from "./core/utils.js"
let dirs = ["cli", "main"]
let kitGet = (
_target: any,
key: string,
_receiver: any
) => {
if ((global as any)[key] && !dirs.includes(key)) {
return (global as any)[key]
}
try {
return new Proxy(
{},
{
get: async (_target, module: string, _receiver) => {
let modulePath = `../${key}/${module}.js?${global.uuid()}`
return await import(modulePath)
},
}
)
} catch (error) {
console.warn(error)
}
}
let kitDefault = new Proxy(kitRun, {
get: kitGet,
})
global.kit = kitDefault
export default kitDefault