|
1 | | -const { build } = require("esbuild"); |
2 | | -const fs = require("fs"); |
3 | | -const path = require("path"); |
4 | | -const glob = require("glob"); |
| 1 | +import { context, build } from "esbuild"; |
| 2 | +import { copyFileSync, mkdirSync } from "fs"; |
| 3 | +import { sync } from "glob"; |
| 4 | +import { join, basename } from "path"; |
5 | 5 |
|
6 | 6 | function copyFiles(srcPattern, destDir) { |
7 | | - glob.sync(srcPattern).forEach((file) => { |
8 | | - const destFile = path.join(destDir, path.basename(file)); |
9 | | - fs.copyFileSync(file, destFile); |
| 7 | + sync(srcPattern).forEach((file) => { |
| 8 | + const destFile = join(destDir, basename(file)); |
| 9 | + copyFileSync(file, destFile); |
10 | 10 | }); |
11 | 11 | } |
12 | 12 |
|
13 | 13 | const minify = process.argv.includes("--minify"); |
14 | 14 | const sourcemap = process.argv.includes("--sourcemap"); |
15 | 15 | const keepNames = process.argv.includes("--keep-names"); |
| 16 | +const watch = process.argv.includes("--watch"); |
16 | 17 |
|
17 | 18 | const baseConfig = { |
18 | 19 | minify, |
@@ -50,24 +51,26 @@ const webviewConfig = { |
50 | 51 |
|
51 | 52 | (async () => { |
52 | 53 | try { |
53 | | - await build(extensionConfig); |
54 | | - console.log("extension build complete"); |
55 | | - await build(serverConfig); |
56 | | - console.log("server build complete"); |
57 | | - await build(webviewConfig); |
| 54 | + mkdirSync("./out", { recursive: true }); |
58 | 55 | copyFiles("src/webview/styles/*.css", "./out"); |
59 | | - copyFiles("node_modules/ag-grid-community/styles/ag-grid.min.css", "./out"); |
60 | | - copyFiles( |
61 | | - "node_modules/ag-grid-community/styles/ag-theme-alpine.min.css", |
62 | | - "./out", |
63 | | - ); |
64 | | - copyFiles( |
65 | | - "node_modules/ag-grid-community/dist/ag-grid-community.min.js", |
66 | | - "./out", |
67 | | - ); |
68 | | - console.log("build complete"); |
| 56 | + |
| 57 | + if (watch) { |
| 58 | + console.log("esbuild:started"); |
| 59 | + const contexts = await Promise.all([ |
| 60 | + context(serverConfig), |
| 61 | + context(webviewConfig), |
| 62 | + context(extensionConfig), |
| 63 | + ]); |
| 64 | + await Promise.all(contexts.map((ctx) => ctx.rebuild())); |
| 65 | + contexts.forEach((ctx) => ctx.watch({ delay: 500 })); |
| 66 | + console.log("esbuild:watching"); |
| 67 | + } else { |
| 68 | + await build(serverConfig); |
| 69 | + await build(webviewConfig); |
| 70 | + await build(extensionConfig); |
| 71 | + } |
69 | 72 | } catch (err) { |
70 | | - process.stderr.write(err.stderr); |
| 73 | + console.error(err); |
71 | 74 | process.exit(1); |
72 | 75 | } |
73 | 76 | })(); |
0 commit comments