From 2289ca5e55e6f7fcfad8c7d6dafb8a6d3ed0b258 Mon Sep 17 00:00:00 2001
From: Andy Pack <andy@sarsoo.xyz>
Date: Sat, 15 Feb 2025 20:50:59 +0000
Subject: [PATCH] adding npm publish and crates publishing

---
 .gitea/workflows/build.yml  |  2 +-
 .github/workflows/build.yml | 65 ++++++++++++++++++++++++++++++++++++-
 finlib/Cargo.toml           |  1 -
 3 files changed, 65 insertions(+), 3 deletions(-)

diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml
index 990bf07..d0364c9 100644
--- a/.gitea/workflows/build.yml
+++ b/.gitea/workflows/build.yml
@@ -157,4 +157,4 @@ jobs:
         uses: actions-rs/cargo@v1
         with:
           command: publish
-          args: --package finlib
\ No newline at end of file
+          args: --package finlib --registry sargit
\ No newline at end of file
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 7d7017b..d967f42 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -129,4 +129,67 @@ jobs:
     steps:
       - name: Deploy to GitHub Pages
         id: deployment
-        uses: actions/deploy-pages@v4
\ No newline at end of file
+        uses: actions/deploy-pages@v4
+
+  publishNPM:
+    name: Publish NPM
+    runs-on: ubuntu-latest
+    needs: [ buildWASM ] # for ignoring bad builds
+    if: github.event_name == 'push' && github.ref == 'refs/heads/master'
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v4
+
+      - name: Install Rust
+        uses: actions-rs/toolchain@v1
+        with:
+          toolchain: stable
+
+      - name: Install wasm-pack
+        run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
+
+      - name: Build Rust for WASM
+        working-directory: ./finlib-wasm
+        run: wasm-pack build --release
+
+      - name: Change Package Name
+        working-directory: ./finlib-wasm
+        run: ./rename-pkg.sh
+
+      - name: Install Node
+        uses: actions/setup-node@v2
+        with:
+          node-version: 22
+
+      - name: Publish
+        working-directory: ./finlib-wasm/pkg
+        run: npm publish
+        env:
+          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
+
+  publishRustLib:
+    runs-on: ubuntu-latest
+    name: Publish Rust Library
+    needs: [ build ] # for ignoring bad builds
+    if: github.event_name == 'push' && github.ref == 'refs/heads/master'
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v4
+
+      - name: Install Rust
+        uses: actions-rs/toolchain@v1
+        with:
+          toolchain: stable
+
+      - name: Add Crates.io Credentials
+        run: |
+          cat <<EOF > ~/.cargo/credentials.toml
+          [registry]
+          token = "Bearer ${{ secrets.CRATES_TOKEN }}"
+          EOF
+
+      - name: Cargo Publish
+        uses: actions-rs/cargo@v1
+        with:
+          command: publish
+          args: --package finlib
\ No newline at end of file
diff --git a/finlib/Cargo.toml b/finlib/Cargo.toml
index 3fc91b6..ff492cd 100644
--- a/finlib/Cargo.toml
+++ b/finlib/Cargo.toml
@@ -1,6 +1,5 @@
 [package]
 name = "finlib"
-publish = ["sargit"]
 version.workspace = true
 authors.workspace = true
 edition.workspace = true