From 19b5e40b197d21ab2b80694b6a86c66ea18f4520 Mon Sep 17 00:00:00 2001 From: Victor Batarse Date: Sun, 14 Jun 2026 01:30:37 +0200 Subject: [PATCH] use host assets for shared packages, and notify for unique assets --- guides/mix-tasks.md | 3 ++- guides/web-ui.md | 2 ++ lib/exograph/web/monaco.ex | 19 +++++++++++++++++++ lib/mix/tasks/exograph.web.ex | 14 +++++++++++++- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/guides/mix-tasks.md b/guides/mix-tasks.md index 7741cb3..d5a92d1 100644 --- a/guides/mix-tasks.md +++ b/guides/mix-tasks.md @@ -114,5 +114,6 @@ Start a standalone web interface for exploring an index. | `--quackdb-token` | `QUACKDB_TOKEN` | QuackDB token | | `--duckdb-database` | `exograph.duckdb` | Managed DuckDB database path when no QuackDB URI is provided | -Requires optional dependencies: `phoenix`, `phoenix_live_view`, `volt`, `bandit`. +Requires optional dependencies: `phoenix`, `phoenix_html`, `phoenix_live_view`, `volt`, `bandit`. +The web task also requires Exograph's asset dependencies. If they are missing, `mix exograph.web` prints the `npm install --prefix .../assets` command to run. See [Web UI](web-ui.md) for editor features, search modes, and API details. diff --git a/guides/web-ui.md b/guides/web-ui.md index 7d5b4df..12fb0fd 100644 --- a/guides/web-ui.md +++ b/guides/web-ui.md @@ -80,4 +80,6 @@ The web UI requires optional dependencies: {:phoenix_iconify, "~> 0.1"} ``` +The web task also requires Exograph's asset dependencies. If they are missing, `mix exograph.web` prints the `npm install --prefix .../assets` command to run. + See [API](api.md) for the JSON API exposed by the same server. diff --git a/lib/exograph/web/monaco.ex b/lib/exograph/web/monaco.ex index cf04003..764b231 100644 --- a/lib/exograph/web/monaco.ex +++ b/lib/exograph/web/monaco.ex @@ -1,11 +1,16 @@ defmodule Exograph.Web.Monaco do @moduledoc false + alias Mix + @app_root Path.expand("../../..", __DIR__) + @assets_root Path.join(@app_root, "assets") @entry Path.join(@app_root, "assets/node_modules/monaco-editor/esm/vs/editor/edcore.main.js") @css_src Path.join(@app_root, "assets/node_modules/monaco-editor/min/vs/editor/editor.main.css") def ensure_bundled! do + ensure_installed!() + outdir = Volt.Config.build().outdir |> to_string() vendor_dir = Path.join(outdir, "vendor") @@ -38,6 +43,20 @@ defmodule Exograph.Web.Monaco do end end + defp ensure_installed! do + unless File.regular?(@entry) and File.regular?(@css_src) do + Mix.raise(""" + mix exograph.web requires Monaco editor assets. + + Run: + + npm install --prefix #{@assets_root} + + Then rerun mix exograph.web. + """) + end + end + defp copy_css!(vendor_dir) do path = Path.join(vendor_dir, "monaco.css") diff --git a/lib/mix/tasks/exograph.web.ex b/lib/mix/tasks/exograph.web.ex index 088975f..a71ef7a 100644 --- a/lib/mix/tasks/exograph.web.ex +++ b/lib/mix/tasks/exograph.web.ex @@ -176,7 +176,8 @@ defmodule Mix.Tasks.Exograph.Web do outdir: Path.join(@app_root, "priv/static/assets"), target: :es2020, hash: false, - resolve_dirs: [Path.join(assets_root, "node_modules"), Path.join(@app_root, "deps")], + external: [], + resolve_dirs: resolve_dirs(assets_root), module_types: %{".css" => :empty, ".ttf" => :empty}, tailwind: [ css: Path.join(@app_root, "assets/web/app.css"), @@ -193,10 +194,21 @@ defmodule Mix.Tasks.Exograph.Web do ) end + defp resolve_dirs(assets_root) do + [ + Path.join(assets_root, "node_modules"), + Mix.Project.deps_path(), + Path.join(@app_root, "deps") + ] + |> Enum.map(&Path.expand/1) + |> Enum.uniq() + end + defp ensure_web_dependencies! do missing = [ {:phoenix, Phoenix}, + {:phoenix_html, Phoenix.HTML}, {:phoenix_live_view, Phoenix.LiveView}, {:volt, Volt}, {:volt, Volt.Config},