Skip to content

Commit

Permalink
feat: add build script
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Mar 21, 2024
1 parent 0a686f1 commit fcf73dd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,28 @@ Parse a `BucketEntry` framed stream from a bucket file:
stellar-xdr decode --type BucketEntry --input stream-framed --output json-formatted bucket.xdr
```

## Wasm pack

`wasm-pack.sh` will use [`wasm-pack`](https://rustwasm.github.io/wasm-pack/installer/) to build a npm package and use [yalc](https://github.com/wclr/yalc) pubilsh it locally. It uses the following environment variables:
- `PROFILE` - default `dev`
- `TARGETS` - default `bundler nodejs web no-modules`

After running the script you can install the package corresponding target with yalc:

```
yalc add stellar-xdr-wasm-web
yalc link stellar-xdr-wasm-web
```

Then you can import package as normal

```ts
import * as xdr from "stellar-xdr-wasm-web";
```

#### cargo watch for changes

```
cargo watch -s "TARGETS=web ./wasm-pack.sh"
```
License: Apache-2.0
1 change: 0 additions & 1 deletion src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub enum Error {

use schemars::{
gen::SchemaSettings,
schema::SchemaObject,
visit::{self, Visitor},
};
use std::str::FromStr;
Expand Down
23 changes: 23 additions & 0 deletions wasm-pack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

set -e
alias npx='npx -y'
(
cd crates/stellar-xdr-wasm
# iterates over all targets and builds each on in it's on folder
for TARGET in ${TARGETS:-bundler nodejs web no-modules} ; do
OUT_DIR=pkg/$TARGET
npx wasm-pack build --"${PROFILE:-dev}" \
--target "$TARGET" \
--out-dir "$OUT_DIR" \
--out-name "stellar-xdr-wasm-$TARGET"
(
cd "$OUT_DIR";
# shellcheck disable=SC2016
npx node-jq --arg TARGET "stellar-xdr-wasm-$TARGET" \
'.name = $TARGET' package.json > tmp.json;
mv tmp.json package.json;
npx yalc publish;
)
done
)

0 comments on commit fcf73dd

Please sign in to comment.