-
Notifications
You must be signed in to change notification settings - Fork 3
Ignite installer #48
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
Open
alexiob
wants to merge
5
commits into
smartrent:main
Choose a base branch
from
alexiob:ignite-installer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Ignite installer #48
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5ef48ab
Ignite installer
alexiob 405fb35
chore: config file detection and cleanup
alexiob acb04eb
chore: test target.exts
alexiob 14b7872
Update lib/mix/tasks/ramoops_logger.install.ex
alexiob 26d1987
Update lib/mix/tasks/ramoops_logger.install.ex
alexiob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
defmodule Mix.Tasks.RamoopsLogger.Install.Docs do | ||
@moduledoc false | ||
|
||
def short_doc do | ||
"Install RamoopsLogger with the default configuration" | ||
end | ||
|
||
def example do | ||
"mix ramoops_logger.install --example arg" | ||
end | ||
|
||
def long_doc do | ||
""" | ||
#{short_doc()} | ||
""" | ||
end | ||
end | ||
|
||
if Code.ensure_loaded?(Igniter) do | ||
defmodule Mix.Tasks.RamoopsLogger.Install do | ||
@shortdoc "#{__MODULE__.Docs.short_doc()}" | ||
|
||
@moduledoc __MODULE__.Docs.long_doc() | ||
|
||
use Igniter.Mix.Task | ||
|
||
@impl Igniter.Mix.Task | ||
def info(_argv, _composing_task) do | ||
%Igniter.Mix.Task.Info{ | ||
# Groups allow for overlapping arguments for tasks by the same author | ||
# See the generators guide for more. | ||
group: :ramoops_logger, | ||
# *other* dependencies to add | ||
# i.e `{:foo, "~> 2.0"}` | ||
adds_deps: [], | ||
# *other* dependencies to add and call their associated installers, if they exist | ||
# i.e `{:foo, "~> 2.0"}` | ||
installs: [], | ||
# An example invocation | ||
example: __MODULE__.Docs.example(), | ||
# A list of environments that this should be installed in. | ||
only: nil, | ||
# a list of positional arguments, i.e `[:file]` | ||
positional: [], | ||
# Other tasks your task composes using `Igniter.compose_task`, passing in the CLI argv | ||
# This ensures your option schema includes options from nested tasks | ||
composes: [], | ||
# `OptionParser` schema | ||
schema: [], | ||
# Default values for the options in the `schema` | ||
defaults: [], | ||
# CLI aliases | ||
aliases: [], | ||
# A list of options in the schema that are required | ||
required: [] | ||
} | ||
end | ||
|
||
@impl Igniter.Mix.Task | ||
def igniter(igniter) do | ||
config_file = | ||
if Igniter.exists?(igniter, "config/target.exs") do | ||
"target.exs" | ||
else | ||
"config.exs" | ||
end | ||
|
||
igniter | ||
|> Igniter.Project.Config.configure(config_file, :logger, [:backends], [RamoopsLogger, :console]) | ||
end | ||
end | ||
else | ||
defmodule Mix.Tasks.RamoopsLogger.Install do | ||
@shortdoc "#{__MODULE__.Docs.short_doc()} | Install `igniter` to use" | ||
|
||
@moduledoc __MODULE__.Docs.long_doc() | ||
|
||
use Mix.Task | ||
|
||
def run(_argv) do | ||
Mix.shell().error(""" | ||
The task 'ramoops_logger.install' requires igniter. Please install igniter and try again. | ||
|
||
For more information, see: https://hexdocs.pm/igniter/readme.html#installation | ||
""") | ||
|
||
exit({:shutdown, 1}) | ||
end | ||
end | ||
end |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
defmodule RamoopsLogger.InstallTest do | ||
use ExUnit.Case, async: true | ||
import Igniter.Test | ||
|
||
require Logger | ||
|
||
setup do | ||
Logger.add_backend(RamoopsLogger, flush: true) | ||
|
||
:ok | ||
end | ||
|
||
test "installer adds ramoops_logger to existing target.exs" do | ||
test_project( | ||
files: %{ | ||
"config/config.exs" => """ | ||
import Config | ||
config :logger, level: :info | ||
config :other_thing, foo: :bar | ||
""" | ||
} | ||
) | ||
|> Igniter.compose_task("ramoops_logger.install", []) | ||
|> assert_has_patch("config/config.exs", ~S""" | ||
1 1 |import Config | ||
2 - |config :logger, level: :info | ||
2 + |config :logger, level: :info, backends: [RamoopsLogger, :console] | ||
3 3 |config :other_thing, foo: :bar | ||
4 + |import_config "#{config_env()}.exs" | ||
""") | ||
end | ||
|
||
test "installer adds ramoops_logger to logger backends for target.exs" do | ||
test_project() | ||
|> Igniter.compose_task("ramoops_logger.install", []) | ||
|> assert_creates("config/config.exs", ~S""" | ||
import Config | ||
config :logger, backends: [RamoopsLogger, :console] | ||
import_config "#{config_env()}.exs" | ||
""") | ||
end | ||
|
||
test "installer adds ramoops_logger to logger backends for target.exs if present" do | ||
test_project( | ||
files: %{ | ||
"config/target.exs" => """ | ||
import Config | ||
config :logger, level: :info | ||
config :other_thing, foo: :bar | ||
""" | ||
} | ||
) | ||
|> Igniter.compose_task("ramoops_logger.install", []) | ||
|> assert_has_patch("config/target.exs", ~S""" | ||
1 1 |import Config | ||
2 - |config :logger, level: :info | ||
2 + |config :logger, level: :info, backends: [RamoopsLogger, :console] | ||
3 3 |config :other_thing, foo: :bar | ||
4 4 | | ||
""") | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.