-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve README documentation for electron & web bindings
- Loading branch information
1 parent
fe36a18
commit 6a56633
Showing
4 changed files
with
108 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -337,6 +337,7 @@ libxkbcommon | |
libxss | ||
linkcheck | ||
linuxsys | ||
liveplay | ||
Ljava | ||
llabel | ||
localdb | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,42 @@ | ||
# libparsec-electron-bindings | ||
|
||
## Build | ||
|
||
tl;dr: `../../make.py er` | ||
|
||
First run (to install dependencies) | ||
|
||
```shell | ||
../../make.py ei # ei is an alias for electron-dev-install | ||
``` | ||
|
||
Subsequent runs | ||
|
||
```shell | ||
../../make.py er # er is an alias for electron-dev-rebuild | ||
``` | ||
|
||
Basically `make.py` wraps the following commands: | ||
|
||
```shell | ||
npm install | ||
# (re)generate index.node | ||
npm run build:dev | ||
# Or for release | ||
npm run build:release | ||
``` | ||
|
||
## Testing (the simple way) | ||
|
||
Start node shell | ||
|
||
```shell | ||
node | ||
``` | ||
|
||
Then import libparsec package and you're good ! | ||
|
||
```javascript | ||
libparsec = require("./bindings/electron/dist/libparsec"); | ||
await libparsec.listAvailableDevices("/foo") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,50 @@ | ||
<div align="center"> | ||
# libparsec-electron-bindings | ||
|
||
<h1><code>wasm-pack-template</code></h1> | ||
Remember to have [`wasm-pack`](../../docs/development/README.md#base-requirement) installed ! | ||
|
||
<strong>A template for kick starting a Rust and WebAssembly project using <a href="https://github.com/rustwasm/wasm-pack">wasm-pack</a>.</strong> | ||
## Build | ||
|
||
<p> | ||
<a href="https://travis-ci.org/rustwasm/wasm-pack-template"><img src="https://img.shields.io/travis/rustwasm/wasm-pack-template.svg?style=flat-square" alt="Build Status" /></a> | ||
</p> | ||
tl;dr: `../../make.py wr` | ||
|
||
<h3> | ||
<a href="https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html">Tutorial</a> | ||
<span> | </span> | ||
<a href="https://discordapp.com/channels/442252698964721669/443151097398296587">Chat</a> | ||
</h3> | ||
First run (to install dependencies) | ||
|
||
<sub>Built with 🦀🕸 by <a href="https://rustwasm.github.io/">The Rust and WebAssembly Working Group</a></sub> | ||
</div> | ||
|
||
## About | ||
```shell | ||
../../make.py wi # wi is an alias for web-dev-install | ||
``` | ||
|
||
[**📚 Read this template tutorial! 📚**][template-docs] | ||
Subsequent runs | ||
|
||
This template is designed for compiling Rust libraries into WebAssembly and | ||
publishing the resulting package to NPM. | ||
```shell | ||
../../make.py wr # wr is an alias for web-dev-rebuild | ||
``` | ||
|
||
Be sure to check out [other `wasm-pack` tutorials online][tutorials] for other | ||
templates and usages of `wasm-pack`. | ||
Basically `make.py` wraps the following commands: | ||
|
||
[tutorials]: https://rustwasm.github.io/docs/wasm-pack/tutorials/index.html | ||
[template-docs]: https://rustwasm.github.io/docs/wasm-pack/tutorials/npm-browser-packages/index.html | ||
```shell | ||
npm install | ||
# (re)generate index.node | ||
npm run build:dev | ||
# Or for release | ||
npm run build:release | ||
``` | ||
|
||
## 🚴 Usage | ||
The internal build command itself relies on [`wasm-pack`](https://github.com/rustwasm/wasm-pack). | ||
|
||
### 🐑 Use `cargo generate` to Clone this Template | ||
## Interactive testing | ||
|
||
[Learn more about `cargo generate` here.](https://github.com/ashleygwilliams/cargo-generate) | ||
To easily play with the bindings: | ||
|
||
``` | ||
cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project | ||
cd my-project | ||
```shell | ||
python ./scripts/liveplay.py | ||
``` | ||
|
||
### 🛠️ Build with `wasm-pack build` | ||
This starts a server exposing a web page with the bindings, from there you | ||
can open your browser console and start playing with `libparsec`. | ||
|
||
``` | ||
wasm-pack build | ||
``` | ||
## Testing | ||
|
||
### 🔬 Test in Headless Browsers with `wasm-pack test` | ||
There is not much tests for now, but you can use them with: | ||
|
||
``` | ||
```shell | ||
wasm-pack test --headless --firefox | ||
``` | ||
|
||
### 🎁 Publish to NPM with `wasm-pack publish` | ||
|
||
``` | ||
wasm-pack publish | ||
``` | ||
|
||
## 🔋 Batteries Included | ||
|
||
* [`wasm-bindgen`](https://github.com/rustwasm/wasm-bindgen) for communicating | ||
between WebAssembly and JavaScript. | ||
* [`console_error_panic_hook`](https://github.com/rustwasm/console_error_panic_hook) | ||
for logging panic messages to the developer console. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#! /usr/bin/env python | ||
# Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS | ||
|
||
|
||
import sys | ||
import subprocess | ||
from pathlib import Path | ||
|
||
|
||
BASEDIR = Path(__file__).parent | ||
PKG_DIR = BASEDIR / "../pkg" | ||
|
||
|
||
INDEX_HTML_SRC = """<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/> | ||
</head> | ||
<body> | ||
<script src="libparsec_bindings_web.js" type="module"></script> | ||
<script type="module"> | ||
console.log("loading libparsec..."); | ||
import initModule, * as libparsec from './libparsec_bindings_web.js'; | ||
await initModule(); | ||
libparsec.initLogger(); | ||
window.libparsec = libparsec; | ||
console.log("libparsec is loaded !"); | ||
</script> | ||
<p>Open you browser console and start with e.g. | ||
<code>libparsec.listAvailableDevices("/foo")</code></p> | ||
</body> | ||
</html> | ||
""" | ||
|
||
|
||
if __name__ == "__main__": | ||
if not PKG_DIR.exists(): | ||
raise SystemExit( | ||
f"{PKG_DIR} doesn't exist, you should build the bindings with `make.py` first !" | ||
) | ||
print(f"Creating {PKG_DIR}/index.html...") | ||
(PKG_DIR / "index.html").write_text(INDEX_HTML_SRC) | ||
|
||
subprocess.check_call([sys.executable, "-m", "http.server", "8000"], cwd=PKG_DIR) |