-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathesbuild.js
More file actions
102 lines (93 loc) · 3.06 KB
/
esbuild.js
File metadata and controls
102 lines (93 loc) · 3.06 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const esbuild = require("esbuild");
const fs = require("fs");
const path = require("path");
const production = process.argv.includes('--production');
const watch = process.argv.includes('--watch');
/**
* @type {import('esbuild').Plugin}
*/
const esbuildProblemMatcherPlugin = {
name: 'esbuild-problem-matcher',
setup(build) {
build.onStart(() => {
console.log('[watch] build started');
});
build.onEnd((result) => {
result.errors.forEach(({ text, location }) => {
console.error(`✘ [ERROR] ${text}`);
console.error(` ${location.file}:${location.line}:${location.column}:`);
});
console.log('[watch] build finished');
});
},
};
async function main() {
// Extension bundle (Node target)
const extensionCtx = await esbuild.context({
entryPoints: ['src/extension.ts'],
bundle: true,
format: 'cjs',
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: 'node',
outfile: 'dist/extension.js',
external: ['vscode'],
logLevel: 'silent',
plugins: [esbuildProblemMatcherPlugin],
});
// Webview bundle(s) (Browser target)
const webviewCtx = await esbuild.context({
entryPoints: {
details: 'src/webview/details/main.ts',
chart: 'src/webview/chart/main.ts',
usage: 'src/webview/usage/main.ts',
diagnostics: 'src/webview/diagnostics/main.ts',
logviewer: 'src/webview/logviewer/main.ts',
maturity: 'src/webview/maturity/main.ts',
dashboard: 'src/webview/dashboard/main.ts',
'fluency-level-viewer': 'src/webview/fluency-level-viewer/main.ts', environmental: 'src/webview/environmental/main.ts', },
bundle: true,
format: 'iife',
minify: production,
sourcemap: !production,
platform: 'browser',
target: 'es2020',
outdir: 'dist/webview',
entryNames: '[name]',
external: ['vscode'],
logLevel: 'silent',
plugins: [esbuildProblemMatcherPlugin],
loader: { '.css': 'text' },
});
if (watch) {
await Promise.all([extensionCtx.watch(), webviewCtx.watch()]);
} else {
await Promise.all([extensionCtx.rebuild(), webviewCtx.rebuild()]);
await extensionCtx.dispose();
await webviewCtx.dispose();
}
// Copy sql.js WASM file to dist/ for OpenCode SQLite support
const wasmSrc = path.join(__dirname, 'node_modules', 'sql.js', 'dist', 'sql-wasm.wasm');
const wasmDst = path.join(__dirname, 'dist', 'sql-wasm.wasm');
if (fs.existsSync(wasmSrc)) {
fs.copyFileSync(wasmSrc, wasmDst);
}
// Copy VS Code Webview UI Toolkit to dist/ for webview usage
const toolkitDir = path.join(__dirname, 'dist', 'toolkit');
if (!fs.existsSync(toolkitDir)) {
fs.mkdirSync(toolkitDir, { recursive: true });
}
const toolkitSrc = path.join(__dirname, 'node_modules', '@vscode', 'webview-ui-toolkit', 'dist');
// Use minified version in production, regular version in development
const toolkitFile = production ? 'toolkit.min.js' : 'toolkit.js';
const src = path.join(toolkitSrc, toolkitFile);
const dst = path.join(toolkitDir, 'toolkit.js'); // Always name it toolkit.js for consistent loading
if (fs.existsSync(src)) {
fs.copyFileSync(src, dst);
}
}
main().catch(e => {
console.error(e);
process.exit(1);
});