improvement: add create_module utility

fix: loadpaths after compiling deps
This commit is contained in:
Zach Daniel 2024-07-31 18:29:11 -04:00
parent c905ead36d
commit c769fe15ae
3 changed files with 28 additions and 19 deletions

View file

@ -105,10 +105,12 @@ defmodule Mix.Tasks.Igniter.New do
"--example" "--example"
end end
install_args = Enum.filter([Enum.join(install, ","), "--yes", example], & &1) install_args =
Enum.filter([Enum.join(install, ","), "--yes", example], & &1)
System.cmd("mix", ["deps.get"]) System.cmd("mix", ["deps.get"])
System.cmd("mix", ["igniter.install" | install_args], use_stdio: false) System.cmd("mix", ["deps.compile"])
System.cmd("mix", ["igniter.install" | install_args])
end end
:ok :ok

View file

@ -45,6 +45,8 @@ defmodule Igniter.Util.DepsCompile do
[include_children: true] [include_children: true]
compile(filter_available_and_local_deps(deps), opts) compile(filter_available_and_local_deps(deps), opts)
Mix.Task.reenable("deps.loadpaths")
Mix.Task.run("deps.loadpaths", ["--no-deps-check"])
end end
@doc false @doc false

View file

@ -31,6 +31,24 @@ defmodule Igniter.Code.Module do
igniter igniter
{:error, igniter} -> {:error, igniter} ->
create_module(igniter, module_name, contents, opts)
end
end
def find_and_update_or_create_module(
igniter,
module_name,
contents,
updater,
path
)
when is_binary(path) do
Logger.warning("You should use `opts` instead of `path` and pass `path` as a keyword.")
find_and_update_or_create_module(igniter, module_name, contents, updater, path: path)
end
@doc "Creates a new file & module in its appropriate location."
def create_module(igniter, module_name, contents, opts \\ []) do
contents = contents =
""" """
defmodule #{inspect(module_name)} do defmodule #{inspect(module_name)} do
@ -49,19 +67,6 @@ defmodule Igniter.Code.Module do
Igniter.create_new_elixir_file(igniter, location, contents) Igniter.create_new_elixir_file(igniter, location, contents)
end end
end
def find_and_update_or_create_module(
igniter,
module_name,
contents,
updater,
path
)
when is_binary(path) do
Logger.warning("You should use `opts` instead of `path` and pass `path` as a keyword.")
find_and_update_or_create_module(igniter, module_name, contents, updater, path: path)
end
@doc "Checks if a module is defined somewhere in the project. The returned igniter should not be discarded." @doc "Checks if a module is defined somewhere in the project. The returned igniter should not be discarded."
def module_exists?(igniter, module_name) do def module_exists?(igniter, module_name) do