-
Notifications
You must be signed in to change notification settings - Fork 501
Expand file tree
/
Copy pathesbuild.mjs
More file actions
207 lines (188 loc) · 5.81 KB
/
Copy pathesbuild.mjs
File metadata and controls
207 lines (188 loc) · 5.81 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as esbuild from 'esbuild';
import * as fs from 'fs';
import * as path from 'path';
const isWatch = process.argv.includes('--watch');
// Stamp the build time into the bundle so the UI can show which build is running.
const define = { __BUILD_TIME__: JSON.stringify(new Date().toISOString()) };
// Bundle the extension host
const extensionBuild = esbuild.build({
entryPoints: ['src/extension.ts'],
bundle: true,
platform: 'node',
target: 'es2022',
format: 'cjs',
outfile: 'dist/extension.js',
sourcemap: true,
external: ['vscode'],
define,
});
// Bundle the warm-up worker (runs off the extension host thread)
const workerBuild = esbuild.build({
entryPoints: ['src/core/warm-up-worker.ts'],
bundle: true,
platform: 'node',
target: 'es2022',
format: 'cjs',
outfile: 'dist/warm-up-worker.js',
sourcemap: true,
external: ['vscode'],
});
// Bundle the parse worker (runs the full parse pipeline off the extension host thread)
const parseWorkerBuild = esbuild.build({
entryPoints: ['src/core/parse-worker.ts'],
bundle: true,
platform: 'node',
target: 'es2022',
format: 'cjs',
outfile: 'dist/parse-worker.js',
sourcemap: true,
external: ['vscode'],
});
// Bundle the cache write worker (writes cache data to disk off the main thread)
const cacheWriteWorkerBuild = esbuild.build({
entryPoints: ['src/core/cache-write-worker.ts'],
bundle: true,
platform: 'node',
target: 'es2022',
format: 'cjs',
outfile: 'dist/cache-write-worker.js',
sourcemap: true,
external: ['vscode'],
});
// Bundle the canvas host (serves the webview as a Copilot app canvas; no vscode)
const canvasHostBuild = esbuild.build({
entryPoints: ['src/canvas/host.ts'],
bundle: true,
platform: 'node',
target: 'es2022',
format: 'cjs',
outfile: 'dist/canvas-host.cjs',
sourcemap: true,
external: ['vscode'],
});
// Bundle the webview script
const webviewBuild = esbuild.build({
entryPoints: ['src/webview/app.ts'],
bundle: true,
platform: 'browser',
target: 'es2022',
format: 'iife',
outfile: 'dist/webview/app.js',
sourcemap: true,
});
await Promise.all([extensionBuild, workerBuild, parseWorkerBuild, cacheWriteWorkerBuild, canvasHostBuild, webviewBuild]);
// Copy static webview assets
const webviewDist = 'dist/webview';
fs.mkdirSync(webviewDist, { recursive: true });
// Copy rule markdown files to dist/rules/
const rulesSrc = 'src/core/rules';
const rulesDist = 'dist/rules';
fs.mkdirSync(rulesDist, { recursive: true });
if (fs.existsSync(rulesSrc)) {
for (const file of fs.readdirSync(rulesSrc).filter(f => f.endsWith('.md'))) {
fs.copyFileSync(path.join(rulesSrc, file), path.join(rulesDist, file));
}
}
// Copy metric definition files to dist/metrics/
const metricsSrc = 'src/core/metrics';
const metricsDist = 'dist/metrics';
fs.mkdirSync(metricsDist, { recursive: true });
if (fs.existsSync(metricsSrc)) {
for (const file of fs.readdirSync(metricsSrc).filter(f => f.endsWith('.metric.md'))) {
fs.copyFileSync(path.join(metricsSrc, file), path.join(metricsDist, file));
}
}
const cssSources = [
'src/webview/styles.css',
'src/webview/styles-pages.css',
'src/webview/styles-skills.css',
'src/webview/styles-learning.css',
];
function bundleCss() {
const bundledCss = cssSources
.map(source => fs.readFileSync(source, 'utf-8').trimEnd())
.join('\n\n');
fs.writeFileSync(path.join(webviewDist, 'styles.css'), `${bundledCss}\n`);
}
bundleCss();
// Copy sidebar CSS separately (sidebar is its own webview)
fs.copyFileSync('src/webview/styles-sidebar.css', path.join(webviewDist, 'sidebar.css'));
console.log('Build complete.');
if (isWatch) {
const ctx1 = await esbuild.context({
entryPoints: ['src/extension.ts'],
bundle: true,
platform: 'node',
target: 'es2022',
format: 'cjs',
outfile: 'dist/extension.js',
sourcemap: true,
external: ['vscode'],
define,
});
const ctx2 = await esbuild.context({
entryPoints: ['src/core/warm-up-worker.ts'],
bundle: true,
platform: 'node',
target: 'es2022',
format: 'cjs',
outfile: 'dist/warm-up-worker.js',
sourcemap: true,
external: ['vscode'],
});
const ctx3 = await esbuild.context({
entryPoints: ['src/core/parse-worker.ts'],
bundle: true,
platform: 'node',
target: 'es2022',
format: 'cjs',
outfile: 'dist/parse-worker.js',
sourcemap: true,
external: ['vscode'],
});
const ctx5 = await esbuild.context({
entryPoints: ['src/core/cache-write-worker.ts'],
bundle: true,
platform: 'node',
target: 'es2022',
format: 'cjs',
outfile: 'dist/cache-write-worker.js',
sourcemap: true,
external: ['vscode'],
});
const ctxCanvas = await esbuild.context({
entryPoints: ['src/canvas/host.ts'],
bundle: true,
platform: 'node',
target: 'es2022',
format: 'cjs',
outfile: 'dist/canvas-host.cjs',
sourcemap: true,
external: ['vscode'],
});
const ctx4 = await esbuild.context({
entryPoints: ['src/webview/app.ts'],
bundle: true,
platform: 'browser',
target: 'es2022',
format: 'iife',
outfile: 'dist/webview/app.js',
sourcemap: true,
});
await Promise.all([ctx1.watch(), ctx2.watch(), ctx3.watch(), ctx4.watch(), ctx5.watch(), ctxCanvas.watch()]);
for (const source of cssSources) {
fs.watch(source, () => {
try {
bundleCss();
console.log(`CSS rebuilt (${source} changed)`);
} catch (err) {
console.error('CSS rebuild failed:', err);
}
});
}
console.log('Watching for changes...');
}