default: build

build-webview:
    cd ../ui-shares && just build-all
    cd ./webview && bun install
    cd ./webview && bun run build
    @echo "Webview built successfully"

build-cli:
    @echo "Building CLI..."
    cd ../cli && just build

# Copies all the binaries to the bin directory
copy-over-binaries:
    @echo "Copy builds over to bin"
    mkdir -p bin
    cp ../../target/release/tangleguard bin/tangleguard-cli-aarch64-apple-darwin
    cp ../../target/x86_64-apple-darwin/release/tangleguard bin/tangleguard-cli-x86_64-apple-darwin
    cp ../../target/x86_64-unknown-linux-gnu/release/tangleguard bin/tangleguard-cli-x86_64-unknown-linux-gnu
    cp ../../target/aarch64-unknown-linux-gnu/release/tangleguard bin/tangleguard-cli-aarch64-unknown-linux-gnu
    cp ../../target/x86_64-pc-windows-gnu/release/tangleguard.exe bin/tangleguard-cli-x86_64-pc-windows-gnu.exe

# Full webview build pipeline
build: build-cli build-webview copy-over-binaries
    @echo "Copying webview build to extension..."
    rm -rf webview-dist
    mkdir -p webview-dist
    cp -r webview/build/* webview-dist/
    bun install
    bun run compile
    @echo "Webview built and copied to webview-dist/"

# Build all and release to stores
release: build
    @echo "Package extension"
    vsce package --no-dependencies --allow-missing-repository
    @echo "Publishing to Microsoft Marketplace"
    vsce publish --no-dependencies --allow-missing-repository
    @echo "Publishing to Open VSX Marketplace"
    # Hopefully soon with the --allow-missing-repository option
    # See: https://github.com/eclipse-openvsx/openvsx/issues/1735
    ovsx publish --no-dependencies
