Skip to content

Commit

Permalink
Merge pull request #278 from nimblehq/release/4.4.0
Browse files Browse the repository at this point in the history
Release - 4.4.0
  • Loading branch information
byhbt authored Sep 30, 2022
2 parents 0c83774 + 136d301 commit e5545fc
Show file tree
Hide file tree
Showing 33 changed files with 282 additions and 143 deletions.
3 changes: 2 additions & 1 deletion .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@
{Credo.Check.Readability.StrictModuleLayout,
[
order:
~w/shortdoc moduledoc behaviour use import alias require module_attribute defstruct callback/a
~w/shortdoc moduledoc behaviour use import alias require module_attribute defstruct callback public_fun private_fun/a,
ignore: ~w/callback_impl/a
]},
{Credo.Check.Consistency.MultiAliasImportRequireUse, []},
{Credo.Check.Consistency.UnusedVariableNames, []},
Expand Down
28 changes: 0 additions & 28 deletions .github/ISSUE_TEMPLATE/rfc_template.md

This file was deleted.

4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
erlang 25.0.1
elixir 1.13.4-otp-25
erlang 25.0.4
elixir 1.14.0-otp-25
nodejs 16.15.0
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Phoenix/Mix template for projects at [Nimble](https://nimblehq.co/).
NimbleTemplate has been developed and actively tested with the below environment:

- Mix 1.13.3
- Elixir 1.13.3
- Erlang/OTP 24.2.2
- Elixir 1.14.0
- Erlang/OTP 25.0.4
- Phoenix 1.6.11
- Node 16.15.0

Expand All @@ -31,7 +31,7 @@ Step 2: Add `nimble_template` dependency to `mix.exs`:
```elixir
def deps do
[
{:nimble_template, "~> 4.3.0", only: :dev, runtime: false},
{:nimble_template, "~> 4.4.0", only: :dev, runtime: false},
# other dependencies ...
]
end
Expand Down
5 changes: 4 additions & 1 deletion lib/nimble_template/addons/addon.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ defmodule NimbleTemplate.Addons.Addon do
alias NimbleTemplate.Generator
alias NimbleTemplate.Hex.Package
alias NimbleTemplate.Projects.Project
alias NimbleTemplate.ProjectHelper

def apply(%Project{} = project, opts \\ %{}) when is_map(opts) do
Generator.print_log("* applying ", inspect(__MODULE__))

do_apply(project, opts)
project
|> do_apply(opts)
|> ProjectHelper.append_installed_addon(__MODULE__)
end

def do_apply(%Project{} = project, opts) when is_map(opts), do: project
Expand Down
3 changes: 3 additions & 0 deletions lib/nimble_template/addons/git.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ defmodule NimbleTemplate.Addons.Git do
# Iex
.iex.exs
# Ignore ElixirLS files
.elixir_ls
""")

project
Expand Down
15 changes: 15 additions & 0 deletions lib/nimble_template/addons/iex.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule NimbleTemplate.Addons.Iex do
@moduledoc false

use NimbleTemplate.Addons.Addon

@impl true
def do_apply(%Project{base_module: base_module, web_project?: web_project?} = project, _opts) do
Generator.copy_file([{:eex, ".iex.exs.eex", ".iex.exs"}],
base_module: base_module,
web_project?: web_project?
)

project
end
end
12 changes: 6 additions & 6 deletions lib/nimble_template/addons/variants/phoenix/api/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.Config do
edit_files(project)
end

defp edit_files(%Project{} = project) do
edit_config_prod(project)

project
end

def edit_config_prod(%Project{otp_app: otp_app, web_module: web_module} = project) do
Generator.delete_content(
"config/prod.exs",
Expand Down Expand Up @@ -42,4 +36,10 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.Config do

project
end

defp edit_files(%Project{} = project) do
edit_config_prod(project)

project
end
end
12 changes: 6 additions & 6 deletions lib/nimble_template/addons/variants/phoenix/api/json_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.JsonApi do
edit_files(project)
end

defp edit_files(%Project{} = project) do
project
|> inject_mix_dependency()
|> edit_config()
end

def inject_mix_dependency(project) do
Generator.inject_mix_dependency({:jsonapi, latest_package_version(:jsonapi)})

Expand All @@ -37,4 +31,10 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.JsonApi do

project
end

defp edit_files(%Project{} = project) do
project
|> inject_mix_dependency()
|> edit_config()
end
end
28 changes: 14 additions & 14 deletions lib/nimble_template/addons/variants/phoenix/ex_machina.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ defmodule NimbleTemplate.Addons.Phoenix.ExMachina do
|> edit_files()
end

def edit_mix_elixirc_paths(%Project{} = project) do
Generator.replace_content(
"mix.exs",
"""
defp elixirc_paths(:test), do: ["lib", "test/support"]
""",
"""
defp elixirc_paths(:test), do: ["lib", "test/support", "test/factories"]
"""
)

project
end

defp copy_files(%Project{base_module: base_module} = project) do
Generator.copy_file([{:eex, "test/support/factory.ex.eex", "test/support/factory.ex"}],
base_module: base_module
Expand All @@ -34,20 +48,6 @@ defmodule NimbleTemplate.Addons.Phoenix.ExMachina do
project
end

def edit_mix_elixirc_paths(%Project{} = project) do
Generator.replace_content(
"mix.exs",
"""
defp elixirc_paths(:test), do: ["lib", "test/support"]
""",
"""
defp elixirc_paths(:test), do: ["lib", "test/support", "test/factories"]
"""
)

project
end

defp edit_test_helper(%Project{} = project) do
Generator.replace_content(
"test/test_helper.exs",
Expand Down
2 changes: 1 addition & 1 deletion lib/nimble_template/addons/variants/phoenix/health_plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlug do
# coveralls-ignore-stop
forward Application.get_env(:#{otp_app}, #{web_module}.Endpoint)[:health_path], #{web_module}.HealthPlug
forward Application.compile_env(:#{otp_app}, #{web_module}.Endpoint)[:health_path], #{web_module}.HealthPlug
"""
)

Expand Down
16 changes: 8 additions & 8 deletions lib/nimble_template/addons/variants/phoenix/web/core_js.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.CoreJS do
edit_files(project)
end

defp edit_files(%Project{} = project) do
project
|> edit_package_json()
|> edit_app_js()

project
end

def edit_package_json(%Project{} = project) do
Generator.replace_content(
"assets/package.json",
Expand Down Expand Up @@ -47,4 +39,12 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.CoreJS do

project
end

defp edit_files(%Project{} = project) do
project
|> edit_package_json()
|> edit_app_js()

project
end
end
28 changes: 14 additions & 14 deletions lib/nimble_template/addons/variants/phoenix/web/es_lint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsLint do
|> copy_files()
end

def edit_app_js(%Project{live_project?: true} = project) do
update_topbar_js_variables()

project
end

def edit_app_js(%Project{web_project?: true} = project) do
update_topbar_js_variables()

project
end

def edit_app_js(project), do: project

defp edit_files(%Project{} = project) do
project
|> edit_assets_package()
Expand Down Expand Up @@ -80,20 +94,6 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsLint do
project
end

def edit_app_js(%Project{live_project?: true} = project) do
update_topbar_js_variables()

project
end

def edit_app_js(%Project{web_project?: true} = project) do
update_topbar_js_variables()

project
end

def edit_app_js(project), do: project

defp update_topbar_js_variables do
Generator.replace_content(
"assets/js/app.js",
Expand Down
49 changes: 28 additions & 21 deletions lib/nimble_template/addons/variants/phoenix/web/wallaby.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,45 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Wallaby do

use NimbleTemplate.Addons.Addon

alias NimbleTemplate.Addons.Phoenix.ExVCR

@impl true
def do_apply(%Project{} = project, _opts) do
project
|> copy_files()
|> edit_files()
end

def edit_endpoint(%Project{otp_app: otp_app} = project) do
Generator.replace_content(
"lib/#{otp_app}_web/endpoint.ex",
"""
use Phoenix.Endpoint, otp_app: :#{otp_app}
""",
"""
use Phoenix.Endpoint, otp_app: :#{otp_app}
if Application.compile_env(:#{otp_app}, :sql_sandbox) do
plug Phoenix.Ecto.SQL.Sandbox
end
"""
)

project
end

defp copy_files(
%Project{web_module: web_module, base_module: base_module, web_test_path: web_test_path} =
project
%Project{
web_module: web_module,
base_module: base_module,
web_test_path: web_test_path,
installed_addons: installed_addons
} = project
) do
binding = [
web_module: web_module,
base_module: base_module
base_module: base_module,
with_ex_vcr?: ExVCR in installed_addons
]

files = [
Expand Down Expand Up @@ -69,24 +94,6 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Wallaby do
project
end

def edit_endpoint(%Project{otp_app: otp_app} = project) do
Generator.replace_content(
"lib/#{otp_app}_web/endpoint.ex",
"""
use Phoenix.Endpoint, otp_app: :#{otp_app}
""",
"""
use Phoenix.Endpoint, otp_app: :#{otp_app}
if Application.get_env(:#{otp_app}, :sql_sandbox) do
plug Phoenix.Ecto.SQL.Sandbox
end
"""
)

project
end

defp edit_test_config(%Project{otp_app: otp_app} = project) do
Generator.replace_content(
"config/test.exs",
Expand Down
10 changes: 10 additions & 0 deletions lib/nimble_template/helpers/project.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule NimbleTemplate.ProjectHelper do
alias NimbleTemplate.Projects.Project

def append_installed_addon(
%Project{installed_addons: existing_installed_addons} = project,
new_addon_module_name
) do
Map.put(project, :installed_addons, [new_addon_module_name | existing_installed_addons])
end
end
10 changes: 6 additions & 4 deletions lib/nimble_template/projects/project.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ defmodule NimbleTemplate.Projects.Project do
@moduledoc false

@alpine_version "3.14.6"
@elixir_version "1.13.4"
@erlang_version "25.0.1"
@elixir_version "1.14.0"
@erlang_version "25.0.4"
@node_asdf_version "16.15.0"

defstruct base_module: nil,
Expand All @@ -23,7 +23,8 @@ defmodule NimbleTemplate.Projects.Project do
api_project?: false,
live_project?: false,
web_project?: false,
mix_project?: false
mix_project?: false,
installed_addons: []

def new(opts \\ %{}) do
%__MODULE__{
Expand All @@ -38,7 +39,8 @@ defmodule NimbleTemplate.Projects.Project do
web_project?: web_project?(opts),
live_project?: live_project?(opts),
mix_project?: mix_project?(opts),
elixir_asdf_version: "#{@elixir_version}-otp-#{get_otp_major_version(@erlang_version)}"
elixir_asdf_version: "#{@elixir_version}-otp-#{get_otp_major_version(@erlang_version)}",
installed_addons: []
}
end

Expand Down
Loading

0 comments on commit e5545fc

Please sign in to comment.