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"
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", ["igniter.install" | install_args], use_stdio: false)
System.cmd("mix", ["deps.compile"])
System.cmd("mix", ["igniter.install" | install_args])
end
:ok

View file

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

View file

@ -31,23 +31,7 @@ defmodule Igniter.Code.Module do
igniter
{:error, igniter} ->
contents =
"""
defmodule #{inspect(module_name)} do
#{contents}
end
"""
location =
case Keyword.get(opts, :path, nil) do
nil ->
proper_location(module_name)
path ->
path
end
Igniter.create_new_elixir_file(igniter, location, contents)
create_module(igniter, module_name, contents, opts)
end
end
@ -63,6 +47,27 @@ defmodule Igniter.Code.Module do
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 =
"""
defmodule #{inspect(module_name)} do
#{contents}
end
"""
location =
case Keyword.get(opts, :path, nil) do
nil ->
proper_location(module_name)
path ->
path
end
Igniter.create_new_elixir_file(igniter, location, contents)
end
@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
case find_module(igniter, module_name) do