Skip to content

Commit

Permalink
Add NodeJS support
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed May 24, 2022
1 parent 10fccbc commit dee5a4b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
target/
.idea/

pkg-node/
pkg/
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "nekoton-wasm"
version = "0.1.15"
version = "0.1.16"
edition = "2021"
authors = ["Ivan Kalinin <[email protected]>"]
description = "Nekoton bindings for WASM"
Expand Down
37 changes: 37 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

set -e

# Check if jq is installed
if ! [ -x "$(command -v jq)" ]; then
echo "jq is not installed" >& 2
exit 1
fi

# Clean previous packages
if [ -d "pkg" ]; then
rm -rf pkg
fi

if [ -d "pkg-node" ]; then
rm -rf pkg-node
fi

# Build for both targets
wasm-pack build --release -t nodejs -d pkg-node
wasm-pack build --release -t web -d pkg

# Get the package name
PKG_NAME=$(jq -r .name pkg/package.json | sed 's/\-/_/g')

# Merge nodejs & browser packages
cp "pkg-node/${PKG_NAME}.js" "pkg/${PKG_NAME}_main.js"
cp "pkg-node/${PKG_NAME}.d.ts" "pkg/${PKG_NAME}_main.d.ts"

sed -i "s/__wbindgen_placeholder__/wbg/g" "pkg/${PKG_NAME}_main.js"

jq ".main = \"${PKG_NAME}_main.js\"" pkg/package.json |
jq ".browser = \"${PKG_NAME}.js\"" > pkg/temp.json
mv pkg/temp.json pkg/package.json

rm -rf pkg-node
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub fn unpack_from_cell(

#[wasm_bindgen(js_name = "extractPublicKey")]
pub fn extract_public_key(boc: &str) -> Result<String, JsValue> {
crate::utils::parse_account_stuff(boc)
parse_account_stuff(boc)
.and_then(|x| nt_abi::extract_public_key(&x).handle_error())
.map(hex::encode)
}
Expand Down

0 comments on commit dee5a4b

Please sign in to comment.