diff --git a/example_project/.gitignore b/example_project/.gitignore index 8ac9b76..5ea471f 100644 --- a/example_project/.gitignore +++ b/example_project/.gitignore @@ -28,9 +28,6 @@ example-*.tar # Ignore assets that are produced by build tools. /priv/static/assets/ -# Ignore ssr build for svelte. -/priv/svelte/ - # Ignore digested assets cache. /priv/static/cache_manifest.json @@ -40,3 +37,6 @@ npm-debug.log # Ignore automatically generated Svelte files by the ~V sigil /assets/svelte/_build/ + +# Ignore ssr build for svelte. +/priv/svelte/ diff --git a/lib/mix/tasks/configure_phoenix.ex b/lib/mix/tasks/configure_phoenix.ex index 35b6e2d..0d0a11c 100644 --- a/lib/mix/tasks/configure_phoenix.ex +++ b/lib/mix/tasks/configure_phoenix.ex @@ -1,6 +1,6 @@ defmodule Mix.Tasks.LiveSvelte.ConfigurePhoenix do @moduledoc """ - Configures any necessary code changes inside Phoenix to make LiveSvelte work. + Configures any necessary code changes inside Phoenix to make LiveSvelte work. """ import LiveSvelte.Logger @@ -8,6 +8,7 @@ defmodule Mix.Tasks.LiveSvelte.ConfigurePhoenix do @watcher_regex ~r/watchers:\s\[(?!\s+node:)/ @esbuild_regex ~r/(? log_error(err.message) end @@ -23,27 +25,45 @@ defmodule Mix.Tasks.LiveSvelte.ConfigurePhoenix do end defp configure_dev_config() do - watcher = ~s""" + text = ~s""" node: ["build.js", "--watch", cd: Path.expand("../assets", __DIR__)],\ """ {path, file} = path_and_file("config/", "dev.exs") File.read!(path) - |> insert(@watcher_regex, watcher, "'#{watcher}' in #{file}") + |> insert(@watcher_regex, text, "'#{text}' in #{file}") |> comment(@esbuild_regex, "old esbuild watcher in #{file}") |> save(path) end defp configure_application() do - nodeSupervisor = ~s""" + text = ~s""" {NodeJS.Supervisor, [path: LiveSvelte.SSR.server_path(), pool_size: 4]},\ """ {path, file} = path_and_file("lib/**/", "application.ex") File.read!(path) - |> insert(@nodejs_regex, nodeSupervisor, "'#{nodeSupervisor}' in #{file}") + |> insert(@nodejs_regex, text, "'#{text}' in #{file}") + |> save(path) + end + + defp configure_gitignore() do + text = ~s""" + + + # Ignore automatically generated Svelte files by the ~V sigil + /assets/svelte/_build/ + + # Ignore ssr build for svelte. + /priv/svelte/\ + """ + + {path, file} = path_and_file("", ".gitignore") + + File.read!(path) + |> insert(@gitignore_regex, text, "'#{text}' in #{file}") |> save(path) end