-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathesbuild.mjs
More file actions
88 lines (75 loc) · 2.03 KB
/
Copy pathesbuild.mjs
File metadata and controls
88 lines (75 loc) · 2.03 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import esbuild from 'esbuild';
import { mkdirSync, copyFileSync, existsSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const isWatch = process.argv.includes('--watch');
// Ensure out directory exists
const outDir = join(__dirname, 'out');
const webviewOutDir = join(outDir, 'webview');
if (!existsSync(outDir)) {
mkdirSync(outDir, { recursive: true });
}
if (!existsSync(webviewOutDir)) {
mkdirSync(webviewOutDir, { recursive: true });
}
// Copy webview files
function copyWebviewFiles() {
const webviewSrcDir = join(__dirname, 'src', 'webview');
const files = ['main.js', 'styles.css'];
files.forEach((file) => {
const src = join(webviewSrcDir, file);
const dest = join(webviewOutDir, file);
if (existsSync(src)) {
copyFileSync(src, dest);
console.log(`Copied ${file}`);
}
});
}
const extensionBuildOptions = {
entryPoints: ['src/extension.ts'],
bundle: true,
outfile: 'out/extension.js',
external: ['vscode'],
format: 'cjs',
platform: 'node',
target: 'node18',
sourcemap: true,
logLevel: 'info',
};
const mcpServerBuildOptions = {
entryPoints: ['src/mcpServer.ts'],
bundle: true,
outfile: 'out/mcpServer.js',
external: ['vscode'],
format: 'cjs',
platform: 'node',
target: 'node18',
sourcemap: true,
logLevel: 'info',
banner: {
js: '#!/usr/bin/env node',
},
};
async function build() {
await Promise.all([
esbuild.build(extensionBuildOptions),
esbuild.build(mcpServerBuildOptions),
]);
copyWebviewFiles();
console.log('Build complete');
}
if (isWatch) {
const extensionCtx = await esbuild.context(extensionBuildOptions);
const mcpServerCtx = await esbuild.context(mcpServerBuildOptions);
await Promise.all([
extensionCtx.watch(),
mcpServerCtx.watch(),
]);
copyWebviewFiles();
console.log('Watching for changes...');
console.log('Note: Webview file changes require manual rebuild');
} else {
await build();
}