forked from smithery-ai/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.mjs
More file actions
67 lines (56 loc) · 1.78 KB
/
Copy pathbuild.mjs
File metadata and controls
67 lines (56 loc) · 1.78 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { config } from "dotenv"
import * as esbuild from "esbuild"
import { existsSync, mkdirSync } from "node:fs"
// Load environment variables into a define object
config()
const define = {}
for (const k in process.env) {
/* Skip environment variables that should be evaluated at runtime */
if (["HOME", "USER", "XDG_CONFIG_HOME"].includes(k)) continue
define[`process.env.${k}`] = JSON.stringify(process.env[k])
}
// Compile bootstrap TypeScript files to JavaScript
console.log("Compiling bootstrap files...")
const shttpResult = await esbuild.build({
entryPoints: ["src/runtime/shttp-bootstrap.ts"],
bundle: true,
platform: "node",
target: "node18",
format: "cjs",
write: false,
external: ["virtual:user-module"],
})
const stdioResult = await esbuild.build({
entryPoints: ["src/runtime/stdio-bootstrap.ts"],
bundle: true,
platform: "node",
target: "node18",
format: "cjs",
write: false,
external: ["virtual:user-module"],
})
// Get the compiled code as strings and inject via define
const shttpBootstrapJs = shttpResult.outputFiles[0].text
const stdioBootstrapJs = stdioResult.outputFiles[0].text
// Inject bootstrap content as global constants
define.__SMITHERY_SHTTP_BOOTSTRAP__ = JSON.stringify(shttpBootstrapJs)
define.__SMITHERY_STDIO_BOOTSTRAP__ = JSON.stringify(stdioBootstrapJs)
console.log("✓ Compiled bootstrap files")
// Build main CLI entry point
await esbuild.build({
entryPoints: ["src/index.ts"],
bundle: true,
platform: "node",
target: "node18",
minify: true,
treeShaking: true,
outfile: "dist/index.js",
external: ["@ngrok/ngrok", "esbuild"],
define,
})
// Copy runtime files to dist/runtime/
const runtimeDir = "dist/runtime"
if (!existsSync(runtimeDir)) {
mkdirSync(runtimeDir, { recursive: true })
}
console.log("✓ Build complete - runtime files copied")