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
3 changes: 2 additions & 1 deletion guides/mix-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 2 additions & 0 deletions guides/web-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
19 changes: 19 additions & 0 deletions lib/exograph/web/monaco.ex
Original file line number Diff line number Diff line change
@@ -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")

Expand Down Expand Up @@ -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")

Expand Down
14 changes: 13 additions & 1 deletion lib/mix/tasks/exograph.web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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},
Expand Down
Loading