chore: updated monaco and tools to update monaco

This commit is contained in:
2026-07-02 12:50:03 +02:00
parent e7d5cba01b
commit ef6c970654
139 changed files with 246442 additions and 71612 deletions

View File

@@ -17,13 +17,7 @@ defmodule BDS.Desktop.Endpoint do
plug(Plug.Static,
at: "/assets",
from: {:bds, "priv/static/assets"},
only: ["app.css", "app.js"]
)
plug(Plug.Static,
at: "/monaco",
from: {:bds, "priv/ui/monaco"},
only: ["vs"]
only: ["app.css", "app.js", "monaco.css", "monaco.js"]
)
plug(BDS.Desktop.Router)

View File

@@ -13,6 +13,7 @@ defmodule BDS.Desktop.Layouts do
<title><%= @page_title || "Blogging Desktop Server" %></title>
<meta name="csrf-token" content={Phoenix.Controller.get_csrf_token()} />
<link phx-track-static rel="stylesheet" href="/assets/app.css" />
<link phx-track-static rel="stylesheet" href="/assets/monaco.css" />
</head>
<body>
<%= @inner_content %>

View File

@@ -0,0 +1,86 @@
defmodule Mix.Tasks.Monaco.Update do
@shortdoc "Update monaco-editor to a given version and rebuild its bundle"
@moduledoc """
Update the monaco-editor npm package and rebuild the Monaco ESM bundle.
mix monaco.update 0.55.1
This task:
1. Runs `npm install monaco-editor@<version> --save-dev`
2. Removes the old `priv/static/assets/monaco.js` and `monaco.css`
3. Rebuilds the Monaco bundle via esbuild (both dev and minified)
Use `mix monaco.version` to check the result.
See `npm view monaco-editor` or https://www.npmjs.com/package/monaco-editor
for available versions.
"""
use Mix.Task
@impl Mix.Task
def run(args) do
case args do
[] ->
Mix.shell().error("Missing version argument.")
Mix.shell().info("Usage: mix monaco.update <version>")
Mix.shell().info("Example: mix monaco.update 0.55.1")
System.at_exit(fn _ -> System.halt(1) end)
[version] ->
do_update(version)
_ ->
Mix.shell().error("Too many arguments. Usage: mix monaco.update <version>")
System.at_exit(fn _ -> System.halt(1) end)
end
end
defp do_update(version) do
current = current_version()
Mix.shell().info("Updating monaco-editor: #{current}#{version}")
# 1. npm install
{_, 0} = System.cmd("npm", ["install", "monaco-editor@#{version}", "--save-dev"], into: IO.stream(:stdio, :line))
{_, 0} = System.cmd("npm", ["install"], into: IO.stream(:stdio, :line))
# 2. Clean old bundle
monaco_js = Path.join(File.cwd!(), "priv/static/assets/monaco.js")
monaco_css = Path.join(File.cwd!(), "priv/static/assets/monaco.css")
for path <- [monaco_js, monaco_css] do
if File.exists?(path) do
File.rm!(path)
end
end
Mix.shell().info("Removed old monaco.js and monaco.css")
# 3. Rebuild via esbuild (dev + minified)
Mix.Task.run("esbuild", ["monaco"])
Mix.Task.run("esbuild", ["monaco", "--minify"])
# 4. Verify
new = current_version()
Mix.shell().info("monaco-editor is now at #{new}")
end
defp current_version do
lock = Path.join(File.cwd!(), "package-lock.json")
case File.read(lock) do
{:ok, content} ->
data = Jason.decode!(content)
case Map.get(Map.get(data, "packages", %{}), "node_modules/monaco-editor") do
%{"version" => v} -> v
_ -> "unknown"
end
_ ->
"unknown"
end
end
end

View File

@@ -0,0 +1,41 @@
defmodule Mix.Tasks.Monaco.Version do
@shortdoc "Show current monaco-editor version"
@moduledoc """
Show the currently installed monaco-editor version.
mix monaco.version
Reads the version from package-lock.json. The Monaco bundle lives at
`priv/static/assets/monaco.js` and is built via `mix esbuild monaco`.
"""
use Mix.Task
@impl Mix.Task
def run(_args) do
lock = Path.join(File.cwd!(), "package-lock.json")
case File.read(lock) do
{:ok, content} ->
data = Jason.decode!(content)
version =
case Map.get(Map.get(data, "packages", %{}), "node_modules/monaco-editor") do
%{"version" => v} -> v
_ -> nil
end
case version do
v when is_binary(v) -> Mix.shell().info("monaco-editor: #{v}")
nil ->
Mix.shell().error("Could not find monaco-editor in package-lock.json")
System.at_exit(fn _ -> System.halt(1) end)
end
{:error, reason} ->
Mix.shell().error("package-lock.json not found: #{reason}")
System.at_exit(fn _ -> System.halt(1) end)
end
end
end