Skip to content

Commit

Permalink
wip mix blend.clean
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Feb 28, 2024
1 parent 583a1b3 commit 2b7ed1f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
21 changes: 16 additions & 5 deletions lib/mix/tasks/blend/clean.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@ defmodule Mix.Tasks.Blend.Clean do

@impl true
def run(args) do
Blend.blends()
|> Map.keys()
|> Enum.map(fn blend_id ->
IO.puts("Cleaning blend #{blend_id}")
blend_names =
Blend.blends()
|> Map.keys()

Path.wildcard("blend/*.mix.lock")
|> Enum.reject(fn path ->
path in Enum.map(blend_names, fn name -> "blend/#{name}.mix.lock" end)
end)
|> Enum.each(fn path ->
File.rm!(path)
end)

blend_names
|> Enum.map(fn blend_name ->
IO.puts("Cleaning blend #{blend_name}")

Blend.within(
blend_id,
blend_name,
fn ->
Mix.Task.rerun("clean", ["--deps" | args])
end
Expand Down
28 changes: 24 additions & 4 deletions test/blend_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,42 @@ defmodule BlendTest do
end

@tag :tmp_dir
test "blend.get task", %{tmp_dir: tmp_dir} do

test "blend.clean", %{tmp_dir: tmp_dir} do
File.cd!(
tmp_dir,
fn ->
File.write(
"blend.exs",
"""
%{
"jason-1-0": [{:jason, "~> 1.0"}]
jason_1: [{:jason, "~> 1.0"}]
}
"""
)

Mix.Task.run("blend.get")
assert File.exists?("blend/jason-1-0.mix.lock")
run("blend.get")
assert File.exists?("blend/jason_1.mix.lock")

File.write(
"blend.exs",
"""
%{
plug_1: [{:plug, "~> 1.0"}]
}
"""
)

run("blend.get")
run("blend.clean")

assert File.exists?("blend/plug_1.mix.lock")
refute File.exists?("blend/jason_1.mix.lock")
end
)
end

defp run(args) do
Mix.Task.rerun(args)
end
end

0 comments on commit 2b7ed1f

Please sign in to comment.