Skip to content

Commit

Permalink
modify salad.init task to automatically patch application.ex
Browse files Browse the repository at this point in the history
  • Loading branch information
selenil committed Dec 7, 2024
1 parent 3e09eda commit 43cfd8a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/mix/tasks/salad.init.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ defmodule Mix.Tasks.Salad.Init do
env = Atom.to_string(Mix.env())
app_name = Mix.Project.config()[:app] |> Atom.to_string() |> String.downcase()
assets_path = build_assets_path(env)
application_file_path = Path.join(File.cwd!(), "lib/#{app_name}/application.ex")

node_opts = if env == "test", do: [skip: true], else: []

File.mkdir_p!(component_path)

with :ok <- write_config(component_path),
:ok <- init_tw_merge_cache(application_file_path),
:ok <- patch_css(color_scheme, assets_path),
:ok <- patch_js(assets_path),
:ok <- copy_tailwind_colors(assets_path),
Expand Down Expand Up @@ -117,6 +119,23 @@ defmodule Mix.Tasks.Salad.Init do
end
end

defp init_tw_merge_cache(application_file_path) do
cache_module = "TwMerge.Cache"
description = "Start TwMerge cache"

Mix.shell().info("Adding Tailwind merge cache to application supervisor")

if File.exists?(application_file_path) do
Patcher.patch_elixir_application(
application_file_path,
cache_module,
description
)
else
{:error, "application.ex not found"}
end
end

defp patch_css(color_scheme, assets_path) do
app_css_path = Path.join(File.cwd!(), "assets/css/app.css")
css_color_scheme_path = Path.join([assets_path, "colors", "#{color_scheme}.css"])
Expand Down

0 comments on commit 43cfd8a

Please sign in to comment.