-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
115 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters