-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesbuild.js
More file actions
101 lines (92 loc) · 2.61 KB
/
Copy pathesbuild.js
File metadata and controls
101 lines (92 loc) · 2.61 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
const esbuild = require("esbuild");
const fs = require("fs/promises"); // For copying assets
const path = require("path"); // For path manipulation
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}`);
if (location) {
console.error(` ${location.file}:${location.line}:${location.column}:`);
}
});
console.log('[watch] build finished');
});
},
};
// Function to copy assets
async function copyAssets() {
const assets = [
{ from: 'webview-ui/references.html', to: 'dist/references.html' },
// { from: 'webview-ui/styles.css', to: 'dist/styles.css' }, // Uncomment if styles.css is created
{ from: path.join('node_modules', '@vscode', 'codicons', 'dist', 'codicon.css'), to: path.join('dist', 'codicon.css') },
{ from: path.join('node_modules', '@vscode', 'codicons', 'dist', 'codicon.ttf'), to: path.join('dist', 'codicon.ttf') },
];
try {
await fs.mkdir('dist', { recursive: true });
console.log('[copy] Ensured dist directory exists.');
} catch (err) {
console.error('[copy] Error creating dist directory:', err);
throw err;
}
for (const asset of assets) {
try {
await fs.copyFile(asset.from, asset.to);
console.log(`[copy] ${path.basename(asset.from)} -> ${asset.to}`);
} catch (err) {
// Handle case where source file might not exist yet (e.g., index.html, styles.css)
if (err.code === 'ENOENT') {
console.warn(`[copy] Source file not found, skipping: ${asset.from}`);
} else {
console.error(`[copy] Error copying ${asset.from}:`, err);
throw err; // Re-throw other errors
}
}
}
}
async function main() {
// Copy assets first
try {
await copyAssets();
} catch (err) {
process.exit(1); // Exit if asset copying fails critically
}
const ctx = await esbuild.context({
entryPoints: [
'src/extension.ts',
'src/ReferencesWebview.ts'
],
bundle: true,
format: 'cjs',
minify: production,
sourcemap: !production,
sourcesContent: false,
platform: 'node',
outdir: 'dist',
external: ['vscode'],
logLevel: 'silent',
plugins: [
/* add to the end of plugins array */
esbuildProblemMatcherPlugin,
],
});
if (watch) {
await ctx.watch();
} else {
await ctx.rebuild();
await ctx.dispose();
}
}
main().catch(e => {
console.error(e);
process.exit(1);
});