From fe02a7be90b73842ff8f36e9c0351ff4b6c570d6 Mon Sep 17 00:00:00 2001 From: Norton Andreev Date: Mon, 7 Oct 2024 15:46:12 +0300 Subject: [PATCH] w3sper: Add a build step Resolves #2612 --- w3sper.js/deno.json | 7 +++--- w3sper.js/deno.lock | 7 ++++++ w3sper.js/scripts/build.ts | 45 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 w3sper.js/scripts/build.ts diff --git a/w3sper.js/deno.json b/w3sper.js/deno.json index a07a0b7ac6..d79c939417 100644 --- a/w3sper.js/deno.json +++ b/w3sper.js/deno.json @@ -1,5 +1,6 @@ { - "tasks": { - "test": "deno test --allow-read --allow-net --allow-write --allow-run --trace-leaks" - } + "tasks": { + "build": "deno run --allow-write --allow-read scripts/build.ts", + "test": "deno test --allow-read --allow-net --allow-write --allow-run --trace-leaks" + } } diff --git a/w3sper.js/deno.lock b/w3sper.js/deno.lock index 2c1b275bfa..3a6064767d 100644 --- a/w3sper.js/deno.lock +++ b/w3sper.js/deno.lock @@ -1,5 +1,8 @@ { "version": "3", + "redirects": { + "https://deno.land/x/esbuild/mod.js": "https://deno.land/x/esbuild@v0.24.0/mod.js" + }, "remote": { "http://rawcdn.githack.com/mio-mini/test-harness/0.1.0/mod.js": "b3a4ef318038bb186610b894c13f417850190ed926caf5e72ae1733ef0879b6c", "https://deno.land/std@0.136.0/_util/assert.ts": "e94f2eb37cebd7f199952e242c77654e43333c1ac4c5c700e929ea3aa5489f74", @@ -40,6 +43,10 @@ "https://deno.land/std@0.210.0/assert/unimplemented.ts": "4e3e504792c87c485dbc5f4020489d8806ef697741403af2008dfa7b5a4711e8", "https://deno.land/std@0.210.0/assert/unreachable.ts": "1af8c99421cc5fb7332454b2b9eca074a4e394895a180bc837750dedcca75338", "https://deno.land/std@0.210.0/fmt/colors.ts": "2685c524bef9b16b3059a417daf6860c754eb755e19e812762ef5dff62f24481", + "https://deno.land/x/denoflate@1.2.1/mod.ts": "f5628e44b80b3d80ed525afa2ba0f12408e3849db817d47a883b801f9ce69dd6", + "https://deno.land/x/denoflate@1.2.1/pkg/denoflate.js": "b9f9ad9457d3f12f28b1fb35c555f57443427f74decb403113d67364e4f2caf4", + "https://deno.land/x/denoflate@1.2.1/pkg/denoflate_bg.wasm.js": "d581956245407a2115a3d7e8d85a9641c032940a8e810acbd59ca86afd34d44d", + "https://deno.land/x/esbuild@v0.24.0/mod.js": "15b51f08198c373555700a695b6c6630a86f2c254938e81be7711eb6d4edc74e", "https://rawcdn.githack.com/dusk-network/exu/v0.1.2/src/mod.js": "ce6fcb436bf24ed79bf187ccac9ea6f59ee824afa6c90b2df45af47be52d78b6", "https://rawcdn.githack.com/dusk-network/exu/v0.1.2/src/proxies.js": "a38eeb3735a4fc1e4be1f57837e87f8c28398efb89c62e067cdbb0e196d7e4ea", "https://rawcdn.githack.com/dusk-network/exu/v0.1.2/src/sandbox/mod.js": "a7afe21ef1bf1ef9f69878eea25998eabb412726bd0077ba473a633085ac064a", diff --git a/w3sper.js/scripts/build.ts b/w3sper.js/scripts/build.ts new file mode 100644 index 0000000000..915734ea5f --- /dev/null +++ b/w3sper.js/scripts/build.ts @@ -0,0 +1,45 @@ +import { build, stop } from "https://deno.land/x/esbuild/mod.js"; + +const entryPoint = "./src/mod.js"; + +const outputDir = "./dist"; +const outputFile = `${outputDir}/w3sper.js`; + +if (Deno.statSync(outputDir).isDirectory) { + Deno.removeSync(outputDir, { recursive: true }); +} + +Deno.mkdirSync(outputDir, { recursive: true }); + +// Build the SDK using esbuild +const result = await build({ + entryPoints: [entryPoint], + outfile: outputFile, + bundle: true, + minify: false, + format: "esm", + sourcemap: true, +}); + +console.log("w3sper SDK has been built:", result); + +stop(); + +const packageJsonContent = { + name: "@dusk-network/w3sper.js", + version: "0.0.1", + main: "w3sper.js", + type: "module", + exports: { + ".": "./w3sper.js", + }, +}; + +const packageJsonPath = "./dist/package.json"; + +Deno.writeTextFileSync( + packageJsonPath, + JSON.stringify(packageJsonContent, null, 2) +); + +console.log("package.json has been generated:", packageJsonContent);