From d320f2b01b8869b944c05861862e64cb51c49c14 Mon Sep 17 00:00:00 2001 From: Xevion Date: Mon, 29 Dec 2025 00:43:34 -0600 Subject: [PATCH] feat(web): auto-install emsdk and set default caddy port - Clone and install emsdk automatically if not present - Configure caddy to listen on port 8547 by default --- Justfile | 2 +- pacman/web.build.ts | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Justfile b/Justfile index 783c5df..31b1acc 100644 --- a/Justfile +++ b/Justfile @@ -38,7 +38,7 @@ samply: web *args: bun run pacman/web.build.ts {{args}} bun run --cwd web build - caddy file-server --root web/dist/client + caddy file-server --root web/dist/client --listen :8547 # Fix linting errors & formatting fix: diff --git a/pacman/web.build.ts b/pacman/web.build.ts index c20f65e..7501a8c 100644 --- a/pacman/web.build.ts +++ b/pacman/web.build.ts @@ -147,11 +147,40 @@ async function activateEmsdk( return { vars: null }; } - // Check if the emsdk directory exists + // Check if the emsdk directory exists, clone and install if not if (!(await fs.exists(emsdkDir))) { - return { - err: `Emscripten SDK directory not found at ${emsdkDir}. Please install or clone 'emsdk' and try again.`, - }; + logger.info("Emscripten SDK not found, cloning and installing..."); + + // Clone the emsdk repository + logger.debug("Cloning emsdk repository..."); + const cloneResult = + await $`git clone https://github.com/emscripten-core/emsdk.git ${emsdkDir}`.quiet(); + if (cloneResult.exitCode !== 0) { + return { + err: `Failed to clone emsdk: ${cloneResult.stderr.toString()}`, + }; + } + + // Install latest version + logger.debug("Installing latest Emscripten version..."); + const emsdkBinary = join(emsdkDir, os.type === "windows" ? "emsdk.bat" : "emsdk"); + const installResult = await $`${emsdkBinary} install latest`.quiet(); + if (installResult.exitCode !== 0) { + return { + err: `Failed to install emsdk: ${installResult.stderr.toString()}`, + }; + } + + // Activate latest version + logger.debug("Activating latest Emscripten version..."); + const activateResult = await $`${emsdkBinary} activate latest`.quiet(); + if (activateResult.exitCode !== 0) { + return { + err: `Failed to activate emsdk: ${activateResult.stderr.toString()}`, + }; + } + + logger.info("Emscripten SDK installed and activated successfully"); } // Check if the emsdk directory is activated/installed properly for the current OS