Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore dev and umbrella dependencies. #6

Merged
merged 4 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 55 additions & 12 deletions lib/kudos.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule Kudos do
## Examples

iex> Kudos.generate() |> String.length()
8174
529

"""
def generate do
Expand All @@ -31,6 +31,14 @@ defmodule Kudos do
"""
end

defp format(:umbrella) do
""
end

defp format(:dev) do
""
end

defp format(meta_data) do
"""
### #{meta_data.name} (Version #{meta_data.version} | Checksum: #{checksum(meta_data.checksum)})
Expand Down Expand Up @@ -89,21 +97,56 @@ defmodule Kudos do
Mix.Dep.load_on_environment([])
|> Enum.map(fn dep ->
Mix.Dep.in_dependency(dep, fn _ ->
%{
name: Atom.to_string(Mix.Project.config()[:app]),
version: Mix.Project.config()[:version],
checksum: elem(dep.opts[:lock], 3),
description: Mix.Project.config()[:description],
source_url: Mix.Project.config()[:source_url],
links: get_in(Mix.Project.config(), [:package, :links]),
maintainers: get_in(Mix.Project.config(), [:package, :maintainers]),
licenses: get_in(Mix.Project.config(), [:package, :licenses]),
license_file: get_license_file_content(dep.opts[:dest])
}
case is_umbrella?(dep) do
true ->
:umbrella

false ->
case is_prod?(dep) do
false ->
:dev

_ ->
%{
name: Atom.to_string(Mix.Project.config()[:app]),
version: Mix.Project.config()[:version],
checksum: elem(dep.opts[:lock], 3),
description: Mix.Project.config()[:description],
source_url: Mix.Project.config()[:source_url],
links: get_in(Mix.Project.config(), [:package, :links]),
maintainers: get_in(Mix.Project.config(), [:package, :maintainers]),
licenses: get_in(Mix.Project.config(), [:package, :licenses]),
license_file: get_license_file_content(dep.opts[:dest])
}
end
end
end)
end)
end

defp is_umbrella?(dep) do
case List.keyfind(dep.opts, :in_umbrella, 0, {:in_umbrella, false}) do
{:in_umbrella, true} -> true
{:in_umbrella, false} -> from_umbrella?(dep)
end
end

defp from_umbrella?(dep) do
case List.keyfind(dep.opts, :from_umbrella, 0, {:from_umbrella, false}) do
{:from_umbrella, true} -> true
{:from_umbrella, false} -> false
end
end

defp is_prod?(dep) do
only = List.keyfind(dep.opts, :only, 0, [])

case only do
[] -> true
_ -> false
end
end

defp get_license_file_content(path) do
(File.ls!(path) -- File.ls!(path) -- @license_file_names)
|> read_license_file(path)
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/kudos.generate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Mix.Tasks.Kudos.Generate do
use Mix.Task

@shortdoc "Generates a licenses file"
@recursive true
@recursive false

def run(args \\ []) do
IO.puts("Generating Licenses file...")
Expand Down