Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tap-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@
"node": ">=20"
},
"scripts": {
"build": "tsc --project tsconfig.build.json && vite build",
"build:wasm": "./scripts/build-wasm.sh",
"build": "npm run build:wasm && tsc --project tsconfig.build.json && vite build",
"dev": "vite",
"pretest": "npm run build:wasm",
"test": "vitest --no-watch",
"test:watch": "vitest",
"test:coverage": "vitest --coverage",
Expand Down
29 changes: 29 additions & 0 deletions tap-ts/scripts/build-wasm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
set -e

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TS_DIR="$(dirname "$SCRIPT_DIR")"
WASM_DIR="$TS_DIR/../tap-wasm"

# Check if wasm-pack is installed
if ! command -v wasm-pack &> /dev/null; then
echo "Error: wasm-pack is not installed."
echo "Install with: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh"
exit 1
fi

# Build WASM
echo "Building WASM..."
cd "$WASM_DIR"
wasm-pack build --target web --out-dir pkg --release

# Copy WASM files to tap-ts/wasm/
echo "Copying WASM files to tap-ts/wasm/..."
rm -rf "$TS_DIR/wasm"
mkdir -p "$TS_DIR/wasm"
cp pkg/tap_wasm_bg.wasm "$TS_DIR/wasm/"
cp pkg/tap_wasm_bg.wasm.d.ts "$TS_DIR/wasm/" 2>/dev/null || true
cp pkg/tap_wasm.js "$TS_DIR/wasm/"
cp pkg/tap_wasm.d.ts "$TS_DIR/wasm/"

echo "WASM build complete."
35 changes: 3 additions & 32 deletions tap-ts/scripts/prepare-publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,8 @@ set -e

echo "Preparing @taprsvp/agent for publishing..."

# Build WASM if needed
if [ ! -f "../tap-wasm/pkg/tap_wasm_bg.wasm" ]; then
echo "WASM files not found. Building WASM..."

# Check if wasm-pack is installed
if ! command -v wasm-pack &> /dev/null; then
echo "Error: wasm-pack is not installed."
echo "Please install it with: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh"
exit 1
fi

cd ../tap-wasm
wasm-pack build --target web --out-dir pkg --release
cd ../tap-ts
fi

# Clean and create wasm directory
rm -rf wasm
mkdir -p wasm

# Copy WASM files
echo "Copying WASM files..."
cp ../tap-wasm/pkg/tap_wasm_bg.wasm wasm/
cp ../tap-wasm/pkg/tap_wasm_bg.wasm.d.ts wasm/ 2>/dev/null || true
cp ../tap-wasm/pkg/tap_wasm.js wasm/
cp ../tap-wasm/pkg/tap_wasm.d.ts wasm/

# Update imports in the copied files to use relative paths
echo "Updating import paths..."
sed -i.bak "s|'./tap_wasm_bg.wasm'|'./tap_wasm_bg.wasm'|g" wasm/tap_wasm.js
rm wasm/*.bak 2>/dev/null || true
# Build WASM and copy files
npm run build:wasm

# Build TypeScript
echo "Building TypeScript..."
Expand All @@ -43,4 +14,4 @@ echo "Package ready for publishing!"
echo "Files to be included:"
ls -la wasm/
echo ""
echo "To publish, run: npm publish"
echo "To publish, run: npm publish"