-
Notifications
You must be signed in to change notification settings - Fork 11
/
compile.ts
50 lines (44 loc) · 1.14 KB
/
compile.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
import { BuildResult, context, Plugin, PluginBuild } from "esbuild";
import { existsSync, rmSync } from "fs";
const srcPath = "src";
const distPath = "dist";
const args = process.argv.slice(2);
const isProd = process.env.NODE_ENV === "production";
const watch = args.includes("--watch");
const createLoggerPlugin = (name: string): Plugin => {
return {
name,
setup(build: PluginBuild): void {
build.onEnd((result: BuildResult) => {
if (result.errors.length) {
console.error(
`[${name}] build failed with ${result.errors.length} error(s)`,
);
} else {
console.log(`[${name}] build succeeded`);
}
});
},
};
};
if (existsSync(distPath)) {
rmSync(distPath, { recursive: true });
}
(async function () {
const ctx = await context({
entryPoints: [`${srcPath}/extension.ts`],
bundle: true,
platform: "node",
external: ["vscode"],
outfile: `${distPath}/extension.js`,
minify: isProd,
plugins: [createLoggerPlugin("extension")],
});
if (watch) {
await ctx.watch();
process.once("SIGINT", () => ctx.dispose());
} else {
await ctx.rebuild();
await ctx.dispose();
}
})().catch(() => process.exit(1));