Last active
September 26, 2016 17:08
-
-
Save ivan/b5740156c547460f676fcd4ce256be25 to your computer and use it in GitHub Desktop.
Hacking mix to globally map Hex dependencies to audited git repositories
This file contains hidden or 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
| # ~/.mix/depmapper.exs | |
| defmodule Mix.DepMapper do | |
| @repos_path "/ejail/code/erlang" | |
| # The branch to check out. My workflow is to mark audited known-good | |
| # commits with both a branch and timestamped tag using | |
| # https://github.com/ludios/tagmyrebase | |
| @default_branch "bien" | |
| def mapdep(dep) do | |
| #IO.puts("dep: #{inspect dep, pretty: true, width: 0}") | |
| opts = Enum.into(dep.opts, %{}) | |
| if not Map.has_key?(opts, :hex) do | |
| # TODO: convert other git, github deps as well | |
| dep | |
| else | |
| dest = opts.dest | |
| name = Atom.to_string(opts.hex) | |
| git = Path.join(@repos_path, name) | |
| if System.get_env("DEPMAPPER_DEBUG") do | |
| IO.puts("[depmapper] Hex #{name} -> git #{git}") | |
| end | |
| opts = opts | |
| |> Map.delete(:hex) | |
| |> Map.put(:checkout, dest) | |
| |> Map.put(:git, git) | |
| |> Map.put(:branch, @default_branch) | |
| dep | |
| |> Map.put(:requirement, nil) | |
| |> Map.put(:scm, Mix.SCM.Git) | |
| |> Map.put(:opts, Enum.into(opts, [])) | |
| end | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
depmapper.exsconverts a Hex dependency likeinto a git dependency like