Skip to content

Commit

Permalink
refactor: rename juggler => blend
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Feb 6, 2024
1 parent 25461ab commit f9c8e02
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ erl_crash.dump
*.ez

# Ignore package tarball (built via "mix hex.build").
juggler-*.tar
blend-*.tar

# Temporary files, for example, from tests.
/tmp/
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Juggler
# Blend

Generates and maintains multiple lockfiles so that you can test your elixir app
against different variations of your dependencies

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `juggler` to your list of dependencies in `mix.exs`:
by adding `blend` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:juggler, "~> 0.1.0"}
{:blend, "~> 0.1.0"}
]
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at <https://hexdocs.pm/juggler>.
be found at <https://hexdocs.pm/blend>.

80 changes: 80 additions & 0 deletions lib/blend.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
defmodule Blend do
require Logger

@moduledoc """
Documentation for `Blend`.
"""

@blend_dir "blend"
@blendfile_path "blend.exs"
@blendfile_template """
# Example for testing against 1.x and 2.x of some dependency
# %{
# "dep-name-1-0": [{:dep_name, "~> 1.0"}],
# "dep-name-2-0": [{:dep_name, "~> 2.0"}],
# }
"""

def init do
case File.read(@blendfile_path) do
{:ok, _} ->
Logger.info("#{@blendfile_path} file already exists, doing nothing")

{:error, :enoent} ->
File.write(@blendfile_path, @blendfile_template)
Logger.info("Successfully created #{@blendfile_path} file")
end
end

def within(blend_id, fun) do
with_project(blend_id, blend_deps(blend_id), fun)
end

def blends do
case File.read(@blendfile_path) do
{:ok, contents} ->
case Code.eval_string(contents) do
{%{} = map, _} ->
map

_ ->
raise "Couldn't find a map defining your blends in #{@blendfile_path} file"
end

{:error, :enoent} ->
raise "Couldn't find a #{@blendfile_path} file"
end
end

defp blend_deps(blend_id) do
blends() |> Map.fetch!(blend_id)
end

defp with_project(blend_id, deps, fun) do
:ok =
Mix.ProjectStack.push(
Blend.TmpProject,
Mix.Project.config()
|> Keyword.merge(
app: blend_id,
deps:
deps
|> Enum.reduce(
Mix.Project.config()[:deps],
fn dep, acc ->
acc
|> List.keystore(elem(dep, 0), 0, dep)
end
),
lockfile: "#{@blend_dir}/#{blend_id}.mix.lock",
build_path: "#{@blend_dir}/_build/#{blend_id}",
deps_path: "#{@blend_dir}/deps/#{blend_id}"
),
"nofile"
)

fun.()
after
Mix.ProjectStack.pop()
end
end
76 changes: 0 additions & 76 deletions lib/juggler.ex

This file was deleted.

18 changes: 18 additions & 0 deletions lib/mix/tasks/blend/get.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule Mix.Tasks.Blend.Get do
use Mix.Task

@shortdoc "Generates lockfiles from blend.exs"

@impl true
def run(args) do
Blend.blends()
|> Enum.map(fn {blend_id, _deps} ->
Blend.within(
blend_id,
fn ->
Mix.Task.rerun("deps.get", args)
end
)
end)
end
end
18 changes: 0 additions & 18 deletions lib/mix/tasks/juggler/get.ex

This file was deleted.

10 changes: 0 additions & 10 deletions lib/mix/tasks/juggler/init.ex

This file was deleted.

18 changes: 0 additions & 18 deletions lib/mix/tasks/juggler/update.ex

This file was deleted.

4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defmodule Juggler.MixProject do
defmodule Blend.MixProject do
use Mix.Project

def project do
[
app: :juggler,
app: :blend,
version: "0.1.0",
elixir: "~> 1.15",
start_permanent: Mix.env() == :prod,
Expand Down
20 changes: 10 additions & 10 deletions test/juggler_test.exs → test/blend_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule JugglerTest do
defmodule BlendTest do
use ExUnit.Case
doctest Juggler
doctest Blend

@tmp_path Path.expand("../tmp", __DIR__)

Expand All @@ -10,32 +10,32 @@ defmodule JugglerTest do
:ok
end

test "init/0 generates juggles file" do
test "init/0 generates blend file" do
File.cd!(
@tmp_path,
fn ->
refute File.exists?("juggles.exs")
assert Juggler.init() == :ok
assert File.exists?("juggles.exs")
refute File.exists?("blend.exs")
assert Blend.init() == :ok
assert File.exists?("blend.exs")
end
)
end

test "juggler.get task" do
test "blend.get task" do
File.cd!(
@tmp_path,
fn ->
File.write(
"juggles.exs",
"blend.exs",
"""
%{
"jason-1-0": [{:jason, "~> 1.0"}]
}
"""
)

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

Expand Down

0 comments on commit f9c8e02

Please sign in to comment.