mirror of
https://github.com/ash-project/igniter.git
synced 2024-09-19 13:02:51 +12:00
This commit is contained in:
parent
18713f8578
commit
e776b2cb7d
9 changed files with 36 additions and 36 deletions
|
@ -796,12 +796,12 @@ defmodule Igniter do
|
|||
"**/.formatter.exs"
|
||||
|> Path.wildcard()
|
||||
|> Enum.reduce(igniter, fn path, igniter ->
|
||||
Igniter.include_existing_elixir_file(igniter, path)
|
||||
Igniter.include_existing_file(igniter, path)
|
||||
end)
|
||||
|
||||
igniter =
|
||||
if File.exists?(".formatter.exs") do
|
||||
Igniter.include_existing_elixir_file(igniter, ".formatter.exs")
|
||||
Igniter.include_existing_file(igniter, ".formatter.exs")
|
||||
else
|
||||
igniter
|
||||
end
|
||||
|
@ -1038,7 +1038,7 @@ defmodule Igniter do
|
|||
read_source!(path, Rewrite.Source.Ex)
|
||||
end
|
||||
|
||||
defp read_source!(path, source_handler \\ Rewrite.Source) do
|
||||
defp read_source!(path, source_handler) do
|
||||
source = source_handler.read!(path)
|
||||
|
||||
content =
|
||||
|
|
|
@ -65,7 +65,7 @@ defmodule Igniter.Code.Module do
|
|||
path
|
||||
end
|
||||
|
||||
Igniter.create_new_elixir_file(igniter, location, contents)
|
||||
Igniter.create_new_file(igniter, location, contents)
|
||||
end
|
||||
|
||||
@doc "Checks if a module is defined somewhere in the project. The returned igniter should not be discarded."
|
||||
|
|
|
@ -114,7 +114,7 @@ defmodule Igniter.Project.Application do
|
|||
end
|
||||
"""
|
||||
|
||||
Igniter.create_new_elixir_file(igniter, path, contents)
|
||||
Igniter.create_new_file(igniter, path, contents)
|
||||
end
|
||||
|
||||
defp point_to_application_in_mix_exs(igniter, application) do
|
||||
|
|
|
@ -57,7 +57,7 @@ defmodule Igniter.Project.Config do
|
|||
|
||||
igniter
|
||||
|> ensure_default_configs_exist(file_path)
|
||||
|> Igniter.include_or_create_elixir_file(file_path, file_contents)
|
||||
|> Igniter.include_or_create_file(file_path, file_contents)
|
||||
|> Igniter.update_elixir_file(file_path, fn zipper ->
|
||||
case Zipper.find(zipper, fn
|
||||
{:import, _, [Config]} ->
|
||||
|
@ -81,17 +81,17 @@ defmodule Igniter.Project.Config do
|
|||
defp ensure_default_configs_exist(igniter, file)
|
||||
when file in ["config/dev.exs", "config/test.exs", "config/prod.exs"] do
|
||||
igniter
|
||||
|> Igniter.include_or_create_elixir_file("config/config.exs", """
|
||||
|> Igniter.include_or_create_file("config/config.exs", """
|
||||
import Config
|
||||
""")
|
||||
|> ensure_config_evaluates_env()
|
||||
|> Igniter.include_or_create_elixir_file("config/dev.exs", """
|
||||
|> Igniter.include_or_create_file("config/dev.exs", """
|
||||
import Config
|
||||
""")
|
||||
|> Igniter.include_or_create_elixir_file("config/test.exs", """
|
||||
|> Igniter.include_or_create_file("config/test.exs", """
|
||||
import Config
|
||||
""")
|
||||
|> Igniter.include_or_create_elixir_file("config/prod.exs", """
|
||||
|> Igniter.include_or_create_file("config/prod.exs", """
|
||||
import Config
|
||||
""")
|
||||
end
|
||||
|
@ -378,7 +378,7 @@ defmodule Igniter.Project.Config do
|
|||
config_file_path = Path.join("config", config_file_name)
|
||||
|
||||
igniter =
|
||||
Igniter.include_existing_elixir_file(igniter, config_file_path, required?: false)
|
||||
Igniter.include_existing_file(igniter, config_file_path, required?: false)
|
||||
|
||||
case Rewrite.source(igniter.rewrite, config_file_path) do
|
||||
{:ok, source} ->
|
||||
|
|
|
@ -69,7 +69,7 @@ defmodule Igniter.Project.Deps do
|
|||
def get_dependency_declaration(igniter, name) do
|
||||
zipper =
|
||||
igniter
|
||||
|> Igniter.include_existing_elixir_file("mix.exs")
|
||||
|> Igniter.include_existing_file("mix.exs")
|
||||
|> Map.get(:rewrite)
|
||||
|> Rewrite.source!("mix.exs")
|
||||
|> Rewrite.Source.get(:quoted)
|
||||
|
|
|
@ -16,7 +16,7 @@ defmodule Igniter.Project.Formatter do
|
|||
@spec import_dep(Igniter.t(), dep :: atom) :: Igniter.t()
|
||||
def import_dep(igniter, dep) do
|
||||
igniter
|
||||
|> Igniter.include_or_create_elixir_file(".formatter.exs", @default_formatter)
|
||||
|> Igniter.include_or_create_file(".formatter.exs", @default_formatter)
|
||||
|> Igniter.update_elixir_file(".formatter.exs", fn zipper ->
|
||||
zipper
|
||||
|> Zipper.down()
|
||||
|
@ -62,7 +62,7 @@ defmodule Igniter.Project.Formatter do
|
|||
@spec add_formatter_plugin(Igniter.t(), plugin :: module()) :: Igniter.t()
|
||||
def add_formatter_plugin(igniter, plugin) do
|
||||
igniter
|
||||
|> Igniter.include_or_create_elixir_file(".formatter.exs", @default_formatter)
|
||||
|> Igniter.include_or_create_file(".formatter.exs", @default_formatter)
|
||||
|> Igniter.update_elixir_file(".formatter.exs", fn zipper ->
|
||||
zipper
|
||||
|> Zipper.down()
|
||||
|
|
|
@ -9,8 +9,8 @@ defmodule Igniter.Code.ModuleTest do
|
|||
|> Igniter.assign(:igniter_exs,
|
||||
module_location: :inside_matching_folder
|
||||
)
|
||||
|> Igniter.include_or_create_elixir_file("lib/foo/bar.ex", "defmodule Foo.Bar do\nend")
|
||||
|> Igniter.include_or_create_elixir_file(
|
||||
|> Igniter.include_or_create_file("lib/foo/bar.ex", "defmodule Foo.Bar do\nend")
|
||||
|> Igniter.include_or_create_file(
|
||||
"lib/foo/bar/baz.ex",
|
||||
"defmodule Foo.Bar.Baz do\nend"
|
||||
)
|
||||
|
@ -25,7 +25,7 @@ defmodule Igniter.Code.ModuleTest do
|
|||
test "modules can be found anywhere across the project" do
|
||||
%{rewrite: rewrite} =
|
||||
Igniter.new()
|
||||
|> Igniter.create_new_elixir_file("lib/foo/bar.ex", """
|
||||
|> Igniter.create_new_file("lib/foo/bar.ex", """
|
||||
defmodule Foo.Bar do
|
||||
defmodule Baz do
|
||||
10
|
||||
|
@ -59,7 +59,7 @@ defmodule Igniter.Code.ModuleTest do
|
|||
test "modules will be created if they do not exist, in the conventional place" do
|
||||
%{rewrite: rewrite} =
|
||||
Igniter.new()
|
||||
|> Igniter.create_new_elixir_file("lib/foo/bar.ex", """
|
||||
|> Igniter.create_new_file("lib/foo/bar.ex", """
|
||||
defmodule Foo.Bar do
|
||||
end
|
||||
""")
|
||||
|
@ -91,7 +91,7 @@ defmodule Igniter.Code.ModuleTest do
|
|||
|> Igniter.assign(:igniter_exs,
|
||||
module_location: :inside_matching_folder
|
||||
)
|
||||
|> Igniter.create_new_elixir_file("lib/foo/bar/something.ex", """
|
||||
|> Igniter.create_new_file("lib/foo/bar/something.ex", """
|
||||
defmodule Foo.Bar.Something do
|
||||
end
|
||||
""")
|
||||
|
|
|
@ -21,7 +21,7 @@ defmodule Igniter.Project.ConfigTest do
|
|||
test "it merges with 2 arg version of existing config" do
|
||||
%{rewrite: rewrite} =
|
||||
Igniter.new()
|
||||
|> Igniter.create_new_elixir_file("config/fake.exs", """
|
||||
|> Igniter.create_new_file("config/fake.exs", """
|
||||
import Config
|
||||
|
||||
config :fake, buz: [:blat]
|
||||
|
@ -67,7 +67,7 @@ defmodule Igniter.Project.ConfigTest do
|
|||
test "it merges with 2 arg version of existing config with a single path item" do
|
||||
%{rewrite: rewrite} =
|
||||
Igniter.new()
|
||||
|> Igniter.create_new_elixir_file("config/fake.exs", """
|
||||
|> Igniter.create_new_file("config/fake.exs", """
|
||||
import Config
|
||||
|
||||
config :fake, buz: [:blat]
|
||||
|
@ -86,7 +86,7 @@ defmodule Igniter.Project.ConfigTest do
|
|||
test "it chooses the 3 arg version when first item in path is not pretty" do
|
||||
%{rewrite: rewrite} =
|
||||
Igniter.new()
|
||||
|> Igniter.create_new_elixir_file("config/fake.exs", """
|
||||
|> Igniter.create_new_file("config/fake.exs", """
|
||||
import Config
|
||||
""")
|
||||
|> Igniter.Project.Config.configure("fake.exs", :fake, [Foo.Bar, :bar], "baz")
|
||||
|
@ -102,7 +102,7 @@ defmodule Igniter.Project.ConfigTest do
|
|||
test "it chooses the 3 arg version when first item in path is not pretty, and merges that way" do
|
||||
%{rewrite: rewrite} =
|
||||
Igniter.new()
|
||||
|> Igniter.create_new_elixir_file("config/fake.exs", """
|
||||
|> Igniter.create_new_file("config/fake.exs", """
|
||||
import Config
|
||||
""")
|
||||
|> Igniter.Project.Config.configure("fake.exs", :fake, [Foo.Bar, :bar], "baz")
|
||||
|
@ -119,7 +119,7 @@ defmodule Igniter.Project.ConfigTest do
|
|||
test "it merges with 3 arg version of existing config" do
|
||||
%{rewrite: rewrite} =
|
||||
Igniter.new()
|
||||
|> Igniter.create_new_elixir_file("config/fake.exs", """
|
||||
|> Igniter.create_new_file("config/fake.exs", """
|
||||
import Config
|
||||
|
||||
config :fake, :buz, [:blat]
|
||||
|
@ -140,7 +140,7 @@ defmodule Igniter.Project.ConfigTest do
|
|||
test "it merges with 3 arg version of existing config with the config set to []" do
|
||||
%{rewrite: rewrite} =
|
||||
Igniter.new()
|
||||
|> Igniter.create_new_elixir_file("config/fake.exs", """
|
||||
|> Igniter.create_new_file("config/fake.exs", """
|
||||
import Config
|
||||
|
||||
config :foo, SomeModule, []
|
||||
|
@ -165,7 +165,7 @@ defmodule Igniter.Project.ConfigTest do
|
|||
test "it merges with 3 arg version of existing config with the config set to [] and the path is one level deeper than existing" do
|
||||
%{rewrite: rewrite} =
|
||||
Igniter.new()
|
||||
|> Igniter.create_new_elixir_file("config/fake.exs", """
|
||||
|> Igniter.create_new_file("config/fake.exs", """
|
||||
import Config
|
||||
|
||||
config :foo, SomeModule, [level1: []]
|
||||
|
@ -189,7 +189,7 @@ defmodule Igniter.Project.ConfigTest do
|
|||
test "it merges with 3 arg version of existing config with a single path item" do
|
||||
%{rewrite: rewrite} =
|
||||
Igniter.new()
|
||||
|> Igniter.create_new_elixir_file("config/fake.exs", """
|
||||
|> Igniter.create_new_file("config/fake.exs", """
|
||||
import Config
|
||||
|
||||
config :fake, :buz, [:blat]
|
||||
|
@ -209,7 +209,7 @@ defmodule Igniter.Project.ConfigTest do
|
|||
test "present values can be updated" do
|
||||
%{rewrite: rewrite} =
|
||||
Igniter.new()
|
||||
|> Igniter.create_new_elixir_file("config/fake.exs", """
|
||||
|> Igniter.create_new_file("config/fake.exs", """
|
||||
import Config
|
||||
|
||||
config :fake, :buz, [:blat]
|
||||
|
@ -232,7 +232,7 @@ defmodule Igniter.Project.ConfigTest do
|
|||
test "we merge configs even in large config files" do
|
||||
%{rewrite: rewrite} =
|
||||
Igniter.new()
|
||||
|> Igniter.create_new_elixir_file("config/fake.exs", """
|
||||
|> Igniter.create_new_file("config/fake.exs", """
|
||||
# this is too
|
||||
|
||||
import Config
|
||||
|
@ -268,7 +268,7 @@ defmodule Igniter.Project.ConfigTest do
|
|||
test "integers can be used as values" do
|
||||
%{rewrite: rewrite} =
|
||||
Igniter.new()
|
||||
|> Igniter.create_new_elixir_file("config/fake.exs", """
|
||||
|> Igniter.create_new_file("config/fake.exs", """
|
||||
import Config
|
||||
|
||||
config :fake, :buz, [:blat]
|
||||
|
@ -287,7 +287,7 @@ defmodule Igniter.Project.ConfigTest do
|
|||
test "present values can be updated by updating map keys" do
|
||||
%{rewrite: rewrite} =
|
||||
Igniter.new()
|
||||
|> Igniter.create_new_elixir_file("config/fake.exs", """
|
||||
|> Igniter.create_new_file("config/fake.exs", """
|
||||
import Config
|
||||
|
||||
config :fake, foo: %{"a" => ["a", "b"]}
|
||||
|
@ -314,7 +314,7 @@ defmodule Igniter.Project.ConfigTest do
|
|||
test "it presents users with instructions on how to update a malformed config" do
|
||||
%{warnings: [warning]} =
|
||||
Igniter.new()
|
||||
|> Igniter.create_new_elixir_file("config/fake.exs", """
|
||||
|> Igniter.create_new_file("config/fake.exs", """
|
||||
config :fake, foo: %{"a" => ["a", "b"]}
|
||||
""")
|
||||
|> Igniter.Project.Config.configure("fake.exs", :fake, [:foo], %{"b" => ["c", "d"]},
|
||||
|
@ -334,7 +334,7 @@ defmodule Igniter.Project.ConfigTest do
|
|||
test "configures_root_key?/3" do
|
||||
igniter =
|
||||
Igniter.new()
|
||||
|> Igniter.create_new_elixir_file("config/fake.exs", """
|
||||
|> Igniter.create_new_file("config/fake.exs", """
|
||||
import Config
|
||||
|
||||
config :foo, key1: "key1"
|
||||
|
@ -352,7 +352,7 @@ defmodule Igniter.Project.ConfigTest do
|
|||
%{
|
||||
igniter:
|
||||
Igniter.new()
|
||||
|> Igniter.create_new_elixir_file("config/fake.exs", """
|
||||
|> Igniter.create_new_file("config/fake.exs", """
|
||||
import Config
|
||||
|
||||
config :foo, key1: [key2: "key2"]
|
||||
|
|
|
@ -7,7 +7,7 @@ defmodule Igniter.Project.TestTest do
|
|||
test "it adds the path if it doesn't exist" do
|
||||
assert %{rewrite: rewrite} =
|
||||
Igniter.new()
|
||||
|> Igniter.include_existing_elixir_file("mix.exs")
|
||||
|> Igniter.include_existing_file("mix.exs")
|
||||
|> Map.update!(:rewrite, fn rewrite ->
|
||||
source = Rewrite.source!(rewrite, "mix.exs")
|
||||
|
||||
|
@ -47,7 +47,7 @@ defmodule Igniter.Project.TestTest do
|
|||
test "it doesnt change anything if the setting is already configured" do
|
||||
assert %{rewrite: rewrite} =
|
||||
Igniter.new()
|
||||
|> Igniter.include_existing_elixir_file("mix.exs")
|
||||
|> Igniter.include_existing_file("mix.exs")
|
||||
|> Map.update!(:rewrite, fn rewrite ->
|
||||
source = Rewrite.source!(rewrite, "mix.exs")
|
||||
|
||||
|
|
Loading…
Reference in a new issue