From: MA Beaudet Date: Thu, 4 Nov 2021 16:24:57 +0000 (+0100) Subject: feat(wasm): add wasm js generated files and basic web example X-Git-Url: https://git.beaudet.xyz/?a=commitdiff_plain;h=234fcde992552dfae0ddff36140e9326e1da08b3;p=poker-eval.git feat(wasm): add wasm js generated files and basic web example --- diff --git a/README.md b/README.md index fbeadbe..1eb65c6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,20 @@ Poker hand evaluator -This project can be built using wasm-pack.\ +This project can be built using cargo and wasm-bindgen-cli (only some functions are available for wasm).\ An example is available [here](https://poker-eval.beaudet.xyz). + +To build the web version locally, you should run + +```sh +cargo build --lib --release --target=wasm32-unknown-unknown +wasm-bindgen --target web --no-typescript --out-dir static target/wasm32-unknown-unknown/release/poker_eval.wasm +miniserve static/ # or any other webserver you use... +``` + +The released binary is light so I included it in the `static folder`. + +A deployment script is available in the `static` folder. You should use it as a post-receive git hook script on the server and set it as an executable. + Based on Kevin L. Suffecool [poker hand evaluator](http://suffe.cool/poker/evaluator.html) diff --git a/static/deploy.sh b/static/deploy.sh new file mode 100644 index 0000000..d64c987 --- /dev/null +++ b/static/deploy.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +GIT_REPO="/srv/git/poker-eval.git" +TMP_GIT_CLONE="/tmp/poker-eval" +PROD_WWW="/srv/www/poker-eval" +STAGING_WWW="/srv/www/poker-eval-staging" + +while read -r _ _ refname +do + branch=$(git rev-parse --symbolic --abbrev-ref "${refname}") + + if [ "$branch" = "main" ]; then + git clone -b main "$GIT_REPO" "$TMP_GIT_CLONE" + cp -r "$TMP_GIT_CLONE/static/." "$PROD_WWW" + cargo build --manifest-path="$TMP_GIT_CLONE/Cargo.toml" --release --target=wasm32-unknown-unknown + wasm-bindgen --target web --no-typescript --out-dir "$PROD_WWW" "$TMP_GIT_CLONE/target/wasm32-unknown-unknown/release/poker_eval.wasm" + elif [ "$branch" = "staging" ]; then + git clone -b staging "$GIT_REPO" "$TMP_GIT_CLONE" + cp -r "$TMP_GIT_CLONE/static/." "$STAGING_WWW" + cargo build --manifest-path="$TMP_GIT_CLONE/Cargo.toml" --release --target=wasm32-unknown-unknown + wasm-bindgen --target web --no-typescript --out-dir "$STAGING_WWW" "$TMP_GIT_CLONE/target/wasm32-unknown-unknown/release/poker_eval.wasm" + fi + + rm -rf "$TMP_GIT_CLONE" +done diff --git a/static/favicon.ico b/static/favicon.ico new file mode 100644 index 0000000..b8ad237 Binary files /dev/null and b/static/favicon.ico differ diff --git a/static/index.html b/static/index.html new file mode 100644 index 0000000..a9abd05 --- /dev/null +++ b/static/index.html @@ -0,0 +1,27 @@ + + + + + Poker hand evaluator + + + + + +

Poker hand evaluator

+

Based on Kevin L. Suffecool poker hand evaluator.

+

Returns the hand's equivalence value. + The evaluator orders hands from 1 to 7462. + The lower the score is, the better it is. +

+

You should pass five-hand or seven-hand poker cards.
+ A card contains one of '23456789TJQKA' followed by one of 'cdhs'. This is case-sensitive.

+ + + + +
Score:
Hand value:
+