Skip to content

Commit

Permalink
Use esbuild. Add node.js support. Update emcc. (#6)
Browse files Browse the repository at this point in the history
* Use esbuild. Add node.js support. Update emcc.

* Include typings in package. Remove outdated types

* Correct path to exported types

* Fix node.js example
  • Loading branch information
Aksem authored Apr 19, 2023
1 parent a473d9c commit 02c567b
Show file tree
Hide file tree
Showing 47 changed files with 10,268 additions and 25,220 deletions.
14 changes: 0 additions & 14 deletions .babelrc

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
__pycache__

build
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ Libavoid port for js. This port is created mostly using [WebIDL Bindings](https:

There are two versions of the library:

- **Production version** of the library is in `dist` directory
- **Release version** of the library is in `dist` directory
- **Debug version** of the library is in `examples/lib` directory

A usage example is in `examples` directory. To try it out start http server in this
directory, just opening index.html in your browser doesn't work unfortunately.

The library works in both webbrowser and node.js environments.

## Documentation

Library API Documentation is in `api_docs_build` directory, just open `index.html`
Expand All @@ -26,10 +28,13 @@ Library API Documentation is in `api_docs_build` directory, just open `index.htm

### Build commands

- `python3 ../tools/generate.py`

It will generate both production and debug versions of the library, also update documentation.
1. `python3 ../tools/generate.py`

It will generate both release and debug versions of the library, also update documentation.

2. `npm run build`

It will create a package with generated release version of the library.

### Debugging

Expand All @@ -39,7 +44,6 @@ Also, symlink to adaptagrams should be in `examples` directory to provide libavo

## TODO

- idea: docs from c++
- tests
- extend WebIDL bindings to provide the same abilities as C++ library
- host API Docs in platform such Github Pages
89 changes: 89 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const fs = require("fs");
const esbuild = require("esbuild");
const { copy } = require("esbuild-plugin-copy");

// release esm/mjs
esbuild
.build({
entryPoints: ["src/index.js"],
outdir: "dist",
outExtension: {
".js": ".mjs",
},
bundle: true,
sourcemap: true,
minify: true,
splitting: true,
format: "esm",
platform: "neutral",
external: ["module"],
plugins: [
copy({
resolveFrom: "cwd",
assets: {
from: ["./src/generated/libavoid.wasm"],
to: ["./dist", "./examples/dist"],
},
watch: true,
}),
],
})
.then(() => {
fs.copyFile("./dist/index.mjs", "./examples/dist/index.mjs", (err) => {
if (err) throw err;
});
fs.copyFile(
"./dist/index.mjs.map",
"./examples/dist/index.mjs.map",
(err) => {
if (err) throw err;
}
);
})
.catch(() => process.exit(1));

// debug esm / mjs
esbuild
.build({
entryPoints: ["examples/debug-src/index.js"],
outdir: "examples/debug-dist",
outExtension: {
".js": ".mjs",
},
bundle: true,
minify: false,
splitting: true,
format: "esm",
platform: "neutral",
external: ["module"],
plugins: [
copy({
resolveFrom: "cwd",
assets: {
from: [
"./examples/debug-src/generated/libavoid.wasm",
"./examples/debug-src/generated/libavoid.wasm.map",
],
to: ["./examples/debug-dist"],
},
watch: true,
}),
],
})
.catch(() => process.exit(1));

// release cjs
// esbuild
// .build({
// entryPoints: ['src/index.js'],
// outdir: 'dist',
// outExtension: {
// '.js': '.cjs'
// },
// bundle: true,
// sourcemap: true,
// minify: true,
// platform: 'node',
// target: ['node10.4']
// })
// .catch(() => process.exit(1));
1 change: 0 additions & 1 deletion dist/index.js

This file was deleted.

3 changes: 3 additions & 0 deletions dist/index.mjs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions dist/index.mjs.map

Large diffs are not rendered by default.

Binary file modified dist/libavoid.wasm
100755 → 100644
Binary file not shown.
6,988 changes: 0 additions & 6,988 deletions examples/_libavoid.js

This file was deleted.

Binary file removed examples/_libavoid.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion examples/_libavoid.wasm.map

This file was deleted.

1 change: 0 additions & 1 deletion examples/adaptagrams

This file was deleted.

14 changes: 10 additions & 4 deletions examples/benchmark.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import initAvoid from "./libavoid.js";
import { AvoidLib } from './dist/index.mjs';

let Avoid;

Expand Down Expand Up @@ -438,7 +438,9 @@ function route() {

/* Test 1: full router creation & routing */
async function test_1() {
Avoid = await initAvoid();
await AvoidLib.load();
Avoid = AvoidLib.getInstance();

const measurements = [];
for (let i = 0; i < 100; i++) {
const startTime = performance.now();
Expand All @@ -460,7 +462,9 @@ function moveShape(router, shape) {

/* Test 2: create router once and move one shape repeatedly */
async function test_2() {
Avoid = await initAvoid();
await AvoidLib.load();
Avoid = AvoidLib.getInstance();

const measurements = [];
const [router, shape] = prepareRouter();
for (let i = 0; i < 100; i++) {
Expand All @@ -483,7 +487,9 @@ async function test_2() {

/* Test 3: measure processing transactions without actions */
async function test_3() {
Avoid = await initAvoid();
await AvoidLib.load();
Avoid = AvoidLib.getInstance();

const measurements = [];
const [router] = prepareRouter();
for (let i = 0; i < 100; i++) {
Expand Down
Loading

0 comments on commit 02c567b

Please sign in to comment.