From 0379a55b189e8df4180ea7bf29e36fec65729595 Mon Sep 17 00:00:00 2001 From: unityaisolutions Date: Fri, 26 Sep 2025 12:46:57 +0000 Subject: [PATCH] feat: add setup script for automatic project setup Co-authored-by: Genie --- package.json | 3 ++- scripts/setup.sh | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 scripts/setup.sh diff --git a/package.json b/package.json index 4c09a63..177d0e6 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "author": "Genie", "license": "MIT", "scripts": { - "build:wasm": "bash scripts/build-openssl-wasm.sh" + "build:wasm": "bash scripts/build-openssl-wasm.sh", + "setup": "bash scripts/setup.sh" } } \ No newline at end of file diff --git a/scripts/setup.sh b/scripts/setup.sh new file mode 100644 index 0000000..dd71d34 --- /dev/null +++ b/scripts/setup.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Automatic project setup script for WebOpenSSL. +# - Builds the minified UMD bundle at dist/webopenssl.min.js using esbuild (via npx) +# - Optionally builds the OpenSSL WASM provider (pass --with-wasm) +# +# Usage: +# bash scripts/setup.sh +# bash scripts/setup.sh --with-wasm # also builds the WASM provider +# +# Requirements: +# - Node.js >= 16 with npm +# - Bash, curl (for optional WASM build path) + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +DIST_DIR="${ROOT}/dist" +WITH_WASM=0 + +for arg in "$@"; do + case "$arg" in + --with-wasm) WITH_WASM=1 ;; + *) echo "Unknown argument: $arg" >&2; exit 1 ;; + esac +done + +function need_cmd() { + command -v "$1" >/dev/null 2>&1 || { echo "Missing dependency: $1" >&2; exit 1; } +} + +echo "==> Checking prerequisites..." +need_cmd node +need_cmd npm +need_cmd npx + +mkdir -p "${DIST_DIR}" + +echo "==> Building UMD bundle (dist/webopenssl.min.js) with esbuild..." +# Use npx to avoid editing package.json dependencies. This fetches esbuild if not cached. +npx --yes esbuild "${ROOT}/src/index.js" \ + --bundle \ + --minify \ + --platform=browser \ + --format=iife \ + --global-name=WebOpenSSL \ + --outfile="${DIST_DIR}/webopenssl.min.js" + +echo "==> Bundle built at: ${DIST_DIR}/webopenssl.min.js" + +if [ "${WITH_WASM}" -eq 1 ]; then + echo "==> Building OpenSSL WASM provider..." + bash "${ROOT}/scripts/build-openssl-wasm.sh" +else + echo "==> Skipping WASM build (pass --with-wasm to enable)" +fi + +echo "==> Setup complete." \ No newline at end of file