diff --git a/gui/esbuild.js b/gui/esbuild.js index e647de2b..ae41211b 100644 --- a/gui/esbuild.js +++ b/gui/esbuild.js @@ -1,8 +1,10 @@ -import { build } from 'esbuild'; +import { build, context } from 'esbuild'; import { join } from 'path'; import alias from 'esbuild-plugin-alias'; +import { copy } from 'esbuild-plugin-copy'; -const debug = process.env['DEBUG'] === 'TRUE' +const debug = process.env['DEBUG'] === 'TRUE'; +const watch = process.env['WATCH'] === 'TRUE'; const root = process.cwd(); const plugins = []; @@ -14,7 +16,7 @@ if (debug) { })); } -build({ +const config = { bundle: true, define: { global: 'window', @@ -27,4 +29,40 @@ build({ platform: 'browser', plugins, sourcemap: true, -}).catch(() => process.exit(1)); +}; + +if(watch) { + const copyArray = (files) => files.map(file => + copy({ + resolveFrom: 'cwd', + assets: { + from: [file], + to: ['out/'], + }, + }) + ); + + const ctx = await context({ + ...config, + entryPoints: [ + join(root, 'src/main.tsx'), + ], + plugins: [ + ...plugins, + ...copyArray(['src/index.html', 'examples/config.json']), + ], + banner: { + js: `new EventSource('/esbuild').addEventListener('change', () => location.reload());`, + }, + }); + + await ctx.watch(); + + const { host, port } = await ctx.serve({ + servedir: 'out/', + }); + + console.log(`Serving on http://${host}:${port}`); +} else { + build(config).catch(() => process.exit(1)); +} \ No newline at end of file diff --git a/gui/package.json b/gui/package.json index 960ae092..eeddedb9 100644 --- a/gui/package.json +++ b/gui/package.json @@ -40,6 +40,7 @@ "chai-as-promised": "^7.1.1", "esbuild": "^0.17.0", "esbuild-plugin-alias": "^0.2.1", + "esbuild-plugin-copy": "^2.0.2", "eslint": "^8.31.0", "eslint-plugin-chai": "^0.0.1", "eslint-plugin-chai-expect": "^3.0.0", diff --git a/gui/yarn.lock b/gui/yarn.lock index 97ce6285..ebd8ec9c 100644 --- a/gui/yarn.lock +++ b/gui/yarn.lock @@ -990,7 +990,7 @@ chalk@^2.0.0: escape-string-regexp "^1.0.5" supports-color "^5.3.0" -chalk@^4.0.0, chalk@^4.1.0: +chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== @@ -1299,6 +1299,15 @@ esbuild-plugin-alias@^0.2.1: resolved "https://registry.yarnpkg.com/esbuild-plugin-alias/-/esbuild-plugin-alias-0.2.1.tgz#45a86cb941e20e7c2bc68a2bea53562172494fcb" integrity sha512-jyfL/pwPqaFXyKnj8lP8iLk6Z0m099uXR45aSN8Av1XD4vhvQutxxPzgA2bTcAwQpa1zCXDcWOlhFgyP3GKqhQ== +esbuild-plugin-copy@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/esbuild-plugin-copy/-/esbuild-plugin-copy-2.0.2.tgz#3c215c421b35a4e48a3b3c5362e75a95602d9c4f" + integrity sha512-HlDgkHXagBCwaoB8tlQFeH08/i5a2ey6Pc26annV1YcG5CkAHzzRzmCwp3wdi5KHI//HVUgipS+Zsy2tQmn9gQ== + dependencies: + chalk "^4.1.2" + fs-extra "^10.0.1" + globby "^11.0.3" + esbuild@^0.17.0: version "0.17.8" resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.17.8.tgz#f7f799abc7cdce3f0f2e3e0c01f120d4d55193b4" @@ -1633,6 +1642,15 @@ foreground-child@^2.0.0: cross-spawn "^7.0.0" signal-exit "^3.0.2" +fs-extra@^10.0.1: + version "10.1.0" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.1.0.tgz#02873cfbc4084dde127eaa5f9905eef2325d1abf" + integrity sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ== + dependencies: + graceful-fs "^4.2.0" + jsonfile "^6.0.1" + universalify "^2.0.0" + fs.realpath@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" @@ -1742,7 +1760,7 @@ globalthis@^1.0.3: dependencies: define-properties "^1.1.3" -globby@^11.1.0: +globby@^11.0.3, globby@^11.1.0: version "11.1.0" resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b" integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g== @@ -1761,6 +1779,11 @@ gopd@^1.0.1: dependencies: get-intrinsic "^1.1.3" +graceful-fs@^4.1.6, graceful-fs@^4.2.0: + version "4.2.10" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c" + integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA== + grapheme-splitter@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/grapheme-splitter/-/grapheme-splitter-1.0.4.tgz#9cf3a665c6247479896834af35cf1dbb4400767e" @@ -2118,6 +2141,15 @@ json5@^1.0.1: dependencies: minimist "^1.2.0" +jsonfile@^6.0.1: + version "6.1.0" + resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-6.1.0.tgz#bc55b2634793c679ec6403094eb13698a6ec0aae" + integrity sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ== + dependencies: + universalify "^2.0.0" + optionalDependencies: + graceful-fs "^4.1.6" + just-extend@^4.0.2: version "4.2.1" resolved "https://registry.yarnpkg.com/just-extend/-/just-extend-4.2.1.tgz#ef5e589afb61e5d66b24eca749409a8939a8c744" @@ -3029,6 +3061,11 @@ unbox-primitive@^1.0.2: has-symbols "^1.0.3" which-boxed-primitive "^1.0.2" +universalify@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717" + integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ== + unload@2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/unload/-/unload-2.2.0.tgz#ccc88fdcad345faa06a92039ec0f80b488880ef7"