Switch to .mts files and build typescript bindings in genbindings.sh
[ldk-java] / genbindings.sh
index 13dba4a0a5189ad88d8f8f657271823d9a7f9094..a378a1e154eaadfda05cb08ecf9a5b4a220e4394 100755 (executable)
@@ -1,15 +1,17 @@
 #!/bin/bash
 usage() {
 #!/bin/bash
 usage() {
-       echo "USAGE: path/to/ldk-c-bindings \"JNI_CFLAGS\" debug android"
+       echo "USAGE: path/to/ldk-c-bindings \"JNI_CFLAGS\" debug android web"
        echo "For JNI_CFLAGS you probably want -I/usr/lib/jvm/java-11-openjdk-amd64/include/ -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux/"
        echo "debug should either be true, false, or leaks"
        echo "debug of leaks turns on leak tracking on an optimized release bianry"
        echo "android should either be true or false"
        echo "For JNI_CFLAGS you probably want -I/usr/lib/jvm/java-11-openjdk-amd64/include/ -I/usr/lib/jvm/java-11-openjdk-amd64/include/linux/"
        echo "debug should either be true, false, or leaks"
        echo "debug of leaks turns on leak tracking on an optimized release bianry"
        echo "android should either be true or false"
+       echo "web should either be true or false"
        exit 1
 }
 [ "$1" = "" ] && usage
 [ "$3" != "true" -a "$3" != "false" -a "$3" != "leaks" ] && usage
 [ "$4" != "true" -a "$4" != "false" ] && usage
        exit 1
 }
 [ "$1" = "" ] && usage
 [ "$3" != "true" -a "$3" != "false" -a "$3" != "leaks" ] && usage
 [ "$4" != "true" -a "$4" != "false" ] && usage
+[ "$5" != "true" -a "$5" != "false" ] && usage
 
 set -x
 
 
 set -x
 
@@ -173,8 +175,12 @@ fi
 
 echo "Creating TS bindings..."
 mkdir -p ts/{enums,structs}
 
 echo "Creating TS bindings..."
 mkdir -p ts/{enums,structs}
-rm -f ts/{enums,structs}/*.ts
-./genbindings.py "./lightning.h" ts ts ts $DEBUG_ARG typescript
+rm -f ts/{enums,structs,}/*.{mjs,mts}
+if [ "$5" = "true" ]; then
+       ./genbindings.py "./lightning.h" ts ts ts $DEBUG_ARG typescript node
+else
+       ./genbindings.py "./lightning.h" ts ts ts $DEBUG_ARG typescript browser
+fi
 rm -f ts/bindings.c
 if [ "$3" = "true" ]; then
        echo "#define LDK_DEBUG_BUILD" > ts/bindings.c
 rm -f ts/bindings.c
 if [ "$3" = "true" ]; then
        echo "#define LDK_DEBUG_BUILD" > ts/bindings.c
@@ -198,3 +204,20 @@ if [ "$3" = "true" ]; then
 else
        $COMPILE -o liblightningjs_release.wasm -s -Os -I"$1"/lightning-c-bindings/include/ ts/bindings.c "$1"/lightning-c-bindings/target/wasm32-wasi/release/libldk.a $EXTRA_LINK
 fi
 else
        $COMPILE -o liblightningjs_release.wasm -s -Os -I"$1"/lightning-c-bindings/include/ ts/bindings.c "$1"/lightning-c-bindings/target/wasm32-wasi/release/libldk.a $EXTRA_LINK
 fi
+
+if [ -x "$(which tsc)" ]; then
+       cd ts
+rm -r structs # TODO: Make the human-types compile
+       if [ "$5" = "false" ]; then
+               tsc
+       else
+               tsc --types node --typeRoots .
+               cd ..
+               if [ -x "$(which node)" ]; then
+                       NODE_V="$(node --version)"
+                       if [ "${NODE_V:1:2}" -gt 14 ]; then
+                               node ts/test/
+                       fi
+               fi
+       fi
+fi