Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

w3sper: Add a build step #2619

Open
wants to merge 2 commits into
base: w3sper-js
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 --allow-env 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.

65 changes: 65 additions & 0 deletions w3sper.js/scripts/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { build, stop } from "https://deno.land/x/esbuild/mod.js";

const outputDir = "./dist";

const dirs = [
{ source: "./src/mod.js", dest: `${outputDir}/w3sper.js` },
{ source: "./src/network/mod.js", dest: `${outputDir}/network.js` },
{
source: "./src/protocol-driver/mod.js",
dest: `${outputDir}/protocol-driver.js`,
},
];

try {
if (Deno.statSync(outputDir).isDirectory) {
Deno.removeSync(outputDir, { recursive: true });
}
Deno.mkdirSync(outputDir, { recursive: true });
} catch (err) {
console.error("Error setting up the output directory:", err);
}

for (const dir of dirs) {
try {
const result = await build({
entryPoints: [dir.source],
outfile: dir.dest,
bundle: false,
minify: false,
format: "esm",
sourcemap: true,
platform: "node",
});

console.log(`${dir.source} has been built:`, result);
} catch (err) {
console.error(`Build failed for ${dir.source}:`, err);
}
}

stop();

const packageJsonContent = {
name: "@dusk-network/w3sper.js",
version: "0.0.1",
main: "w3sper.js",
type: "module",
exports: {
".": "./w3sper.js",
"./network": "./network.js",
"./protocol-driver": "./protocol-driver.js",
},
};

const packageJsonPath = `${outputDir}/package.json`;

try {
Deno.writeTextFileSync(
packageJsonPath,
JSON.stringify(packageJsonContent, null, 2)
);
console.log("package.json has been generated:", packageJsonContent);
} catch (err) {
console.error("Failed to write package.json:", err);
}
Loading