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

Add flag to include dev dependencies #12

Merged
merged 2 commits into from
May 26, 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
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ jobs:
if: ${{ matrix.lint }}

- run: mix test

- run: mix kudos.generate

- run: mix kudos.generate --dry-run

- run: mix kudos.generate --include-dev-deps
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be a future improvement: What do you think about committing the licensed.md file and asserting that it matches to what this command generates.

Submitting the license file is also a nice way to show visitors an example of the generated file

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the idea of committing the licenses.md unfortunately for non dev it would be empty.

Or what about a checker wich can be called in the pipeline, like mix kudos.compliant or mix kudos.complete. Will merge this for now. We can think about adding this in the next release.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Print licenses to console:

`mix kudos.generate --dry-run`

Including dev dependencies:

`mix kudos.generate --include-dev-deps`

## Documentation

[https://hexdocs.pm/kudos](https://hexdocs.pm/kudos).
14 changes: 10 additions & 4 deletions lib/kudos.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ defmodule Kudos do
iex> Kudos.generate() |> String.length()
219

iex> Kudos.generate(false) |> String.length()
219

iex> Kudos.generate(true) |> String.length()
19050

"""
def generate do
load_deps_meta_data()
def generate(include_dev_deps \\ false) do
load_deps_meta_data(include_dev_deps)
|> Enum.reduce(header(), fn meta_data, resp ->
resp <> format(meta_data)
end)
Expand Down Expand Up @@ -94,7 +100,7 @@ defmodule Kudos do
"[#{key}](#{value})"
end

defp load_deps_meta_data() do
defp load_deps_meta_data(include_dev_deps) do
Mix.Dep.load_on_environment([])
|> Enum.map(fn dep ->
Mix.Dep.in_dependency(dep, fn _ ->
Expand All @@ -103,7 +109,7 @@ defmodule Kudos do
:umbrella

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

Expand Down
7 changes: 6 additions & 1 deletion lib/mix/tasks/kudos.generate.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ defmodule Mix.Tasks.Kudos.Generate do
IO.puts("Generating Licenses file...")

resp =
Kudos.generate()
include_dev_deps?(args)
|> Kudos.generate()
|> handle_licenses(dry_run?(args))

case resp do
Expand All @@ -29,4 +30,8 @@ defmodule Mix.Tasks.Kudos.Generate do
defp dry_run?(args) do
Enum.member?(args, "--dry-run")
end

defp include_dev_deps?(args) do
Enum.member?(args, "--include-dev-deps")
end
end