From 349b0c14a6d86cda57115a0de266f7c30e494f27 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 20 Mar 2024 20:38:13 -0400 Subject: [PATCH] feat: add build script --- README.md | 17 +++++++++++++++++ src/schema.rs | 1 - wasm-pack.sh | 23 +++++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100755 wasm-pack.sh diff --git a/README.md b/README.md index 5ec42dc6..2e694c99 100644 --- a/README.md +++ b/README.md @@ -87,4 +87,21 @@ 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 with yalc: + +``` +yalc add stellar-xdr-wasm-web +yalc link stellar-xdr-wasm-web +``` +#### cargo watch for changes + +``` +cargo watch -s "TARGETS=web ./wasm-pack.sh" +``` License: Apache-2.0 diff --git a/src/schema.rs b/src/schema.rs index d153eba3..7afccf39 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -8,7 +8,6 @@ pub enum Error { use schemars::{ gen::SchemaSettings, - schema::SchemaObject, visit::{self, Visitor}, }; use std::str::FromStr; diff --git a/wasm-pack.sh b/wasm-pack.sh new file mode 100755 index 00000000..90ad545f --- /dev/null +++ b/wasm-pack.sh @@ -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 +)