-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.config.ts
106 lines (101 loc) · 2.46 KB
/
esbuild.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// esbuild.config.ts
import { build, Format, Platform, LogLevel } from 'esbuild';
import path from 'path';
import fs from 'fs';
const OUTPUT_DIR = 'dist';
const GENERATED_DIR = 'generated';
const shebangPlugin = {
name: 'shebang',
setup(build: any) {
build.onEnd(result => {
for (const output of result.outputFiles || []) {
if (output.path.endsWith('cli.js')) {
const shebang = '#!/usr/bin/env node\n';
const contents = shebang + output.text;
fs.writeFileSync(output.path, contents);
}
}
});
}
};
const sharedOptions = {
bundle: true,
platform: 'node' as Platform,
format: 'esm' as Format,
target: 'node16',
sourcemap: true,
minify: false,
external: [
"@modelcontextprotocol/sdk",
"@modelcontextprotocol",
"@redocly",
"@ianvs/prettier-plugin-sort-imports",
"prettier-plugin-packagejson",
"ts-morph",
"zod",
"fs",
"path",
"node:perf_hooks",
"yaml",
"openapi-typescript",
"remeda",
"prettier",
"express",
"async_hooks",
"commander",
"node-stdlib-browser",
"detect-port",
"crypto",
"stream",
"http",
"https",
"url",
"os",
"child_process",
],
plugins: [shebangPlugin],
absWorkingDir: process.cwd(),
logLevel: 'info' as LogLevel,
alias: {
src: path.resolve('./src')
},
mainFields: ['module', 'main'],
resolveExtensions: ['.ts', '.js', '.mjs', '.jsx', '.json'],
nodePaths: [path.join(process.cwd(), 'node_modules')]
};
// Build CLI bundle
await build({
...sharedOptions,
entryPoints: ['./src/cli.ts'],
outfile: path.join(OUTPUT_DIR, 'cli.js'),
write: false,
}).then(result => {
if (result.outputFiles) {
for (const output of result.outputFiles) {
if (output.path.endsWith('cli.js') ) {
const shebang = '#!/usr/bin/env node\n';
fs.writeFileSync(output.path, shebang + output.text);
} else {
fs.writeFileSync(output.path, output.text);
}
}
}
});
// Build Runtime bundle
await build({
...sharedOptions,
entryPoints: ['./src/runtime/index.ts'],
outfile: path.join(OUTPUT_DIR, 'server.js'),
write: false,
}).then(result => {
if (result.outputFiles) {
for (const output of result.outputFiles) {
if (output.path.endsWith('server.js')) {
const shebang = '#!/usr/bin/env node\n';
fs.writeFileSync(output.path, shebang + output.text);
} else {
fs.writeFileSync(output.path, output.text);
}
}
}
});