Skip to content

Commit

Permalink
w3sper: Add a build step
Browse files Browse the repository at this point in the history
Resolves #2612
  • Loading branch information
nortonandreev committed Oct 9, 2024
1 parent 333889b commit fe02a7b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
7 changes: 4 additions & 3 deletions w3sper.js/deno.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
7 changes: 7 additions & 0 deletions w3sper.js/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions w3sper.js/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit fe02a7b

Please sign in to comment.