From ca853c2a51cf361b296542fed6fd2fd51bf88f06 Mon Sep 17 00:00:00 2001 From: Micky Jittjana Date: Wed, 16 Nov 2022 16:27:50 +0700 Subject: [PATCH 01/43] [#291] Display install prompt before applying addons --- lib/nimble_template/helpers/addon.ex | 19 +++++- lib/nimble_template/helpers/project.ex | 14 ++++ lib/nimble_template/projects/project.ex | 3 +- lib/nimble_template/templates/template.ex | 8 ++- .../templates/variants/mix/template.ex | 8 ++- .../templates/variants/phoenix/template.ex | 19 +++++- .../variants/phoenix/web/template.ex | 65 +++++++++---------- 7 files changed, 91 insertions(+), 45 deletions(-) diff --git a/lib/nimble_template/helpers/addon.ex b/lib/nimble_template/helpers/addon.ex index be699552..cb2cdeb8 100644 --- a/lib/nimble_template/helpers/addon.ex +++ b/lib/nimble_template/helpers/addon.ex @@ -1,4 +1,19 @@ defmodule NimbleTemplate.AddonHelper do - def install_addon_prompt?(addon), - do: Mix.shell().yes?("\nWould you like to add the #{addon} addon?") + alias NimbleTemplate.ProjectHelper + + def install_addon_prompt(project, addon, addon_label \\ nil) do + if Mix.shell().yes?( + "\nWould you like to add the #{build_addon_label(addon, addon_label)} addon?" + ) do + ProjectHelper.append_addon(project, addon) + end + end + + defp build_addon_label(addon, nil) do + addon + |> Module.split() + |> List.last() + end + + defp build_addon_label(_, addon_label), do: addon_label end diff --git a/lib/nimble_template/helpers/project.ex b/lib/nimble_template/helpers/project.ex index 756d91fe..dab6d776 100644 --- a/lib/nimble_template/helpers/project.ex +++ b/lib/nimble_template/helpers/project.ex @@ -7,4 +7,18 @@ defmodule NimbleTemplate.ProjectHelper do ) do Map.put(project, :installed_addons, [new_addon_module_name | existing_installed_addons]) end + + def append_addon( + %Project{addons: existing_addons} = project, + addon_module + ) do + Map.put(project, :addons, existing_addons ++ [addon_module]) + end + + def append_addons( + %Project{addons: existing_addons} = project, + addon_modules + ) do + Map.put(project, :addons, existing_addons ++ addon_modules) + end end diff --git a/lib/nimble_template/projects/project.ex b/lib/nimble_template/projects/project.ex index 1fac9dc4..0d77370c 100644 --- a/lib/nimble_template/projects/project.ex +++ b/lib/nimble_template/projects/project.ex @@ -24,7 +24,8 @@ defmodule NimbleTemplate.Projects.Project do live_project?: false, web_project?: false, mix_project?: false, - installed_addons: [] + installed_addons: [], + addons: [] @type t :: %__MODULE__{ base_module: String.t() | nil, diff --git a/lib/nimble_template/templates/template.ex b/lib/nimble_template/templates/template.ex index 42771cc2..60515170 100644 --- a/lib/nimble_template/templates/template.ex +++ b/lib/nimble_template/templates/template.ex @@ -9,7 +9,9 @@ defmodule NimbleTemplate.Templates.Template do alias NimbleTemplate.Templates.Phoenix.Template, as: PhoenixTemplate def apply(%Project{mix_project?: true} = project) do - MixTemplate.apply(project) + project + |> MixTemplate.pre_apply() + |> MixTemplate.apply() ExUnit.apply(project) @@ -17,7 +19,9 @@ defmodule NimbleTemplate.Templates.Template do end def apply(%Project{mix_project?: false} = project) do - PhoenixTemplate.apply(project) + project + |> PhoenixTemplate.pre_apply() + |> PhoenixTemplate.apply() ExUnit.apply(project) diff --git a/lib/nimble_template/templates/variants/mix/template.ex b/lib/nimble_template/templates/variants/mix/template.ex index 25bda993..78025705 100644 --- a/lib/nimble_template/templates/variants/mix/template.ex +++ b/lib/nimble_template/templates/variants/mix/template.ex @@ -6,6 +6,10 @@ defmodule NimbleTemplate.Templates.Mix.Template do alias NimbleTemplate.Addons alias NimbleTemplate.Projects.Project + def pre_apply(%Project{} = project) do + install_addon_prompt(project, Addons.Mimic) + end + def apply(%Project{} = project) do project |> apply_default_mix_addons() @@ -26,7 +30,7 @@ defmodule NimbleTemplate.Templates.Mix.Template do |> Addons.Iex.apply() end - defp apply_optional_mix_addons(project) do + defp apply_optional_mix_addons(%Project{addons: addons} = project) do if host_on_github?() do if generate_github_template?(), do: Addons.Github.apply(project, %{github_template: true}) @@ -51,7 +55,7 @@ defmodule NimbleTemplate.Templates.Mix.Template do }) end - if install_addon_prompt?("Mimic"), do: Addons.Mimic.apply(project) + if Addons.Mimic in addons, do: Addons.Mimic.apply(project) project end diff --git a/lib/nimble_template/templates/variants/phoenix/template.ex b/lib/nimble_template/templates/variants/phoenix/template.ex index d7224849..74353da2 100644 --- a/lib/nimble_template/templates/variants/phoenix/template.ex +++ b/lib/nimble_template/templates/variants/phoenix/template.ex @@ -10,12 +10,25 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do alias NimbleTemplate.Templates.Phoenix.Live.Template, as: LiveTemplate alias NimbleTemplate.Templates.Phoenix.Web.Template, as: WebTemplate + def pre_apply(%Project{} = project) do + project + |> install_addon_prompt(PhoenixAddons.Oban) + |> install_addon_prompt(PhoenixAddons.ExVCR) + |> pre_apply_variant_prompt() + end + def apply(%Project{} = project) do project |> apply_phoenix_common_setup() |> apply_phoenix_variant_setup() end + defp pre_apply_variant_prompt(%Project{web_project?: true} = project) do + WebTemplate.pre_apply(project) + end + + defp pre_apply_variant_prompt(project), do: project + # credo:disable-for-next-line Credo.Check.Refactor.ABCSize defp apply_phoenix_common_setup(%Project{} = project) do # TODO: Remove me after the Phoenix generator fix releases: https://github.com/phoenixframework/phoenix/pull/4894 @@ -71,9 +84,9 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do project end - defp apply_optional_phoenix_addons(project) do - if install_addon_prompt?("Oban"), do: PhoenixAddons.Oban.apply(project) - if install_addon_prompt?("ExVCR"), do: PhoenixAddons.ExVCR.apply(project) + defp apply_optional_phoenix_addons(%Project{addons: addons} = project) do + if PhoenixAddons.Oban in addons, do: PhoenixAddons.Oban.apply(project) + if PhoenixAddons.ExVCR in addons, do: PhoenixAddons.ExVCR.apply(project) project end diff --git a/lib/nimble_template/templates/variants/phoenix/web/template.ex b/lib/nimble_template/templates/variants/phoenix/web/template.ex index b7242ebf..cffa7cce 100644 --- a/lib/nimble_template/templates/variants/phoenix/web/template.ex +++ b/lib/nimble_template/templates/variants/phoenix/web/template.ex @@ -6,12 +6,30 @@ defmodule NimbleTemplate.Templates.Phoenix.Web.Template do alias NimbleTemplate.Addons.Phoenix.Web alias NimbleTemplate.Projects.Project + def pre_apply(%Project{} = project) do + project + |> install_addon_prompt(Web.SvgSprite, "SVG Sprite") + |> install_addon_prompt(Web.DartSass, "Dart Sass") + |> dart_sass_additional_addons_prompt() + |> install_addon_prompt(Web.NimbleJS, "Nimble JS") + end + def apply(%Project{} = project) do project |> apply_default_web_addons() |> apply_optional_web_addons() end + defp dart_sass_additional_addons_prompt(%Project{addons: addons} = project) do + if Web.DartSass in addons do + project + |> install_addon_prompt(Web.NimbleCSS, "Nimble CSS") + |> install_addon_prompt(Web.Bootstrap) + else + project + end + end + defp apply_default_web_addons(project) do project |> Web.NodePackage.apply() @@ -27,45 +45,22 @@ defmodule NimbleTemplate.Templates.Phoenix.Web.Template do |> Web.HeexFormatter.apply() end - defp apply_optional_web_addons(project) do - if install_addon_prompt?("SVG Sprite"), do: Web.SvgSprite.apply(project) - - if install_addon_prompt?("Dart Sass") do - Web.DartSass.apply(project) + defp apply_optional_web_addons(%Project{addons: addons} = project) do + with_nimble_css_addon? = NimbleCSS in addons + with_nimble_js_addon? = NimbleJS in addons - apply_dart_sass_requires_addons(project) - else - if install_addon_prompt?("Nimble JS"), do: Web.NimbleJS.apply(project) - end + if Web.SvgSprite in addons, do: Web.SvgSprite.apply(project) + if Web.DartSass in addons, do: Web.DartSass.apply(project) + if with_nimble_css_addon?, do: Web.NimbleCSS.apply(project) + if with_nimble_js_addon?, do: Web.NimbleJS.apply(project) - project - end - - # These addons depend on the DartSass - defp apply_dart_sass_requires_addons(project) do - with_nimble_css_addon = - if install_addon_prompt?("Nimble CSS") do - Web.NimbleCSS.apply(project) - - true - else - false - end - - with_nimble_js_addon = - if install_addon_prompt?("Nimble JS") do - Web.NimbleJS.apply(project) - - true - else - false - end - - if install_addon_prompt?("Bootstrap"), + if Web.Bootstrap in addons, do: Web.Bootstrap.apply(project, %{ - with_nimble_css_addon: with_nimble_css_addon, - with_nimble_js_addon: with_nimble_js_addon + with_nimble_css_addon: with_nimble_css_addon?, + with_nimble_js_addon: with_nimble_js_addon? }) + + project end end From c929489ec17bdb589c66733b9cec9a22efbbe5c3 Mon Sep 17 00:00:00 2001 From: Micky Jittjana Date: Wed, 16 Nov 2022 16:41:35 +0700 Subject: [PATCH 02/43] [#291] Fix nimble addon prompt --- lib/nimble_template/helpers/addon.ex | 4 ++-- lib/nimble_template/helpers/project.ex | 11 ++--------- .../templates/variants/phoenix/web/template.ex | 4 ++-- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/nimble_template/helpers/addon.ex b/lib/nimble_template/helpers/addon.ex index cb2cdeb8..07f7f2da 100644 --- a/lib/nimble_template/helpers/addon.ex +++ b/lib/nimble_template/helpers/addon.ex @@ -5,7 +5,7 @@ defmodule NimbleTemplate.AddonHelper do if Mix.shell().yes?( "\nWould you like to add the #{build_addon_label(addon, addon_label)} addon?" ) do - ProjectHelper.append_addon(project, addon) + ProjectHelper.prepend_addon(project, addon) end end @@ -15,5 +15,5 @@ defmodule NimbleTemplate.AddonHelper do |> List.last() end - defp build_addon_label(_, addon_label), do: addon_label + defp build_addon_label(_addon, addon_label), do: addon_label end diff --git a/lib/nimble_template/helpers/project.ex b/lib/nimble_template/helpers/project.ex index dab6d776..4e1f333a 100644 --- a/lib/nimble_template/helpers/project.ex +++ b/lib/nimble_template/helpers/project.ex @@ -8,17 +8,10 @@ defmodule NimbleTemplate.ProjectHelper do Map.put(project, :installed_addons, [new_addon_module_name | existing_installed_addons]) end - def append_addon( + def prepend_addon( %Project{addons: existing_addons} = project, addon_module ) do - Map.put(project, :addons, existing_addons ++ [addon_module]) - end - - def append_addons( - %Project{addons: existing_addons} = project, - addon_modules - ) do - Map.put(project, :addons, existing_addons ++ addon_modules) + Map.put(project, :addons, [addon_module | existing_addons]) end end diff --git a/lib/nimble_template/templates/variants/phoenix/web/template.ex b/lib/nimble_template/templates/variants/phoenix/web/template.ex index cffa7cce..bd2aabee 100644 --- a/lib/nimble_template/templates/variants/phoenix/web/template.ex +++ b/lib/nimble_template/templates/variants/phoenix/web/template.ex @@ -46,8 +46,8 @@ defmodule NimbleTemplate.Templates.Phoenix.Web.Template do end defp apply_optional_web_addons(%Project{addons: addons} = project) do - with_nimble_css_addon? = NimbleCSS in addons - with_nimble_js_addon? = NimbleJS in addons + with_nimble_css_addon? = Web.NimbleCSS in addons + with_nimble_js_addon? = Web.NimbleJS in addons if Web.SvgSprite in addons, do: Web.SvgSprite.apply(project) if Web.DartSass in addons, do: Web.DartSass.apply(project) From 4b1358e1e91439b58378eb9da48fa0087458f172 Mon Sep 17 00:00:00 2001 From: Micky Jittjana Date: Wed, 16 Nov 2022 17:57:06 +0700 Subject: [PATCH 03/43] [#291] Code refactoring --- lib/nimble_template/addons/addon.ex | 4 +--- .../addons/variants/phoenix/web/wallaby.ex | 4 ++-- lib/nimble_template/helpers/addon.ex | 7 +++++-- lib/nimble_template/helpers/project.ex | 17 ----------------- lib/nimble_template/projects/project.ex | 15 +++++++++++---- .../templates/variants/mix/template.ex | 4 ++-- .../templates/variants/phoenix/template.ex | 6 +++--- .../templates/variants/phoenix/web/template.ex | 16 ++++++++-------- .../addons/asdf_tool_version_test.exs | 11 ----------- .../variants/phoenix/web/wallaby_test.exs | 4 +++- 10 files changed, 35 insertions(+), 53 deletions(-) delete mode 100644 lib/nimble_template/helpers/project.ex diff --git a/lib/nimble_template/addons/addon.ex b/lib/nimble_template/addons/addon.ex index 629175ca..2be52399 100644 --- a/lib/nimble_template/addons/addon.ex +++ b/lib/nimble_template/addons/addon.ex @@ -21,9 +21,7 @@ defmodule NimbleTemplate.Addons.Addon do def apply(%Project{} = project, opts \\ %{}) when is_map(opts) do Generator.print_log("* applying ", inspect(__MODULE__)) - project - |> do_apply(opts) - |> ProjectHelper.append_installed_addon(__MODULE__) + do_apply(project, opts) end def do_apply(%Project{} = project, opts) when is_map(opts), do: project diff --git a/lib/nimble_template/addons/variants/phoenix/web/wallaby.ex b/lib/nimble_template/addons/variants/phoenix/web/wallaby.ex index c63fa41e..487697c1 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/wallaby.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/wallaby.ex @@ -35,13 +35,13 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Wallaby do web_module: web_module, base_module: base_module, web_test_path: web_test_path, - installed_addons: installed_addons + optional_addons: optional_addons } = project ) do binding = [ web_module: web_module, base_module: base_module, - with_ex_vcr?: ExVCR in installed_addons + with_ex_vcr?: ExVCR in optional_addons ] files = [ diff --git a/lib/nimble_template/helpers/addon.ex b/lib/nimble_template/helpers/addon.ex index 07f7f2da..2e1cc324 100644 --- a/lib/nimble_template/helpers/addon.ex +++ b/lib/nimble_template/helpers/addon.ex @@ -1,11 +1,14 @@ defmodule NimbleTemplate.AddonHelper do - alias NimbleTemplate.ProjectHelper + alias NimbleTemplate.Projects.Project + @spec install_addon_prompt(Project.t(), atom(), String.t() | nil) :: Project.t() def install_addon_prompt(project, addon, addon_label \\ nil) do if Mix.shell().yes?( "\nWould you like to add the #{build_addon_label(addon, addon_label)} addon?" ) do - ProjectHelper.prepend_addon(project, addon) + Project.prepend_optional_addon(project, addon) + else + project end end diff --git a/lib/nimble_template/helpers/project.ex b/lib/nimble_template/helpers/project.ex deleted file mode 100644 index 4e1f333a..00000000 --- a/lib/nimble_template/helpers/project.ex +++ /dev/null @@ -1,17 +0,0 @@ -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 - - def prepend_addon( - %Project{addons: existing_addons} = project, - addon_module - ) do - Map.put(project, :addons, [addon_module | existing_addons]) - end -end diff --git a/lib/nimble_template/projects/project.ex b/lib/nimble_template/projects/project.ex index 0d77370c..7fb6f813 100644 --- a/lib/nimble_template/projects/project.ex +++ b/lib/nimble_template/projects/project.ex @@ -24,8 +24,7 @@ defmodule NimbleTemplate.Projects.Project do live_project?: false, web_project?: false, mix_project?: false, - installed_addons: [], - addons: [] + optional_addons: [] @type t :: %__MODULE__{ base_module: String.t() | nil, @@ -44,7 +43,7 @@ defmodule NimbleTemplate.Projects.Project do live_project?: boolean(), web_project?: boolean(), mix_project?: boolean(), - installed_addons: list(atom()) + optional_addons: list(atom()) } @spec new(map()) :: __MODULE__.t() @@ -56,7 +55,7 @@ defmodule NimbleTemplate.Projects.Project do live_project?: live_project?(opts), mix_project?: mix_project?(opts), elixir_asdf_version: "#{@elixir_version}-otp-#{get_otp_major_version(@erlang_version)}", - installed_addons: [] + optional_addons: [] } |> init_base_module_fields() |> maybe_init_web_fields() @@ -81,6 +80,14 @@ defmodule NimbleTemplate.Projects.Project do |> List.first() end + @spec prepend_optional_addon(__MODULE__.t(), atom()) :: __MODULE__.t() + def prepend_optional_addon( + %__MODULE__{optional_addons: existing_addons} = project, + addon_module + ) do + Map.put(project, :optional_addons, [addon_module | existing_addons]) + end + defp api_project?(opts), do: opts[:api] === true defp web_project?(opts), do: opts[:web] === true || opts[:live] === true diff --git a/lib/nimble_template/templates/variants/mix/template.ex b/lib/nimble_template/templates/variants/mix/template.ex index 78025705..520f6672 100644 --- a/lib/nimble_template/templates/variants/mix/template.ex +++ b/lib/nimble_template/templates/variants/mix/template.ex @@ -30,7 +30,7 @@ defmodule NimbleTemplate.Templates.Mix.Template do |> Addons.Iex.apply() end - defp apply_optional_mix_addons(%Project{addons: addons} = project) do + defp apply_optional_mix_addons(%Project{optional_addons: optional_addons} = project) do if host_on_github?() do if generate_github_template?(), do: Addons.Github.apply(project, %{github_template: true}) @@ -55,7 +55,7 @@ defmodule NimbleTemplate.Templates.Mix.Template do }) end - if Addons.Mimic in addons, do: Addons.Mimic.apply(project) + if Addons.Mimic in optional_addons, do: Addons.Mimic.apply(project) project end diff --git a/lib/nimble_template/templates/variants/phoenix/template.ex b/lib/nimble_template/templates/variants/phoenix/template.ex index 74353da2..cd6df8a1 100644 --- a/lib/nimble_template/templates/variants/phoenix/template.ex +++ b/lib/nimble_template/templates/variants/phoenix/template.ex @@ -84,9 +84,9 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do project end - defp apply_optional_phoenix_addons(%Project{addons: addons} = project) do - if PhoenixAddons.Oban in addons, do: PhoenixAddons.Oban.apply(project) - if PhoenixAddons.ExVCR in addons, do: PhoenixAddons.ExVCR.apply(project) + defp apply_optional_phoenix_addons(%Project{optional_addons: optional_addons} = project) do + if PhoenixAddons.Oban in optional_addons, do: PhoenixAddons.Oban.apply(project) + if PhoenixAddons.ExVCR in optional_addons, do: PhoenixAddons.ExVCR.apply(project) project end diff --git a/lib/nimble_template/templates/variants/phoenix/web/template.ex b/lib/nimble_template/templates/variants/phoenix/web/template.ex index bd2aabee..b1bb4433 100644 --- a/lib/nimble_template/templates/variants/phoenix/web/template.ex +++ b/lib/nimble_template/templates/variants/phoenix/web/template.ex @@ -20,8 +20,8 @@ defmodule NimbleTemplate.Templates.Phoenix.Web.Template do |> apply_optional_web_addons() end - defp dart_sass_additional_addons_prompt(%Project{addons: addons} = project) do - if Web.DartSass in addons do + defp dart_sass_additional_addons_prompt(%Project{optional_addons: optional_addons} = project) do + if Web.DartSass in optional_addons do project |> install_addon_prompt(Web.NimbleCSS, "Nimble CSS") |> install_addon_prompt(Web.Bootstrap) @@ -45,16 +45,16 @@ defmodule NimbleTemplate.Templates.Phoenix.Web.Template do |> Web.HeexFormatter.apply() end - defp apply_optional_web_addons(%Project{addons: addons} = project) do - with_nimble_css_addon? = Web.NimbleCSS in addons - with_nimble_js_addon? = Web.NimbleJS in addons + defp apply_optional_web_addons(%Project{optional_addons: optional_addons} = project) do + with_nimble_css_addon? = Web.NimbleCSS in optional_addons + with_nimble_js_addon? = Web.NimbleJS in optional_addons - if Web.SvgSprite in addons, do: Web.SvgSprite.apply(project) - if Web.DartSass in addons, do: Web.DartSass.apply(project) + if Web.SvgSprite in optional_addons, do: Web.SvgSprite.apply(project) + if Web.DartSass in optional_addons, do: Web.DartSass.apply(project) if with_nimble_css_addon?, do: Web.NimbleCSS.apply(project) if with_nimble_js_addon?, do: Web.NimbleJS.apply(project) - if Web.Bootstrap in addons, + if Web.Bootstrap in optional_addons, do: Web.Bootstrap.apply(project, %{ with_nimble_css_addon: with_nimble_css_addon?, diff --git a/test/nimble_template/addons/asdf_tool_version_test.exs b/test/nimble_template/addons/asdf_tool_version_test.exs index eb996779..291f80dd 100644 --- a/test/nimble_template/addons/asdf_tool_version_test.exs +++ b/test/nimble_template/addons/asdf_tool_version_test.exs @@ -21,17 +21,6 @@ defmodule NimbleTemplate.Addons.AsdfToolVersionTest do end) end) end - - test "appends NimbleTemplate.Addons.AsdfToolVersion to project installed_addons list", %{ - project: project, - test_project_path: test_project_path - } do - in_test_project(test_project_path, fn -> - %Project{installed_addons: installed_addons} = Addons.AsdfToolVersion.apply(project) - - assert AsdfToolVersion in installed_addons == true - end) - end end describe "#apply/2 with api_project" do diff --git a/test/nimble_template/addons/variants/phoenix/web/wallaby_test.exs b/test/nimble_template/addons/variants/phoenix/web/wallaby_test.exs index 5c5923d3..9ed29c22 100644 --- a/test/nimble_template/addons/variants/phoenix/web/wallaby_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/wallaby_test.exs @@ -1,6 +1,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.WallabyTest do use NimbleTemplate.AddonCase, async: false + alias NimbleTemplate.Projects.Project + describe "#apply/2" do @describetag mock_latest_package_versions: [{:wallaby, "0.26.2"}] @@ -44,7 +46,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.WallabyTest do test_project_path: test_project_path } do in_test_project(test_project_path, fn -> - project = ProjectHelper.append_installed_addon(project, NimbleTemplate.Addons.Phoenix.ExVCR) + project = Project.prepend_optional_addon(project, NimbleTemplate.Addons.Phoenix.ExVCR) WebAddons.Wallaby.apply(project) From 970603fbd388dd773fab641bf788bc39de5dfbe7 Mon Sep 17 00:00:00 2001 From: Micky Jittjana Date: Wed, 16 Nov 2022 19:02:28 +0700 Subject: [PATCH 04/43] [#291] Add tests --- .../addons/asdf_tool_version_test.exs | 7 +-- test/nimble_template/helpers/addon_test.exs | 60 +++++++++++++++++++ .../nimble_template/projects/project_test.exs | 13 +++- 3 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 test/nimble_template/helpers/addon_test.exs diff --git a/test/nimble_template/addons/asdf_tool_version_test.exs b/test/nimble_template/addons/asdf_tool_version_test.exs index 291f80dd..470088bc 100644 --- a/test/nimble_template/addons/asdf_tool_version_test.exs +++ b/test/nimble_template/addons/asdf_tool_version_test.exs @@ -2,7 +2,6 @@ defmodule NimbleTemplate.Addons.AsdfToolVersionTest do use NimbleTemplate.AddonCase, async: false alias NimbleTemplate.Addons.AsdfToolVersion - alias NimbleTemplate.Projects.Project describe "#apply/2 with web_project" do test "copies the .tool-versions", %{ @@ -10,7 +9,7 @@ defmodule NimbleTemplate.Addons.AsdfToolVersionTest do test_project_path: test_project_path } do in_test_project(test_project_path, fn -> - Addons.AsdfToolVersion.apply(project) + AsdfToolVersion.apply(project) assert_file(".tool-versions", fn file -> assert file =~ """ @@ -31,7 +30,7 @@ defmodule NimbleTemplate.Addons.AsdfToolVersionTest do project = %{project | api_project?: true, web_project?: false} in_test_project(test_project_path, fn -> - Addons.AsdfToolVersion.apply(project) + AsdfToolVersion.apply(project) assert_file(".tool-versions", fn file -> assert file =~ """ @@ -53,7 +52,7 @@ defmodule NimbleTemplate.Addons.AsdfToolVersionTest do test_project_path: test_project_path } do in_test_project(test_project_path, fn -> - Addons.AsdfToolVersion.apply(project) + AsdfToolVersion.apply(project) assert_file(".tool-versions", fn file -> assert file =~ """ diff --git a/test/nimble_template/helpers/addon_test.exs b/test/nimble_template/helpers/addon_test.exs new file mode 100644 index 00000000..ca16f35b --- /dev/null +++ b/test/nimble_template/helpers/addon_test.exs @@ -0,0 +1,60 @@ +defmodule NimbleTemplate.AddonTest do + use NimbleTemplate.AddonCase, async: false + + import ExUnit.CaptureIO + + alias NimbleTemplate.AddonHelper + alias NimbleTemplate.Projects.Project + + describe "install_addon_prompt/3" do + test "when response prompt with 'Y', prepends the addon to the project", %{project: project} do + display_prompt = + capture_io([input: "Y\n"], fn -> + project = + project + |> Project.prepend_optional_addon(NimbleTemplate.Addons.FirstAddon) + |> AddonHelper.install_addon_prompt(NimbleTemplate.Addons.SecondAddon) + + assert project.optional_addons == [ + NimbleTemplate.Addons.SecondAddon, + NimbleTemplate.Addons.FirstAddon + ] + end) + + assert display_prompt =~ "Would you like to add the SecondAddon addon? [Yn]" + end + + test "when response prompt with 'N', does not prepend the addon to the project", %{ + project: project + } do + display_prompt = + capture_io([input: "N\n"], fn -> + project = + project + |> Project.prepend_optional_addon(NimbleTemplate.Addons.FirstAddon) + |> AddonHelper.install_addon_prompt(NimbleTemplate.Addons.SecondAddon) + + assert project.optional_addons == [ + NimbleTemplate.Addons.FirstAddon + ] + end) + + assert display_prompt =~ "Would you like to add the SecondAddon addon? [Yn]" + end + + test "given addon label, shows prompts with the given label", %{ + project: project + } do + display_prompt = + capture_io(fn -> + AddonHelper.install_addon_prompt( + project, + NimbleTemplate.Addons.FirstAddon, + "Custom addon name" + ) + end) + + assert display_prompt =~ "Would you like to add the Custom addon name addon? [Yn]" + end + end +end diff --git a/test/nimble_template/projects/project_test.exs b/test/nimble_template/projects/project_test.exs index d27190a8..1765b892 100644 --- a/test/nimble_template/projects/project_test.exs +++ b/test/nimble_template/projects/project_test.exs @@ -3,7 +3,7 @@ defmodule NimbleTemplate.Projects.ProjectTest do alias NimbleTemplate.Projects.Project - describe "#new/1" do + describe "new/1" do @tag mix_project?: true test "given mix project, returns project without web modules and paths", %{ test_project_path: test_project_path @@ -164,4 +164,15 @@ defmodule NimbleTemplate.Projects.ProjectTest do end) end end + + describe "prepend_optional_addon/2" do + test "prepends the given addon to the project" do + project = + Project.new() + |> Project.prepend_optional_addon(FirstAddon) + |> Project.prepend_optional_addon(SecondAddon) + + assert project.optional_addons == [SecondAddon, FirstAddon] + end + end end From b6c78a2f905c42e76f0e2de3ad9f87203453044f Mon Sep 17 00:00:00 2001 From: Micky Jittjana Date: Thu, 17 Nov 2022 12:53:10 +0700 Subject: [PATCH 05/43] [#291] Minor module refactor --- .../templates/variants/phoenix/template.ex | 17 +++++++++++++++- .../variants/phoenix/web/template.ex | 20 ------------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/lib/nimble_template/templates/variants/phoenix/template.ex b/lib/nimble_template/templates/variants/phoenix/template.ex index cd6df8a1..59630e79 100644 --- a/lib/nimble_template/templates/variants/phoenix/template.ex +++ b/lib/nimble_template/templates/variants/phoenix/template.ex @@ -5,6 +5,7 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do alias NimbleTemplate.{Addons, Generator} alias NimbleTemplate.Addons.Phoenix, as: PhoenixAddons + alias NimbleTemplate.Addons.Phoenix.Web, as: WebAddons alias NimbleTemplate.Projects.Project alias NimbleTemplate.Templates.Phoenix.Api.Template, as: ApiTemplate alias NimbleTemplate.Templates.Phoenix.Live.Template, as: LiveTemplate @@ -24,11 +25,25 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do end defp pre_apply_variant_prompt(%Project{web_project?: true} = project) do - WebTemplate.pre_apply(project) + project + |> install_addon_prompt(WebAddons.SvgSprite, "SVG Sprite") + |> install_addon_prompt(WebAddons.DartSass, "Dart Sass") + |> dart_sass_additional_addons_prompt() + |> install_addon_prompt(WebAddons.NimbleJS, "Nimble JS") end defp pre_apply_variant_prompt(project), do: project + defp dart_sass_additional_addons_prompt(%Project{optional_addons: optional_addons} = project) do + if WebAddons.DartSass in optional_addons do + project + |> install_addon_prompt(WebAddons.NimbleCSS, "Nimble CSS") + |> install_addon_prompt(WebAddons.Bootstrap) + else + project + end + end + # credo:disable-for-next-line Credo.Check.Refactor.ABCSize defp apply_phoenix_common_setup(%Project{} = project) do # TODO: Remove me after the Phoenix generator fix releases: https://github.com/phoenixframework/phoenix/pull/4894 diff --git a/lib/nimble_template/templates/variants/phoenix/web/template.ex b/lib/nimble_template/templates/variants/phoenix/web/template.ex index b1bb4433..b1208989 100644 --- a/lib/nimble_template/templates/variants/phoenix/web/template.ex +++ b/lib/nimble_template/templates/variants/phoenix/web/template.ex @@ -1,35 +1,15 @@ defmodule NimbleTemplate.Templates.Phoenix.Web.Template do @moduledoc false - import NimbleTemplate.AddonHelper - alias NimbleTemplate.Addons.Phoenix.Web alias NimbleTemplate.Projects.Project - def pre_apply(%Project{} = project) do - project - |> install_addon_prompt(Web.SvgSprite, "SVG Sprite") - |> install_addon_prompt(Web.DartSass, "Dart Sass") - |> dart_sass_additional_addons_prompt() - |> install_addon_prompt(Web.NimbleJS, "Nimble JS") - end - def apply(%Project{} = project) do project |> apply_default_web_addons() |> apply_optional_web_addons() end - defp dart_sass_additional_addons_prompt(%Project{optional_addons: optional_addons} = project) do - if Web.DartSass in optional_addons do - project - |> install_addon_prompt(Web.NimbleCSS, "Nimble CSS") - |> install_addon_prompt(Web.Bootstrap) - else - project - end - end - defp apply_default_web_addons(project) do project |> Web.NodePackage.apply() From 46f9cd810c10e673221fd9d4ed1043d6d923da7e Mon Sep 17 00:00:00 2001 From: Micky Jittjana Date: Thu, 17 Nov 2022 17:03:02 +0700 Subject: [PATCH 06/43] Temporary suppress log --- lib/nimble_template/helpers/generator.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/nimble_template/helpers/generator.ex b/lib/nimble_template/helpers/generator.ex index e0b1cd0f..e59a18ea 100644 --- a/lib/nimble_template/helpers/generator.ex +++ b/lib/nimble_template/helpers/generator.ex @@ -148,7 +148,9 @@ defmodule NimbleTemplate.Generator do end end - def print_log(prefix, content \\ ""), do: Mix.shell().info([:green, prefix, :reset, content]) + def print_log(prefix, content \\ "") do + # Mix.shell().info([:green, prefix, :reset, content]) + end defp split_with_self(contents, text) do case :binary.split(contents, text) do From c18510899d3e73b4d2dbb54803ef5a805276b021 Mon Sep 17 00:00:00 2001 From: Micky Jittjana Date: Fri, 18 Nov 2022 11:16:11 +0700 Subject: [PATCH 07/43] [#293] Refactor VersionTest test logic not to use git --- lib/nimble_template/helpers/generator.ex | 4 +- test/nimble_template/version_test.exs | 270 ++++++++++++----------- test/support/addon_case.ex | 31 +-- test/support/helpers/file_helper.ex | 33 +++ test/support/template_case.ex | 26 +++ 5 files changed, 210 insertions(+), 154 deletions(-) create mode 100644 test/support/helpers/file_helper.ex create mode 100644 test/support/template_case.ex diff --git a/lib/nimble_template/helpers/generator.ex b/lib/nimble_template/helpers/generator.ex index e59a18ea..e0b1cd0f 100644 --- a/lib/nimble_template/helpers/generator.ex +++ b/lib/nimble_template/helpers/generator.ex @@ -148,9 +148,7 @@ defmodule NimbleTemplate.Generator do end end - def print_log(prefix, content \\ "") do - # Mix.shell().info([:green, prefix, :reset, content]) - end + def print_log(prefix, content \\ ""), do: Mix.shell().info([:green, prefix, :reset, content]) defp split_with_self(contents, text) do case :binary.split(contents, text) do diff --git a/test/nimble_template/version_test.exs b/test/nimble_template/version_test.exs index a631404b..58bf571e 100644 --- a/test/nimble_template/version_test.exs +++ b/test/nimble_template/version_test.exs @@ -1,168 +1,190 @@ defmodule NimbleTemplate.VersionTest do - use NimbleTemplate.AddonCase, async: false + use NimbleTemplate.TemplateCase, async: false alias NimbleTemplate.Version - setup do - on_exit(fn -> - Mix.shell().cmd("git checkout .") - end) - end - describe "bump/1" do - test "updates the version in mix.exs and README.md files given a valid version number" do - current_version = Mix.Project.config()[:version] - - patch_number = - current_version - |> String.split(".") - |> List.last() - |> String.to_integer() - - # Increase the patch version to 1 - new_version = - current_version - |> String.split(".") - |> List.replace_at(2, patch_number + 1) - |> Enum.join(".") - - assert Version.bump(new_version) == :ok - - assert_file("mix.exs", fn file -> - assert file =~ "version: \"#{new_version}\"" - refute file =~ "version: \"#{current_version}\"" - end) - - assert_file("README.md", fn file -> - assert file =~ "{:nimble_template, \"~> #{new_version}\", only: :dev, runtime: false}," - refute file =~ "{:nimble_template, \"~> #{current_version}\", only: :dev, runtime: false}," + test "updates the version in mix.exs and README.md files given a valid version number", %{ + test_project_path: test_project_path + } do + in_test_project(test_project_path, fn -> + current_version = Mix.Project.config()[:version] + + patch_number = + current_version + |> String.split(".") + |> List.last() + |> String.to_integer() + + # Increase the patch version to 1 + new_version = + current_version + |> String.split(".") + |> List.replace_at(2, patch_number + 1) + |> Enum.join(".") + + assert Version.bump(new_version) == :ok + + assert_file("mix.exs", fn file -> + assert file =~ "version: \"#{new_version}\"" + refute file =~ "version: \"#{current_version}\"" + end) + + assert_file("README.md", fn file -> + assert file =~ "{:nimble_template, \"~> #{new_version}\", only: :dev, runtime: false}," + + refute file =~ + "{:nimble_template, \"~> #{current_version}\", only: :dev, runtime: false}," + end) end) end - test "raises Mix.Error exception given an invalid version number" do - current_version = Mix.Project.config()[:version] - - major_number = - current_version - |> String.split(".") - |> List.first() - |> String.to_integer() - - # Decrease the major version to 1 - new_version = - current_version - |> String.split(".") - |> List.replace_at(0, major_number - 1) - |> Enum.join(".") - - assert_raise Mix.Error, "The new version must be greater than #{current_version}", fn -> - Version.bump(new_version) - end - - assert_file("mix.exs", fn file -> - assert file =~ "version: \"#{current_version}\"" - refute file =~ "version: \"#{new_version}\"" - end) - - assert_file("README.md", fn file -> - assert file =~ "{:nimble_template, \"~> #{current_version}\", only: :dev, runtime: false}," - refute file =~ "{:nimble_template, \"~> #{new_version}\", only: :dev, runtime: false}," + test "raises Mix.Error exception given an invalid version number", %{ + test_project_path: test_project_path + } do + in_test_project(test_project_path, fn -> + current_version = Mix.Project.config()[:version] + + major_number = + current_version + |> String.split(".") + |> List.first() + |> String.to_integer() + + # Decrease the major version to 1 + new_version = + current_version + |> String.split(".") + |> List.replace_at(0, major_number - 1) + |> Enum.join(".") + + assert_raise Mix.Error, "The new version must be greater than #{current_version}", fn -> + Version.bump(new_version) + end + + assert_file("mix.exs", fn file -> + assert file =~ "version: \"#{current_version}\"" + refute file =~ "version: \"#{new_version}\"" + end) + + assert_file("README.md", fn file -> + assert file =~ + "{:nimble_template, \"~> #{current_version}\", only: :dev, runtime: false}," + + refute file =~ "{:nimble_template, \"~> #{new_version}\", only: :dev, runtime: false}," + end) end) end end describe "upgrade_stack/1" do - test "upgrade elixir version given the new elixir_version" do - assert Version.upgrade_stack(elixir: "a.b.c") == :ok + test "upgrade elixir version given the new elixir_version", %{ + test_project_path: test_project_path + } do + in_test_project(test_project_path, fn -> + assert Version.upgrade_stack(elixir: "a.b.c") == :ok - assert_file("lib/nimble_template/projects/project.ex", fn file -> - assert file =~ "@elixir_version \"a.b.c\"" - end) + assert_file("lib/nimble_template/projects/project.ex", fn file -> + assert file =~ "@elixir_version \"a.b.c\"" + end) - assert_file(".tool-versions", fn file -> - assert file =~ "elixir a.b.c-otp-" - end) + assert_file(".tool-versions", fn file -> + assert file =~ "elixir a.b.c-otp-" + end) - assert_file("test/nimble_template/addons/asdf_tool_version_test.exs", fn file -> - assert file =~ "elixir a.b.c-otp-" - end) + assert_file("test/nimble_template/addons/asdf_tool_version_test.exs", fn file -> + assert file =~ "elixir a.b.c-otp-" + end) - assert_file("test/nimble_template/addons/github_test.exs", fn file -> - assert file =~ "Elixir a.b.c" - end) + assert_file("test/nimble_template/addons/github_test.exs", fn file -> + assert file =~ "Elixir a.b.c" + end) - assert_file("test/nimble_template/addons/readme_test.exs", fn file -> - assert file =~ "Elixir a.b.c" - end) + assert_file("test/nimble_template/addons/readme_test.exs", fn file -> + assert file =~ "Elixir a.b.c" + end) - assert_file("test/nimble_template/addons/variants/docker_test.exs", fn file -> - assert file =~ "ELIXIR_IMAGE_VERSION=a.b.c" + assert_file("test/nimble_template/addons/variants/docker_test.exs", fn file -> + assert file =~ "ELIXIR_IMAGE_VERSION=a.b.c" + end) end) end - test "upgrade erlang version given the new erlang_version" do - assert Version.upgrade_stack(erlang: "x.y.z") == :ok + test "upgrade erlang version given the new erlang_version", %{ + test_project_path: test_project_path + } do + in_test_project(test_project_path, fn -> + assert Version.upgrade_stack(erlang: "x.y.z") == :ok - assert_file("lib/nimble_template/projects/project.ex", fn file -> - assert file =~ "@erlang_version \"x.y.z\"" - end) + assert_file("lib/nimble_template/projects/project.ex", fn file -> + assert file =~ "@erlang_version \"x.y.z\"" + end) - assert_file(".tool-versions", fn file -> - assert file =~ "erlang x.y.z" - assert file =~ "-otp-x" - end) + assert_file(".tool-versions", fn file -> + assert file =~ "erlang x.y.z" + assert file =~ "-otp-x" + end) - assert_file("test/nimble_template/addons/asdf_tool_version_test.exs", fn file -> - assert file =~ "erlang x.y.z" - assert file =~ "-otp-x" - end) + assert_file("test/nimble_template/addons/asdf_tool_version_test.exs", fn file -> + assert file =~ "erlang x.y.z" + assert file =~ "-otp-x" + end) - assert_file("test/nimble_template/addons/github_test.exs", fn file -> - assert file =~ "Erlang x.y.z" - end) + assert_file("test/nimble_template/addons/github_test.exs", fn file -> + assert file =~ "Erlang x.y.z" + end) - assert_file("test/nimble_template/addons/readme_test.exs", fn file -> - assert file =~ "Erlang x.y.z" - end) + assert_file("test/nimble_template/addons/readme_test.exs", fn file -> + assert file =~ "Erlang x.y.z" + end) - assert_file("test/nimble_template/addons/variants/docker_test.exs", fn file -> - assert file =~ "ERLANG_IMAGE_VERSION=x.y.z" + assert_file("test/nimble_template/addons/variants/docker_test.exs", fn file -> + assert file =~ "ERLANG_IMAGE_VERSION=x.y.z" + end) end) end - test "upgrade node version given the new node_version" do - assert Version.upgrade_stack(node: "a.s.d") == :ok + test "upgrade node version given the new node_version", %{ + test_project_path: test_project_path + } do + in_test_project(test_project_path, fn -> + assert Version.upgrade_stack(node: "a.s.d") == :ok - assert_file("lib/nimble_template/projects/project.ex", fn file -> - assert file =~ "@node_asdf_version \"a.s.d\"" - end) + assert_file("lib/nimble_template/projects/project.ex", fn file -> + assert file =~ "@node_asdf_version \"a.s.d\"" + end) - assert_file(".tool-versions", fn file -> - assert file =~ "nodejs a.s.d" - end) + assert_file(".tool-versions", fn file -> + assert file =~ "nodejs a.s.d" + end) - assert_file("test/nimble_template/addons/asdf_tool_version_test.exs", fn file -> - assert file =~ "nodejs a.s.d" - end) + assert_file("test/nimble_template/addons/asdf_tool_version_test.exs", fn file -> + assert file =~ "nodejs a.s.d" + end) - assert_file("test/nimble_template/addons/github_test.exs", fn file -> - assert file =~ "Node a.s.d" - end) + assert_file("test/nimble_template/addons/github_test.exs", fn file -> + assert file =~ "Node a.s.d" + end) - assert_file("test/nimble_template/addons/readme_test.exs", fn file -> - assert file =~ "Node a.s.d" + assert_file("test/nimble_template/addons/readme_test.exs", fn file -> + assert file =~ "Node a.s.d" + end) end) end - test "upgrade alpine version given the new alpine_version" do - assert Version.upgrade_stack(alpine: "z.x.c") == :ok + test "upgrade alpine version given the new alpine_version", %{ + test_project_path: test_project_path + } do + in_test_project(test_project_path, fn -> + assert Version.upgrade_stack(alpine: "z.x.c") == :ok - assert_file("lib/nimble_template/projects/project.ex", fn file -> - assert file =~ "@alpine_version \"z.x.c\"" - end) + assert_file("lib/nimble_template/projects/project.ex", fn file -> + assert file =~ "@alpine_version \"z.x.c\"" + end) - assert_file("test/nimble_template/addons/variants/docker_test.exs", fn file -> - assert file =~ "RELEASE_IMAGE_VERSION=z.x.c" + assert_file("test/nimble_template/addons/variants/docker_test.exs", fn file -> + assert file =~ "RELEASE_IMAGE_VERSION=z.x.c" + end) end) end end diff --git a/test/support/addon_case.ex b/test/support/addon_case.ex index d194d8a6..5c181511 100644 --- a/test/support/addon_case.ex +++ b/test/support/addon_case.ex @@ -8,6 +8,7 @@ defmodule NimbleTemplate.AddonCase do alias NimbleTemplate.Addons.Phoenix.Web, as: WebAddons alias NimbleTemplate.Hex.Package alias NimbleTemplate.Projects.Project + alias NimbleTemplate.Test.FileHelper @default_project_name "nimble_template" @@ -19,28 +20,13 @@ defmodule NimbleTemplate.AddonCase do alias NimbleTemplate.Addons.Phoenix.Web, as: WebAddons alias NimbleTemplate.ProjectHelper - # ATTENTION: File.cd! doesn't support `async: true`, the test will fail randomly in async mode - # https://elixirforum.com/t/randomly-getting-compilationerror-on-tests/17298/3 - defp in_test_project(test_project_path, function), do: File.cd!(test_project_path, function) - - defp assert_file(path), - do: assert(File.regular?(path), "Expected #{path} to exist, but does not") - - defp assert_directory(path), - do: assert(File.dir?(path), "Expected #{path} to exist, but does not") - - defp assert_file(path, match) do - assert_file(path) - match.(File.read!(path)) - end - - defp refute_file(path), - do: refute(File.regular?(path), "Expected #{path} does not exist, but it does") + import NimbleTemplate.Test.FileHelper end end setup context do - parent_test_project_path = Path.join(tmp_path(), parent_test_project_path()) + parent_test_project_path = FileHelper.parent_test_project_path() + test_project_path = Path.join(parent_test_project_path, "/#{@default_project_name}") opts = Map.get(context, :opts, "") @@ -103,13 +89,4 @@ defmodule NimbleTemplate.AddonCase do "printf \"N\n\" | make create_mix_project PROJECT_DIRECTORY=#{test_project_path} OPTIONS=#{opts} > /dev/null" ) end - - defp parent_test_project_path do - 20 - |> :crypto.strong_rand_bytes() - |> Base.url_encode64(padding: false) - |> String.downcase() - end - - defp tmp_path, do: Path.expand("../../tmp", __DIR__) end diff --git a/test/support/helpers/file_helper.ex b/test/support/helpers/file_helper.ex new file mode 100644 index 00000000..3de13128 --- /dev/null +++ b/test/support/helpers/file_helper.ex @@ -0,0 +1,33 @@ +defmodule NimbleTemplate.Test.FileHelper do + import ExUnit.Assertions + + # ATTENTION: File.cd! doesn't support `async: true`, the test will fail randomly in async mode + # https://elixirforum.com/t/randomly-getting-compilationerror-on-tests/17298/3 + def in_test_project(test_project_path, function), do: File.cd!(test_project_path, function) + + def assert_file(path), + do: assert(File.regular?(path), "Expected #{path} to exist, but does not") + + def assert_directory(path), + do: assert(File.dir?(path), "Expected #{path} to exist, but does not") + + def assert_file(path, match) do + assert_file(path) + match.(File.read!(path)) + end + + def refute_file(path), + do: refute(File.regular?(path), "Expected #{path} does not exist, but it does") + + def parent_test_project_path do + project_directory = + 20 + |> :crypto.strong_rand_bytes() + |> Base.url_encode64(padding: false) + |> String.downcase() + + tmp_path = Path.expand("../../../tmp", __DIR__) + + Path.join(tmp_path, project_directory) + end +end diff --git a/test/support/template_case.ex b/test/support/template_case.ex new file mode 100644 index 00000000..6efbfb9c --- /dev/null +++ b/test/support/template_case.ex @@ -0,0 +1,26 @@ +defmodule NimbleTemplate.TemplateCase do + use ExUnit.CaseTemplate + + alias NimbleTemplate.Test.FileHelper + + using do + quote do + import NimbleTemplate.Test.FileHelper + end + end + + setup do + test_project_path = FileHelper.parent_test_project_path() + + File.mkdir_p!(test_project_path) + + Mix.shell().cmd("cp ./* .tool-versions #{test_project_path} 2> /dev/null") + Mix.shell().cmd("cp -r ./lib ./test #{test_project_path} 2> /dev/null") + + on_exit(fn -> + File.rm_rf!(test_project_path) + end) + + {:ok, test_project_path: test_project_path} + end +end From 8180c8ed9d805bf8baa59b7a05569102757c6d0a Mon Sep 17 00:00:00 2001 From: An Duong Date: Thu, 10 Nov 2022 11:26:01 +0700 Subject: [PATCH 08/43] [gh-230] Rename the method --- .github/wiki/Contribution.md | 44 +++--- lib/mix/tasks/nimble_template.bump_version.ex | 2 +- lib/mix/tasks/nimble_template.gen.ex | 4 +- .../tasks/nimble_template.upgrade_stack.ex | 2 +- lib/nimble_template/addons/addon.ex | 12 +- .../addons/asdf_tool_version.ex | 6 +- lib/nimble_template/addons/credo.ex | 24 +-- lib/nimble_template/addons/dialyxir.ex | 4 +- lib/nimble_template/addons/ex_coveralls.ex | 48 +++--- lib/nimble_template/addons/ex_unit.ex | 6 +- lib/nimble_template/addons/faker.ex | 4 +- lib/nimble_template/addons/git.ex | 4 +- lib/nimble_template/addons/github.ex | 47 +++--- lib/nimble_template/addons/iex.ex | 4 +- lib/nimble_template/addons/mimic.ex | 28 ++-- lib/nimble_template/addons/readme.ex | 14 +- lib/nimble_template/addons/test_env.ex | 40 ++--- .../addons/test_interactive.ex | 12 +- .../addons/variants/phoenix/api/config.ex | 16 +- .../phoenix/api/empty_body_params_plug.ex | 14 +- .../addons/variants/phoenix/api/error_view.ex | 12 +- .../phoenix/api/fallback_controller.ex | 14 +- .../addons/variants/phoenix/api/json_api.ex | 18 +-- .../variants/phoenix/api/params_validation.ex | 18 +-- .../addons/variants/phoenix/docker.ex | 4 +- .../variants/phoenix/ecto_data_migration.ex | 22 +-- .../addons/variants/phoenix/ex_machina.ex | 40 ++--- .../addons/variants/phoenix/ex_vcr.ex | 32 ++-- .../addons/variants/phoenix/gettext.ex | 8 +- .../addons/variants/phoenix/health_plug.ex | 52 +++---- .../addons/variants/phoenix/makefile.ex | 4 +- .../addons/variants/phoenix/mix_release.ex | 18 +-- .../addons/variants/phoenix/oban.ex | 44 +++--- .../addons/variants/phoenix/seeds.ex | 8 +- .../addons/variants/phoenix/web/assets.ex | 12 +- .../addons/variants/phoenix/web/bootstrap.ex | 62 ++++---- .../addons/variants/phoenix/web/core_js.ex | 18 +-- .../addons/variants/phoenix/web/dart_sass.ex | 36 ++--- .../addons/variants/phoenix/web/es_lint.ex | 46 +++--- .../addons/variants/phoenix/web/esbuild.ex | 16 +- .../variants/phoenix/web/heex_formatter.ex | 8 +- .../addons/variants/phoenix/web/nimble_css.ex | 18 +-- .../addons/variants/phoenix/web/nimble_js.ex | 32 ++-- .../variants/phoenix/web/node_package.ex | 4 +- .../addons/variants/phoenix/web/post_css.ex | 32 ++-- .../addons/variants/phoenix/web/prettier.ex | 42 +++--- .../addons/variants/phoenix/web/sobelow.ex | 24 +-- .../addons/variants/phoenix/web/style_lint.ex | 28 ++-- .../addons/variants/phoenix/web/svg_sprite.ex | 42 +++--- .../addons/variants/phoenix/web/wallaby.ex | 42 +++--- lib/nimble_template/helpers/dependency.ex | 2 +- lib/nimble_template/helpers/generator.ex | 141 ++++++++++-------- lib/nimble_template/templates/template.ex | 22 +-- .../templates/variants/mix/template.ex | 32 ++-- .../variants/phoenix/api/template.ex | 14 +- .../variants/phoenix/live/template.ex | 4 +- .../templates/variants/phoenix/template.ex | 67 ++++----- .../variants/phoenix/web/template.ex | 36 ++--- lib/nimble_template/version.ex | 50 +++---- .../addons/asdf_tool_version_test.exs | 22 +-- test/nimble_template/addons/credo_test.exs | 28 ++-- test/nimble_template/addons/dialyxir_test.exs | 6 +- .../addons/ex_coveralls_test.exs | 36 ++--- test/nimble_template/addons/ex_unit_test.exs | 6 +- test/nimble_template/addons/faker_test.exs | 6 +- test/nimble_template/addons/git_test.exs | 12 +- test/nimble_template/addons/github_test.exs | 134 ++++++++--------- test/nimble_template/addons/iex_test.exs | 12 +- test/nimble_template/addons/mimic_test.exs | 14 +- test/nimble_template/addons/readme_test.exs | 18 +-- test/nimble_template/addons/test_env_test.exs | 40 ++--- .../addons/test_interactive_test.exs | 16 +- .../addons/variants/docker_test.exs | 28 ++-- .../variants/ecto_data_migration_test.exs | 18 +-- .../addons/variants/ex_machina_test.exs | 22 +-- .../addons/variants/ex_vcr_test.exs | 18 +-- .../addons/variants/gettext_test.exs | 6 +- .../addons/variants/health_plug_test.exs | 22 +-- .../addons/variants/makefile_test.exs | 6 +- .../addons/variants/mix_release_test.exs | 10 +- .../addons/variants/oban_test.exs | 26 ++-- .../variants/phoenix/api/config_test.exs | 6 +- .../phoenix/api/empty_body_plug_test.exs | 14 +- .../variants/phoenix/api/error_view_test.exs | 6 +- .../phoenix/api/fallback_controller_test.exs | 10 +- .../variants/phoenix/api/json_api_test.exs | 10 +- .../phoenix/api/params_validation_test.exs | 10 +- .../variants/phoenix/web/assets_test.exs | 6 +- .../variants/phoenix/web/bootstrap_test.exs | 52 +++---- .../variants/phoenix/web/core_js_test.exs | 16 +- .../variants/phoenix/web/dart_sass_test.exs | 26 ++-- .../variants/phoenix/web/es_lint_test.exs | 28 ++-- .../variants/phoenix/web/esbuild_test.exs | 14 +- .../phoenix/web/hex_formatter_test.exs | 6 +- .../variants/phoenix/web/nimble_css_test.exs | 14 +- .../variants/phoenix/web/nimble_js_test.exs | 18 +-- .../phoenix/web/node_package_test.exs | 6 +- .../variants/phoenix/web/post_css_test.exs | 22 +-- .../variants/phoenix/web/prettier_test.exs | 22 +-- .../variants/phoenix/web/sobelow_test.exs | 14 +- .../variants/phoenix/web/style_lint_test.exs | 22 +-- .../variants/phoenix/web/svg_sprite_test.exs | 40 ++--- .../variants/phoenix/web/wallaby_test.exs | 34 ++--- .../addons/variants/seeds_test.exs | 6 +- .../helpers/dependency_test.exs | 6 +- .../nimble_template/projects/project_test.exs | 16 +- test/nimble_template/version_test.exs | 16 +- test/support/addon_case.ex | 12 +- 108 files changed, 1218 insertions(+), 1199 deletions(-) diff --git a/.github/wiki/Contribution.md b/.github/wiki/Contribution.md index fe99c471..55046231 100644 --- a/.github/wiki/Contribution.md +++ b/.github/wiki/Contribution.md @@ -18,13 +18,13 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SampleAddon do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, opts) do + def do_apply!(%Project{} = project, opts) do project end end ``` -The module should implement `do_apply` callbacks of a behaviour. +The module should implement `do_apply!` callbacks of a behaviour. With a new corresponding test file at `test/nimble_template/addons/variants/phoenix/web/addon_test.exs`. @@ -36,7 +36,7 @@ These are functions from `NimbleTemplate.Generator` which can be called. --- -`copy_directory(source_path, target_path, binding \\ [])` +`copy_directory!(source_path, target_path, binding \\ [])` Copy a directory and its content from source path to target path. @@ -48,12 +48,12 @@ Copy a directory and its content from source path to target path. Example ```elixir -Generator.copy_directory("assets/nimble_js", "assets/js") +Generator.copy_directory!("assets/nimble_js", "assets/js") ``` --- -`copy_file(files, binding \\ [])` +`copy_file!(files, binding \\ [])` Copy a list of files from source path to target path. @@ -64,7 +64,7 @@ Copy a list of files from source path to target path. Example ```elixir -Generator.copy_file([ +Generator.copy_file!([ {:eex, "bin/start.sh.eex", "bin/start.sh"}, {:text, "assets/bootstrap_css/vendor/_bootstrap.scss", "assets/css/vendor/_bootstrap.scss"} ]) @@ -72,7 +72,7 @@ Generator.copy_file([ --- -`rename_file(old_path, new_path)` +`rename_file!(old_path, new_path)` Rename a file from old path to new path. @@ -83,12 +83,12 @@ Rename a file from old path to new path. Example ```elixir -Generator.rename_file("assets/css/app.css", "assets/css/app.scss") +Generator.rename_file!("assets/css/app.css", "assets/css/app.scss") ``` --- -`replace_content(file_path, anchor, content)` +`replace_content!(file_path, anchor, content)` Find and replace specified content of an existing file. @@ -100,7 +100,7 @@ Find and replace specified content of an existing file. Example ```elixir -Generator.replace_content( +Generator.replace_content!( "test/test_helper.exs", """ ExUnit.start() @@ -113,7 +113,7 @@ Generator.replace_content( --- -`delete_content(file_path, anchor)` +`delete_content!(file_path, anchor)` Find and remove specified content of an existing file. @@ -124,7 +124,7 @@ Find and remove specified content of an existing file. Example ```elixir -Generator.delete_content( +Generator.delete_content!( "assets/js/app.js", """ // We import the CSS which is extracted to its own file by esbuild. @@ -137,7 +137,7 @@ Generator.delete_content( --- -`inject_content(file_path, anchor, content)` +`inject_content!(file_path, anchor, content)` Inject a specified content below a specified content of an existing file. @@ -149,7 +149,7 @@ Inject a specified content below a specified content of an existing file. Example ```elixir -Generator.inject_content( +Generator.inject_content!( support_case_path, """ use ExUnit.CaseTemplate @@ -163,7 +163,7 @@ Generator.inject_content( --- -`append_content(file_path, content)` +`append_content!(file_path, content)` Append a specified content to the end of an existing file. @@ -174,7 +174,7 @@ Append a specified content to the end of an existing file. Example ```elixir -Generator.append_content( +Generator.append_content!( "assets/css/_variables.scss", """ Content @@ -184,7 +184,7 @@ Generator.append_content( --- -`inject_mix_dependency(dependency)` +`inject_mix_dependency!(dependency)` Inject a new mix dependency into `mix.exs` file. @@ -196,14 +196,14 @@ Inject a new mix dependency into `mix.exs` file. Example ```elixir -Generator.inject_mix_dependency( +Generator.inject_mix_dependency!( {:credo, latest_package_version(:credo), only: [:dev, :test], runtime: false} ) ``` --- -`make_directory(path, touch_directory \\ true)` +`make_directory!(path, touch_directory \\ true)` Create a new directory. @@ -214,12 +214,12 @@ Create a new directory. Example ```elixir -Generator.make_directory("assets/css/vendor/", false) +Generator.make_directory!("assets/css/vendor/", false) ``` --- -`create_file(path, content)` +`create_file!(path, content)` Create a new file with specified content. @@ -230,7 +230,7 @@ Create a new file with specified content. Example ```elixir -Generator.create_file( +Generator.create_file!( "assets/css/_variables.scss", """ Content diff --git a/lib/mix/tasks/nimble_template.bump_version.ex b/lib/mix/tasks/nimble_template.bump_version.ex index 24337757..bfda7d26 100644 --- a/lib/mix/tasks/nimble_template.bump_version.ex +++ b/lib/mix/tasks/nimble_template.bump_version.ex @@ -20,7 +20,7 @@ defmodule Mix.Tasks.NimbleTemplate.BumpVersion do def run(args) do new_version = parse_opts(args) - Version.bump(new_version) + Version.bump!(new_version) end defp parse_opts(args) do diff --git a/lib/mix/tasks/nimble_template.gen.ex b/lib/mix/tasks/nimble_template.gen.ex index 7b68c09b..8a70a46f 100644 --- a/lib/mix/tasks/nimble_template.gen.ex +++ b/lib/mix/tasks/nimble_template.gen.ex @@ -42,7 +42,9 @@ defmodule Mix.Tasks.NimbleTemplate.Gen do {:ok, _} = Application.ensure_all_started(:httpoison) - Template.apply(Project.new(opts)) + opts + |> Project.new() + |> Template.apply!() end defp parse_opts(args) do diff --git a/lib/mix/tasks/nimble_template.upgrade_stack.ex b/lib/mix/tasks/nimble_template.upgrade_stack.ex index 7cfd9a55..540606bc 100644 --- a/lib/mix/tasks/nimble_template.upgrade_stack.ex +++ b/lib/mix/tasks/nimble_template.upgrade_stack.ex @@ -24,7 +24,7 @@ defmodule Mix.Tasks.NimbleTemplate.UpgradeStack do def run(args) do stack_versions = parse_opts(args) - Version.upgrade_stack(stack_versions) + Version.upgrade_stack!(stack_versions) end defp parse_opts(args) do diff --git a/lib/nimble_template/addons/addon.ex b/lib/nimble_template/addons/addon.ex index 8efe210e..c3e8454b 100644 --- a/lib/nimble_template/addons/addon.ex +++ b/lib/nimble_template/addons/addon.ex @@ -4,8 +4,8 @@ defmodule NimbleTemplate.Addons.Addon do alias __MODULE__ alias NimbleTemplate.Projects.Project - @callback apply(%Project{}, %{}) :: %Project{} - @callback do_apply(%Project{}, %{}) :: %Project{} + @callback apply!(%Project{}, %{}) :: %Project{} + @callback do_apply!(%Project{}, %{}) :: %Project{} defmacro __using__(opts) do quote location: :keep, bind_quoted: [opts: opts] do @@ -18,21 +18,21 @@ defmodule NimbleTemplate.Addons.Addon do alias NimbleTemplate.Projects.Project alias NimbleTemplate.ProjectHelper - def apply(%Project{} = project, opts \\ %{}) when is_map(opts) do + def apply!(%Project{} = project, opts \\ %{}) when is_map(opts) do Generator.info_log("* applying ", inspect(__MODULE__)) project - |> do_apply(opts) + |> do_apply!(opts) |> ProjectHelper.append_installed_addon(__MODULE__) end - def do_apply(%Project{} = project, opts) when is_map(opts), do: project + def do_apply!(%Project{} = project, opts) when is_map(opts), do: project defp latest_package_version(package) do "~> " <> Package.get_latest_version(package) end - defoverridable do_apply: 2 + defoverridable do_apply!: 2 end end end diff --git a/lib/nimble_template/addons/asdf_tool_version.ex b/lib/nimble_template/addons/asdf_tool_version.ex index eb3b9357..a3cd2b5e 100644 --- a/lib/nimble_template/addons/asdf_tool_version.ex +++ b/lib/nimble_template/addons/asdf_tool_version.ex @@ -4,7 +4,7 @@ defmodule NimbleTemplate.Addons.AsdfToolVersion do use NimbleTemplate.Addons.Addon @impl true - def do_apply( + def do_apply!( %Project{ erlang_version: erlang_version, elixir_asdf_version: elixir_asdf_version, @@ -13,13 +13,13 @@ defmodule NimbleTemplate.Addons.AsdfToolVersion do } = project, _opts ) do - Generator.copy_file([{:eex, ".tool-versions.eex", ".tool-versions"}], + Generator.copy_file!([{:eex, ".tool-versions.eex", ".tool-versions"}], erlang_version: erlang_version, elixir_asdf_version: elixir_asdf_version ) if web_project? do - Generator.append_content( + Generator.append_content!( ".tool-versions", """ nodejs #{node_asdf_version} diff --git a/lib/nimble_template/addons/credo.ex b/lib/nimble_template/addons/credo.ex index 53009ca1..78077774 100644 --- a/lib/nimble_template/addons/credo.ex +++ b/lib/nimble_template/addons/credo.ex @@ -4,26 +4,26 @@ defmodule NimbleTemplate.Addons.Credo do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> copy_files() - |> edit_files() + |> copy_files!() + |> edit_files!() end - defp copy_files(%Project{} = project) do - Generator.copy_file([{:text, ".credo.exs", ".credo.exs"}]) + defp copy_files!(%Project{} = project) do + Generator.copy_file!([{:text, ".credo.exs", ".credo.exs"}]) project end - defp edit_files(%Project{} = project) do + defp edit_files!(%Project{} = project) do project - |> inject_mix_dependency() - |> edit_mix() + |> inject_mix_dependency!() + |> edit_mix!() end - defp inject_mix_dependency(project) do - Generator.inject_mix_dependency([ + defp inject_mix_dependency!(project) do + Generator.inject_mix_dependency!([ {:credo, latest_package_version(:credo), only: [:dev, :test], runtime: false}, {:compass_credo_plugin, latest_package_version(:compass_credo_plugin), only: [:dev, :test], runtime: false} @@ -32,8 +32,8 @@ defmodule NimbleTemplate.Addons.Credo do project end - defp edit_mix(project) do - Generator.replace_content( + defp edit_mix!(project) do + Generator.replace_content!( "mix.exs", """ codebase: [ diff --git a/lib/nimble_template/addons/dialyxir.ex b/lib/nimble_template/addons/dialyxir.ex index 7015027d..1186cdaf 100644 --- a/lib/nimble_template/addons/dialyxir.ex +++ b/lib/nimble_template/addons/dialyxir.ex @@ -4,8 +4,8 @@ defmodule NimbleTemplate.Addons.Dialyxir do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do - Generator.inject_mix_dependency( + def do_apply!(%Project{} = project, _opts) do + Generator.inject_mix_dependency!( {:dialyxir, latest_package_version(:dialyxir), only: [:dev], runtime: false} ) diff --git a/lib/nimble_template/addons/ex_coveralls.ex b/lib/nimble_template/addons/ex_coveralls.ex index 407888bf..b0785b3a 100644 --- a/lib/nimble_template/addons/ex_coveralls.ex +++ b/lib/nimble_template/addons/ex_coveralls.ex @@ -4,13 +4,13 @@ defmodule NimbleTemplate.Addons.ExCoveralls do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> copy_files() - |> edit_files() + |> copy_files!() + |> edit_files!() end - defp copy_files(%Project{otp_app: otp_app, mix_project?: mix_project?} = project) do + defp copy_files!(%Project{otp_app: otp_app, mix_project?: mix_project?} = project) do binding = [ otp_app: otp_app, minimum_coverage: 100, @@ -24,38 +24,38 @@ defmodule NimbleTemplate.Addons.ExCoveralls do "coveralls.json.eex" end - Generator.copy_file([{:eex, template_file_path, "coveralls.json"}], binding) + Generator.copy_file!([{:eex, template_file_path, "coveralls.json"}], binding) project end - defp edit_files(%Project{mix_project?: true} = project) do + defp edit_files!(%Project{mix_project?: true} = project) do project - |> inject_mix_dependency() - |> edit_mix() + |> inject_mix_dependency!() + |> edit_mix!() project end - defp edit_files(%Project{} = project) do + defp edit_files!(%Project{} = project) do project - |> inject_mix_dependency() - |> edit_mix() - |> edit_web_router() + |> inject_mix_dependency!() + |> edit_mix!() + |> edit_web_router!() project end - defp inject_mix_dependency(project) do - Generator.inject_mix_dependency( + defp inject_mix_dependency!(project) do + Generator.inject_mix_dependency!( {:excoveralls, latest_package_version(:excoveralls), only: :test} ) project end - defp edit_mix(project) do - Generator.replace_content( + defp edit_mix!(project) do + Generator.replace_content!( "mix.exs", """ deps: deps() @@ -72,7 +72,7 @@ defmodule NimbleTemplate.Addons.ExCoveralls do """ ) - Generator.inject_content( + Generator.inject_content!( "mix.exs", """ defp aliases do @@ -86,14 +86,14 @@ defmodule NimbleTemplate.Addons.ExCoveralls do project end - defp edit_web_router(%Project{} = project) do + defp edit_web_router!(%Project{} = project) do project - |> ignore_ex_coverall_on_api_pipeline() - |> ignore_ex_coverall_on_live_dashboard() + |> ignore_ex_coverall_on_api_pipeline!() + |> ignore_ex_coverall_on_live_dashboard!() end - defp ignore_ex_coverall_on_api_pipeline(%Project{web_path: web_path} = project) do - Generator.replace_content( + defp ignore_ex_coverall_on_api_pipeline!(%Project{web_path: web_path} = project) do + Generator.replace_content!( "#{web_path}/router.ex", """ pipeline :api do @@ -113,10 +113,10 @@ defmodule NimbleTemplate.Addons.ExCoveralls do project end - defp ignore_ex_coverall_on_live_dashboard( + defp ignore_ex_coverall_on_live_dashboard!( %Project{web_path: web_path, web_module: web_module} = project ) do - Generator.replace_content( + Generator.replace_content!( "#{web_path}/router.ex", """ live_dashboard "/dashboard", metrics: #{web_module}.Telemetry diff --git a/lib/nimble_template/addons/ex_unit.ex b/lib/nimble_template/addons/ex_unit.ex index 38d997cf..50a87933 100644 --- a/lib/nimble_template/addons/ex_unit.ex +++ b/lib/nimble_template/addons/ex_unit.ex @@ -4,10 +4,10 @@ defmodule NimbleTemplate.Addons.ExUnit do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts), do: edit_test_helper(project) + def do_apply!(%Project{} = project, _opts), do: edit_test_helper!(project) - defp edit_test_helper(%Project{} = project) do - Generator.replace_content( + defp edit_test_helper!(%Project{} = project) do + Generator.replace_content!( "test/test_helper.exs", """ ExUnit.start() diff --git a/lib/nimble_template/addons/faker.ex b/lib/nimble_template/addons/faker.ex index 5bb81b06..1ae40ca6 100644 --- a/lib/nimble_template/addons/faker.ex +++ b/lib/nimble_template/addons/faker.ex @@ -4,8 +4,8 @@ defmodule NimbleTemplate.Addons.Faker do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do - Generator.inject_mix_dependency( + def do_apply!(%Project{} = project, _opts) do + Generator.inject_mix_dependency!( {:faker, latest_package_version(:faker), only: [:dev, :test], runtime: false} ) diff --git a/lib/nimble_template/addons/git.ex b/lib/nimble_template/addons/git.ex index 7852ab9a..08cea932 100644 --- a/lib/nimble_template/addons/git.ex +++ b/lib/nimble_template/addons/git.ex @@ -4,8 +4,8 @@ defmodule NimbleTemplate.Addons.Git do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do - Generator.append_content(".gitignore", """ + def do_apply!(%Project{} = project, _opts) do + Generator.append_content!(".gitignore", """ # Mac OS .DS_Store diff --git a/lib/nimble_template/addons/github.ex b/lib/nimble_template/addons/github.ex index 24dae13c..70d8af70 100644 --- a/lib/nimble_template/addons/github.ex +++ b/lib/nimble_template/addons/github.ex @@ -4,7 +4,7 @@ defmodule NimbleTemplate.Addons.Github do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, %{github_template: true}) do + def do_apply!(%Project{} = project, %{github_template: true}) do files = [ {:text, Path.join([".github", "ISSUE_TEMPLATE.md"]), Path.join([".github", "ISSUE_TEMPLATE.md"])}, @@ -14,13 +14,13 @@ defmodule NimbleTemplate.Addons.Github do Path.join([".github", "PULL_REQUEST_TEMPLATE", "RELEASE_TEMPLATE.md"])} ] - Generator.copy_file(files) + Generator.copy_file!(files) project end @impl true - def do_apply( + def do_apply!( %Project{ web_project?: web_project?, mix_project?: mix_project?, @@ -46,13 +46,13 @@ defmodule NimbleTemplate.Addons.Github do {:eex, template_file_path, ".github/workflows/test.yml"} ] - Generator.copy_file(files, binding) + Generator.copy_file!(files, binding) project end @impl true - def do_apply( + def do_apply!( %Project{} = project, %{ github_workflows_readme: true, @@ -61,7 +61,7 @@ defmodule NimbleTemplate.Addons.Github do with_deploy_to_heroku_workflow?: with_deploy_to_heroku_workflow? } ) do - Generator.copy_file( + Generator.copy_file!( [ {:eex, ".github/workflows/README.md.eex", ".github/workflows/README.md"} ], @@ -74,22 +74,25 @@ defmodule NimbleTemplate.Addons.Github do end @impl true - def do_apply(%Project{mix_project?: false, otp_app: otp_app, web_module: web_module} = project, %{ - github_action_deploy_heroku: true - }) do - Generator.copy_file([ + def do_apply!( + %Project{mix_project?: false, otp_app: otp_app, web_module: web_module} = project, + %{ + github_action_deploy_heroku: true + } + ) do + Generator.copy_file!([ {:eex, ".github/workflows/deploy_heroku.yml", ".github/workflows/deploy_heroku.yml"} ]) - Generator.replace_content("config/runtime.exs", "# ssl: true,", "ssl: true,") + Generator.replace_content!("config/runtime.exs", "# ssl: true,", "ssl: true,") - Generator.replace_content( + Generator.replace_content!( "config/runtime.exs", "url: [host: host,", "url: [scheme: \"https\", host: host," ) - Generator.append_content( + Generator.append_content!( "config/prod.exs", """ config :#{otp_app}, #{web_module}.Endpoint, @@ -101,15 +104,15 @@ defmodule NimbleTemplate.Addons.Github do end @impl true - def do_apply(%Project{} = project, %{github_wiki: true}) do + def do_apply!(%Project{} = project, %{github_wiki: true}) do project - |> copy_wiki_files() - |> append_wiki_into_readme() + |> copy_wiki_files!() + |> append_wiki_into_readme!() project end - defp copy_wiki_files( + defp copy_wiki_files!( %Project{ mix_project?: true, erlang_version: erlang_version, @@ -133,12 +136,12 @@ defmodule NimbleTemplate.Addons.Github do {:text, sidebar_path, ".github/wiki/_Sidebar.md"} ] - Generator.copy_file(files, binding) + Generator.copy_file!(files, binding) project end - defp copy_wiki_files( + defp copy_wiki_files!( %Project{ web_project?: web_project?, mix_project?: false, @@ -170,13 +173,13 @@ defmodule NimbleTemplate.Addons.Github do {:eex, environment_variables_path, ".github/wiki/Environment-Variables.md"} ] - Generator.copy_file(files, binding) + Generator.copy_file!(files, binding) project end - defp append_wiki_into_readme(project) do - Generator.append_content( + defp append_wiki_into_readme!(project) do + Generator.append_content!( "README.md", """ diff --git a/lib/nimble_template/addons/iex.ex b/lib/nimble_template/addons/iex.ex index 5153bee7..62b0cfbe 100644 --- a/lib/nimble_template/addons/iex.ex +++ b/lib/nimble_template/addons/iex.ex @@ -4,8 +4,8 @@ defmodule NimbleTemplate.Addons.Iex do 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"}], + 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? ) diff --git a/lib/nimble_template/addons/mimic.ex b/lib/nimble_template/addons/mimic.ex index fbc7d865..6af83a6e 100644 --- a/lib/nimble_template/addons/mimic.ex +++ b/lib/nimble_template/addons/mimic.ex @@ -4,27 +4,27 @@ defmodule NimbleTemplate.Addons.Mimic do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do - edit_files(project) + def do_apply!(%Project{} = project, _opts) do + edit_files!(project) end - defp edit_files(%Project{} = project) do + defp edit_files!(%Project{} = project) do project - |> inject_mix_dependency() - |> edit_test_helper() - |> edit_case() + |> inject_mix_dependency!() + |> edit_test_helper!() + |> edit_case!() project end - defp inject_mix_dependency(project) do - Generator.inject_mix_dependency({:mimic, latest_package_version(:mimic), only: :test}) + defp inject_mix_dependency!(project) do + Generator.inject_mix_dependency!({:mimic, latest_package_version(:mimic), only: :test}) project end - defp edit_test_helper(project) do - Generator.replace_content( + defp edit_test_helper!(project) do + Generator.replace_content!( "test/test_helper.exs", """ ExUnit.start() @@ -39,8 +39,8 @@ defmodule NimbleTemplate.Addons.Mimic do project end - defp edit_case(%Project{mix_project?: false} = project) do - Generator.inject_content( + defp edit_case!(%Project{mix_project?: false} = project) do + Generator.inject_content!( "test/support/conn_case.ex", """ quote do @@ -51,7 +51,7 @@ defmodule NimbleTemplate.Addons.Mimic do """ ) - Generator.inject_content( + Generator.inject_content!( "test/support/data_case.ex", """ quote do @@ -65,7 +65,7 @@ defmodule NimbleTemplate.Addons.Mimic do project end - defp edit_case(project) do + defp edit_case!(project) do project end end diff --git a/lib/nimble_template/addons/readme.ex b/lib/nimble_template/addons/readme.ex index 689bb8a3..ff37b157 100644 --- a/lib/nimble_template/addons/readme.ex +++ b/lib/nimble_template/addons/readme.ex @@ -4,19 +4,19 @@ defmodule NimbleTemplate.Addons.Readme do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> delete_files() - |> copy_files() + |> delete_files!() + |> copy_files!() end - def delete_files(project) do - File.rm("README.md") + def delete_files!(project) do + File.rm!("README.md") project end - defp copy_files( + defp copy_files!( %Project{ web_project?: web_project?, mix_project?: mix_project?, @@ -32,7 +32,7 @@ defmodule NimbleTemplate.Addons.Readme do "README.md.eex" end - Generator.copy_file([{:eex, template_file_path, "README.md"}], + Generator.copy_file!([{:eex, template_file_path, "README.md"}], erlang_version: erlang_version, elixir_version: elixir_version, node_asdf_version: node_asdf_version, diff --git a/lib/nimble_template/addons/test_env.ex b/lib/nimble_template/addons/test_env.ex index 41717747..61c0bd8e 100644 --- a/lib/nimble_template/addons/test_env.ex +++ b/lib/nimble_template/addons/test_env.ex @@ -4,25 +4,25 @@ defmodule NimbleTemplate.Addons.TestEnv do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{mix_project?: true} = project, _opts) do + def do_apply!(%Project{mix_project?: true} = project, _opts) do project - |> edit_mix() + |> edit_mix!() |> edit_formatter_exs() - |> edit_test_helper() + |> edit_test_helper!() end @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> edit_mix() + |> edit_mix!() |> edit_formatter_exs() - |> edit_test_helper() - |> edit_test_config() + |> edit_test_helper!() + |> edit_test_config!() |> edit_test_support_cases() end - defp edit_mix(%Project{mix_project?: true} = project) do - Generator.replace_content( + defp edit_mix!(%Project{mix_project?: true} = project) do + Generator.replace_content!( "mix.exs", """ deps: deps() @@ -34,7 +34,7 @@ defmodule NimbleTemplate.Addons.TestEnv do """ ) - Generator.replace_content( + Generator.replace_content!( "mix.exs", """ # Run "mix help deps" to learn about dependencies. @@ -64,8 +64,8 @@ defmodule NimbleTemplate.Addons.TestEnv do project end - defp edit_mix(project) do - Generator.inject_content( + defp edit_mix!(project) do + Generator.inject_content!( "mix.exs", """ defp aliases do @@ -86,8 +86,8 @@ defmodule NimbleTemplate.Addons.TestEnv do project end - defp edit_test_helper(%Project{} = project) do - Generator.replace_content( + defp edit_test_helper!(%Project{} = project) do + Generator.replace_content!( "test/test_helper.exs", """ ExUnit.start() @@ -102,8 +102,8 @@ defmodule NimbleTemplate.Addons.TestEnv do project end - defp edit_test_config(project) do - Generator.replace_content( + defp edit_test_config!(project) do + Generator.replace_content!( "config/test.exs", """ hostname: "localhost", @@ -117,7 +117,7 @@ defmodule NimbleTemplate.Addons.TestEnv do end defp edit_formatter_exs(project) do - Generator.inject_content( + Generator.inject_content!( ".formatter.exs", "[", String.slice( @@ -139,7 +139,7 @@ defmodule NimbleTemplate.Addons.TestEnv do defp edit_test_support_case(project, support_case_name) do support_case_path = "test/support/" <> support_case_name <> ".ex" - Generator.inject_content( + Generator.inject_content!( support_case_path, """ use ExUnit.CaseTemplate @@ -150,13 +150,13 @@ defmodule NimbleTemplate.Addons.TestEnv do """ ) - Generator.replace_content( + Generator.replace_content!( support_case_path, "Ecto.Adapters.SQL.Sandbox.start_owner!", "Sandbox.start_owner!" ) - Generator.replace_content( + Generator.replace_content!( support_case_path, "Ecto.Adapters.SQL.Sandbox.stop_owner", "Sandbox.stop_owner" diff --git a/lib/nimble_template/addons/test_interactive.ex b/lib/nimble_template/addons/test_interactive.ex index 95212527..a251956b 100644 --- a/lib/nimble_template/addons/test_interactive.ex +++ b/lib/nimble_template/addons/test_interactive.ex @@ -4,20 +4,20 @@ defmodule NimbleTemplate.Addons.TestInteractive do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do latest_version = latest_package_version(:mix_test_interactive) - Generator.inject_mix_dependency( + Generator.inject_mix_dependency!( {:mix_test_interactive, latest_version, only: :dev, runtime: false} ) - add_dev_config(project) + add_dev_config!(project) end - defp add_dev_config(%Project{mix_project?: true} = project), do: project + defp add_dev_config!(%Project{mix_project?: true} = project), do: project - defp add_dev_config(project) do - Generator.append_content( + defp add_dev_config!(project) do + Generator.append_content!( "config/dev.exs", """ config :mix_test_interactive, diff --git a/lib/nimble_template/addons/variants/phoenix/api/config.ex b/lib/nimble_template/addons/variants/phoenix/api/config.ex index 40f8da06..d5435c64 100644 --- a/lib/nimble_template/addons/variants/phoenix/api/config.ex +++ b/lib/nimble_template/addons/variants/phoenix/api/config.ex @@ -4,12 +4,12 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.Config do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do - edit_files(project) + def do_apply!(%Project{} = project, _opts) do + edit_files!(project) end - def edit_config_prod(%Project{otp_app: otp_app, web_module: web_module} = project) do - Generator.delete_content( + def edit_config_prod!(%Project{otp_app: otp_app, web_module: web_module} = project) do + Generator.delete_content!( "config/prod.exs", """ # For production, don't forget to configure the url host @@ -24,12 +24,12 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.Config do """ ) - Generator.delete_content( + Generator.delete_content!( "config/prod.exs", "config :#{otp_app}, #{web_module}.Endpoint," ) - Generator.delete_content( + Generator.delete_content!( "config/prod.exs", "cache_static_manifest: \"priv/static/cache_manifest.json\"" ) @@ -37,8 +37,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.Config do project end - defp edit_files(%Project{} = project) do - edit_config_prod(project) + defp edit_files!(%Project{} = project) do + edit_config_prod!(project) project end diff --git a/lib/nimble_template/addons/variants/phoenix/api/empty_body_params_plug.ex b/lib/nimble_template/addons/variants/phoenix/api/empty_body_params_plug.ex index 22a11bce..c9aef682 100644 --- a/lib/nimble_template/addons/variants/phoenix/api/empty_body_params_plug.ex +++ b/lib/nimble_template/addons/variants/phoenix/api/empty_body_params_plug.ex @@ -4,13 +4,13 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.EmptyBodyParamsPlug do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> copy_files() - |> edit_files() + |> copy_files!() + |> edit_files!() end - defp copy_files( + defp copy_files!( %Project{ web_module: web_module, web_path: web_path, @@ -28,13 +28,13 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.EmptyBodyParamsPlug do "#{web_test_path}/plugs/check_empty_body_params_plug_test.exs"} ] - Generator.copy_file(files, binding) + Generator.copy_file!(files, binding) project end - defp edit_files(%Project{web_path: web_path, web_module: web_module} = project) do - Generator.replace_content( + defp edit_files!(%Project{web_path: web_path, web_module: web_module} = project) do + Generator.replace_content!( "#{web_path}/router.ex", """ pipeline :api do diff --git a/lib/nimble_template/addons/variants/phoenix/api/error_view.ex b/lib/nimble_template/addons/variants/phoenix/api/error_view.ex index e13e5cfd..c86ce1de 100644 --- a/lib/nimble_template/addons/variants/phoenix/api/error_view.ex +++ b/lib/nimble_template/addons/variants/phoenix/api/error_view.ex @@ -4,19 +4,19 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.ErrorView do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> delete_files() - |> copy_files() + |> delete_files!() + |> copy_files!() end - defp delete_files(%Project{web_path: web_path} = project) do + defp delete_files!(%Project{web_path: web_path} = project) do File.rm!("#{web_path}/views/error_helpers.ex") project end - defp copy_files( + defp copy_files!( %Project{ base_module: base_module, web_module: web_module, @@ -39,7 +39,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.ErrorView do {:eex, "test/support/view_case.ex.eex", "test/support/view_case.ex"} ] - Generator.copy_file(files, binding) + Generator.copy_file!(files, binding) project end diff --git a/lib/nimble_template/addons/variants/phoenix/api/fallback_controller.ex b/lib/nimble_template/addons/variants/phoenix/api/fallback_controller.ex index 41b1af2f..7bb87277 100644 --- a/lib/nimble_template/addons/variants/phoenix/api/fallback_controller.ex +++ b/lib/nimble_template/addons/variants/phoenix/api/fallback_controller.ex @@ -4,13 +4,13 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.FallbackController do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> edit_files() - |> copy_files() + |> edit_files!() + |> copy_files!() end - defp copy_files(%Project{web_module: web_module, web_path: web_path} = project) do + defp copy_files!(%Project{web_module: web_module, web_path: web_path} = project) do binding = [ web_module: web_module ] @@ -20,13 +20,13 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.FallbackController do "#{web_path}/controllers/api/fallback_controller.ex"} ] - Generator.copy_file(files, binding) + Generator.copy_file!(files, binding) project end - defp edit_files(%Project{web_module: web_module, web_path: web_entry_point} = project) do - Generator.replace_content( + defp edit_files!(%Project{web_module: web_module, web_path: web_entry_point} = project) do + Generator.replace_content!( "#{web_entry_point}.ex", """ def controller do diff --git a/lib/nimble_template/addons/variants/phoenix/api/json_api.ex b/lib/nimble_template/addons/variants/phoenix/api/json_api.ex index 097e69cc..3b1c7d6c 100644 --- a/lib/nimble_template/addons/variants/phoenix/api/json_api.ex +++ b/lib/nimble_template/addons/variants/phoenix/api/json_api.ex @@ -4,18 +4,18 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.JsonApi do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do - edit_files(project) + def do_apply!(%Project{} = project, _opts) do + edit_files!(project) end - def inject_mix_dependency(project) do - Generator.inject_mix_dependency({:jsonapi, latest_package_version(:jsonapi)}) + def inject_mix_dependency!(project) do + Generator.inject_mix_dependency!({:jsonapi, latest_package_version(:jsonapi)}) project end - def edit_config(project) do - Generator.replace_content( + def edit_config!(project) do + Generator.replace_content!( "config/config.exs", """ # Import environment specific config. This must remain at the bottom @@ -32,9 +32,9 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.JsonApi do project end - defp edit_files(%Project{} = project) do + defp edit_files!(%Project{} = project) do project - |> inject_mix_dependency() - |> edit_config() + |> inject_mix_dependency!() + |> edit_config!() end end diff --git a/lib/nimble_template/addons/variants/phoenix/api/params_validation.ex b/lib/nimble_template/addons/variants/phoenix/api/params_validation.ex index bc1a41fc..d4c419e5 100644 --- a/lib/nimble_template/addons/variants/phoenix/api/params_validation.ex +++ b/lib/nimble_template/addons/variants/phoenix/api/params_validation.ex @@ -3,18 +3,18 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.ParamsValidation do use NimbleTemplate.Addons.Addon - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> copy_files() - |> edit_files() + |> copy_files!() + |> edit_files!() end - defp edit_files(project) do - edit_web_entry_point(project) + defp edit_files!(project) do + edit_web_entry_point!(project) end - defp edit_web_entry_point(%Project{web_module: web_module, web_path: web_entry_point} = project) do - Generator.replace_content( + defp edit_web_entry_point!(%Project{web_module: web_module, web_path: web_entry_point} = project) do + Generator.replace_content!( "#{web_entry_point}.ex", """ def controller do @@ -41,7 +41,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.ParamsValidation do project end - defp copy_files( + defp copy_files!( %Project{ base_module: base_module, web_module: web_module, @@ -62,7 +62,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.ParamsValidation do "#{web_test_path}/params/params_validator_test.exs"} ] - Generator.copy_file(files, binding) + Generator.copy_file!(files, binding) project end diff --git a/lib/nimble_template/addons/variants/phoenix/docker.ex b/lib/nimble_template/addons/variants/phoenix/docker.ex index e39363f9..d7c13915 100644 --- a/lib/nimble_template/addons/variants/phoenix/docker.ex +++ b/lib/nimble_template/addons/variants/phoenix/docker.ex @@ -4,7 +4,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Docker do use NimbleTemplate.Addons.Addon @impl true - def do_apply( + def do_apply!( %Project{ web_project?: web_project?, otp_app: otp_app, @@ -15,7 +15,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Docker do } = project, _opts ) do - Generator.copy_file( + Generator.copy_file!( [ {:eex, "docker-compose.dev.yml.eex", "docker-compose.dev.yml"}, {:eex, "docker-compose.yml.eex", "docker-compose.yml"}, diff --git a/lib/nimble_template/addons/variants/phoenix/ecto_data_migration.ex b/lib/nimble_template/addons/variants/phoenix/ecto_data_migration.ex index 939961ac..b3a7d744 100644 --- a/lib/nimble_template/addons/variants/phoenix/ecto_data_migration.ex +++ b/lib/nimble_template/addons/variants/phoenix/ecto_data_migration.ex @@ -4,28 +4,28 @@ defmodule NimbleTemplate.Addons.Phoenix.EctoDataMigration do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> copy_files() - |> edit_files() + |> copy_files!() + |> edit_files!() end - defp copy_files(%Project{} = project) do - Generator.copy_file([ + defp copy_files!(%Project{} = project) do + Generator.copy_file!([ {:text, "priv/repo/data_migrations/.keep", "priv/repo/data_migrations/.keep"} ]) project end - defp edit_files(%Project{} = project) do - edit_mix(project) + defp edit_files!(%Project{} = project) do + edit_mix!(project) project end - defp edit_mix(project) do - Generator.inject_content( + defp edit_mix!(project) do + Generator.inject_content!( "mix.exs", """ defp aliases do @@ -38,7 +38,7 @@ defmodule NimbleTemplate.Addons.Phoenix.EctoDataMigration do """ ) - Generator.replace_content( + Generator.replace_content!( "mix.exs", """ end @@ -58,7 +58,7 @@ defmodule NimbleTemplate.Addons.Phoenix.EctoDataMigration do """ ) - Generator.replace_content( + Generator.replace_content!( "mix.exs", """ "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"], diff --git a/lib/nimble_template/addons/variants/phoenix/ex_machina.ex b/lib/nimble_template/addons/variants/phoenix/ex_machina.ex index 4d9039c2..05566498 100644 --- a/lib/nimble_template/addons/variants/phoenix/ex_machina.ex +++ b/lib/nimble_template/addons/variants/phoenix/ex_machina.ex @@ -4,14 +4,14 @@ defmodule NimbleTemplate.Addons.Phoenix.ExMachina do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> copy_files() - |> edit_files() + |> copy_files!() + |> edit_files!() end - def edit_mix_elixirc_paths(%Project{} = project) do - Generator.replace_content( + def edit_mix_elixirc_paths!(%Project{} = project) do + Generator.replace_content!( "mix.exs", """ defp elixirc_paths(:test), do: ["lib", "test/support"] @@ -24,32 +24,34 @@ defmodule NimbleTemplate.Addons.Phoenix.ExMachina do 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"}], + 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 ) project end - defp edit_files(%Project{} = project) do + defp edit_files!(%Project{} = project) do project - |> inject_mix_dependency() - |> edit_mix_elixirc_paths() - |> edit_test_helper() - |> import_factory() + |> inject_mix_dependency!() + |> edit_mix_elixirc_paths!() + |> edit_test_helper!() + |> import_factory!() project end - defp inject_mix_dependency(%Project{} = project) do - Generator.inject_mix_dependency({:ex_machina, latest_package_version(:ex_machina), only: :test}) + defp inject_mix_dependency!(%Project{} = project) do + Generator.inject_mix_dependency!( + {:ex_machina, latest_package_version(:ex_machina), only: :test} + ) project end - defp edit_test_helper(%Project{} = project) do - Generator.replace_content( + defp edit_test_helper!(%Project{} = project) do + Generator.replace_content!( "test/test_helper.exs", """ ExUnit.start() @@ -64,8 +66,8 @@ defmodule NimbleTemplate.Addons.Phoenix.ExMachina do project end - defp import_factory(%Project{base_module: base_module, web_module: web_module} = project) do - Generator.replace_content( + defp import_factory!(%Project{base_module: base_module, web_module: web_module} = project) do + Generator.replace_content!( "test/support/data_case.ex", """ import #{base_module}.DataCase @@ -76,7 +78,7 @@ defmodule NimbleTemplate.Addons.Phoenix.ExMachina do """ ) - Generator.replace_content( + Generator.replace_content!( "test/support/conn_case.ex", """ import #{web_module}.ConnCase diff --git a/lib/nimble_template/addons/variants/phoenix/ex_vcr.ex b/lib/nimble_template/addons/variants/phoenix/ex_vcr.ex index 617cfd21..848e1202 100644 --- a/lib/nimble_template/addons/variants/phoenix/ex_vcr.ex +++ b/lib/nimble_template/addons/variants/phoenix/ex_vcr.ex @@ -6,29 +6,29 @@ defmodule NimbleTemplate.Addons.Phoenix.ExVCR do @cassette_directory "test/support/fixtures/vcr_cassettes" @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> edit_files() - |> create_cassette_directory() + |> edit_files!() + |> create_cassette_directory!() end - defp edit_files(%Project{} = project) do + defp edit_files!(%Project{} = project) do project - |> inject_mix_dependency() - |> edit_test_config() - |> edit_case() + |> inject_mix_dependency!() + |> edit_test_config!() + |> edit_case!() project end - defp inject_mix_dependency(%Project{} = project) do - Generator.inject_mix_dependency({:exvcr, latest_package_version(:exvcr), only: :test}) + defp inject_mix_dependency!(%Project{} = project) do + Generator.inject_mix_dependency!({:exvcr, latest_package_version(:exvcr), only: :test}) project end - defp edit_test_config(project) do - Generator.append_content( + defp edit_test_config!(project) do + Generator.append_content!( "config/test.exs", """ @@ -42,8 +42,8 @@ defmodule NimbleTemplate.Addons.Phoenix.ExVCR do project end - defp edit_case(project) do - Generator.inject_content( + defp edit_case!(project) do + Generator.inject_content!( "test/support/conn_case.ex", """ quote do @@ -54,7 +54,7 @@ defmodule NimbleTemplate.Addons.Phoenix.ExVCR do """ ) - Generator.inject_content( + Generator.inject_content!( "test/support/data_case.ex", """ quote do @@ -68,8 +68,8 @@ defmodule NimbleTemplate.Addons.Phoenix.ExVCR do project end - defp create_cassette_directory(project) do - Generator.make_directory(@cassette_directory) + defp create_cassette_directory!(project) do + Generator.make_directory!(@cassette_directory) project end diff --git a/lib/nimble_template/addons/variants/phoenix/gettext.ex b/lib/nimble_template/addons/variants/phoenix/gettext.ex index 6e6771a7..bca2b533 100644 --- a/lib/nimble_template/addons/variants/phoenix/gettext.ex +++ b/lib/nimble_template/addons/variants/phoenix/gettext.ex @@ -4,12 +4,12 @@ defmodule NimbleTemplate.Addons.Phoenix.Gettext do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do - edit_mix(project) + def do_apply!(%Project{} = project, _opts) do + edit_mix!(project) end - defp edit_mix(%Project{} = project) do - Generator.inject_content( + defp edit_mix!(%Project{} = project) do + Generator.inject_content!( "mix.exs", """ defp aliases do diff --git a/lib/nimble_template/addons/variants/phoenix/health_plug.ex b/lib/nimble_template/addons/variants/phoenix/health_plug.ex index 1e98a9f6..2621f83b 100644 --- a/lib/nimble_template/addons/variants/phoenix/health_plug.ex +++ b/lib/nimble_template/addons/variants/phoenix/health_plug.ex @@ -4,13 +4,13 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlug do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> copy_files() - |> edit_files() + |> copy_files!() + |> edit_files!() end - defp copy_files( + defp copy_files!( %Project{ web_module: web_module, base_module: base_module, @@ -35,21 +35,21 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlug do "#{web_test_path}/requests/_health/readiness_request_test.exs"} ] - Generator.copy_file(files, binding) + Generator.copy_file!(files, binding) project end - defp edit_files(project) do + defp edit_files!(project) do project - |> edit_config() - |> create_router_helper() - |> edit_router() - |> edit_test_helper() + |> edit_config!() + |> create_router_helper!() + |> edit_router!() + |> edit_test_helper!() end - defp edit_config(%Project{web_module: web_module, otp_app: otp_app} = project) do - Generator.replace_content( + defp edit_config!(%Project{web_module: web_module, otp_app: otp_app} = project) do + Generator.replace_content!( "config/config.exs", """ config :#{otp_app}, #{web_module}.Endpoint, @@ -60,7 +60,7 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlug do """ ) - Generator.replace_content( + Generator.replace_content!( "config/runtime.exs", """ config :#{otp_app}, #{web_module}.Endpoint, @@ -74,7 +74,7 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlug do project end - defp create_router_helper( + defp create_router_helper!( %Project{ web_module: web_module, web_path: web_path, @@ -94,25 +94,15 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlug do "#{web_test_path}/helpers/router_helper_test.exs"} ] - Generator.copy_file(files, binding) + Generator.copy_file!(files, binding) project end - defp edit_router(%Project{web_path: web_path, web_module: web_module} = project) do - Generator.replace_content( - "#{web_path}/router.ex", - """ - use #{web_module}, :router - """, - """ - use #{web_module}, :router - - alias #{web_module}.RouterHelper - """ - ) - - Generator.replace_content( + defp edit_router!( + %Project{web_path: web_path, web_module: web_module} = project + ) do + Generator.replace_content!( "#{web_path}/router.ex", """ # coveralls-ignore-start @@ -137,8 +127,8 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlug do project end - defp edit_test_helper(project) do - Generator.replace_content( + defp edit_test_helper!(project) do + Generator.replace_content!( "test/test_helper.exs", """ ExUnit.start() diff --git a/lib/nimble_template/addons/variants/phoenix/makefile.ex b/lib/nimble_template/addons/variants/phoenix/makefile.ex index 555e6404..a1f486bb 100644 --- a/lib/nimble_template/addons/variants/phoenix/makefile.ex +++ b/lib/nimble_template/addons/variants/phoenix/makefile.ex @@ -4,8 +4,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Makefile do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do - Generator.copy_file([{:text, "Makefile", "Makefile"}]) + def do_apply!(%Project{} = project, _opts) do + Generator.copy_file!([{:text, "Makefile", "Makefile"}]) project end diff --git a/lib/nimble_template/addons/variants/phoenix/mix_release.ex b/lib/nimble_template/addons/variants/phoenix/mix_release.ex index 0839935d..a94add13 100644 --- a/lib/nimble_template/addons/variants/phoenix/mix_release.ex +++ b/lib/nimble_template/addons/variants/phoenix/mix_release.ex @@ -4,18 +4,18 @@ defmodule NimbleTemplate.Addons.Phoenix.MixRelease do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> copy_files() - |> edit_files() + |> copy_files!() + |> edit_files!() project end - defp copy_files( + defp copy_files!( %Project{otp_app: otp_app, base_module: base_module, base_path: base_path} = project ) do - Generator.copy_file( + Generator.copy_file!( [ {:eex, "lib/otp_app/release_tasks.ex.eex", base_path <> "/release_tasks.ex"} ], @@ -26,8 +26,8 @@ defmodule NimbleTemplate.Addons.Phoenix.MixRelease do project end - defp edit_files(%{otp_app: otp_app, web_module: web_module} = project) do - Generator.delete_content( + defp edit_files!(%{otp_app: otp_app, web_module: web_module} = project) do + Generator.delete_content!( "config/runtime.exs", """ @@ -47,7 +47,7 @@ defmodule NimbleTemplate.Addons.Phoenix.MixRelease do """ ) - Generator.replace_content( + Generator.replace_content!( "config/runtime.exs", """ config :#{otp_app}, #{web_module}.Endpoint, @@ -58,7 +58,7 @@ defmodule NimbleTemplate.Addons.Phoenix.MixRelease do """ ) - Generator.replace_content( + Generator.replace_content!( "config/runtime.exs", """ host = System.get_env("PHX_HOST") || "example.com" diff --git a/lib/nimble_template/addons/variants/phoenix/oban.ex b/lib/nimble_template/addons/variants/phoenix/oban.ex index 6f6028f9..a721ebe3 100644 --- a/lib/nimble_template/addons/variants/phoenix/oban.ex +++ b/lib/nimble_template/addons/variants/phoenix/oban.ex @@ -4,17 +4,17 @@ defmodule NimbleTemplate.Addons.Phoenix.Oban do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> copy_files() - |> edit_files() - |> create_folders() + |> copy_files!() + |> edit_files!() + |> create_folders!() end - defp copy_files(%Project{base_module: base_module} = project) do + defp copy_files!(%Project{base_module: base_module} = project) do migrate_version = Calendar.strftime(DateTime.utc_now(), "%Y%m%d%I%M%S") - Generator.copy_file( + Generator.copy_file!( [ {:eex, "priv/repo/migrations/add_oban_jobs_table.exs.eex", "priv/repo/migrations/#{migrate_version}_add_oban_jobs_table.exs"} @@ -25,32 +25,32 @@ defmodule NimbleTemplate.Addons.Phoenix.Oban do project end - defp edit_files(project) do + defp edit_files!(project) do project - |> inject_mix_dependency - |> edit_application_ex - |> edit_config - |> edit_test_config + |> inject_mix_dependency! + |> edit_application_ex!() + |> edit_config!() + |> edit_test_config!() project end - defp create_folders(%Project{otp_app: otp_app} = project) do - Generator.make_directory("lib/" <> Atom.to_string(otp_app) <> "_worker") + defp create_folders!(%Project{otp_app: otp_app} = project) do + Generator.make_directory!("lib/" <> Atom.to_string(otp_app) <> "_worker") project end - defp inject_mix_dependency(project) do - Generator.inject_mix_dependency({:oban, latest_package_version(:oban)}) + defp inject_mix_dependency!(project) do + Generator.inject_mix_dependency!({:oban, latest_package_version(:oban)}) project end - defp edit_application_ex( + defp edit_application_ex!( %Project{otp_app: otp_app, base_path: base_path, web_module: web_module} = project ) do - Generator.replace_content( + Generator.replace_content!( "#{base_path}/application.ex", """ #{web_module}.Endpoint @@ -61,7 +61,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Oban do """ ) - Generator.inject_content( + Generator.inject_content!( "#{base_path}/application.ex", """ # Tell Phoenix to update the endpoint configuration @@ -82,8 +82,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Oban do project end - defp edit_config(%Project{otp_app: otp_app, base_module: base_module} = project) do - Generator.inject_content( + defp edit_config!(%Project{otp_app: otp_app, base_module: base_module} = project) do + Generator.inject_content!( "config/config.exs", """ config :phoenix, :json_library, Jason @@ -100,8 +100,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Oban do project end - defp edit_test_config(%Project{otp_app: otp_app} = project) do - Generator.inject_content( + defp edit_test_config!(%Project{otp_app: otp_app} = project) do + Generator.inject_content!( "config/test.exs", """ config :logger, level: :warn diff --git a/lib/nimble_template/addons/variants/phoenix/seeds.ex b/lib/nimble_template/addons/variants/phoenix/seeds.ex index 134b7c4c..eb5e39ac 100644 --- a/lib/nimble_template/addons/variants/phoenix/seeds.ex +++ b/lib/nimble_template/addons/variants/phoenix/seeds.ex @@ -4,14 +4,14 @@ defmodule NimbleTemplate.Addons.Phoenix.Seeds do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do - edit_seeds_file(project) + def do_apply!(%Project{} = project, _opts) do + edit_seeds_file!(project) project end - defp edit_seeds_file(project) do - Generator.append_content("priv/repo/seeds.exs", """ + defp edit_seeds_file!(project) do + Generator.append_content!("priv/repo/seeds.exs", """ if Mix.env() == :dev || System.get_env("ENABLE_DB_SEED") == "true" do end """) diff --git a/lib/nimble_template/addons/variants/phoenix/web/assets.ex b/lib/nimble_template/addons/variants/phoenix/web/assets.ex index 30e3a6d1..41e5dd72 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/assets.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/assets.ex @@ -4,18 +4,18 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Assets do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do - edit_files(project) + def do_apply!(%Project{} = project, _opts) do + edit_files!(project) end - defp edit_files(%Project{} = project) do - enable_gzip_for_static_assets(project) + defp edit_files!(%Project{} = project) do + enable_gzip_for_static_assets!(project) project end - defp enable_gzip_for_static_assets(%Project{web_path: web_path} = project) do - Generator.replace_content( + defp enable_gzip_for_static_assets!(%Project{web_path: web_path} = project) do + Generator.replace_content!( "#{web_path}/endpoint.ex", """ gzip: false, diff --git a/lib/nimble_template/addons/variants/phoenix/web/bootstrap.ex b/lib/nimble_template/addons/variants/phoenix/web/bootstrap.ex index b302a18d..5cbbe2b1 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/bootstrap.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/bootstrap.ex @@ -4,31 +4,31 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Bootstrap do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, opts) do + def do_apply!(%Project{} = project, opts) do project - |> edit_files(opts) - |> copy_files() + |> edit_files!(opts) + |> copy_files!() end - defp edit_files(%Project{} = project, opts) do + defp edit_files!(%Project{} = project, opts) do project - |> edit_assets_package() - |> edit_app_js(opts) - |> edit_app_scss(opts) - |> edit_vendor_index(opts) - |> edit_css_variables(opts) + |> edit_assets_package!() + |> edit_app_js!(opts) + |> edit_app_scss!(opts) + |> edit_vendor_index!(opts) + |> edit_css_variables!(opts) project end - defp copy_files(%Project{} = project) do - copy_bootstrap_vendor(project) + defp copy_files!(%Project{} = project) do + copy_bootstrap_vendor!(project) project end - defp edit_assets_package(%Project{} = project) do - Generator.replace_content( + defp edit_assets_package!(%Project{} = project) do + Generator.replace_content!( "assets/package.json", """ "dependencies": { @@ -43,8 +43,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Bootstrap do project end - defp edit_app_js(project, %{with_nimble_js_addon: true}) do - Generator.replace_content( + defp edit_app_js!(project, %{with_nimble_js_addon: true}) do + Generator.replace_content!( "assets/js/app.js", """ import "phoenix_html" @@ -60,8 +60,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Bootstrap do project end - defp edit_app_js(project, %{with_nimble_js_addon: false}) do - Generator.replace_content( + defp edit_app_js!(project, %{with_nimble_js_addon: false}) do + Generator.replace_content!( "assets/js/app.js", """ import "phoenix_html" @@ -77,10 +77,10 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Bootstrap do project end - defp edit_app_scss(project, %{with_nimble_css_addon: true}), do: project + defp edit_app_scss!(project, %{with_nimble_css_addon: true}), do: project - defp edit_app_scss(project, %{with_nimble_css_addon: false}) do - Generator.replace_content( + defp edit_app_scss!(project, %{with_nimble_css_addon: false}) do + Generator.replace_content!( "assets/css/app.scss", """ @import "./phoenix.css"; @@ -95,8 +95,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Bootstrap do project end - defp edit_css_variables(project, %{with_nimble_css_addon: false}) do - Generator.create_file( + defp edit_css_variables!(project, %{with_nimble_css_addon: false}) do + Generator.create_file!( "assets/css/_variables.scss", """ //////////////////////////////// @@ -113,8 +113,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Bootstrap do project end - defp edit_css_variables(project, %{with_nimble_css_addon: true}) do - Generator.append_content( + defp edit_css_variables!(project, %{with_nimble_css_addon: true}) do + Generator.append_content!( "assets/css/_variables.scss", """ //////////////////////////////// @@ -131,21 +131,21 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Bootstrap do project end - defp edit_vendor_index(project, %{with_nimble_css_addon: true}) do - Generator.append_content("assets/css/vendor/_index.scss", "@import './bootstrap';") + defp edit_vendor_index!(project, %{with_nimble_css_addon: true}) do + Generator.append_content!("assets/css/vendor/_index.scss", "@import './bootstrap';") project end - defp edit_vendor_index(project, %{with_nimble_css_addon: false}) do - Generator.make_directory("assets/css/vendor/", false) - Generator.create_file("assets/css/vendor/_index.scss", "@import './bootstrap';") + defp edit_vendor_index!(project, %{with_nimble_css_addon: false}) do + Generator.make_directory!("assets/css/vendor/", false) + Generator.create_file!("assets/css/vendor/_index.scss", "@import './bootstrap';") project end - defp copy_bootstrap_vendor(%Project{} = project) do - Generator.copy_file([ + defp copy_bootstrap_vendor!(%Project{} = project) do + Generator.copy_file!([ {:text, "assets/bootstrap_css/vendor/_bootstrap.scss", "assets/css/vendor/_bootstrap.scss"} ]) diff --git a/lib/nimble_template/addons/variants/phoenix/web/core_js.ex b/lib/nimble_template/addons/variants/phoenix/web/core_js.ex index 92833f46..0d36a1ea 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/core_js.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/core_js.ex @@ -4,12 +4,12 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.CoreJS do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do - edit_files(project) + def do_apply!(%Project{} = project, _opts) do + edit_files!(project) end - def edit_package_json(%Project{} = project) do - Generator.replace_content( + def edit_package_json!(%Project{} = project) do + Generator.replace_content!( "assets/package.json", """ "dependencies": { @@ -23,8 +23,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.CoreJS do project end - def edit_app_js(project) do - Generator.replace_content( + def edit_app_js!(project) do + Generator.replace_content!( "assets/js/app.js", """ import "phoenix_html" @@ -40,10 +40,10 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.CoreJS do project end - defp edit_files(%Project{} = project) do + defp edit_files!(%Project{} = project) do project - |> edit_package_json() - |> edit_app_js() + |> edit_package_json!() + |> edit_app_js!() project end diff --git a/lib/nimble_template/addons/variants/phoenix/web/dart_sass.ex b/lib/nimble_template/addons/variants/phoenix/web/dart_sass.ex index 0965df77..73dc3f72 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/dart_sass.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/dart_sass.ex @@ -6,21 +6,21 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.DartSass do @dart_sass_version "1.49.11" @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> inject_mix_dependency() - |> edit_config() - |> edit_mix() - |> edit_app_js() - |> rename_app_css() + |> inject_mix_dependency!() + |> edit_config!() + |> edit_mix!() + |> edit_app_js!() + |> rename_app_css!() end - defp inject_mix_dependency(%Project{} = project) do - Generator.inject_mix_dependency( + defp inject_mix_dependency!(%Project{} = project) do + Generator.inject_mix_dependency!( {:dart_sass, latest_package_version(:dart_sass), runtime: "Mix.env() == :dev"} ) - Generator.replace_content( + Generator.replace_content!( "mix.exs", "runtime: \"Mix.env() == :dev\"", "runtime: Mix.env() == :dev" @@ -29,8 +29,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.DartSass do project end - defp edit_config(%Project{} = project) do - Generator.replace_content( + defp edit_config!(%Project{} = project) do + Generator.replace_content!( "config/config.exs", """ # Configure esbuild (the version is required) @@ -52,7 +52,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.DartSass do """ ) - Generator.replace_content( + Generator.replace_content!( "config/dev.exs", """ watchers: [ @@ -70,8 +70,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.DartSass do project end - defp edit_mix(project) do - Generator.replace_content( + defp edit_mix!(project) do + Generator.replace_content!( "mix.exs", """ "assets.deploy": [ @@ -93,8 +93,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.DartSass do project end - defp edit_app_js(project) do - Generator.delete_content( + defp edit_app_js!(project) do + Generator.delete_content!( "assets/js/app.js", """ // We import the CSS which is extracted to its own file by esbuild. @@ -107,8 +107,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.DartSass do project end - defp rename_app_css(project) do - Generator.rename_file( + defp rename_app_css!(project) do + Generator.rename_file!( "assets/css/app.css", "assets/css/app.scss" ) diff --git a/lib/nimble_template/addons/variants/phoenix/web/es_lint.ex b/lib/nimble_template/addons/variants/phoenix/web/es_lint.ex index 3f4ecb13..4525eb2a 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/es_lint.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/es_lint.ex @@ -4,43 +4,43 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsLint do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> edit_files() - |> copy_files() + |> edit_files!() + |> copy_files!() end - def edit_app_js(%Project{live_project?: true} = project) do - update_topbar_js_variables() + 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() + def edit_app_js!(%Project{web_project?: true} = project) do + update_topbar_js_variables!() project end - def edit_app_js(project), do: project + def edit_app_js!(project), do: project - defp edit_files(%Project{} = project) do + defp edit_files!(%Project{} = project) do project - |> edit_assets_package() - |> edit_mix() - |> edit_app_js() + |> edit_assets_package!() + |> edit_mix!() + |> edit_app_js!() project end - defp copy_files(%Project{} = project) do - Generator.copy_file([{:text, "assets/.eslintrc.json", "assets/.eslintrc.json"}]) + defp copy_files!(%Project{} = project) do + Generator.copy_file!([{:text, "assets/.eslintrc.json", "assets/.eslintrc.json"}]) project end - defp edit_assets_package(%Project{} = project) do - Generator.replace_content( + defp edit_assets_package!(%Project{} = project) do + Generator.replace_content!( "assets/package.json", """ "scripts": { @@ -52,7 +52,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsLint do """ ) - Generator.replace_content( + Generator.replace_content!( "assets/package.json", """ "devDependencies": { @@ -68,8 +68,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsLint do project end - defp edit_mix(%Project{} = project) do - Generator.replace_content( + defp edit_mix!(%Project{} = project) do + Generator.replace_content!( "mix.exs", """ codebase: [ @@ -80,7 +80,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsLint do """ ) - Generator.replace_content( + Generator.replace_content!( "mix.exs", """ "codebase.fix": [ @@ -94,14 +94,14 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsLint do project end - defp update_topbar_js_variables do - Generator.replace_content( + defp update_topbar_js_variables! do + Generator.replace_content!( "assets/js/app.js", "window.addEventListener(\"phx:page-loading-start\", info => topbar.show())", "window.addEventListener(\"phx:page-loading-start\", _info => topbar.show())" ) - Generator.replace_content( + Generator.replace_content!( "assets/js/app.js", "window.addEventListener(\"phx:page-loading-stop\", info => topbar.hide())", "window.addEventListener(\"phx:page-loading-stop\", _info => topbar.hide())" diff --git a/lib/nimble_template/addons/variants/phoenix/web/esbuild.ex b/lib/nimble_template/addons/variants/phoenix/web/esbuild.ex index 02aea30a..5837f93e 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/esbuild.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/esbuild.ex @@ -4,22 +4,22 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsBuild do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> edit_config() - |> edit_mix() + |> edit_config!() + |> edit_mix!() end - defp edit_config(%Project{} = project) do - Generator.replace_content("config/config.exs", "default: [", "app: [") + defp edit_config!(%Project{} = project) do + Generator.replace_content!("config/config.exs", "default: [", "app: [") - Generator.replace_content("config/dev.exs", "[:default", "[:app") + Generator.replace_content!("config/dev.exs", "[:default", "[:app") project end - defp edit_mix(project) do - Generator.replace_content("mix.exs", "esbuild default", "esbuild app") + defp edit_mix!(project) do + Generator.replace_content!("mix.exs", "esbuild default", "esbuild app") project end diff --git a/lib/nimble_template/addons/variants/phoenix/web/heex_formatter.ex b/lib/nimble_template/addons/variants/phoenix/web/heex_formatter.ex index e35d73a4..d060f216 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/heex_formatter.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/heex_formatter.ex @@ -4,16 +4,16 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.HeexFormatter do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do - Generator.replace_content(".formatter.exs", "\"*.{ex,exs}\"", "\"*.{heex,ex,exs}\"") + def do_apply!(%Project{} = project, _opts) do + Generator.replace_content!(".formatter.exs", "\"*.{ex,exs}\"", "\"*.{heex,ex,exs}\"") - Generator.replace_content( + Generator.replace_content!( ".formatter.exs", "\"{config,lib,test}/**/*.{ex,exs}\"", "\"{config,lib,test}/**/*.{heex,ex,exs}\"" ) - Generator.replace_content( + Generator.replace_content!( ".formatter.exs", """ import_deps: [:ecto, :phoenix], diff --git a/lib/nimble_template/addons/variants/phoenix/web/nimble_css.ex b/lib/nimble_template/addons/variants/phoenix/web/nimble_css.ex index e0d1a7fe..6757ffce 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/nimble_css.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/nimble_css.ex @@ -4,27 +4,27 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.NimbleCSS do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> remove_default_phoenix_structure() - |> copy_nimble_structure() - |> edit_style_lint_rc() + |> remove_default_phoenix_structure!() + |> copy_nimble_structure!() + |> edit_style_lint_rc!() end - defp remove_default_phoenix_structure(project) do + defp remove_default_phoenix_structure!(project) do File.rm_rf!("assets/css") project end - defp copy_nimble_structure(project) do - Generator.copy_directory("assets/nimble_css", "assets/css") + defp copy_nimble_structure!(project) do + Generator.copy_directory!("assets/nimble_css", "assets/css") project end - defp edit_style_lint_rc(project) do - Generator.replace_content( + defp edit_style_lint_rc!(project) do + Generator.replace_content!( "assets/.stylelintrc.json", """ "ignoreFiles": [ diff --git a/lib/nimble_template/addons/variants/phoenix/web/nimble_js.ex b/lib/nimble_template/addons/variants/phoenix/web/nimble_js.ex index 2a3ccd34..2dd77d99 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/nimble_js.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/nimble_js.ex @@ -4,28 +4,28 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.NimbleJS do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> copy_nimble_structure() - |> moving_js_vendor() - |> edit_app_js() - |> edit_es_lint_config() + |> copy_nimble_structure!() + |> moving_js_vendor!() + |> edit_app_js!() + |> edit_es_lint_config!() end - defp copy_nimble_structure(project) do - Generator.copy_directory("assets/nimble_js", "assets/js") + defp copy_nimble_structure!(project) do + Generator.copy_directory!("assets/nimble_js", "assets/js") project end - defp moving_js_vendor(project) do - Generator.rename_file("assets/vendor", "assets/js/vendor") + defp moving_js_vendor!(project) do + Generator.rename_file!("assets/vendor", "assets/js/vendor") project end - defp edit_app_js(project) do - Generator.append_content( + defp edit_app_js!(project) do + Generator.append_content!( "assets/js/app.js", """ @@ -36,21 +36,21 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.NimbleJS do """ ) - Generator.replace_content("assets/js/app.js", "assets/vendor", "assets/js/vendor") + Generator.replace_content!("assets/js/app.js", "assets/vendor", "assets/js/vendor") - Generator.replace_content( + Generator.replace_content!( "assets/js/app.js", "../vendor/some-package.js", "./vendor/some-package.js" ) - Generator.replace_content("assets/js/app.js", "../vendor/topbar", "./vendor/topbar") + Generator.replace_content!("assets/js/app.js", "../vendor/topbar", "./vendor/topbar") project end - defp edit_es_lint_config(project) do - Generator.replace_content( + defp edit_es_lint_config!(project) do + Generator.replace_content!( "assets/.eslintrc.json", "/vendor/topbar.js", "/js/vendor/topbar.js" diff --git a/lib/nimble_template/addons/variants/phoenix/web/node_package.ex b/lib/nimble_template/addons/variants/phoenix/web/node_package.ex index 771e704e..4f8fa21c 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/node_package.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/node_package.ex @@ -4,8 +4,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.NodePackage do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do - Generator.copy_file([{:text, "assets/package.json", "assets/package.json"}]) + def do_apply!(%Project{} = project, _opts) do + Generator.copy_file!([{:text, "assets/package.json", "assets/package.json"}]) project end diff --git a/lib/nimble_template/addons/variants/phoenix/web/post_css.ex b/lib/nimble_template/addons/variants/phoenix/web/post_css.ex index bffa4f62..deb82e1a 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/post_css.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/post_css.ex @@ -4,23 +4,23 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PostCSS do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> edit_files() - |> copy_files() + |> edit_files!() + |> copy_files!() end - defp edit_files(%Project{} = project) do + defp edit_files!(%Project{} = project) do project - |> edit_package() - |> edit_mix() - |> edit_phoenix_watcher() + |> edit_package!() + |> edit_mix!() + |> edit_phoenix_watcher!() project end - defp edit_package(project) do - Generator.replace_content( + defp edit_package!(project) do + Generator.replace_content!( "assets/package.json", """ "devDependencies": { @@ -34,7 +34,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PostCSS do """ ) - Generator.replace_content( + Generator.replace_content!( "assets/package.json", """ "scripts": { @@ -49,8 +49,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PostCSS do project end - defp edit_mix(project) do - Generator.replace_content( + defp edit_mix!(project) do + Generator.replace_content!( "mix.exs", """ "assets.deploy": ["esbuild app --minify", "phx.digest"] @@ -67,8 +67,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PostCSS do project end - defp edit_phoenix_watcher(project) do - Generator.replace_content( + defp edit_phoenix_watcher!(project) do + Generator.replace_content!( "config/dev.exs", """ watchers: [ @@ -86,8 +86,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PostCSS do project end - defp copy_files(%Project{} = project) do - Generator.copy_file([{:text, "assets/postcss.config.js", "assets/postcss.config.js"}]) + defp copy_files!(%Project{} = project) do + Generator.copy_file!([{:text, "assets/postcss.config.js", "assets/postcss.config.js"}]) project end diff --git a/lib/nimble_template/addons/variants/phoenix/web/prettier.ex b/lib/nimble_template/addons/variants/phoenix/web/prettier.ex index 437e080b..86cba294 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/prettier.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/prettier.ex @@ -4,22 +4,22 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Prettier do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> edit_files() - |> copy_files() + |> edit_files!() + |> copy_files!() end - defp edit_files(%Project{} = project) do + defp edit_files!(%Project{} = project) do project - |> edit_npm_dev_dependencies() - |> edit_mix() + |> edit_npm_dev_dependencies!() + |> edit_mix!() project end - defp edit_npm_dev_dependencies(%Project{} = project) do - Generator.replace_content( + defp edit_npm_dev_dependencies!(%Project{} = project) do + Generator.replace_content!( "assets/package.json", """ "devDependencies": { @@ -34,15 +34,15 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Prettier do project end - defp edit_mix(%Project{} = project) do + defp edit_mix!(%Project{} = project) do project - |> add_prettier_aliases() - |> add_prettier_into_codebase() - |> add_prettier_fix_into_codebase_fix() + |> add_prettier_aliases!() + |> add_prettier_into_codebase!() + |> add_prettier_fix_into_codebase_fix!() end - defp add_prettier_aliases(%Project{} = project) do - Generator.inject_content( + defp add_prettier_aliases!(%Project{} = project) do + Generator.inject_content!( "mix.exs", """ defp aliases do @@ -57,8 +57,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Prettier do project end - defp add_prettier_into_codebase(%Project{} = project) do - Generator.replace_content( + defp add_prettier_into_codebase!(%Project{} = project) do + Generator.replace_content!( "mix.exs", """ codebase: [ @@ -72,8 +72,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Prettier do project end - defp add_prettier_fix_into_codebase_fix(%Project{} = project) do - Generator.replace_content( + defp add_prettier_fix_into_codebase_fix!(%Project{} = project) do + Generator.replace_content!( "mix.exs", """ "codebase.fix": [ @@ -87,9 +87,9 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Prettier do project end - defp copy_files(%Project{} = project) do - Generator.copy_file([{:text, ".prettierignore", ".prettierignore"}]) - Generator.copy_file([{:text, ".prettierrc.yaml", ".prettierrc.yaml"}]) + defp copy_files!(%Project{} = project) do + Generator.copy_file!([{:text, ".prettierignore", ".prettierignore"}]) + Generator.copy_file!([{:text, ".prettierrc.yaml", ".prettierrc.yaml"}]) project end diff --git a/lib/nimble_template/addons/variants/phoenix/web/sobelow.ex b/lib/nimble_template/addons/variants/phoenix/web/sobelow.ex index 3388123f..9e70df1f 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/sobelow.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/sobelow.ex @@ -4,34 +4,34 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Sobelow do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> copy_files() - |> edit_files() + |> copy_files!() + |> edit_files!() end - defp copy_files(%Project{} = project) do - Generator.copy_file([{:text, ".sobelow-conf", ".sobelow-conf"}]) + defp copy_files!(%Project{} = project) do + Generator.copy_file!([{:text, ".sobelow-conf", ".sobelow-conf"}]) project end - defp edit_files(%Project{} = project) do + defp edit_files!(%Project{} = project) do project - |> inject_mix_dependency() - |> edit_mix() + |> inject_mix_dependency!() + |> edit_mix!() end - defp inject_mix_dependency(%Project{} = project) do - Generator.inject_mix_dependency( + defp inject_mix_dependency!(%Project{} = project) do + Generator.inject_mix_dependency!( {:sobelow, latest_package_version(:sobelow), only: [:dev, :test], runtime: false} ) project end - defp edit_mix(%Project{} = project) do - Generator.replace_content( + defp edit_mix!(%Project{} = project) do + Generator.replace_content!( "mix.exs", """ codebase: [ diff --git a/lib/nimble_template/addons/variants/phoenix/web/style_lint.ex b/lib/nimble_template/addons/variants/phoenix/web/style_lint.ex index 32993aa0..15bceed4 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/style_lint.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/style_lint.ex @@ -4,28 +4,28 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.StyleLint do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> edit_files() - |> copy_files() + |> edit_files!() + |> copy_files!() end - defp edit_files(%Project{} = project) do + defp edit_files!(%Project{} = project) do project - |> edit_assets_package() - |> edit_mix() + |> edit_assets_package!() + |> edit_mix!() project end - defp copy_files(%Project{} = project) do - Generator.copy_file([{:text, "assets/.stylelintrc.json", "assets/.stylelintrc.json"}]) + defp copy_files!(%Project{} = project) do + Generator.copy_file!([{:text, "assets/.stylelintrc.json", "assets/.stylelintrc.json"}]) project end - defp edit_assets_package(%Project{} = project) do - Generator.replace_content( + defp edit_assets_package!(%Project{} = project) do + Generator.replace_content!( "assets/package.json", """ "scripts": { @@ -37,7 +37,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.StyleLint do """ ) - Generator.replace_content( + Generator.replace_content!( "assets/package.json", """ "devDependencies": { @@ -53,8 +53,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.StyleLint do project end - defp edit_mix(%Project{} = project) do - Generator.replace_content( + defp edit_mix!(%Project{} = project) do + Generator.replace_content!( "mix.exs", """ codebase: [ @@ -65,7 +65,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.StyleLint do """ ) - Generator.replace_content( + Generator.replace_content!( "mix.exs", """ "codebase.fix": [ diff --git a/lib/nimble_template/addons/variants/phoenix/web/svg_sprite.ex b/lib/nimble_template/addons/variants/phoenix/web/svg_sprite.ex index ddbc280f..84c1cab1 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/svg_sprite.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/svg_sprite.ex @@ -4,31 +4,31 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SvgSprite do use NimbleTemplate.Addons.Addon @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> edit_files() - |> copy_files() + |> edit_files!() + |> copy_files!() end - defp edit_files(%Project{} = project) do + defp edit_files!(%Project{} = project) do project - |> edit_assets_package() - |> edit_web_entry_point() - |> edit_wiki_sidebar() + |> edit_assets_package!() + |> edit_web_entry_point!() + |> edit_wiki_sidebar!() project end - defp copy_files(%Project{} = project) do + defp copy_files!(%Project{} = project) do project - |> copy_icon_helper() - |> copy_wiki_documentation() + |> copy_icon_helper!() + |> copy_wiki_documentation!() project end - defp edit_assets_package(%Project{} = project) do - Generator.replace_content( + defp edit_assets_package!(%Project{} = project) do + Generator.replace_content!( "assets/package.json", """ "scripts": { @@ -39,7 +39,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SvgSprite do """ ) - Generator.replace_content( + Generator.replace_content!( "assets/package.json", """ "devDependencies": { @@ -53,8 +53,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SvgSprite do project end - defp edit_web_entry_point(%Project{web_module: web_module, web_path: web_path} = project) do - Generator.replace_content( + defp edit_web_entry_point!(%Project{web_module: web_module, web_path: web_path} = project) do + Generator.replace_content!( "#{web_path}.ex", """ # Include shared imports and aliases for views @@ -71,9 +71,9 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SvgSprite do project end - defp edit_wiki_sidebar(project) do + defp edit_wiki_sidebar!(project) do if has_github_wiki_directory?() do - Generator.replace_content( + Generator.replace_content!( ".github/wiki/_Sidebar.md", """ - [[Getting Started]] @@ -91,11 +91,11 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SvgSprite do project end - defp copy_icon_helper( + defp copy_icon_helper!( %Project{web_module: web_module, web_path: web_path, web_test_path: web_test_path} = project ) do - Generator.copy_file( + Generator.copy_file!( [ {:eex, "lib/otp_app_web/helpers/icon_helper.ex.eex", "#{web_path}/helpers/icon_helper.ex"}, {:eex, "test/otp_app_web/helpers/icon_helper_test.exs.eex", @@ -107,9 +107,9 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SvgSprite do project end - defp copy_wiki_documentation(%Project{} = project) do + defp copy_wiki_documentation!(%Project{} = project) do if has_github_wiki_directory?() do - Generator.copy_file([{:text, ".github/wiki/Icon-Sprite.md", ".github/wiki/Icon-Sprite.md"}]) + Generator.copy_file!([{:text, ".github/wiki/Icon-Sprite.md", ".github/wiki/Icon-Sprite.md"}]) end project diff --git a/lib/nimble_template/addons/variants/phoenix/web/wallaby.ex b/lib/nimble_template/addons/variants/phoenix/web/wallaby.ex index d84c99f6..aa1bc173 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/wallaby.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/wallaby.ex @@ -6,14 +6,14 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Wallaby do alias NimbleTemplate.Addons.Phoenix.ExVCR @impl true - def do_apply(%Project{} = project, _opts) do + def do_apply!(%Project{} = project, _opts) do project - |> copy_files() - |> edit_files() + |> copy_files!() + |> edit_files!() end - def edit_endpoint(%Project{otp_app: otp_app} = project) do - Generator.replace_content( + 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} @@ -28,7 +28,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Wallaby do project end - defp copy_files( + defp copy_files!( %Project{ web_module: web_module, base_module: base_module, @@ -48,32 +48,32 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Wallaby do "#{web_test_path}/features/home_page/view_home_page_test.exs"} ] - Generator.copy_file(files, binding) + Generator.copy_file!(files, binding) project end - defp edit_files(%Project{} = project) do + defp edit_files!(%Project{} = project) do project - |> inject_mix_dependency() - |> edit_test_helper() - |> edit_endpoint() - |> edit_test_config() - |> edit_gitignore() + |> inject_mix_dependency!() + |> edit_test_helper!() + |> edit_endpoint!() + |> edit_test_config!() + |> edit_gitignore!() project end - defp inject_mix_dependency(%Project{} = project) do - Generator.inject_mix_dependency( + defp inject_mix_dependency!(%Project{} = project) do + Generator.inject_mix_dependency!( {:wallaby, latest_package_version(:wallaby), only: :test, runtime: false} ) project end - defp edit_test_helper(%Project{base_module: base_module, web_module: web_module} = project) do - Generator.replace_content( + defp edit_test_helper!(%Project{base_module: base_module, web_module: web_module} = project) do + Generator.replace_content!( "test/test_helper.exs", """ ExUnit.start() @@ -92,8 +92,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Wallaby do project end - defp edit_test_config(%Project{otp_app: otp_app} = project) do - Generator.replace_content( + defp edit_test_config!(%Project{otp_app: otp_app} = project) do + Generator.replace_content!( "config/test.exs", """ server: false @@ -114,8 +114,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Wallaby do project end - defp edit_gitignore(%Project{} = project) do - Generator.replace_content( + defp edit_gitignore!(%Project{} = project) do + Generator.replace_content!( ".gitignore", """ /_build/ diff --git a/lib/nimble_template/helpers/dependency.ex b/lib/nimble_template/helpers/dependency.ex index eb6ad62b..ce02185c 100644 --- a/lib/nimble_template/helpers/dependency.ex +++ b/lib/nimble_template/helpers/dependency.ex @@ -12,7 +12,7 @@ defmodule NimbleTemplate.DependencyHelper do |> Enum.sort() |> Enum.join(",\n") - Generator.replace_content("mix.exs", dependencies, ordered_dependencies) + Generator.replace_content!("mix.exs", dependencies, ordered_dependencies) end defp extract_dependencies(contents) do diff --git a/lib/nimble_template/helpers/generator.ex b/lib/nimble_template/helpers/generator.ex index 6e930dd5..ea2db802 100644 --- a/lib/nimble_template/helpers/generator.ex +++ b/lib/nimble_template/helpers/generator.ex @@ -3,17 +3,17 @@ defmodule NimbleTemplate.Generator do @template_resource "priv/templates/nimble_template" - def copy_directory(source_path, target_path, binding \\ []) do + def copy_directory!(source_path, target_path, binding \\ []) do root = Application.app_dir(:nimble_template, @template_resource) "#{root}/#{source_path}/**/*" |> Path.wildcard(match_dot: true) |> Enum.reject(&File.dir?/1) |> Enum.map(&String.replace(&1, "#{root}/", "")) - |> Enum.each(©_file([{:text, &1, String.replace(&1, source_path, target_path)}], binding)) + |> Enum.each(©_file!([{:text, &1, String.replace(&1, source_path, target_path)}], binding)) end - def copy_file(files, binding \\ []) do + def copy_file!(files, binding \\ []) do Mix.Phoenix.copy_from( [:nimble_template], @template_resource, @@ -22,61 +22,50 @@ defmodule NimbleTemplate.Generator do ) end - def rename_file(old_path, new_path), do: File.rename(old_path, new_path) + def rename_file!(old_path, new_path), do: File.rename!(old_path, new_path) - def replace_content(file_path, anchor, content, raise_exception \\ true) - - def replace_content(_file_path, anchor, content, _raise_exception) when anchor == content, - do: :ok + def replace_content!(file_path, anchor, content) do + case replace_content(file_path, anchor, content) do + :ok -> + :ok - def replace_content(file_path, anchor, content, raise_exception) do - file = Path.join([file_path]) + {:error, error_message} -> + Mix.raise(error_message) + end + end - file_content = - case File.read(file) do - {:ok, bin} -> bin - {:error, _} -> Mix.raise(~s[Can't read #{file}]) - end + def replace_content(_file_path, anchor, content) when anchor == content, do: :ok - case split_with_self(file_content, anchor) do - [left, _middle, right] -> - info_log("* replacing ", Path.relative_to_cwd(file_path)) - - File.write!(file, [left, content, right]) + def replace_content(file_path, anchor, content) do + file = Path.join([file_path]) - :error -> - if raise_exception do - Mix.raise(~s[Could not find #{anchor} in #{file_path}]) - else - :error - end + with {:ok, file_content} <- read_file(file), + :ok <- do_replace_content(file, file_path, file_content, content, anchor) do + :ok + else + {:error, error_message} -> + {:error, error_message} end end def replace_content_all(_file_path, anchor, content) when anchor == content, do: :ok def replace_content_all(file_path, anchor, content) do - case replace_content(file_path, anchor, content, false) do + case replace_content(file_path, anchor, content) do :ok -> replace_content_all(file_path, anchor, content) - :error -> + {:error, _} -> nil end end - def delete_content(file_path, anchor) do - replace_content(file_path, anchor, "") - end + def delete_content!(file_path, anchor), do: replace_content!(file_path, anchor, "") - def inject_content(file_path, anchor, content) do + def inject_content!(file_path, anchor, content) do file = Path.join([file_path]) - file_content = - case File.read(file) do - {:ok, bin} -> bin - {:error, _} -> Mix.raise(~s[Can't read #{file}]) - end + {:ok, file_content} = read_file!(file) case split_with_self(file_content, anchor) do [left, middle, right] -> @@ -115,21 +104,17 @@ defmodule NimbleTemplate.Generator do end end - def append_content(file_path, content) do + def append_content!(file_path, content) do file = Path.join([file_path]) - file_content = - case File.read(file) do - {:ok, bin} -> bin - {:error, _} -> Mix.raise(~s[Can't read #{file}]) - end + {:ok, file_content} = read_file!(file) info_log("* appending ", Path.relative_to_cwd(file_path)) File.write!(file, [file_content, content]) end - def inject_mix_dependency(dependencies) when is_list(dependencies) do - inject_content( + def inject_mix_dependency!(dependencies) when is_list(dependencies) do + inject_content!( "mix.exs", """ defp deps do @@ -141,8 +126,8 @@ defmodule NimbleTemplate.Generator do ) end - def inject_mix_dependency(dependency) do - inject_content( + def inject_mix_dependency!(dependency) do + inject_content!( "mix.exs", """ defp deps do @@ -152,7 +137,7 @@ defmodule NimbleTemplate.Generator do ) end - def make_directory(path, touch_directory \\ true) do + def make_directory!(path, touch_directory \\ true) do case File.mkdir_p(path) do :ok -> :ok @@ -161,10 +146,10 @@ defmodule NimbleTemplate.Generator do Mix.raise(~s[Failed to make directory #{path} reason: #{Atom.to_string(reason)}]) end - create_keep_file(path, touch_directory) + create_keep_file!(path, touch_directory) end - def create_file(path, content) do + def create_file!(path, content) do case File.write(path, content) do :ok -> :ok @@ -178,14 +163,7 @@ defmodule NimbleTemplate.Generator do def error_log(content \\ ""), do: Mix.shell().error(content) - defp split_with_self(contents, text) do - case :binary.split(contents, text) do - [left, right] -> [left, text, right] - [_] -> :error - end - end - - defp create_keep_file(path, true) do + defp create_keep_file!(path, true) do case File.touch("#{path}/.keep") do :ok -> :ok @@ -195,5 +173,50 @@ defmodule NimbleTemplate.Generator do end end - defp create_keep_file(_path, _touch_directory), do: :ok + defp create_keep_file!(_path, _touch_directory), do: :ok + + defp read_file(file) do + case File.read(file) do + {:ok, file_content} -> + {:ok, file_content} + + {:error, _} -> + {:error, ~s[Can't read #{file}]} + end + end + + defp read_file!(file) do + case read_file(file) do + {:ok, file_content} -> + {:ok, file_content} + + {:error, error_message} -> + Mix.raise(error_message) + end + end + + defp do_replace_content(file, file_path, file_content, content, anchor) do + case split_with_self(file_content, anchor) do + [left, _middle, right] -> + info_log("* replacing ", Path.relative_to_cwd(file_path)) + + case File.write(file, [left, content, right]) do + :ok -> + :ok + + {:error, _} -> + {:error, ~s[Could not replace content in #{file_path}]} + end + + :error -> + {:error, ~s[Could not find #{anchor} in #{file_path}]} + end + end + + defp split_with_self(contents, text) do + case :binary.split(contents, text) do + [left, right] -> [left, text, right] + [_] -> :error + end + end end diff --git a/lib/nimble_template/templates/template.ex b/lib/nimble_template/templates/template.ex index 4ac13364..3cf0a611 100644 --- a/lib/nimble_template/templates/template.ex +++ b/lib/nimble_template/templates/template.ex @@ -9,37 +9,37 @@ defmodule NimbleTemplate.Templates.Template do alias NimbleTemplate.Templates.Mix.Template, as: MixTemplate alias NimbleTemplate.Templates.Phoenix.Template, as: PhoenixTemplate - def apply(%Project{mix_project?: true} = project) do - MixTemplate.apply(project) + def apply!(%Project{mix_project?: true} = project) do + MixTemplate.apply!(project) - ExUnit.apply(project) + ExUnit.apply!(project) - post_apply(project) + post_apply!(project) end - def apply(%Project{mix_project?: false} = project) do - PhoenixTemplate.apply(project) + def apply!(%Project{mix_project?: false} = project) do + PhoenixTemplate.apply!(project) - ExUnit.apply(project) + ExUnit.apply!(project) - post_apply(project) + post_apply!(project) end - defp post_apply(%Project{mix_project?: true} = project) do + defp post_apply!(%Project{mix_project?: true} = project) do order_dependencies!() fetch_and_install_elixir_dependencies() suppress_necessary_credo_warnings(project) format_codebase() end - defp post_apply(%Project{api_project?: true} = project) do + defp post_apply!(%Project{api_project?: true} = project) do order_dependencies!() fetch_and_install_elixir_dependencies() suppress_necessary_credo_warnings(project) format_codebase() end - defp post_apply(%Project{web_project?: true} = project) do + defp post_apply!(%Project{web_project?: true} = project) do order_dependencies!() fetch_and_install_elixir_dependencies() fetch_and_install_node_dependencies() diff --git a/lib/nimble_template/templates/variants/mix/template.ex b/lib/nimble_template/templates/variants/mix/template.ex index 25bda993..2909d598 100644 --- a/lib/nimble_template/templates/variants/mix/template.ex +++ b/lib/nimble_template/templates/variants/mix/template.ex @@ -6,7 +6,7 @@ defmodule NimbleTemplate.Templates.Mix.Template do alias NimbleTemplate.Addons alias NimbleTemplate.Projects.Project - def apply(%Project{} = project) do + def apply!(%Project{} = project) do project |> apply_default_mix_addons() |> apply_optional_mix_addons() @@ -14,36 +14,36 @@ defmodule NimbleTemplate.Templates.Mix.Template do defp apply_default_mix_addons(project) do project - |> Addons.AsdfToolVersion.apply() - |> Addons.Readme.apply() - |> Addons.TestEnv.apply() - |> Addons.Credo.apply() - |> Addons.Dialyxir.apply() - |> Addons.ExCoveralls.apply() - |> Addons.Faker.apply() - |> Addons.Git.apply() - |> Addons.TestInteractive.apply() - |> Addons.Iex.apply() + |> Addons.AsdfToolVersion.apply!() + |> Addons.Readme.apply!() + |> Addons.TestEnv.apply!() + |> Addons.Credo.apply!() + |> Addons.Dialyxir.apply!() + |> Addons.ExCoveralls.apply!() + |> Addons.Faker.apply!() + |> Addons.Git.apply!() + |> Addons.TestInteractive.apply!() + |> Addons.Iex.apply!() end defp apply_optional_mix_addons(project) do if host_on_github?() do if generate_github_template?(), - do: Addons.Github.apply(project, %{github_template: true}) + do: Addons.Github.apply!(project, %{github_template: true}) generate_github_action_test? = generate_github_action_test?() if generate_github_action_test?, - do: Addons.Github.apply(project, %{github_action_test: true}) + do: Addons.Github.apply!(project, %{github_action_test: true}) generate_github_wiki? = generate_github_wiki?() if generate_github_wiki?, - do: Addons.Github.apply(project, %{github_wiki: true}) + do: Addons.Github.apply!(project, %{github_wiki: true}) if generate_github_workflows_readme?(), do: - Addons.Github.apply(project, %{ + Addons.Github.apply!(project, %{ github_workflows_readme: true, with_test_workflow?: generate_github_action_test?, with_github_wiki?: generate_github_wiki?, @@ -51,7 +51,7 @@ defmodule NimbleTemplate.Templates.Mix.Template do }) end - if install_addon_prompt?("Mimic"), do: Addons.Mimic.apply(project) + if install_addon_prompt?("Mimic"), do: Addons.Mimic.apply!(project) project end diff --git a/lib/nimble_template/templates/variants/phoenix/api/template.ex b/lib/nimble_template/templates/variants/phoenix/api/template.ex index 4924c5e7..9fcf9ba4 100644 --- a/lib/nimble_template/templates/variants/phoenix/api/template.ex +++ b/lib/nimble_template/templates/variants/phoenix/api/template.ex @@ -4,17 +4,17 @@ defmodule NimbleTemplate.Templates.Phoenix.Api.Template do alias NimbleTemplate.Addons.Phoenix.Api alias NimbleTemplate.Projects.Project - def apply(%Project{} = project) do + def apply!(%Project{} = project) do apply_default_api_addons(project) end defp apply_default_api_addons(project) do project - |> Api.Config.apply() - |> Api.EmptyBodyParamsPlug.apply() - |> Api.ParamsValidation.apply() - |> Api.ErrorView.apply() - |> Api.JsonApi.apply() - |> Api.FallbackController.apply() + |> Api.Config.apply!() + |> Api.EmptyBodyParamsPlug.apply!() + |> Api.ParamsValidation.apply!() + |> Api.ErrorView.apply!() + |> Api.JsonApi.apply!() + |> Api.FallbackController.apply!() end end diff --git a/lib/nimble_template/templates/variants/phoenix/live/template.ex b/lib/nimble_template/templates/variants/phoenix/live/template.ex index d226357a..462a9d3c 100644 --- a/lib/nimble_template/templates/variants/phoenix/live/template.ex +++ b/lib/nimble_template/templates/variants/phoenix/live/template.ex @@ -4,11 +4,11 @@ defmodule NimbleTemplate.Templates.Phoenix.Live.Template do alias NimbleTemplate.Projects.Project alias NimbleTemplate.Templates.Phoenix.Web.Template, as: WebTemplate - def apply(%Project{} = project) do + def apply!(%Project{} = project) do apply_web_addons(project) end defp apply_web_addons(project) do - WebTemplate.apply(project) + WebTemplate.apply!(project) end end diff --git a/lib/nimble_template/templates/variants/phoenix/template.ex b/lib/nimble_template/templates/variants/phoenix/template.ex index d7224849..77ae5d4f 100644 --- a/lib/nimble_template/templates/variants/phoenix/template.ex +++ b/lib/nimble_template/templates/variants/phoenix/template.ex @@ -10,7 +10,7 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do alias NimbleTemplate.Templates.Phoenix.Live.Template, as: LiveTemplate alias NimbleTemplate.Templates.Phoenix.Web.Template, as: WebTemplate - def apply(%Project{} = project) do + def apply!(%Project{} = project) do project |> apply_phoenix_common_setup() |> apply_phoenix_variant_setup() @@ -19,7 +19,7 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do # credo:disable-for-next-line Credo.Check.Refactor.ABCSize defp apply_phoenix_common_setup(%Project{} = project) do # TODO: Remove me after the Phoenix generator fix releases: https://github.com/phoenixframework/phoenix/pull/4894 - remove_mix_compiler_config() + remove_mix_compiler_config!() project |> apply_default_common_phoenix_addons() @@ -34,29 +34,29 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do defp apply_default_common_addons(project) do project - |> Addons.AsdfToolVersion.apply() - |> Addons.Readme.apply() - |> Addons.TestEnv.apply() - |> Addons.Credo.apply() - |> Addons.Dialyxir.apply() - |> Addons.ExCoveralls.apply() - |> Addons.Mimic.apply() - |> Addons.Faker.apply() - |> Addons.Git.apply() - |> Addons.TestInteractive.apply() - |> Addons.Iex.apply() + |> Addons.AsdfToolVersion.apply!() + |> Addons.Readme.apply!() + |> Addons.TestEnv.apply!() + |> Addons.Credo.apply!() + |> Addons.Dialyxir.apply!() + |> Addons.ExCoveralls.apply!() + |> Addons.Mimic.apply!() + |> Addons.Faker.apply!() + |> Addons.Git.apply!() + |> Addons.TestInteractive.apply!() + |> Addons.Iex.apply!() end defp apply_default_phoenix_addons(project) do project - |> PhoenixAddons.ExMachina.apply() - |> PhoenixAddons.Makefile.apply() - |> PhoenixAddons.Docker.apply() - |> PhoenixAddons.EctoDataMigration.apply() - |> PhoenixAddons.MixRelease.apply() - |> PhoenixAddons.HealthPlug.apply() - |> PhoenixAddons.Gettext.apply(project) - |> PhoenixAddons.Seeds.apply(project) + |> PhoenixAddons.ExMachina.apply!() + |> PhoenixAddons.Makefile.apply!() + |> PhoenixAddons.Docker.apply!() + |> PhoenixAddons.EctoDataMigration.apply!() + |> PhoenixAddons.MixRelease.apply!() + |> PhoenixAddons.HealthPlug.apply!() + |> PhoenixAddons.Gettext.apply!(project) + |> PhoenixAddons.Seeds.apply!(project) end defp apply_optional_common_phoenix_addons(project) do @@ -72,31 +72,31 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do end defp apply_optional_phoenix_addons(project) do - if install_addon_prompt?("Oban"), do: PhoenixAddons.Oban.apply(project) - if install_addon_prompt?("ExVCR"), do: PhoenixAddons.ExVCR.apply(project) + if install_addon_prompt?("Oban"), do: PhoenixAddons.Oban.apply!(project) + if install_addon_prompt?("ExVCR"), do: PhoenixAddons.ExVCR.apply!(project) project end defp github_addons_setup(%Project{} = project) do if generate_github_template?(), - do: Addons.Github.apply(project, %{github_template: true}) + do: Addons.Github.apply!(project, %{github_template: true}) generate_github_action_test? = generate_github_action_test?() if generate_github_action_test?, - do: Addons.Github.apply(project, %{github_action_test: true}) + do: Addons.Github.apply!(project, %{github_action_test: true}) generate_github_action_deploy_heroku? = generate_github_action_deploy_heroku?() if generate_github_action_deploy_heroku?, - do: Addons.Github.apply(project, %{github_action_deploy_heroku: true}) + do: Addons.Github.apply!(project, %{github_action_deploy_heroku: true}) generate_github_wiki? = generate_github_wiki?() if generate_github_workflows_readme?(), do: - Addons.Github.apply(project, %{ + Addons.Github.apply!(project, %{ github_workflows_readme: true, with_test_workflow?: generate_github_action_test?, with_github_wiki?: generate_github_wiki?, @@ -104,19 +104,18 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do }) if generate_github_wiki?, - do: Addons.Github.apply(project, %{github_wiki: true}) + do: Addons.Github.apply!(project, %{github_wiki: true}) end defp apply_phoenix_variant_setup(%Project{api_project?: true} = project), - do: ApiTemplate.apply(project) + do: ApiTemplate.apply!(project) defp apply_phoenix_variant_setup(%Project{web_project?: true, live_project?: false} = project), - do: WebTemplate.apply(project) + do: WebTemplate.apply!(project) defp apply_phoenix_variant_setup(%Project{web_project?: true, live_project?: true} = project), - do: LiveTemplate.apply(project) + do: LiveTemplate.apply!(project) - defp remove_mix_compiler_config() do - Generator.delete_content("mix.exs", "compilers: [:gettext] ++ Mix.compilers(),") - end + defp remove_mix_compiler_config!(), + do: Generator.delete_content!("mix.exs", "compilers: [:gettext] ++ Mix.compilers(),") end diff --git a/lib/nimble_template/templates/variants/phoenix/web/template.ex b/lib/nimble_template/templates/variants/phoenix/web/template.ex index b7242ebf..e60bc408 100644 --- a/lib/nimble_template/templates/variants/phoenix/web/template.ex +++ b/lib/nimble_template/templates/variants/phoenix/web/template.ex @@ -6,7 +6,7 @@ defmodule NimbleTemplate.Templates.Phoenix.Web.Template do alias NimbleTemplate.Addons.Phoenix.Web alias NimbleTemplate.Projects.Project - def apply(%Project{} = project) do + def apply!(%Project{} = project) do project |> apply_default_web_addons() |> apply_optional_web_addons() @@ -14,28 +14,28 @@ defmodule NimbleTemplate.Templates.Phoenix.Web.Template do defp apply_default_web_addons(project) do project - |> Web.NodePackage.apply() - |> Web.Assets.apply() - |> Web.CoreJS.apply() - |> Web.Prettier.apply() - |> Web.Sobelow.apply() - |> Web.Wallaby.apply() - |> Web.EsLint.apply() - |> Web.StyleLint.apply() - |> Web.EsBuild.apply() - |> Web.PostCSS.apply() - |> Web.HeexFormatter.apply() + |> Web.NodePackage.apply!() + |> Web.Assets.apply!() + |> Web.CoreJS.apply!() + |> Web.Prettier.apply!() + |> Web.Sobelow.apply!() + |> Web.Wallaby.apply!() + |> Web.EsLint.apply!() + |> Web.StyleLint.apply!() + |> Web.EsBuild.apply!() + |> Web.PostCSS.apply!() + |> Web.HeexFormatter.apply!() end defp apply_optional_web_addons(project) do - if install_addon_prompt?("SVG Sprite"), do: Web.SvgSprite.apply(project) + if install_addon_prompt?("SVG Sprite"), do: Web.SvgSprite.apply!(project) if install_addon_prompt?("Dart Sass") do - Web.DartSass.apply(project) + Web.DartSass.apply!(project) apply_dart_sass_requires_addons(project) else - if install_addon_prompt?("Nimble JS"), do: Web.NimbleJS.apply(project) + if install_addon_prompt?("Nimble JS"), do: Web.NimbleJS.apply!(project) end project @@ -45,7 +45,7 @@ defmodule NimbleTemplate.Templates.Phoenix.Web.Template do defp apply_dart_sass_requires_addons(project) do with_nimble_css_addon = if install_addon_prompt?("Nimble CSS") do - Web.NimbleCSS.apply(project) + Web.NimbleCSS.apply!(project) true else @@ -54,7 +54,7 @@ defmodule NimbleTemplate.Templates.Phoenix.Web.Template do with_nimble_js_addon = if install_addon_prompt?("Nimble JS") do - Web.NimbleJS.apply(project) + Web.NimbleJS.apply!(project) true else @@ -63,7 +63,7 @@ defmodule NimbleTemplate.Templates.Phoenix.Web.Template do if install_addon_prompt?("Bootstrap"), do: - Web.Bootstrap.apply(project, %{ + Web.Bootstrap.apply!(project, %{ with_nimble_css_addon: with_nimble_css_addon, with_nimble_js_addon: with_nimble_js_addon }) diff --git a/lib/nimble_template/version.ex b/lib/nimble_template/version.ex index 9dcce2ea..dd722243 100644 --- a/lib/nimble_template/version.ex +++ b/lib/nimble_template/version.ex @@ -4,11 +4,11 @@ defmodule NimbleTemplate.Version do alias NimbleTemplate.Generator alias NimbleTemplate.Projects.Project - def bump(new_version) do + def bump!(new_version) do current_version = Mix.Project.config()[:version] if new_version > current_version do - bump_version_to(current_version, new_version) + bump_version_to!(current_version, new_version) :ok else @@ -16,55 +16,55 @@ defmodule NimbleTemplate.Version do end end - def upgrade_stack(elixir_erlang_node_alpine_versions) do + def upgrade_stack!(elixir_erlang_node_alpine_versions) do elixir_version = Keyword.get(elixir_erlang_node_alpine_versions, :elixir, "") erlang_version = Keyword.get(elixir_erlang_node_alpine_versions, :erlang, "") node_version = Keyword.get(elixir_erlang_node_alpine_versions, :node, "") alpine_version = Keyword.get(elixir_erlang_node_alpine_versions, :alpine, "") if elixir_version != "" do - upgrade_elixir(elixir_version) + upgrade_elixir!(elixir_version) end if erlang_version != "" do - upgrade_erlang(erlang_version) + upgrade_erlang!(erlang_version) end if alpine_version != "" do - upgrade_alpine(alpine_version) + upgrade_alpine!(alpine_version) end if node_version != "" do - upgrade_node(node_version) + upgrade_node!(node_version) end :ok end - defp bump_version_to(current_version, new_version) do - Generator.replace_content( + defp bump_version_to!(current_version, new_version) do + Generator.replace_content!( "mix.exs", "version: \"#{current_version}\",", "version: \"#{new_version}\"," ) - Generator.replace_content( + Generator.replace_content!( "README.md", "{:nimble_template, \"~> #{current_version}\", only: :dev, runtime: false},", "{:nimble_template, \"~> #{new_version}\", only: :dev, runtime: false}," ) end - defp upgrade_elixir(new_version) do + defp upgrade_elixir!(new_version) do current_version = Project.elixir_version() - Generator.replace_content( + Generator.replace_content!( "lib/nimble_template/projects/project.ex", "@elixir_version \"#{current_version}\"", "@elixir_version \"#{new_version}\"" ) - Generator.replace_content( + Generator.replace_content!( ".tool-versions", "elixir #{current_version}", "elixir #{new_version}" @@ -88,29 +88,29 @@ defmodule NimbleTemplate.Version do "Elixir #{new_version}" ) - Generator.replace_content( + Generator.replace_content!( "test/nimble_template/addons/variants/docker_test.exs", "ELIXIR_IMAGE_VERSION=#{current_version}", "ELIXIR_IMAGE_VERSION=#{new_version}" ) end - defp upgrade_erlang(new_version) do + defp upgrade_erlang!(new_version) do current_version = Project.erlang_version() - Generator.replace_content( + Generator.replace_content!( "lib/nimble_template/projects/project.ex", "@erlang_version \"#{current_version}\"", "@erlang_version \"#{new_version}\"" ) - Generator.replace_content( + Generator.replace_content!( ".tool-versions", "erlang #{current_version}", "erlang #{new_version}" ) - Generator.replace_content( + Generator.replace_content!( ".tool-versions", "-otp-#{Project.get_otp_major_version(current_version)}", "-otp-#{Project.get_otp_major_version(new_version)}" @@ -140,39 +140,39 @@ defmodule NimbleTemplate.Version do "Erlang #{new_version}" ) - Generator.replace_content( + Generator.replace_content!( "test/nimble_template/addons/variants/docker_test.exs", "ERLANG_IMAGE_VERSION=#{current_version}", "ERLANG_IMAGE_VERSION=#{new_version}" ) end - defp upgrade_alpine(new_version) do + defp upgrade_alpine!(new_version) do current_version = Project.alpine_version() - Generator.replace_content( + Generator.replace_content!( "lib/nimble_template/projects/project.ex", "@alpine_version \"#{current_version}\"", "@alpine_version \"#{new_version}\"" ) - Generator.replace_content( + Generator.replace_content!( "test/nimble_template/addons/variants/docker_test.exs", "RELEASE_IMAGE_VERSION=#{current_version}", "RELEASE_IMAGE_VERSION=#{new_version}" ) end - defp upgrade_node(new_version) do + defp upgrade_node!(new_version) do current_version = Project.node_asdf_version() - Generator.replace_content( + Generator.replace_content!( "lib/nimble_template/projects/project.ex", "@node_asdf_version \"#{current_version}\"", "@node_asdf_version \"#{new_version}\"" ) - Generator.replace_content( + Generator.replace_content!( ".tool-versions", "nodejs #{current_version}", "nodejs #{new_version}" diff --git a/test/nimble_template/addons/asdf_tool_version_test.exs b/test/nimble_template/addons/asdf_tool_version_test.exs index eb996779..758111e0 100644 --- a/test/nimble_template/addons/asdf_tool_version_test.exs +++ b/test/nimble_template/addons/asdf_tool_version_test.exs @@ -4,13 +4,13 @@ defmodule NimbleTemplate.Addons.AsdfToolVersionTest do alias NimbleTemplate.Addons.AsdfToolVersion alias NimbleTemplate.Projects.Project - describe "#apply/2 with web_project" do + describe "#apply!/2 with web_project" do test "copies the .tool-versions", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.AsdfToolVersion.apply(project) + in_test_project!(test_project_path, fn -> + Addons.AsdfToolVersion.apply!(project) assert_file(".tool-versions", fn file -> assert file =~ """ @@ -26,23 +26,23 @@ defmodule NimbleTemplate.Addons.AsdfToolVersionTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - %Project{installed_addons: installed_addons} = Addons.AsdfToolVersion.apply(project) + in_test_project!(test_project_path, fn -> + %Project{installed_addons: installed_addons} = Addons.AsdfToolVersion.apply!(project) assert AsdfToolVersion in installed_addons == true end) end end - describe "#apply/2 with api_project" do + describe "#apply!/2 with api_project" do test "copies the .tool-versions", %{ project: project, test_project_path: test_project_path } do project = %{project | api_project?: true, web_project?: false} - in_test_project(test_project_path, fn -> - Addons.AsdfToolVersion.apply(project) + in_test_project!(test_project_path, fn -> + Addons.AsdfToolVersion.apply!(project) assert_file(".tool-versions", fn file -> assert file =~ """ @@ -56,15 +56,15 @@ defmodule NimbleTemplate.Addons.AsdfToolVersionTest do end end - describe "#apply/2 with mix_project" do + describe "#apply!/2 with mix_project" do @describetag mix_project?: true test "copies the .tool-versions", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.AsdfToolVersion.apply(project) + in_test_project!(test_project_path, fn -> + Addons.AsdfToolVersion.apply!(project) assert_file(".tool-versions", fn file -> assert file =~ """ diff --git a/test/nimble_template/addons/credo_test.exs b/test/nimble_template/addons/credo_test.exs index 96d68aef..31887bd9 100644 --- a/test/nimble_template/addons/credo_test.exs +++ b/test/nimble_template/addons/credo_test.exs @@ -1,7 +1,7 @@ defmodule NimbleTemplate.Addons.CredoTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag mock_latest_package_versions: [{:credo, "1.4"}, {:compass_credo_plugin, "1.0.0"}] @describetag required_addons: [:TestEnv] @@ -9,8 +9,8 @@ defmodule NimbleTemplate.Addons.CredoTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Credo.apply(project) + in_test_project!(test_project_path, fn -> + Addons.Credo.apply!(project) assert_file(".credo.exs") end) @@ -20,8 +20,8 @@ defmodule NimbleTemplate.Addons.CredoTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Credo.apply(project) + in_test_project!(test_project_path, fn -> + Addons.Credo.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -35,8 +35,8 @@ defmodule NimbleTemplate.Addons.CredoTest do end test "adds credo codebase alias", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - Addons.Credo.apply(project) + in_test_project!(test_project_path, fn -> + Addons.Credo.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -50,7 +50,7 @@ defmodule NimbleTemplate.Addons.CredoTest do end end - describe "#apply/2 with mix_project" do + describe "#apply!/2 with mix_project" do @describetag mix_project?: true @describetag mock_latest_package_versions: [{:credo, "1.4"}] @describetag required_addons: [:TestEnv] @@ -59,8 +59,8 @@ defmodule NimbleTemplate.Addons.CredoTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Credo.apply(project) + in_test_project!(test_project_path, fn -> + Addons.Credo.apply!(project) assert_file(".credo.exs") end) @@ -70,8 +70,8 @@ defmodule NimbleTemplate.Addons.CredoTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Credo.apply(project) + in_test_project!(test_project_path, fn -> + Addons.Credo.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -84,8 +84,8 @@ defmodule NimbleTemplate.Addons.CredoTest do end test "adds credo codebase alias", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - Addons.Credo.apply(project) + in_test_project!(test_project_path, fn -> + Addons.Credo.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ diff --git a/test/nimble_template/addons/dialyxir_test.exs b/test/nimble_template/addons/dialyxir_test.exs index e6e0685e..99f72e0b 100644 --- a/test/nimble_template/addons/dialyxir_test.exs +++ b/test/nimble_template/addons/dialyxir_test.exs @@ -1,15 +1,15 @@ defmodule NimbleTemplate.Addons.DialyxirTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag mock_latest_package_versions: [{:dialyxir, "1.0"}] test "injects dialyxir to mix dependency", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Dialyxir.apply(project) + in_test_project!(test_project_path, fn -> + Addons.Dialyxir.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ diff --git a/test/nimble_template/addons/ex_coveralls_test.exs b/test/nimble_template/addons/ex_coveralls_test.exs index 92c5d9d2..ab9d3f48 100644 --- a/test/nimble_template/addons/ex_coveralls_test.exs +++ b/test/nimble_template/addons/ex_coveralls_test.exs @@ -1,15 +1,15 @@ defmodule NimbleTemplate.Addons.ExCoverallsTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag mock_latest_package_versions: [{:excoveralls, "0.12.2"}] test "copies the coveralls.json", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.ExCoveralls.apply(project) + in_test_project!(test_project_path, fn -> + Addons.ExCoveralls.apply!(project) assert_file("coveralls.json", fn file -> assert file =~ "minimum_coverage\": 100" @@ -22,8 +22,8 @@ defmodule NimbleTemplate.Addons.ExCoverallsTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.ExCoveralls.apply(project) + in_test_project!(test_project_path, fn -> + Addons.ExCoveralls.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -36,8 +36,8 @@ defmodule NimbleTemplate.Addons.ExCoverallsTest do end test "sets ExCoveralls tool", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - Addons.ExCoveralls.apply(project) + in_test_project!(test_project_path, fn -> + Addons.ExCoveralls.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -55,8 +55,8 @@ defmodule NimbleTemplate.Addons.ExCoverallsTest do end test "adds coverage alias", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - Addons.ExCoveralls.apply(project) + in_test_project!(test_project_path, fn -> + Addons.ExCoveralls.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -69,7 +69,7 @@ defmodule NimbleTemplate.Addons.ExCoverallsTest do end end - describe "#apply/2 with mix_project" do + describe "#apply!/2 with mix_project" do @describetag mix_project?: true @describetag required_addons: [:TestEnv] @describetag mock_latest_package_versions: [{:excoveralls, "0.12.2"}] @@ -78,8 +78,8 @@ defmodule NimbleTemplate.Addons.ExCoverallsTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.ExCoveralls.apply(project) + in_test_project!(test_project_path, fn -> + Addons.ExCoveralls.apply!(project) assert_file("coveralls.json") end) @@ -89,8 +89,8 @@ defmodule NimbleTemplate.Addons.ExCoverallsTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.ExCoveralls.apply(project) + in_test_project!(test_project_path, fn -> + Addons.ExCoveralls.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -103,8 +103,8 @@ defmodule NimbleTemplate.Addons.ExCoverallsTest do end test "sets ExCoveralls tool", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - Addons.ExCoveralls.apply(project) + in_test_project!(test_project_path, fn -> + Addons.ExCoveralls.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -122,8 +122,8 @@ defmodule NimbleTemplate.Addons.ExCoverallsTest do end test "adds coverage alias", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - Addons.ExCoveralls.apply(project) + in_test_project!(test_project_path, fn -> + Addons.ExCoveralls.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ diff --git a/test/nimble_template/addons/ex_unit_test.exs b/test/nimble_template/addons/ex_unit_test.exs index 3730c54c..2481953d 100644 --- a/test/nimble_template/addons/ex_unit_test.exs +++ b/test/nimble_template/addons/ex_unit_test.exs @@ -1,11 +1,11 @@ defmodule NimbleTemplate.Addons.ExUnitTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do test "sets `ExUnit.start(capture_log: true)` in `test/test_helper.exs`", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - Addons.ExUnit.apply(project) + in_test_project!(test_project_path, fn -> + Addons.ExUnit.apply!(project) assert_file("test/test_helper.exs", fn file -> assert file =~ "ExUnit.start(capture_log: true)" diff --git a/test/nimble_template/addons/faker_test.exs b/test/nimble_template/addons/faker_test.exs index 93ae0646..e21242b5 100644 --- a/test/nimble_template/addons/faker_test.exs +++ b/test/nimble_template/addons/faker_test.exs @@ -1,15 +1,15 @@ defmodule NimbleTemplate.Addons.FakerTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag mock_latest_package_versions: [{:faker, "0.17.0"}] test "injects faker to mix dependency", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Faker.apply(project) + in_test_project!(test_project_path, fn -> + Addons.Faker.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ diff --git a/test/nimble_template/addons/git_test.exs b/test/nimble_template/addons/git_test.exs index 40ce6286..ecabbc3d 100644 --- a/test/nimble_template/addons/git_test.exs +++ b/test/nimble_template/addons/git_test.exs @@ -1,13 +1,13 @@ defmodule NimbleTemplate.Addons.GitTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do test "adjusts the .gitignore file", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Git.apply(project) + in_test_project!(test_project_path, fn -> + Addons.Git.apply!(project) assert_file(".gitignore", fn file -> assert file =~ """ @@ -29,15 +29,15 @@ defmodule NimbleTemplate.Addons.GitTest do end end - describe "#apply/2 with mix_project" do + describe "#apply!/2 with mix_project" do @describetag mix_project?: true test "adjusts the .gitignore file", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Git.apply(project) + in_test_project!(test_project_path, fn -> + Addons.Git.apply!(project) assert_file(".gitignore", fn file -> assert file =~ """ diff --git a/test/nimble_template/addons/github_test.exs b/test/nimble_template/addons/github_test.exs index 02c6ec3b..38f4c066 100644 --- a/test/nimble_template/addons/github_test.exs +++ b/test/nimble_template/addons/github_test.exs @@ -1,13 +1,13 @@ defmodule NimbleTemplate.Addons.GithubTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2 with github_template option" do + describe "#apply!/2 with github_template option" do test "copies the .github/ISSUE_TEMPLATE.md", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_template: true}) + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{github_template: true}) assert_file(".github/ISSUE_TEMPLATE.md") end) @@ -17,8 +17,8 @@ defmodule NimbleTemplate.Addons.GithubTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_template: true}) + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{github_template: true}) assert_file(".github/PULL_REQUEST_TEMPLATE.md") end) @@ -28,23 +28,23 @@ defmodule NimbleTemplate.Addons.GithubTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_template: true}) + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{github_template: true}) assert_file(".github/PULL_REQUEST_TEMPLATE/RELEASE_TEMPLATE.md") end) end end - describe "#apply/2 with mix_project and github_template option" do + describe "#apply!/2 with mix_project and github_template option" do @describetag mix_project?: true test "copies the .github/ISSUE_TEMPLATE.md", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_template: true}) + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{github_template: true}) assert_file(".github/ISSUE_TEMPLATE.md") end) @@ -54,8 +54,8 @@ defmodule NimbleTemplate.Addons.GithubTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_template: true}) + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{github_template: true}) assert_file(".github/PULL_REQUEST_TEMPLATE.md") end) @@ -65,21 +65,21 @@ defmodule NimbleTemplate.Addons.GithubTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_template: true}) + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{github_template: true}) assert_file(".github/PULL_REQUEST_TEMPLATE/RELEASE_TEMPLATE.md") end) end end - describe "#apply/2 with github_workflows_readme option" do + describe "#apply!/2 with github_workflows_readme option" do test "copies the .github/workflows/README.md", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{ + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{ github_workflows_readme: true, with_test_workflow?: true, with_github_wiki?: true, @@ -103,8 +103,8 @@ defmodule NimbleTemplate.Addons.GithubTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{ + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{ github_workflows_readme: true, with_test_workflow?: false, with_github_wiki?: true, @@ -128,8 +128,8 @@ defmodule NimbleTemplate.Addons.GithubTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{ + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{ github_workflows_readme: true, with_test_workflow?: true, with_github_wiki?: false, @@ -154,8 +154,8 @@ defmodule NimbleTemplate.Addons.GithubTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{ + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{ github_workflows_readme: true, with_test_workflow?: true, with_github_wiki?: true, @@ -180,8 +180,8 @@ defmodule NimbleTemplate.Addons.GithubTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{ + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{ github_workflows_readme: true, with_test_workflow?: false, with_github_wiki?: false, @@ -202,15 +202,15 @@ defmodule NimbleTemplate.Addons.GithubTest do end end - describe "#apply/2 with mix_project and github_workflows_readme option" do + describe "#apply!/2 with mix_project and github_workflows_readme option" do @describetag mix_project?: true test "copies the .github/workflows/README.md", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{ + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{ github_workflows_readme: true, with_test_workflow?: true, with_github_wiki?: true, @@ -234,8 +234,8 @@ defmodule NimbleTemplate.Addons.GithubTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{ + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{ github_workflows_readme: true, with_test_workflow?: false, with_github_wiki?: true, @@ -259,8 +259,8 @@ defmodule NimbleTemplate.Addons.GithubTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{ + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{ github_workflows_readme: true, with_test_workflow?: true, with_github_wiki?: false, @@ -281,15 +281,15 @@ defmodule NimbleTemplate.Addons.GithubTest do end end - describe "#apply/2 with api_project and github_action_test option" do + describe "#apply!/2 with api_project and github_action_test option" do test "does NOT include the npm setting", %{ project: project, test_project_path: test_project_path } do project = %{project | api_project?: true, web_project?: false} - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_action_test: true}) + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{github_action_test: true}) assert_file(".github/workflows/test.yml", fn file -> refute file =~ "assets/node_modules" @@ -301,13 +301,13 @@ defmodule NimbleTemplate.Addons.GithubTest do end end - describe "#apply/2 with web_project and github_action_test option" do + describe "#apply!/2 with web_project and github_action_test option" do test "includes the npm setting", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_action_test: true}) + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{github_action_test: true}) assert_file(".github/workflows/test.yml", fn file -> assert file =~ "assets/node_modules" @@ -319,15 +319,15 @@ defmodule NimbleTemplate.Addons.GithubTest do end end - describe "#apply/2 with mix_project and github_action_test option" do + describe "#apply!/2 with mix_project and github_action_test option" do @describetag mix_project?: true test "does NOT include database setting", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_action_test: true}) + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{github_action_test: true}) assert_file(".github/workflows/test.yml", fn file -> refute file =~ "postgres" @@ -341,8 +341,8 @@ defmodule NimbleTemplate.Addons.GithubTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_action_test: true}) + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{github_action_test: true}) assert_file(".github/workflows/test.yml", fn file -> refute file =~ "assets/node_modules" @@ -354,15 +354,15 @@ defmodule NimbleTemplate.Addons.GithubTest do end end - describe "#apply/2 with api_project and github_action_deploy_heroku option" do + describe "#apply!/2 with api_project and github_action_deploy_heroku option" do test "copies the .github/workflows/deploy_heroku.yml file", %{ project: project, test_project_path: test_project_path } do project = %{project | api_project?: true, web_project?: false} - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_action_deploy_heroku: true}) + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{github_action_deploy_heroku: true}) assert_file(".github/workflows/deploy_heroku.yml") end) @@ -374,8 +374,8 @@ defmodule NimbleTemplate.Addons.GithubTest do } do project = %{project | api_project?: true, web_project?: false} - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_action_deploy_heroku: true}) + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{github_action_deploy_heroku: true}) assert_file("config/runtime.exs", fn file -> assert file =~ "url: [scheme: \"https\", host: host," @@ -394,8 +394,8 @@ defmodule NimbleTemplate.Addons.GithubTest do } do project = %{project | api_project?: true, web_project?: false} - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_action_deploy_heroku: true}) + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{github_action_deploy_heroku: true}) assert_file("config/prod.exs", fn file -> assert file =~ """ @@ -407,41 +407,41 @@ defmodule NimbleTemplate.Addons.GithubTest do end end - describe "#apply/2 with web_project and github_action_deploy_heroku option" do + describe "#apply!/2 with web_project and github_action_deploy_heroku option" do test "copies the .github/workflows/deploy_heroku.yml file", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_action_deploy_heroku: true}) + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{github_action_deploy_heroku: true}) assert_file(".github/workflows/deploy_heroku.yml") end) end end - describe "#apply/2 with mix_project and github_action_deploy_heroku option" do + describe "#apply!/2 with mix_project and github_action_deploy_heroku option" do @describetag mix_project?: true test "raises FunctionClauseError exception", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> assert_raise FunctionClauseError, fn -> - Addons.Github.apply(project, %{github_action_deploy_heroku: true}) + Addons.Github.apply!(project, %{github_action_deploy_heroku: true}) end end) end end - describe "#apply/2 with github_wiki option" do + describe "#apply!/2 with github_wiki option" do test "copies the .github/workflows/publish_wiki.yml and Github Wiki files", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_wiki: true}) + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{github_wiki: true}) assert_file(".github/workflows/publish_wiki.yml") @@ -495,8 +495,8 @@ defmodule NimbleTemplate.Addons.GithubTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_wiki: true}) + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{github_wiki: true}) assert_file("README.md", fn file -> assert file =~ """ @@ -509,15 +509,15 @@ defmodule NimbleTemplate.Addons.GithubTest do end end - describe "#apply/2 with api_project and github_wiki option" do + describe "#apply!/2 with api_project and github_wiki option" do test "copies the .github/workflows/publish_wiki.yml and Github Wiki files", %{ project: project, test_project_path: test_project_path } do project = %{project | api_project?: true, web_project?: false} - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_wiki: true}) + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{github_wiki: true}) assert_file(".github/workflows/publish_wiki.yml") @@ -568,15 +568,15 @@ defmodule NimbleTemplate.Addons.GithubTest do end end - describe "#apply/2 with mix_project and github_wiki option" do + describe "#apply!/2 with mix_project and github_wiki option" do @describetag mix_project?: true test "copies the .github/workflows/publish_wiki.yml and Github Wiki files", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_wiki: true}) + in_test_project!(test_project_path, fn -> + Addons.Github.apply!(project, %{github_wiki: true}) assert_file(".github/workflows/publish_wiki.yml") diff --git a/test/nimble_template/addons/iex_test.exs b/test/nimble_template/addons/iex_test.exs index 34d12661..9438cc86 100644 --- a/test/nimble_template/addons/iex_test.exs +++ b/test/nimble_template/addons/iex_test.exs @@ -1,13 +1,13 @@ defmodule NimbleTemplate.Addons.IexTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do test "add the .iex.exs file with the Repo alias", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Iex.apply(project) + in_test_project!(test_project_path, fn -> + Addons.Iex.apply!(project) assert_file(".iex.exs", fn file -> assert file =~ """ @@ -18,15 +18,15 @@ defmodule NimbleTemplate.Addons.IexTest do end end - describe "#apply/2 with mix_project" do + describe "#apply!/2 with mix_project" do @describetag mix_project?: true test "does not include the Repo alias in .iex.exs file", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Iex.apply(project) + in_test_project!(test_project_path, fn -> + Addons.Iex.apply!(project) assert_file(".iex.exs", fn file -> refute file =~ """ diff --git a/test/nimble_template/addons/mimic_test.exs b/test/nimble_template/addons/mimic_test.exs index 857abad4..2e7145d7 100644 --- a/test/nimble_template/addons/mimic_test.exs +++ b/test/nimble_template/addons/mimic_test.exs @@ -1,15 +1,15 @@ defmodule NimbleTemplate.Addons.MimicTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag mock_latest_package_versions: [{:mimic, "1.3.1"}] test "injects mimic to mix dependency", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Mimic.apply(project) + in_test_project!(test_project_path, fn -> + Addons.Mimic.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -25,8 +25,8 @@ defmodule NimbleTemplate.Addons.MimicTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Mimic.apply(project) + in_test_project!(test_project_path, fn -> + Addons.Mimic.apply!(project) assert_file("test/test_helper.exs", fn file -> assert file =~ """ @@ -39,8 +39,8 @@ defmodule NimbleTemplate.Addons.MimicTest do end test "updates test cases", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - Addons.Mimic.apply(project) + in_test_project!(test_project_path, fn -> + Addons.Mimic.apply!(project) assert_file("test/support/data_case.ex", fn file -> assert file =~ "use Mimic" diff --git a/test/nimble_template/addons/readme_test.exs b/test/nimble_template/addons/readme_test.exs index e05f2650..350e55bf 100644 --- a/test/nimble_template/addons/readme_test.exs +++ b/test/nimble_template/addons/readme_test.exs @@ -1,13 +1,13 @@ defmodule NimbleTemplate.Addons.ReadmeTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do test "copies the README.md", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Readme.apply(project) + in_test_project!(test_project_path, fn -> + Addons.Readme.apply!(project) assert_file("README.md", fn file -> assert file =~ "Erlang 25.0.4" @@ -36,15 +36,15 @@ defmodule NimbleTemplate.Addons.ReadmeTest do end end - describe "#apply/2 with api_project" do + describe "#apply!/2 with api_project" do test "copies the README.md", %{ project: project, test_project_path: test_project_path } do project = %{project | api_project?: true, web_project?: false} - in_test_project(test_project_path, fn -> - Addons.Readme.apply(project) + in_test_project!(test_project_path, fn -> + Addons.Readme.apply!(project) assert_file("README.md", fn file -> assert file =~ "Erlang 25.0.4" @@ -73,15 +73,15 @@ defmodule NimbleTemplate.Addons.ReadmeTest do end end - describe "#apply/2 with mix_project" do + describe "#apply!/2 with mix_project" do @describetag mix_project?: true test "copies the README.md", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.Readme.apply(project) + in_test_project!(test_project_path, fn -> + Addons.Readme.apply!(project) assert_file("README.md", fn file -> assert file =~ "Erlang 25.0.4" diff --git a/test/nimble_template/addons/test_env_test.exs b/test/nimble_template/addons/test_env_test.exs index 301bf0d7..e7cc7d4d 100644 --- a/test/nimble_template/addons/test_env_test.exs +++ b/test/nimble_template/addons/test_env_test.exs @@ -1,10 +1,10 @@ defmodule NimbleTemplate.Addons.TestEnvTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do test "injects the DB_HOST ENV", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - Addons.TestEnv.apply(project) + in_test_project!(test_project_path, fn -> + Addons.TestEnv.apply!(project) assert_file("config/test.exs", fn file -> assert file =~ "hostname: System.get_env(\"DB_HOST\") || \"localhost\"," @@ -13,8 +13,8 @@ defmodule NimbleTemplate.Addons.TestEnvTest do end test "adds codebase alias", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - Addons.TestEnv.apply(project) + in_test_project!(test_project_path, fn -> + Addons.TestEnv.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -30,8 +30,8 @@ defmodule NimbleTemplate.Addons.TestEnvTest do end test "adds codebase.fix alias", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - Addons.TestEnv.apply(project) + in_test_project!(test_project_path, fn -> + Addons.TestEnv.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -46,8 +46,8 @@ defmodule NimbleTemplate.Addons.TestEnvTest do test "adds `Code.put_compiler_option(:warnings_as_errors, true)` into `test/test_helper.exs`", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - Addons.TestEnv.apply(project) + in_test_project!(test_project_path, fn -> + Addons.TestEnv.apply!(project) assert_file("test/test_helper.exs", fn file -> assert file =~ """ @@ -63,8 +63,8 @@ defmodule NimbleTemplate.Addons.TestEnvTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.TestEnv.apply(project) + in_test_project!(test_project_path, fn -> + Addons.TestEnv.apply!(project) assert_file(".formatter.exs", fn file -> assert file =~ """ @@ -76,15 +76,15 @@ defmodule NimbleTemplate.Addons.TestEnvTest do end end - describe "#apply/2 with mix_project" do + describe "#apply!/2 with mix_project" do @describetag mix_project?: true test "adds codebase and codebase.fix alias", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.TestEnv.apply(project) + in_test_project!(test_project_path, fn -> + Addons.TestEnv.apply!(project) assert_file("mix.exs", fn file -> assert file =~ "aliases: aliases()" @@ -108,8 +108,8 @@ defmodule NimbleTemplate.Addons.TestEnvTest do end test "adds elixirc_paths", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - Addons.TestEnv.apply(project) + in_test_project!(test_project_path, fn -> + Addons.TestEnv.apply!(project) assert_file("mix.exs", fn file -> assert file =~ "elixirc_paths: elixirc_paths(Mix.env())," @@ -125,8 +125,8 @@ defmodule NimbleTemplate.Addons.TestEnvTest do test "adds `Code.put_compiler_option(:warnings_as_errors, true)` into `test/test_helper.exs`", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - Addons.TestEnv.apply(project) + in_test_project!(test_project_path, fn -> + Addons.TestEnv.apply!(project) assert_file("test/test_helper.exs", fn file -> assert file =~ """ @@ -142,8 +142,8 @@ defmodule NimbleTemplate.Addons.TestEnvTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.TestEnv.apply(project) + in_test_project!(test_project_path, fn -> + Addons.TestEnv.apply!(project) assert_file(".formatter.exs", fn file -> assert file =~ """ diff --git a/test/nimble_template/addons/test_interactive_test.exs b/test/nimble_template/addons/test_interactive_test.exs index e74f1c43..5265f32b 100644 --- a/test/nimble_template/addons/test_interactive_test.exs +++ b/test/nimble_template/addons/test_interactive_test.exs @@ -1,15 +1,15 @@ defmodule NimbleTemplate.Addons.TestInteractiveTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag mock_latest_package_versions: [{:mix_test_interactive, "1.2"}] test "injects mix_test_interactive to mix dependencies list", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.TestInteractive.apply(project) + in_test_project!(test_project_path, fn -> + Addons.TestInteractive.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -25,8 +25,8 @@ defmodule NimbleTemplate.Addons.TestInteractiveTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.TestInteractive.apply(project) + in_test_project!(test_project_path, fn -> + Addons.TestInteractive.apply!(project) assert_file("config/dev.exs", fn file -> assert file =~ """ @@ -38,7 +38,7 @@ defmodule NimbleTemplate.Addons.TestInteractiveTest do end end - describe "#apply/2 with mix_project" do + describe "#apply!/2 with mix_project" do @describetag mix_project?: true @describetag mock_latest_package_versions: [{:mix_test_interactive, "1.2"}] @@ -46,8 +46,8 @@ defmodule NimbleTemplate.Addons.TestInteractiveTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - Addons.TestInteractive.apply(project) + in_test_project!(test_project_path, fn -> + Addons.TestInteractive.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ diff --git a/test/nimble_template/addons/variants/docker_test.exs b/test/nimble_template/addons/variants/docker_test.exs index 1346a923..a576823d 100644 --- a/test/nimble_template/addons/variants/docker_test.exs +++ b/test/nimble_template/addons/variants/docker_test.exs @@ -1,13 +1,13 @@ defmodule NimbleTemplate.Addons.Phoenix.DockerTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do test "copies the docker-compose.dev.yml", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.Docker.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.Docker.apply!(project) assert_file("docker-compose.dev.yml", fn file -> assert file =~ """ @@ -31,8 +31,8 @@ defmodule NimbleTemplate.Addons.Phoenix.DockerTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.Docker.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.Docker.apply!(project) assert_file("docker-compose.yml") end) @@ -42,8 +42,8 @@ defmodule NimbleTemplate.Addons.Phoenix.DockerTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.Docker.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.Docker.apply!(project) assert_file(".dockerignore") end) @@ -53,8 +53,8 @@ defmodule NimbleTemplate.Addons.Phoenix.DockerTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.Docker.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.Docker.apply!(project) assert_file("Dockerfile", fn file -> assert file =~ """ @@ -95,8 +95,8 @@ defmodule NimbleTemplate.Addons.Phoenix.DockerTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.Docker.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.Docker.apply!(project) assert_file("bin/start.sh", fn file -> assert file =~ """ @@ -109,15 +109,15 @@ defmodule NimbleTemplate.Addons.Phoenix.DockerTest do end end - describe "#apply/2 with api_project" do + describe "#apply!/2 with api_project" do test "copies the Dockerfile", %{ project: project, test_project_path: test_project_path } do project = %{project | api_project?: true, web_project?: false} - in_test_project(test_project_path, fn -> - PhoenixAddons.Docker.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.Docker.apply!(project) assert_file("Dockerfile", fn file -> refute file =~ """ diff --git a/test/nimble_template/addons/variants/ecto_data_migration_test.exs b/test/nimble_template/addons/variants/ecto_data_migration_test.exs index e7e9e12d..875a65a2 100644 --- a/test/nimble_template/addons/variants/ecto_data_migration_test.exs +++ b/test/nimble_template/addons/variants/ecto_data_migration_test.exs @@ -1,13 +1,13 @@ defmodule NimbleTemplate.Addons.Phoenix.EctoDataMigrationTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do test "adds `ecto.migrate_all` into mix aliases", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.EctoDataMigration.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.EctoDataMigration.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -23,8 +23,8 @@ defmodule NimbleTemplate.Addons.Phoenix.EctoDataMigrationTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.EctoDataMigration.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.EctoDataMigration.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -44,8 +44,8 @@ defmodule NimbleTemplate.Addons.Phoenix.EctoDataMigrationTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.EctoDataMigration.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.EctoDataMigration.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -59,8 +59,8 @@ defmodule NimbleTemplate.Addons.Phoenix.EctoDataMigrationTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.EctoDataMigration.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.EctoDataMigration.apply!(project) assert_file("priv/repo/data_migrations/.keep") end) diff --git a/test/nimble_template/addons/variants/ex_machina_test.exs b/test/nimble_template/addons/variants/ex_machina_test.exs index 9f655c7c..05001108 100644 --- a/test/nimble_template/addons/variants/ex_machina_test.exs +++ b/test/nimble_template/addons/variants/ex_machina_test.exs @@ -1,15 +1,15 @@ defmodule NimbleTemplate.Addons.Phoenix.ExMachinaTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag mock_latest_package_versions: [{:ex_machina, "2.4"}] test "copies the test/support/factory.ex", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.ExMachina.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.ExMachina.apply!(project) assert_file("test/support/factory.ex") end) @@ -19,8 +19,8 @@ defmodule NimbleTemplate.Addons.Phoenix.ExMachinaTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.ExMachina.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.ExMachina.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -36,8 +36,8 @@ defmodule NimbleTemplate.Addons.Phoenix.ExMachinaTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.ExMachina.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.ExMachina.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -48,8 +48,8 @@ defmodule NimbleTemplate.Addons.Phoenix.ExMachinaTest do end test "updates test/test_helper.exs", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - PhoenixAddons.ExMachina.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.ExMachina.apply!(project) assert_file("test/test_helper.exs", fn file -> assert file =~ """ @@ -62,8 +62,8 @@ defmodule NimbleTemplate.Addons.Phoenix.ExMachinaTest do end test "adds Factory module", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - PhoenixAddons.ExMachina.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.ExMachina.apply!(project) assert_file("test/support/data_case.ex", fn file -> assert file =~ "import NimbleTemplate.Factory" diff --git a/test/nimble_template/addons/variants/ex_vcr_test.exs b/test/nimble_template/addons/variants/ex_vcr_test.exs index e887fae3..67e86151 100644 --- a/test/nimble_template/addons/variants/ex_vcr_test.exs +++ b/test/nimble_template/addons/variants/ex_vcr_test.exs @@ -1,15 +1,15 @@ defmodule NimbleTemplate.Addons.Phoenix.ExVCRTest do use NimbleTemplate.AddonCase - describe "#apply/2" do + describe "#apply!/2" do @describetag mock_latest_package_versions: [{:exvcr, "0.12.2"}] test "injects ExVCR to mix dependency", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.ExVCR.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.ExVCR.apply!(project) assert_file("mix.exs", fn file -> assert file =~ "{:exvcr, \"~> 0.12.2\", [only: :test]}" @@ -21,8 +21,8 @@ defmodule NimbleTemplate.Addons.Phoenix.ExVCRTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.ExVCR.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.ExVCR.apply!(project) assert_file("config/test.exs", fn file -> assert file =~ """ @@ -36,8 +36,8 @@ defmodule NimbleTemplate.Addons.Phoenix.ExVCRTest do end test "updates test cases", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - PhoenixAddons.ExVCR.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.ExVCR.apply!(project) assert_file("test/support/data_case.ex", fn file -> assert file =~ "use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney" @@ -53,8 +53,8 @@ defmodule NimbleTemplate.Addons.Phoenix.ExVCRTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.ExVCR.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.ExVCR.apply!(project) assert(File.exists?("test/support/fixtures/vcr_cassettes/.keep")) == true end) diff --git a/test/nimble_template/addons/variants/gettext_test.exs b/test/nimble_template/addons/variants/gettext_test.exs index e1743aa3..4fdcaeed 100644 --- a/test/nimble_template/addons/variants/gettext_test.exs +++ b/test/nimble_template/addons/variants/gettext_test.exs @@ -1,15 +1,15 @@ defmodule NimbleTemplate.Addons.Phoenix.GettextTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag required_addons: [:TestEnv] test "injects gettext.extract-and-merge command to mix aliases", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.Gettext.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.Gettext.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ diff --git a/test/nimble_template/addons/variants/health_plug_test.exs b/test/nimble_template/addons/variants/health_plug_test.exs index feeb0b47..970e3e2b 100644 --- a/test/nimble_template/addons/variants/health_plug_test.exs +++ b/test/nimble_template/addons/variants/health_plug_test.exs @@ -1,15 +1,15 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlugTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag required_addons: [:ExCoveralls, :"Phoenix.MixRelease"] test "copies the health plug file", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.HealthPlug.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.HealthPlug.apply!(project) assert_file("lib/nimble_template_web/plugs/health_plug.ex") end) @@ -19,8 +19,8 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlugTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.HealthPlug.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.HealthPlug.apply!(project) assert_file("test/nimble_template_web/plugs/health_plug_test.exs") assert_file("test/nimble_template_web/requests/_health/liveness_request_test.exs") @@ -32,8 +32,8 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlugTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.HealthPlug.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.HealthPlug.apply!(project) assert_file("config/config.exs", fn file -> assert file =~ """ @@ -97,8 +97,8 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlugTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.HealthPlug.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.HealthPlug.apply!(project) assert_file("lib/nimble_template_web/router.ex", fn file -> assert file =~ "alias NimbleTemplateWeb.RouterHelper" @@ -111,8 +111,8 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlugTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.HealthPlug.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.HealthPlug.apply!(project) assert_file("test/test_helper.exs", fn file -> assert file =~ "Mimic.copy(Ecto.Adapters.SQL)" diff --git a/test/nimble_template/addons/variants/makefile_test.exs b/test/nimble_template/addons/variants/makefile_test.exs index 10fe5749..d4787ac1 100644 --- a/test/nimble_template/addons/variants/makefile_test.exs +++ b/test/nimble_template/addons/variants/makefile_test.exs @@ -1,10 +1,10 @@ defmodule NimbleTemplate.Addons.Phoenix.MakefileTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do test "copies the Makefile", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - PhoenixAddons.Makefile.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.Makefile.apply!(project) assert_file("Makefile") end) diff --git a/test/nimble_template/addons/variants/mix_release_test.exs b/test/nimble_template/addons/variants/mix_release_test.exs index edef8df6..3e98e971 100644 --- a/test/nimble_template/addons/variants/mix_release_test.exs +++ b/test/nimble_template/addons/variants/mix_release_test.exs @@ -1,13 +1,13 @@ defmodule NimbleTemplate.Addons.Phoenix.MixReleaseTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do test "creates the lib/nimble_template/release_tasks.ex", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.MixRelease.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.MixRelease.apply!(project) assert_file("lib/nimble_template/release_tasks.ex", fn file -> assert file =~ """ @@ -37,8 +37,8 @@ defmodule NimbleTemplate.Addons.Phoenix.MixReleaseTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.MixRelease.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.MixRelease.apply!(project) assert_file("config/runtime.exs", fn file -> assert file =~ """ diff --git a/test/nimble_template/addons/variants/oban_test.exs b/test/nimble_template/addons/variants/oban_test.exs index f3f80895..e5562553 100644 --- a/test/nimble_template/addons/variants/oban_test.exs +++ b/test/nimble_template/addons/variants/oban_test.exs @@ -2,15 +2,15 @@ defmodule NimbleTemplate.Addons.Phoenix.ObanTest do use NimbleTemplate.AddonCase, async: false use Mimic - describe "#apply/2" do + describe "#apply!/2" do @describetag mock_latest_package_versions: [{:oban, "2.3"}] test "injects oban to mix dependency", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.Oban.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.Oban.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -26,10 +26,10 @@ defmodule NimbleTemplate.Addons.Phoenix.ObanTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> expect(Calendar, :strftime, fn _datetime, _format -> "20201120074154" end) - PhoenixAddons.Oban.apply(project) + PhoenixAddons.Oban.apply!(project) assert_file("priv/repo/migrations/20201120074154_add_oban_jobs_table.exs", fn file -> assert file =~ """ @@ -55,8 +55,8 @@ defmodule NimbleTemplate.Addons.Phoenix.ObanTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.Oban.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.Oban.apply!(project) assert_file("lib/nimble_template/application.ex", fn file -> assert file =~ """ @@ -75,8 +75,8 @@ defmodule NimbleTemplate.Addons.Phoenix.ObanTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.Oban.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.Oban.apply!(project) assert_file("config/config.exs", fn file -> assert file =~ """ @@ -93,8 +93,8 @@ defmodule NimbleTemplate.Addons.Phoenix.ObanTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.Oban.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.Oban.apply!(project) assert_file("config/test.exs", fn file -> assert file =~ """ @@ -108,8 +108,8 @@ defmodule NimbleTemplate.Addons.Phoenix.ObanTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.Oban.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.Oban.apply!(project) assert(File.exists?("lib/nimble_template_worker/.keep")) == true end) diff --git a/test/nimble_template/addons/variants/phoenix/api/config_test.exs b/test/nimble_template/addons/variants/phoenix/api/config_test.exs index d8962a70..9229a39a 100644 --- a/test/nimble_template/addons/variants/phoenix/api/config_test.exs +++ b/test/nimble_template/addons/variants/phoenix/api/config_test.exs @@ -1,13 +1,13 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.ConfigTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do test "removes cache_static_manifest setting in config/prod.exs", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - ApiAddons.Config.apply(project) + in_test_project!(test_project_path, fn -> + ApiAddons.Config.apply!(project) assert_file("config/prod.exs", fn file -> refute file =~ "cache_static_manifest: \"priv/static/cache_manifest.json\"" diff --git a/test/nimble_template/addons/variants/phoenix/api/empty_body_plug_test.exs b/test/nimble_template/addons/variants/phoenix/api/empty_body_plug_test.exs index 6e4cddb1..b4205700 100644 --- a/test/nimble_template/addons/variants/phoenix/api/empty_body_plug_test.exs +++ b/test/nimble_template/addons/variants/phoenix/api/empty_body_plug_test.exs @@ -1,13 +1,13 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.EmptyBodyParamsPlugTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do test "copies the empty body plug file", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - ApiAddons.EmptyBodyParamsPlug.apply(project) + in_test_project!(test_project_path, fn -> + ApiAddons.EmptyBodyParamsPlug.apply!(project) assert_file("lib/nimble_template_web/plugs/check_empty_body_params_plug.ex") end) @@ -17,8 +17,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.EmptyBodyParamsPlugTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - ApiAddons.EmptyBodyParamsPlug.apply(project) + in_test_project!(test_project_path, fn -> + ApiAddons.EmptyBodyParamsPlug.apply!(project) assert_file("test/nimble_template_web/plugs/check_empty_body_params_plug_test.exs") end) @@ -28,8 +28,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.EmptyBodyParamsPlugTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - ApiAddons.EmptyBodyParamsPlug.apply(project) + in_test_project!(test_project_path, fn -> + ApiAddons.EmptyBodyParamsPlug.apply!(project) assert_file("lib/nimble_template_web/router.ex", fn file -> assert file =~ """ diff --git a/test/nimble_template/addons/variants/phoenix/api/error_view_test.exs b/test/nimble_template/addons/variants/phoenix/api/error_view_test.exs index c5f7b302..080d5746 100644 --- a/test/nimble_template/addons/variants/phoenix/api/error_view_test.exs +++ b/test/nimble_template/addons/variants/phoenix/api/error_view_test.exs @@ -1,13 +1,13 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.ErrorViewTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do test "copies the error view files", %{ project: project, test_project_path: project_path } do - in_test_project(project_path, fn -> - ApiAddons.ErrorView.apply(project) + in_test_project!(project_path, fn -> + ApiAddons.ErrorView.apply!(project) assert_file("lib/nimble_template_web/views/error_helpers.ex") assert_file("lib/nimble_template_web/views/api/error_view.ex") diff --git a/test/nimble_template/addons/variants/phoenix/api/fallback_controller_test.exs b/test/nimble_template/addons/variants/phoenix/api/fallback_controller_test.exs index ad70fa02..b7d95d10 100644 --- a/test/nimble_template/addons/variants/phoenix/api/fallback_controller_test.exs +++ b/test/nimble_template/addons/variants/phoenix/api/fallback_controller_test.exs @@ -1,15 +1,15 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.FallbackControllerTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag required_addons: [:"Phoenix.Api.ParamsValidation"] test "copies the FallbackController module", %{ project: project, test_project_path: project_path } do - in_test_project(project_path, fn -> - ApiAddons.FallbackController.apply(project) + in_test_project!(project_path, fn -> + ApiAddons.FallbackController.apply!(project) assert_file("lib/nimble_template_web/controllers/api/fallback_controller.ex") end) @@ -19,8 +19,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.FallbackControllerTest do project: project, test_project_path: project_path } do - in_test_project(project_path, fn -> - ApiAddons.FallbackController.apply(project) + in_test_project!(project_path, fn -> + ApiAddons.FallbackController.apply!(project) assert_file("lib/nimble_template_web.ex", fn file -> assert file =~ "action_fallback NimbleTemplateWeb.Api.FallbackController" diff --git a/test/nimble_template/addons/variants/phoenix/api/json_api_test.exs b/test/nimble_template/addons/variants/phoenix/api/json_api_test.exs index a0afd9c8..3ed93a3b 100644 --- a/test/nimble_template/addons/variants/phoenix/api/json_api_test.exs +++ b/test/nimble_template/addons/variants/phoenix/api/json_api_test.exs @@ -1,15 +1,15 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.JsonApiTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag mock_latest_package_versions: [{:jsonapi, "1.3.0"}] test "injects jsonapi to mix dependency", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - ApiAddons.JsonApi.apply(project) + in_test_project!(test_project_path, fn -> + ApiAddons.JsonApi.apply!(project) assert_file("mix.exs", fn file -> assert file =~ "{:jsonapi, \"~> 1.3.0\"}" @@ -21,8 +21,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.JsonApiTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - ApiAddons.JsonApi.apply(project) + in_test_project!(test_project_path, fn -> + ApiAddons.JsonApi.apply!(project) assert_file("config/config.exs", fn file -> assert file =~ "config :jsonapi, remove_links: true" diff --git a/test/nimble_template/addons/variants/phoenix/api/params_validation_test.exs b/test/nimble_template/addons/variants/phoenix/api/params_validation_test.exs index 6e45b1ad..743b46da 100644 --- a/test/nimble_template/addons/variants/phoenix/api/params_validation_test.exs +++ b/test/nimble_template/addons/variants/phoenix/api/params_validation_test.exs @@ -1,13 +1,13 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.ParamsValidationTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do test "copies the params validation module and test files", %{ project: project, test_project_path: project_path } do - in_test_project(project_path, fn -> - ApiAddons.ParamsValidation.apply(project) + in_test_project!(project_path, fn -> + ApiAddons.ParamsValidation.apply!(project) assert_file("lib/nimble_template_web/params/params.ex") assert_file("lib/nimble_template_web/params/params_validator.ex") @@ -19,8 +19,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.ParamsValidationTest do project: project, test_project_path: project_path } do - in_test_project(project_path, fn -> - ApiAddons.ParamsValidation.apply(project) + in_test_project!(project_path, fn -> + ApiAddons.ParamsValidation.apply!(project) assert_file("lib/nimble_template_web.ex", fn file -> assert file =~ "alias NimbleTemplateWeb.ParamsValidator" diff --git a/test/nimble_template/addons/variants/phoenix/web/assets_test.exs b/test/nimble_template/addons/variants/phoenix/web/assets_test.exs index 0bcb25a6..e775b935 100644 --- a/test/nimble_template/addons/variants/phoenix/web/assets_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/assets_test.exs @@ -1,13 +1,13 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.AssetsTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do test "enables gzip for static", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Assets.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.Assets.apply!(project) assert_file("lib/nimble_template_web/endpoint.ex", fn file -> assert file =~ "gzip: true," diff --git a/test/nimble_template/addons/variants/phoenix/web/bootstrap_test.exs b/test/nimble_template/addons/variants/phoenix/web/bootstrap_test.exs index 77bda952..e34b1ed1 100644 --- a/test/nimble_template/addons/variants/phoenix/web/bootstrap_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/bootstrap_test.exs @@ -1,7 +1,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.BootstrapTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2 given no Nimble CSS and Nimble JS structure" do + describe "#apply!/2 given no Nimble CSS and Nimble JS structure" do @describetag required_addons: [ :TestEnv, :"Phoenix.Web.NodePackage", @@ -11,8 +11,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.BootstrapTest do ] test "copies Bootstrap vendor file", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - WebAddons.Bootstrap.apply(project, %{ + in_test_project!(test_project_path, fn -> + WebAddons.Bootstrap.apply!(project, %{ with_nimble_css_addon: false, with_nimble_js_addon: false }) @@ -25,8 +25,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.BootstrapTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Bootstrap.apply(project, %{ + in_test_project!(test_project_path, fn -> + WebAddons.Bootstrap.apply!(project, %{ with_nimble_css_addon: false, with_nimble_js_addon: false }) @@ -45,8 +45,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.BootstrapTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Bootstrap.apply(project, %{ + in_test_project!(test_project_path, fn -> + WebAddons.Bootstrap.apply!(project, %{ with_nimble_js_addon: false, with_nimble_css_addon: false }) @@ -63,8 +63,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.BootstrapTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Bootstrap.apply(project, %{ + in_test_project!(test_project_path, fn -> + WebAddons.Bootstrap.apply!(project, %{ with_nimble_css_addon: false, with_nimble_js_addon: false }) @@ -83,8 +83,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.BootstrapTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Bootstrap.apply(project, %{ + in_test_project!(test_project_path, fn -> + WebAddons.Bootstrap.apply!(project, %{ with_nimble_css_addon: false, with_nimble_js_addon: false }) @@ -99,8 +99,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.BootstrapTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Bootstrap.apply(project, %{ + in_test_project!(test_project_path, fn -> + WebAddons.Bootstrap.apply!(project, %{ with_nimble_css_addon: false, with_nimble_js_addon: false }) @@ -121,7 +121,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.BootstrapTest do end end - describe "#apply/2 given Nimble CSS and Nimble JS structure" do + describe "#apply!/2 given Nimble CSS and Nimble JS structure" do @describetag required_addons: [ :TestEnv, :"Phoenix.Web.NodePackage", @@ -135,8 +135,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.BootstrapTest do ] test "copies Bootstrap vendor file", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - WebAddons.Bootstrap.apply(project, %{ + in_test_project!(test_project_path, fn -> + WebAddons.Bootstrap.apply!(project, %{ with_nimble_css_addon: true, with_nimble_js_addon: true }) @@ -149,8 +149,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.BootstrapTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Bootstrap.apply(project, %{ + in_test_project!(test_project_path, fn -> + WebAddons.Bootstrap.apply!(project, %{ with_nimble_css_addon: true, with_nimble_js_addon: true }) @@ -169,8 +169,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.BootstrapTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Bootstrap.apply(project, %{ + in_test_project!(test_project_path, fn -> + WebAddons.Bootstrap.apply!(project, %{ with_nimble_css_addon: true, with_nimble_js_addon: true }) @@ -187,8 +187,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.BootstrapTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Bootstrap.apply(project, %{ + in_test_project!(test_project_path, fn -> + WebAddons.Bootstrap.apply!(project, %{ with_nimble_css_addon: true, with_nimble_js_addon: true }) @@ -207,8 +207,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.BootstrapTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Bootstrap.apply(project, %{ + in_test_project!(test_project_path, fn -> + WebAddons.Bootstrap.apply!(project, %{ with_nimble_css_addon: true, with_nimble_js_addon: true }) @@ -223,8 +223,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.BootstrapTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Bootstrap.apply(project, %{ + in_test_project!(test_project_path, fn -> + WebAddons.Bootstrap.apply!(project, %{ with_nimble_css_addon: true, with_nimble_js_addon: true }) diff --git a/test/nimble_template/addons/variants/phoenix/web/core_js_test.exs b/test/nimble_template/addons/variants/phoenix/web/core_js_test.exs index a23be1cb..324ceb01 100644 --- a/test/nimble_template/addons/variants/phoenix/web/core_js_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/core_js_test.exs @@ -1,15 +1,15 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.CoreJSTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag required_addons: [:"Phoenix.Web.NodePackage"] test "adds core-js into package.json", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.CoreJS.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.CoreJS.apply!(project) assert_file("assets/package.json", fn file -> assert file =~ """ @@ -21,8 +21,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.CoreJSTest do end test "imports core-js into app.js", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - WebAddons.CoreJS.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.CoreJS.apply!(project) assert_file("assets/js/app.js", fn file -> assert file =~ """ @@ -34,7 +34,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.CoreJSTest do end end - describe "#apply/2 to a Live project" do + describe "#apply!/2 to a Live project" do @describetag live_project?: true @describetag required_addons: [:"Phoenix.Web.NodePackage"] @@ -42,8 +42,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.CoreJSTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.CoreJS.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.CoreJS.apply!(project) assert_file("assets/package.json", fn file -> assert file =~ """ diff --git a/test/nimble_template/addons/variants/phoenix/web/dart_sass_test.exs b/test/nimble_template/addons/variants/phoenix/web/dart_sass_test.exs index dac6b4c9..0ad8d94b 100644 --- a/test/nimble_template/addons/variants/phoenix/web/dart_sass_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/dart_sass_test.exs @@ -1,7 +1,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.DartSassTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag required_addons: [ :"Phoenix.Web.NodePackage", :"Phoenix.Web.EsBuild", @@ -13,8 +13,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.DartSassTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.DartSass.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.DartSass.apply!(project) assert_file("assets/js/app.js", fn file -> refute file =~ """ @@ -31,8 +31,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.DartSassTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.DartSass.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.DartSass.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -51,8 +51,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.DartSassTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.DartSass.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.DartSass.apply!(project) assert_file("config/config.exs", fn file -> assert file =~ """ @@ -76,8 +76,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.DartSassTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.DartSass.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.DartSass.apply!(project) assert_file("config/dev.exs", fn file -> assert file =~ """ @@ -96,8 +96,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.DartSassTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.DartSass.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.DartSass.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -113,8 +113,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.DartSassTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.DartSass.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.DartSass.apply!(project) assert_file("assets/css/app.scss") refute_file("assets/css/app.css") diff --git a/test/nimble_template/addons/variants/phoenix/web/es_lint_test.exs b/test/nimble_template/addons/variants/phoenix/web/es_lint_test.exs index 73b99892..35d8cccd 100644 --- a/test/nimble_template/addons/variants/phoenix/web/es_lint_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/es_lint_test.exs @@ -1,15 +1,15 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsLintTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag required_addons: [:TestEnv, :"Phoenix.Web.NodePackage"] test "adds eslint, eslint-config-prettier and eslint-plugin-prettier into package.json", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.EsLint.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.EsLint.apply!(project) assert_file("assets/package.json", fn file -> assert file =~ """ @@ -26,8 +26,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsLintTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.EsLint.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.EsLint.apply!(project) assert_file("assets/package.json", fn file -> assert file =~ """ @@ -43,8 +43,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsLintTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.EsLint.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.EsLint.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -59,8 +59,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsLintTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.EsLint.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.EsLint.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -75,15 +75,15 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsLintTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.EsLint.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.EsLint.apply!(project) assert_file("assets/.eslintrc.json") end) end end - describe "#apply/2 to a Live project" do + describe "#apply!/2 to a Live project" do @describetag live_project?: true @describetag required_addons: [:TestEnv, :"Phoenix.Web.NodePackage"] @@ -91,8 +91,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsLintTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.EsLint.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.EsLint.apply!(project) assert_file("assets/js/app.js", fn file -> assert file =~ diff --git a/test/nimble_template/addons/variants/phoenix/web/esbuild_test.exs b/test/nimble_template/addons/variants/phoenix/web/esbuild_test.exs index 454a24bc..9d4dbc9f 100644 --- a/test/nimble_template/addons/variants/phoenix/web/esbuild_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/esbuild_test.exs @@ -1,13 +1,13 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsBuildTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do test "renames esbuild namespace to app in the mix assets.deploy alias", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.EsBuild.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.EsBuild.apply!(project) assert_file("mix.exs", fn file -> assert file =~ "\"assets.deploy\": [\"esbuild app --minify\"," @@ -19,8 +19,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsBuildTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.EsBuild.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.EsBuild.apply!(project) assert_file("config/config.exs", fn file -> assert file =~ """ @@ -37,8 +37,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsBuildTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.EsBuild.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.EsBuild.apply!(project) assert_file("config/dev.exs", fn file -> assert file =~ "esbuild: {Esbuild, :install_and_run, [:app," diff --git a/test/nimble_template/addons/variants/phoenix/web/hex_formatter_test.exs b/test/nimble_template/addons/variants/phoenix/web/hex_formatter_test.exs index da40d2a2..3159fa4a 100644 --- a/test/nimble_template/addons/variants/phoenix/web/hex_formatter_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/hex_formatter_test.exs @@ -1,13 +1,13 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.HeexFormatterTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do test "adds the HTMLFormatter into the .formatter.exs", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.HeexFormatter.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.HeexFormatter.apply!(project) assert_file(".formatter.exs", fn file -> assert file =~ """ diff --git a/test/nimble_template/addons/variants/phoenix/web/nimble_css_test.exs b/test/nimble_template/addons/variants/phoenix/web/nimble_css_test.exs index 5658e0f9..b9eefd0f 100644 --- a/test/nimble_template/addons/variants/phoenix/web/nimble_css_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/nimble_css_test.exs @@ -1,15 +1,15 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.NimbleCSSTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag required_addons: [:TestEnv, :"Phoenix.Web.NodePackage", :"Phoenix.Web.StyleLint"] test "copies Nimble CSS structure", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.NimbleCSS.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.NimbleCSS.apply!(project) assert_directory("assets/css/base") assert_directory("assets/css/components") @@ -28,8 +28,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.NimbleCSSTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.NimbleCSS.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.NimbleCSS.apply!(project) refute_file("assets/css/app.css") refute_file("assets/css/phoenix.css") @@ -40,8 +40,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.NimbleCSSTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.NimbleCSS.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.NimbleCSS.apply!(project) assert_file("assets/.stylelintrc.json", fn file -> refute file =~ "css/app.css" diff --git a/test/nimble_template/addons/variants/phoenix/web/nimble_js_test.exs b/test/nimble_template/addons/variants/phoenix/web/nimble_js_test.exs index 9c72b201..98d1c194 100644 --- a/test/nimble_template/addons/variants/phoenix/web/nimble_js_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/nimble_js_test.exs @@ -1,15 +1,15 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.NimbleJSTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag required_addons: [:TestEnv, :"Phoenix.Web.NodePackage", :"Phoenix.Web.EsLint"] test "copies Nimble JS structure", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.NimbleJS.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.NimbleJS.apply!(project) assert_directory("assets/js/adapters") assert_directory("assets/js/components") @@ -27,8 +27,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.NimbleJSTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.NimbleJS.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.NimbleJS.apply!(project) assert_file("assets/js/app.js", fn file -> assert file =~ """ @@ -54,8 +54,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.NimbleJSTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.NimbleJS.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.NimbleJS.apply!(project) assert_file("assets/js/vendor/topbar.js") refute_file("assets/vendor/topbar.js") @@ -66,8 +66,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.NimbleJSTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.NimbleJS.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.NimbleJS.apply!(project) assert_file("assets/.eslintrc.json", fn file -> assert file =~ """ diff --git a/test/nimble_template/addons/variants/phoenix/web/node_package_test.exs b/test/nimble_template/addons/variants/phoenix/web/node_package_test.exs index 0c364908..6dd72c81 100644 --- a/test/nimble_template/addons/variants/phoenix/web/node_package_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/node_package_test.exs @@ -1,13 +1,13 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.NodePackageTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do test "copies the package.json into assets", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.NodePackage.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.NodePackage.apply!(project) assert_file("assets/package.json") end) diff --git a/test/nimble_template/addons/variants/phoenix/web/post_css_test.exs b/test/nimble_template/addons/variants/phoenix/web/post_css_test.exs index d0e9a13b..77ae0e67 100644 --- a/test/nimble_template/addons/variants/phoenix/web/post_css_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/post_css_test.exs @@ -1,7 +1,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PostCSSTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag required_addons: [ :"Phoenix.Web.NodePackage", :"Phoenix.Web.EsBuild" @@ -10,8 +10,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PostCSSTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.PostCSS.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.PostCSS.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -29,8 +29,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PostCSSTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.PostCSS.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.PostCSS.apply!(project) assert_file("config/dev.exs", fn file -> assert file =~ """ @@ -49,8 +49,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PostCSSTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.PostCSS.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.PostCSS.apply!(project) assert_file("assets/package.json", fn file -> assert file =~ """ @@ -68,8 +68,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PostCSSTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.PostCSS.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.PostCSS.apply!(project) assert_file("assets/package.json", fn file -> assert file =~ """ @@ -85,8 +85,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PostCSSTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.PostCSS.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.PostCSS.apply!(project) assert_file("assets/postcss.config.js") end) diff --git a/test/nimble_template/addons/variants/phoenix/web/prettier_test.exs b/test/nimble_template/addons/variants/phoenix/web/prettier_test.exs index c752b91e..ac13e808 100644 --- a/test/nimble_template/addons/variants/phoenix/web/prettier_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/prettier_test.exs @@ -1,15 +1,15 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PrettierTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag required_addons: [:TestEnv, :"Phoenix.Web.NodePackage"] test "adds prettier and prettier-plugin-eex into package.json", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Prettier.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.Prettier.apply!(project) assert_file("assets/package.json", fn file -> assert file =~ """ @@ -25,8 +25,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PrettierTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Prettier.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.Prettier.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -43,8 +43,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PrettierTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Prettier.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.Prettier.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -59,8 +59,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PrettierTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Prettier.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.Prettier.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -75,8 +75,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PrettierTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Prettier.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.Prettier.apply!(project) assert_file(".prettierignore") assert_file(".prettierrc.yaml") diff --git a/test/nimble_template/addons/variants/phoenix/web/sobelow_test.exs b/test/nimble_template/addons/variants/phoenix/web/sobelow_test.exs index 9681c76e..c4d4df78 100644 --- a/test/nimble_template/addons/variants/phoenix/web/sobelow_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/sobelow_test.exs @@ -1,7 +1,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SobelowTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag mock_latest_package_versions: [{:sobelow, "0.8"}] @describetag required_addons: [:TestEnv] @@ -9,8 +9,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SobelowTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Sobelow.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.Sobelow.apply!(project) assert_file(".sobelow-conf") end) @@ -20,8 +20,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SobelowTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Sobelow.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.Sobelow.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -34,8 +34,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SobelowTest do end test "adds sobelow codebase alias", %{project: project, test_project_path: test_project_path} do - in_test_project(test_project_path, fn -> - WebAddons.Sobelow.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.Sobelow.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ diff --git a/test/nimble_template/addons/variants/phoenix/web/style_lint_test.exs b/test/nimble_template/addons/variants/phoenix/web/style_lint_test.exs index fe0f927b..177a81b6 100644 --- a/test/nimble_template/addons/variants/phoenix/web/style_lint_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/style_lint_test.exs @@ -1,7 +1,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.StyleLintTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag required_addons: [:TestEnv, :"Phoenix.Web.NodePackage"] test "adds stylelint, @@ -11,8 +11,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.StyleLintTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.StyleLint.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.StyleLint.apply!(project) assert_file("assets/package.json", fn file -> assert file =~ """ @@ -29,8 +29,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.StyleLintTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.StyleLint.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.StyleLint.apply!(project) assert_file("assets/package.json", fn file -> assert file =~ """ @@ -46,8 +46,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.StyleLintTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.StyleLint.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.StyleLint.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -62,8 +62,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.StyleLintTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.StyleLint.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.StyleLint.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -78,8 +78,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.StyleLintTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.StyleLint.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.StyleLint.apply!(project) assert_file("assets/.stylelintrc.json") end) diff --git a/test/nimble_template/addons/variants/phoenix/web/svg_sprite_test.exs b/test/nimble_template/addons/variants/phoenix/web/svg_sprite_test.exs index b57574ef..398e6d35 100644 --- a/test/nimble_template/addons/variants/phoenix/web/svg_sprite_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/svg_sprite_test.exs @@ -1,15 +1,15 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SvgSpriteTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag required_addons: [:"Phoenix.Web.NodePackage"] test "adds svg-sprite into package.json", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.SvgSprite.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.SvgSprite.apply!(project) assert_file("assets/package.json", fn file -> assert file =~ """ @@ -24,8 +24,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SvgSpriteTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.SvgSprite.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.SvgSprite.apply!(project) assert_file("assets/package.json", fn file -> assert file =~ """ @@ -40,8 +40,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SvgSpriteTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.SvgSprite.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.SvgSprite.apply!(project) assert_file("lib/nimble_template_web.ex", fn file -> assert file =~ """ @@ -55,8 +55,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SvgSpriteTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.SvgSprite.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.SvgSprite.apply!(project) assert_file("lib/nimble_template_web/helpers/icon_helper.ex") end) @@ -66,8 +66,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SvgSpriteTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.SvgSprite.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.SvgSprite.apply!(project) assert_file("test/nimble_template_web/helpers/icon_helper_test.exs") end) @@ -77,8 +77,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SvgSpriteTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.SvgSprite.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.SvgSprite.apply!(project) refute_file(".github/wiki/Icon-Sprite.md") end) @@ -88,23 +88,23 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SvgSpriteTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.SvgSprite.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.SvgSprite.apply!(project) refute_file(".github/wiki/_Sidebar.md") end) end end - describe "#apply/2 with Github Wiki addon" do + describe "#apply!/2 with Github Wiki addon" do @describetag required_addons: [{:Github, %{github_wiki: true}}, :"Phoenix.Web.NodePackage"] test "copies `.github/wiki/Icon-Sprite.md`", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.SvgSprite.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.SvgSprite.apply!(project) assert_file(".github/wiki/Icon-Sprite.md") end) @@ -114,8 +114,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SvgSpriteTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.SvgSprite.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.SvgSprite.apply!(project) assert_file(".github/wiki/_Sidebar.md", fn file -> assert file =~ """ diff --git a/test/nimble_template/addons/variants/phoenix/web/wallaby_test.exs b/test/nimble_template/addons/variants/phoenix/web/wallaby_test.exs index 0ebe26b3..bfe84022 100644 --- a/test/nimble_template/addons/variants/phoenix/web/wallaby_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/wallaby_test.exs @@ -1,15 +1,15 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.WallabyTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do @describetag mock_latest_package_versions: [{:wallaby, "0.26.2"}] test "copies the test/support/feature_case.ex", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Wallaby.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.Wallaby.apply!(project) assert_file("test/support/feature_case.ex", fn file -> assert file =~ """ @@ -43,10 +43,10 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.WallabyTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> project = ProjectHelper.append_installed_addon(project, NimbleTemplate.Addons.Phoenix.ExVCR) - WebAddons.Wallaby.apply(project) + WebAddons.Wallaby.apply!(project) assert_file("test/support/feature_case.ex", fn file -> assert file =~ """ @@ -81,8 +81,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.WallabyTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Wallaby.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.Wallaby.apply!(project) assert_file("test/nimble_template_web/features/home_page/view_home_page_test.exs") end) @@ -92,8 +92,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.WallabyTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Wallaby.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.Wallaby.apply!(project) assert_file("mix.exs", fn file -> assert file =~ """ @@ -109,8 +109,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.WallabyTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Wallaby.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.Wallaby.apply!(project) assert_file("test/test_helper.exs", fn file -> assert file =~ """ @@ -129,8 +129,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.WallabyTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Wallaby.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.Wallaby.apply!(project) assert_file("lib/nimble_template_web/endpoint.ex", fn file -> assert file =~ """ @@ -146,8 +146,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.WallabyTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Wallaby.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.Wallaby.apply!(project) assert_file("config/test.exs", fn file -> assert file =~ """ @@ -169,8 +169,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.WallabyTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - WebAddons.Wallaby.apply(project) + in_test_project!(test_project_path, fn -> + WebAddons.Wallaby.apply!(project) assert_file(".gitignore", fn file -> assert file =~ "**/tmp/" diff --git a/test/nimble_template/addons/variants/seeds_test.exs b/test/nimble_template/addons/variants/seeds_test.exs index c7fad03f..8ea48a5e 100644 --- a/test/nimble_template/addons/variants/seeds_test.exs +++ b/test/nimble_template/addons/variants/seeds_test.exs @@ -1,13 +1,13 @@ defmodule NimbleTemplate.Addons.Phoenix.SeedsTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + describe "#apply!/2" do test "adds the condition into the seeds.exs file", %{ project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.Seeds.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.Seeds.apply!(project) assert_file("priv/repo/seeds.exs", fn file -> assert file =~ """ diff --git a/test/nimble_template/helpers/dependency_test.exs b/test/nimble_template/helpers/dependency_test.exs index 2739f608..ce155b75 100644 --- a/test/nimble_template/helpers/dependency_test.exs +++ b/test/nimble_template/helpers/dependency_test.exs @@ -11,9 +11,9 @@ defmodule NimbleTemplate.DependencyTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - PhoenixAddons.ExVCR.apply(project) - Addons.Mimic.apply(project) + in_test_project!(test_project_path, fn -> + PhoenixAddons.ExVCR.apply!(project) + Addons.Mimic.apply!(project) # Unordered mix dependencies assert_file("mix.exs", fn file -> diff --git a/test/nimble_template/projects/project_test.exs b/test/nimble_template/projects/project_test.exs index d27190a8..f2105251 100644 --- a/test/nimble_template/projects/project_test.exs +++ b/test/nimble_template/projects/project_test.exs @@ -8,7 +8,7 @@ defmodule NimbleTemplate.Projects.ProjectTest do test "given mix project, returns project without web modules and paths", %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> project = Project.new(mix: true) assert project.base_module == "NimbleTemplate" @@ -29,7 +29,7 @@ defmodule NimbleTemplate.Projects.ProjectTest do test "given mix project with a custom module name, returns project with valid base module", %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> project = Project.new(mix: true) assert project.base_module == "SampleCustomModule" @@ -40,7 +40,7 @@ defmodule NimbleTemplate.Projects.ProjectTest do test "given web project, returns valid project with valid modules and paths", %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> project = Project.new(web: true) assert project.base_module == "NimbleTemplate" @@ -62,7 +62,7 @@ defmodule NimbleTemplate.Projects.ProjectTest do %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> project = Project.new(web: true) assert project.base_module == "SampleCustomModule" @@ -83,7 +83,7 @@ defmodule NimbleTemplate.Projects.ProjectTest do test "given live project, returns valid project with valid modules and paths", %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> project = Project.new(live: true) assert project.base_module == "NimbleTemplate" @@ -105,7 +105,7 @@ defmodule NimbleTemplate.Projects.ProjectTest do %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> project = Project.new(live: true) assert project.base_module == "SampleCustomModule" @@ -125,7 +125,7 @@ defmodule NimbleTemplate.Projects.ProjectTest do test "given api project, returns valid project with valid modules and paths", %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> project = Project.new(api: true) assert project.base_module == "NimbleTemplate" @@ -147,7 +147,7 @@ defmodule NimbleTemplate.Projects.ProjectTest do %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> project = Project.new(api: true) assert project.base_module == "SampleCustomModule" diff --git a/test/nimble_template/version_test.exs b/test/nimble_template/version_test.exs index a631404b..b551a963 100644 --- a/test/nimble_template/version_test.exs +++ b/test/nimble_template/version_test.exs @@ -9,7 +9,7 @@ defmodule NimbleTemplate.VersionTest do end) end - describe "bump/1" do + describe "bump!/1" do test "updates the version in mix.exs and README.md files given a valid version number" do current_version = Mix.Project.config()[:version] @@ -26,7 +26,7 @@ defmodule NimbleTemplate.VersionTest do |> List.replace_at(2, patch_number + 1) |> Enum.join(".") - assert Version.bump(new_version) == :ok + assert Version.bump!(new_version) == :ok assert_file("mix.exs", fn file -> assert file =~ "version: \"#{new_version}\"" @@ -56,7 +56,7 @@ defmodule NimbleTemplate.VersionTest do |> Enum.join(".") assert_raise Mix.Error, "The new version must be greater than #{current_version}", fn -> - Version.bump(new_version) + Version.bump!(new_version) end assert_file("mix.exs", fn file -> @@ -71,9 +71,9 @@ defmodule NimbleTemplate.VersionTest do end end - describe "upgrade_stack/1" do + describe "upgrade_stack!/1" do test "upgrade elixir version given the new elixir_version" do - assert Version.upgrade_stack(elixir: "a.b.c") == :ok + assert Version.upgrade_stack!(elixir: "a.b.c") == :ok assert_file("lib/nimble_template/projects/project.ex", fn file -> assert file =~ "@elixir_version \"a.b.c\"" @@ -101,7 +101,7 @@ defmodule NimbleTemplate.VersionTest do end test "upgrade erlang version given the new erlang_version" do - assert Version.upgrade_stack(erlang: "x.y.z") == :ok + assert Version.upgrade_stack!(erlang: "x.y.z") == :ok assert_file("lib/nimble_template/projects/project.ex", fn file -> assert file =~ "@erlang_version \"x.y.z\"" @@ -131,7 +131,7 @@ defmodule NimbleTemplate.VersionTest do end test "upgrade node version given the new node_version" do - assert Version.upgrade_stack(node: "a.s.d") == :ok + assert Version.upgrade_stack!(node: "a.s.d") == :ok assert_file("lib/nimble_template/projects/project.ex", fn file -> assert file =~ "@node_asdf_version \"a.s.d\"" @@ -155,7 +155,7 @@ defmodule NimbleTemplate.VersionTest do end test "upgrade alpine version given the new alpine_version" do - assert Version.upgrade_stack(alpine: "z.x.c") == :ok + assert Version.upgrade_stack!(alpine: "z.x.c") == :ok assert_file("lib/nimble_template/projects/project.ex", fn file -> assert file =~ "@alpine_version \"z.x.c\"" diff --git a/test/support/addon_case.ex b/test/support/addon_case.ex index d194d8a6..20629247 100644 --- a/test/support/addon_case.ex +++ b/test/support/addon_case.ex @@ -21,7 +21,7 @@ defmodule NimbleTemplate.AddonCase do # ATTENTION: File.cd! doesn't support `async: true`, the test will fail randomly in async mode # https://elixirforum.com/t/randomly-getting-compilationerror-on-tests/17298/3 - defp in_test_project(test_project_path, function), do: File.cd!(test_project_path, function) + defp in_test_project!(test_project_path, function), do: File.cd!(test_project_path, function) defp assert_file(path), do: assert(File.regular?(path), "Expected #{path} to exist, but does not") @@ -74,18 +74,18 @@ defmodule NimbleTemplate.AddonCase do if required_addons = context[:required_addons] do File.cd!(test_project_path, fn -> - Enum.each(required_addons, &apply_required_addon(&1, project)) + Enum.each(required_addons, &apply_required_addon!(&1, project)) end) end {:ok, project: project, test_project_path: test_project_path} end - defp apply_required_addon(required_addon, project) when is_atom(required_addon), - do: Module.safe_concat([Addons, required_addon]).apply(project) + defp apply_required_addon!(required_addon, project) when is_atom(required_addon), + do: Module.safe_concat([Addons, required_addon]).apply!(project) - defp apply_required_addon({required_addon_module, required_addon_opt}, project), - do: Module.safe_concat([Addons, required_addon_module]).apply(project, required_addon_opt) + defp apply_required_addon!({required_addon_module, required_addon_opt}, project), + do: Module.safe_concat([Addons, required_addon_module]).apply!(project, required_addon_opt) defp mock_latest_package_version({_package, version}), do: expect(Package, :get_latest_version, fn _package -> version end) From 715e6a21e9036a64cc27dcaf461d12b8a87f2e96 Mon Sep 17 00:00:00 2001 From: Andy Duong Date: Mon, 21 Nov 2022 22:46:26 +0700 Subject: [PATCH 09/43] [gh-230] mix format --- lib/nimble_template/addons/variants/phoenix/health_plug.ex | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/nimble_template/addons/variants/phoenix/health_plug.ex b/lib/nimble_template/addons/variants/phoenix/health_plug.ex index 2621f83b..e688db7e 100644 --- a/lib/nimble_template/addons/variants/phoenix/health_plug.ex +++ b/lib/nimble_template/addons/variants/phoenix/health_plug.ex @@ -99,9 +99,7 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlug do project end - defp edit_router!( - %Project{web_path: web_path, web_module: web_module} = project - ) do + defp edit_router!(%Project{web_path: web_path, web_module: web_module} = project) do Generator.replace_content!( "#{web_path}/router.ex", """ From 7fe67b3789dd94a9b646e75072390110b90b622c Mon Sep 17 00:00:00 2001 From: Andy Duong Date: Mon, 21 Nov 2022 22:49:45 +0700 Subject: [PATCH 10/43] [gh-230] fix the method name --- test/nimble_template/addons/variants/health_plug_test.exs | 4 ++-- test/nimble_template/helpers/credo_test.exs | 2 +- test/nimble_template/helpers/generator_test.exs | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/nimble_template/addons/variants/health_plug_test.exs b/test/nimble_template/addons/variants/health_plug_test.exs index 970e3e2b..7e7f33ee 100644 --- a/test/nimble_template/addons/variants/health_plug_test.exs +++ b/test/nimble_template/addons/variants/health_plug_test.exs @@ -55,7 +55,7 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlugTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> PhoenixAddons.HealthPlug.apply(project) assert_file("lib/nimble_template_web/helpers/router_helper.ex", fn file -> @@ -72,7 +72,7 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlugTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> PhoenixAddons.HealthPlug.apply(project) assert_file("test/nimble_template_web/helpers/router_helper_test.exs", fn file -> diff --git a/test/nimble_template/helpers/credo_test.exs b/test/nimble_template/helpers/credo_test.exs index 9ab90441..d60663e3 100644 --- a/test/nimble_template/helpers/credo_test.exs +++ b/test/nimble_template/helpers/credo_test.exs @@ -7,7 +7,7 @@ defmodule NimbleTemplate.CredoHelperTest do test "prepends credo rule disabling in the given file", %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> File.write!("sample_module.exs", """ defmodule SampleModule do def foo, do: "bar" diff --git a/test/nimble_template/helpers/generator_test.exs b/test/nimble_template/helpers/generator_test.exs index bcc7d8a1..500f84de 100644 --- a/test/nimble_template/helpers/generator_test.exs +++ b/test/nimble_template/helpers/generator_test.exs @@ -7,7 +7,7 @@ defmodule NimbleTemplate.GeneratorTest do test "prepends the given content in the given file", %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> File.write!("sample_module.exs", """ defmodule SampleModule do def foo, do: "bar" @@ -30,7 +30,7 @@ defmodule NimbleTemplate.GeneratorTest do test "when the given file does not exist, returns an error", %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> assert Generator.prepend_content("unknown_file.exs", "# This is sample module\n") == {:error, :failed_to_read_file} end) @@ -41,7 +41,7 @@ defmodule NimbleTemplate.GeneratorTest do test "prepends the given content in the given file", %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> File.write!("sample_module.exs", """ defmodule SampleModule do def foo, do: "bar" @@ -64,7 +64,7 @@ defmodule NimbleTemplate.GeneratorTest do test "when the given file does not exist, raises an error", %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> assert_raise Mix.Error, "Can't read unknown_file.exs", fn -> Generator.prepend_content!("unknown_file.exs", "# This is sample module\n") end From dafdad98da985c41136ff4561e536ec94b0cae4c Mon Sep 17 00:00:00 2001 From: Andy Duong Date: Mon, 21 Nov 2022 23:05:22 +0700 Subject: [PATCH 11/43] [gh-230] fix unit test --- .../addons/variants/phoenix/health_plug.ex | 11 +++++++++++ .../addons/variants/health_plug_test.exs | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/nimble_template/addons/variants/phoenix/health_plug.ex b/lib/nimble_template/addons/variants/phoenix/health_plug.ex index e688db7e..b24ad494 100644 --- a/lib/nimble_template/addons/variants/phoenix/health_plug.ex +++ b/lib/nimble_template/addons/variants/phoenix/health_plug.ex @@ -100,6 +100,17 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlug do end defp edit_router!(%Project{web_path: web_path, web_module: web_module} = project) do + Generator.replace_content!( + "#{web_path}/router.ex", + """ + use #{web_module}, :router + """, + """ + use #{web_module}, :router + alias #{web_module}.RouterHelper + """ + ) + Generator.replace_content!( "#{web_path}/router.ex", """ diff --git a/test/nimble_template/addons/variants/health_plug_test.exs b/test/nimble_template/addons/variants/health_plug_test.exs index 7e7f33ee..e3731e8a 100644 --- a/test/nimble_template/addons/variants/health_plug_test.exs +++ b/test/nimble_template/addons/variants/health_plug_test.exs @@ -56,7 +56,7 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlugTest do test_project_path: test_project_path } do in_test_project!(test_project_path, fn -> - PhoenixAddons.HealthPlug.apply(project) + PhoenixAddons.HealthPlug.apply!(project) assert_file("lib/nimble_template_web/helpers/router_helper.ex", fn file -> assert file =~ """ @@ -73,7 +73,7 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlugTest do test_project_path: test_project_path } do in_test_project!(test_project_path, fn -> - PhoenixAddons.HealthPlug.apply(project) + PhoenixAddons.HealthPlug.apply!(project) assert_file("test/nimble_template_web/helpers/router_helper_test.exs", fn file -> assert file =~ """ From 194bea555a337beb29789e4481f1e933ec871d2a Mon Sep 17 00:00:00 2001 From: An Duong Date: Wed, 9 Nov 2022 12:23:01 +0700 Subject: [PATCH 12/43] Do not allow the test env can call Hex.pm directly --- config/config.exs | 7 +++++++ config/dev.exs | 1 + config/test.exs | 4 ++++ lib/nimble_template/addons/addon.ex | 7 ++++--- .../exception/mock_hex_package_required.ex | 4 ++++ lib/nimble_template/hex/package.ex | 2 ++ lib/nimble_template/hex/package_behaviour.ex | 5 +++++ lib/nimble_template/hex/package_mock.ex | 9 +++++++++ test/nimble_template/hex/package_mock_test.exs.exs | 14 ++++++++++++++ test/support/addon_case.ex | 4 ++-- test/test_helper.exs | 2 +- 11 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 config/dev.exs create mode 100644 config/test.exs create mode 100644 lib/nimble_template/exception/mock_hex_package_required.ex create mode 100644 lib/nimble_template/hex/package_behaviour.ex create mode 100644 lib/nimble_template/hex/package_mock.ex create mode 100644 test/nimble_template/hex/package_mock_test.exs.exs diff --git a/config/config.exs b/config/config.exs index 95a3373f..3a547e36 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,3 +1,10 @@ import Config config :phoenix, :json_library, Jason + +config :nimble_template, + hex_package_resource: NimbleTemplate.Hex.Package + +# Import environment specific config. This must remain at the bottom +# of this file so it overrides the configuration defined above. +import_config "#{config_env()}.exs" diff --git a/config/dev.exs b/config/dev.exs new file mode 100644 index 00000000..becde769 --- /dev/null +++ b/config/dev.exs @@ -0,0 +1 @@ +import Config diff --git a/config/test.exs b/config/test.exs new file mode 100644 index 00000000..ef7010d8 --- /dev/null +++ b/config/test.exs @@ -0,0 +1,4 @@ +import Config + +config :nimble_template, + hex_package_resource: NimbleTemplate.Hex.PackageMock diff --git a/lib/nimble_template/addons/addon.ex b/lib/nimble_template/addons/addon.ex index c3e8454b..24e68401 100644 --- a/lib/nimble_template/addons/addon.ex +++ b/lib/nimble_template/addons/addon.ex @@ -28,9 +28,10 @@ defmodule NimbleTemplate.Addons.Addon do def do_apply!(%Project{} = project, opts) when is_map(opts), do: project - defp latest_package_version(package) do - "~> " <> Package.get_latest_version(package) - end + defp latest_package_version(package), + do: "~> " <> hex_package_resource().get_latest_version(package) + + defp hex_package_resource, do: Application.get_env(:nimble_template, :hex_package_resource) defoverridable do_apply!: 2 end diff --git a/lib/nimble_template/exception/mock_hex_package_required.ex b/lib/nimble_template/exception/mock_hex_package_required.ex new file mode 100644 index 00000000..9cdeb873 --- /dev/null +++ b/lib/nimble_template/exception/mock_hex_package_required.ex @@ -0,0 +1,4 @@ +defmodule NimbleTemplate.Exception.MockHexPackageRequiredException do + defexception message: + "Mock Hex Package with `@describetag mock_latest_package_versions: [{name, version}]` required" +end diff --git a/lib/nimble_template/hex/package.ex b/lib/nimble_template/hex/package.ex index 402e9ed7..6f977cc1 100644 --- a/lib/nimble_template/hex/package.ex +++ b/lib/nimble_template/hex/package.ex @@ -1,6 +1,8 @@ defmodule NimbleTemplate.Hex.Package do @moduledoc false + @behaviour NimbleTemplate.Hex.PackageBehaviour + alias NimbleTemplate.Hex.HexClient def get_latest_version(package) do diff --git a/lib/nimble_template/hex/package_behaviour.ex b/lib/nimble_template/hex/package_behaviour.ex new file mode 100644 index 00000000..69e3de11 --- /dev/null +++ b/lib/nimble_template/hex/package_behaviour.ex @@ -0,0 +1,5 @@ +defmodule NimbleTemplate.Hex.PackageBehaviour do + alias NimbleTemplate.Exception.MockHexPackageRequiredException + + @callback get_latest_version(list(String.t())) :: String.t() | MockHexPackageRequiredException +end diff --git a/lib/nimble_template/hex/package_mock.ex b/lib/nimble_template/hex/package_mock.ex new file mode 100644 index 00000000..169c13d0 --- /dev/null +++ b/lib/nimble_template/hex/package_mock.ex @@ -0,0 +1,9 @@ +defmodule NimbleTemplate.Hex.PackageMock do + @moduledoc false + + @behaviour NimbleTemplate.Hex.PackageBehaviour + + alias NimbleTemplate.Exception.MockHexPackageRequiredException + + def get_latest_version(_package), do: raise(MockHexPackageRequiredException) +end diff --git a/test/nimble_template/hex/package_mock_test.exs.exs b/test/nimble_template/hex/package_mock_test.exs.exs new file mode 100644 index 00000000..b50e4207 --- /dev/null +++ b/test/nimble_template/hex/package_mock_test.exs.exs @@ -0,0 +1,14 @@ +defmodule NimbleTemplate.Hex.PackageMockTest do + use ExUnit.Case, async: true + + alias NimbleTemplate.Hex.PackageMock + alias NimbleTemplate.Exception.MockHexPackageRequiredException + + describe "get_latest_version/1" do + test "raises a MockHexPackageRequiredException" do + assert_raise MockHexPackageRequiredException, fn -> + PackageMock.get_latest_version("credo") + end + end + end +end diff --git a/test/support/addon_case.ex b/test/support/addon_case.ex index 20629247..3947afd5 100644 --- a/test/support/addon_case.ex +++ b/test/support/addon_case.ex @@ -6,7 +6,7 @@ defmodule NimbleTemplate.AddonCase do alias NimbleTemplate.Addons alias NimbleTemplate.Addons.Phoenix.Api, as: ApiAddons alias NimbleTemplate.Addons.Phoenix.Web, as: WebAddons - alias NimbleTemplate.Hex.Package + alias NimbleTemplate.Hex.PackageMock alias NimbleTemplate.Projects.Project @default_project_name "nimble_template" @@ -88,7 +88,7 @@ defmodule NimbleTemplate.AddonCase do do: Module.safe_concat([Addons, required_addon_module]).apply!(project, required_addon_opt) defp mock_latest_package_version({_package, version}), - do: expect(Package, :get_latest_version, fn _package -> version end) + do: expect(PackageMock, :get_latest_version, fn _package -> version end) defp create_phoenix_test_project(test_project_path, opts) do # N - in response to Fetch and install dependencies? diff --git a/test/test_helper.exs b/test/test_helper.exs index 6fc0293f..ee2b2e48 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -3,7 +3,7 @@ Code.put_compiler_option(:warnings_as_errors, true) {:ok, _} = Application.ensure_all_started(:mimic) Mimic.copy(Calendar) -Mimic.copy(NimbleTemplate.Hex.Package) +Mimic.copy(NimbleTemplate.Hex.PackageMock) ExUnit.start(capture_log: true) ExUnit.configure(exclude: :release_version) From 73e2ab6064b5ab9dfbb8be4b79a8085f80eb9ddf Mon Sep 17 00:00:00 2001 From: An Duong Date: Wed, 9 Nov 2022 12:33:59 +0700 Subject: [PATCH 13/43] Correct the MIX_ENV in reusable workflows --- .github/workflows/reusable_mix_project.yml | 6 +++++- .github/workflows/reusable_phoenix_project.yml | 5 +++++ config/config.exs | 3 +-- config/test.exs | 3 +-- test/nimble_template/hex/package_mock_test.exs.exs | 2 +- 5 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/reusable_mix_project.yml b/.github/workflows/reusable_mix_project.yml index 7cdf74b5..fb65faa4 100644 --- a/.github/workflows/reusable_mix_project.yml +++ b/.github/workflows/reusable_mix_project.yml @@ -9,7 +9,7 @@ on: env: BASE_PROJECT_DIRECTORY: sample_project - MIX_ENV: test + MIX_ENV: dev jobs: unit_test: @@ -62,6 +62,10 @@ jobs: - name: Run mix codebase run: cd $BASE_PROJECT_DIRECTORY && mix codebase + env: + MIX_ENV: test - name: Run mix test run: cd $BASE_PROJECT_DIRECTORY && mix test + env: + MIX_ENV: test diff --git a/.github/workflows/reusable_phoenix_project.yml b/.github/workflows/reusable_phoenix_project.yml index 1ad18a8f..b5d402c5 100644 --- a/.github/workflows/reusable_phoenix_project.yml +++ b/.github/workflows/reusable_phoenix_project.yml @@ -14,6 +14,7 @@ env: PHOENIX_VERSION: 1.6.11 BASE_PROJECT_DIRECTORY: sample_project DB_HOST: localhost + MIX_ENV: dev jobs: unit_test: @@ -94,9 +95,13 @@ jobs: - name: Run mix codebase run: cd $BASE_PROJECT_DIRECTORY && mix codebase + env: + MIX_ENV: test - name: Run mix test run: cd $BASE_PROJECT_DIRECTORY && mix coverage + env: + MIX_ENV: test - name: Remove nimble_template dependency run: make remove_nimble_template PROJECT_DIRECTORY=$BASE_PROJECT_DIRECTORY diff --git a/config/config.exs b/config/config.exs index 3a547e36..ffb70a42 100644 --- a/config/config.exs +++ b/config/config.exs @@ -2,8 +2,7 @@ import Config config :phoenix, :json_library, Jason -config :nimble_template, - hex_package_resource: NimbleTemplate.Hex.Package +config :nimble_template, hex_package_resource: NimbleTemplate.Hex.Package # Import environment specific config. This must remain at the bottom # of this file so it overrides the configuration defined above. diff --git a/config/test.exs b/config/test.exs index ef7010d8..44e37c1b 100644 --- a/config/test.exs +++ b/config/test.exs @@ -1,4 +1,3 @@ import Config -config :nimble_template, - hex_package_resource: NimbleTemplate.Hex.PackageMock +config :nimble_template, hex_package_resource: NimbleTemplate.Hex.PackageMock diff --git a/test/nimble_template/hex/package_mock_test.exs.exs b/test/nimble_template/hex/package_mock_test.exs.exs index b50e4207..cb5b193a 100644 --- a/test/nimble_template/hex/package_mock_test.exs.exs +++ b/test/nimble_template/hex/package_mock_test.exs.exs @@ -1,8 +1,8 @@ defmodule NimbleTemplate.Hex.PackageMockTest do use ExUnit.Case, async: true - alias NimbleTemplate.Hex.PackageMock alias NimbleTemplate.Exception.MockHexPackageRequiredException + alias NimbleTemplate.Hex.PackageMock describe "get_latest_version/1" do test "raises a MockHexPackageRequiredException" do From 667c58fac5c265f69c196f1970e3a29414874f0f Mon Sep 17 00:00:00 2001 From: An Duong Date: Wed, 9 Nov 2022 13:45:54 +0700 Subject: [PATCH 14/43] Fix unit test --- lib/nimble_template/addons/addon.ex | 1 - lib/nimble_template/exception/mock_hex_package_required.ex | 3 +-- lib/nimble_template/hex/package_mock.ex | 7 ++++++- test/nimble_template/addons/variants/health_plug_test.exs | 1 + .../addons/variants/phoenix/web/bootstrap_test.exs | 2 ++ 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/nimble_template/addons/addon.ex b/lib/nimble_template/addons/addon.ex index 24e68401..9331c8d8 100644 --- a/lib/nimble_template/addons/addon.ex +++ b/lib/nimble_template/addons/addon.ex @@ -14,7 +14,6 @@ defmodule NimbleTemplate.Addons.Addon do import NimbleTemplate.GithubHelper, only: [has_github_wiki_directory?: 0] alias NimbleTemplate.Generator - alias NimbleTemplate.Hex.Package alias NimbleTemplate.Projects.Project alias NimbleTemplate.ProjectHelper diff --git a/lib/nimble_template/exception/mock_hex_package_required.ex b/lib/nimble_template/exception/mock_hex_package_required.ex index 9cdeb873..187fa786 100644 --- a/lib/nimble_template/exception/mock_hex_package_required.ex +++ b/lib/nimble_template/exception/mock_hex_package_required.ex @@ -1,4 +1,3 @@ defmodule NimbleTemplate.Exception.MockHexPackageRequiredException do - defexception message: - "Mock Hex Package with `@describetag mock_latest_package_versions: [{name, version}]` required" + defexception [:message] end diff --git a/lib/nimble_template/hex/package_mock.ex b/lib/nimble_template/hex/package_mock.ex index 169c13d0..b55fdc45 100644 --- a/lib/nimble_template/hex/package_mock.ex +++ b/lib/nimble_template/hex/package_mock.ex @@ -5,5 +5,10 @@ defmodule NimbleTemplate.Hex.PackageMock do alias NimbleTemplate.Exception.MockHexPackageRequiredException - def get_latest_version(_package), do: raise(MockHexPackageRequiredException) + def get_latest_version(package) do + raise(MockHexPackageRequiredException, + message: + "Mock Hex Package with `@describetag mock_latest_package_versions: [{#{package}, :version}]` required" + ) + end end diff --git a/test/nimble_template/addons/variants/health_plug_test.exs b/test/nimble_template/addons/variants/health_plug_test.exs index e3731e8a..1fbd35ce 100644 --- a/test/nimble_template/addons/variants/health_plug_test.exs +++ b/test/nimble_template/addons/variants/health_plug_test.exs @@ -3,6 +3,7 @@ defmodule NimbleTemplate.Addons.Phoenix.HealthPlugTest do describe "#apply!/2" do @describetag required_addons: [:ExCoveralls, :"Phoenix.MixRelease"] + @describetag mock_latest_package_versions: [{:excoveralls, "0.12.2"}] test "copies the health plug file", %{ project: project, diff --git a/test/nimble_template/addons/variants/phoenix/web/bootstrap_test.exs b/test/nimble_template/addons/variants/phoenix/web/bootstrap_test.exs index e34b1ed1..8cae3214 100644 --- a/test/nimble_template/addons/variants/phoenix/web/bootstrap_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/bootstrap_test.exs @@ -9,6 +9,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.BootstrapTest do :"Phoenix.Web.PostCSS", :"Phoenix.Web.DartSass" ] + @describetag mock_latest_package_versions: [{:dart_sass, "0.26.2"}] test "copies Bootstrap vendor file", %{project: project, test_project_path: test_project_path} do in_test_project!(test_project_path, fn -> @@ -133,6 +134,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.BootstrapTest do :"Phoenix.Web.NimbleCSS", :"Phoenix.Web.NimbleJS" ] + @describetag mock_latest_package_versions: [{:dart_sass, "0.26.2"}] test "copies Bootstrap vendor file", %{project: project, test_project_path: test_project_path} do in_test_project!(test_project_path, fn -> From d9eec28498a341041b1f462c8151500fd6e3b640 Mon Sep 17 00:00:00 2001 From: An Duong Date: Wed, 9 Nov 2022 14:14:25 +0700 Subject: [PATCH 15/43] Fix CI --- config/config.exs | 2 -- config/prod.exs | 1 + lib/nimble_template/addons/addon.ex | 5 ++++- 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 config/prod.exs diff --git a/config/config.exs b/config/config.exs index ffb70a42..c007c955 100644 --- a/config/config.exs +++ b/config/config.exs @@ -4,6 +4,4 @@ config :phoenix, :json_library, Jason config :nimble_template, hex_package_resource: NimbleTemplate.Hex.Package -# Import environment specific config. This must remain at the bottom -# of this file so it overrides the configuration defined above. import_config "#{config_env()}.exs" diff --git a/config/prod.exs b/config/prod.exs new file mode 100644 index 00000000..becde769 --- /dev/null +++ b/config/prod.exs @@ -0,0 +1 @@ +import Config diff --git a/lib/nimble_template/addons/addon.ex b/lib/nimble_template/addons/addon.ex index 9331c8d8..1774ae7f 100644 --- a/lib/nimble_template/addons/addon.ex +++ b/lib/nimble_template/addons/addon.ex @@ -14,6 +14,7 @@ defmodule NimbleTemplate.Addons.Addon do import NimbleTemplate.GithubHelper, only: [has_github_wiki_directory?: 0] alias NimbleTemplate.Generator + alias NimbleTemplate.Hex.Package alias NimbleTemplate.Projects.Project alias NimbleTemplate.ProjectHelper @@ -30,7 +31,9 @@ defmodule NimbleTemplate.Addons.Addon do defp latest_package_version(package), do: "~> " <> hex_package_resource().get_latest_version(package) - defp hex_package_resource, do: Application.get_env(:nimble_template, :hex_package_resource) + # TODO: `Application.get_env(:nimble_template, :hex_package_resource)` returns nil on runtime, temporary fix by fallback to `Package` + defp hex_package_resource, + do: Application.get_env(:nimble_template, :hex_package_resource, Package) defoverridable do_apply!: 2 end From ff8603cebe74794873c65817d8930893dde51aba Mon Sep 17 00:00:00 2001 From: Andy Duong Date: Mon, 21 Nov 2022 22:53:16 +0700 Subject: [PATCH 16/43] Remove the config/dev and prod --- config/config.exs | 4 +++- config/dev.exs | 1 - config/prod.exs | 1 - lib/nimble_template/hex/package_mock.ex | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) delete mode 100644 config/dev.exs delete mode 100644 config/prod.exs diff --git a/config/config.exs b/config/config.exs index c007c955..93ba4cb4 100644 --- a/config/config.exs +++ b/config/config.exs @@ -4,4 +4,6 @@ config :phoenix, :json_library, Jason config :nimble_template, hex_package_resource: NimbleTemplate.Hex.Package -import_config "#{config_env()}.exs" +if File.exists?("config/#{config_env()}.exs") do + import_config "#{config_env()}.exs" +end diff --git a/config/dev.exs b/config/dev.exs deleted file mode 100644 index becde769..00000000 --- a/config/dev.exs +++ /dev/null @@ -1 +0,0 @@ -import Config diff --git a/config/prod.exs b/config/prod.exs deleted file mode 100644 index becde769..00000000 --- a/config/prod.exs +++ /dev/null @@ -1 +0,0 @@ -import Config diff --git a/lib/nimble_template/hex/package_mock.ex b/lib/nimble_template/hex/package_mock.ex index b55fdc45..4459a60f 100644 --- a/lib/nimble_template/hex/package_mock.ex +++ b/lib/nimble_template/hex/package_mock.ex @@ -8,7 +8,7 @@ defmodule NimbleTemplate.Hex.PackageMock do def get_latest_version(package) do raise(MockHexPackageRequiredException, message: - "Mock Hex Package with `@describetag mock_latest_package_versions: [{#{package}, :version}]` required" + "Requires to mock Hex package with `@describetag mock_latest_package_versions: [{#{package}, :version}]`" ) end end From bd342e69ef44d8631c09f0a5fc859c29a89dc77c Mon Sep 17 00:00:00 2001 From: Andy Duong Date: Mon, 21 Nov 2022 22:54:01 +0700 Subject: [PATCH 17/43] Add a comment --- lib/nimble_template/hex/package_mock.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/nimble_template/hex/package_mock.ex b/lib/nimble_template/hex/package_mock.ex index 4459a60f..59cc6ede 100644 --- a/lib/nimble_template/hex/package_mock.ex +++ b/lib/nimble_template/hex/package_mock.ex @@ -5,6 +5,7 @@ defmodule NimbleTemplate.Hex.PackageMock do alias NimbleTemplate.Exception.MockHexPackageRequiredException + # Prevent the call to get the latest version if the test forgets to mock the external library def get_latest_version(package) do raise(MockHexPackageRequiredException, message: From 5e5f71242af0ff0e9af33ef2310c96b828540d9e Mon Sep 17 00:00:00 2001 From: Andy Duong Date: Mon, 21 Nov 2022 23:00:03 +0700 Subject: [PATCH 18/43] fix unit test --- test/nimble_template/addons/credo_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/nimble_template/addons/credo_test.exs b/test/nimble_template/addons/credo_test.exs index 31887bd9..2d4a5440 100644 --- a/test/nimble_template/addons/credo_test.exs +++ b/test/nimble_template/addons/credo_test.exs @@ -52,7 +52,7 @@ defmodule NimbleTemplate.Addons.CredoTest do describe "#apply!/2 with mix_project" do @describetag mix_project?: true - @describetag mock_latest_package_versions: [{:credo, "1.4"}] + @describetag mock_latest_package_versions: [{:credo, "1.4"}, {:compass_credo_plugin, "1.0.0"}] @describetag required_addons: [:TestEnv] test "copies the .credo.exs", %{ From 9782e2ef5fef654f7a75a5bf77f6729d46406c43 Mon Sep 17 00:00:00 2001 From: Micky Jittjana Date: Tue, 22 Nov 2022 17:02:39 +0700 Subject: [PATCH 19/43] [#291] Update spacing --- lib/nimble_template/projects/project.ex | 5 ++--- lib/nimble_template/templates/variants/mix/template.ex | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/nimble_template/projects/project.ex b/lib/nimble_template/projects/project.ex index 7fb6f813..0898b83e 100644 --- a/lib/nimble_template/projects/project.ex +++ b/lib/nimble_template/projects/project.ex @@ -84,9 +84,8 @@ defmodule NimbleTemplate.Projects.Project do def prepend_optional_addon( %__MODULE__{optional_addons: existing_addons} = project, addon_module - ) do - Map.put(project, :optional_addons, [addon_module | existing_addons]) - end + ), + do: Map.put(project, :optional_addons, [addon_module | existing_addons]) defp api_project?(opts), do: opts[:api] === true diff --git a/lib/nimble_template/templates/variants/mix/template.ex b/lib/nimble_template/templates/variants/mix/template.ex index 520f6672..fe435be2 100644 --- a/lib/nimble_template/templates/variants/mix/template.ex +++ b/lib/nimble_template/templates/variants/mix/template.ex @@ -6,9 +6,7 @@ defmodule NimbleTemplate.Templates.Mix.Template do alias NimbleTemplate.Addons alias NimbleTemplate.Projects.Project - def pre_apply(%Project{} = project) do - install_addon_prompt(project, Addons.Mimic) - end + def pre_apply(%Project{} = project), do: install_addon_prompt(project, Addons.Mimic) def apply(%Project{} = project) do project From c7bf08637453b22f90f154e55382f7ae0959351e Mon Sep 17 00:00:00 2001 From: Micky Jittjana Date: Tue, 22 Nov 2022 17:14:09 +0700 Subject: [PATCH 20/43] Add bang to function --- test/nimble_template/version_test.exs | 12 ++++++------ test/support/helpers/file_helper.ex | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/nimble_template/version_test.exs b/test/nimble_template/version_test.exs index 5ae1bb2e..d53f24f9 100644 --- a/test/nimble_template/version_test.exs +++ b/test/nimble_template/version_test.exs @@ -7,7 +7,7 @@ defmodule NimbleTemplate.VersionTest do test "updates the version in mix.exs and README.md files given a valid version number", %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> current_version = Mix.Project.config()[:version] patch_number = @@ -42,7 +42,7 @@ defmodule NimbleTemplate.VersionTest do test "raises Mix.Error exception given an invalid version number", %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> current_version = Mix.Project.config()[:version] major_number = @@ -81,7 +81,7 @@ defmodule NimbleTemplate.VersionTest do test "upgrade elixir version given the new elixir_version", %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> assert Version.upgrade_stack!(elixir: "a.b.c") == :ok assert_file("lib/nimble_template/projects/project.ex", fn file -> @@ -113,7 +113,7 @@ defmodule NimbleTemplate.VersionTest do test "upgrade erlang version given the new erlang_version", %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> assert Version.upgrade_stack!(erlang: "x.y.z") == :ok assert_file("lib/nimble_template/projects/project.ex", fn file -> @@ -147,7 +147,7 @@ defmodule NimbleTemplate.VersionTest do test "upgrade node version given the new node_version", %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> assert Version.upgrade_stack!(node: "a.s.d") == :ok assert_file("lib/nimble_template/projects/project.ex", fn file -> @@ -175,7 +175,7 @@ defmodule NimbleTemplate.VersionTest do test "upgrade alpine version given the new alpine_version", %{ test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> + in_test_project!(test_project_path, fn -> assert Version.upgrade_stack!(alpine: "z.x.c") == :ok assert_file("lib/nimble_template/projects/project.ex", fn file -> diff --git a/test/support/helpers/file_helper.ex b/test/support/helpers/file_helper.ex index 3de13128..48e5212b 100644 --- a/test/support/helpers/file_helper.ex +++ b/test/support/helpers/file_helper.ex @@ -3,7 +3,7 @@ defmodule NimbleTemplate.Test.FileHelper do # ATTENTION: File.cd! doesn't support `async: true`, the test will fail randomly in async mode # https://elixirforum.com/t/randomly-getting-compilationerror-on-tests/17298/3 - def in_test_project(test_project_path, function), do: File.cd!(test_project_path, function) + def in_test_project!(test_project_path, function), do: File.cd!(test_project_path, function) def assert_file(path), do: assert(File.regular?(path), "Expected #{path} to exist, but does not") From 34361088e05b4a620d3c8162c5fadbc744652678 Mon Sep 17 00:00:00 2001 From: Andy Duong Date: Tue, 29 Nov 2022 13:07:04 +0700 Subject: [PATCH 21/43] Move the gettext check to codebase and codebase.fix --- .../addons/variants/phoenix/gettext.ex | 19 +++++++++++++++---- .../.github/workflows/test.yml.eex | 3 --- .../addons/variants/gettext_test.exs | 8 +++++++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/nimble_template/addons/variants/phoenix/gettext.ex b/lib/nimble_template/addons/variants/phoenix/gettext.ex index bca2b533..cb45cbfa 100644 --- a/lib/nimble_template/addons/variants/phoenix/gettext.ex +++ b/lib/nimble_template/addons/variants/phoenix/gettext.ex @@ -9,14 +9,25 @@ defmodule NimbleTemplate.Addons.Phoenix.Gettext do end defp edit_mix!(%Project{} = project) do - Generator.inject_content!( + Generator.replace_content!( "mix.exs", """ - defp aliases do - [ + codebase: [ """, """ - "gettext.extract-and-merge": ["gettext.extract --merge --no-fuzzy"], + codebase: [ + "gettext.extract --check-up-to-date", + """ + ) + + Generator.replace_content!( + "mix.exs", + """ + "codebase.fix": [ + """, + """ + "codebase.fix": [ + "gettext.extract --merge --no-fuzzy", """ ) diff --git a/priv/templates/nimble_template/.github/workflows/test.yml.eex b/priv/templates/nimble_template/.github/workflows/test.yml.eex index 26bd9a96..de7ebd69 100644 --- a/priv/templates/nimble_template/.github/workflows/test.yml.eex +++ b/priv/templates/nimble_template/.github/workflows/test.yml.eex @@ -148,9 +148,6 @@ jobs: - name: Migrate database run: mix ecto.migrate - - name: Ensure that localization files (POs, POTs) are up-to-date. - run: mix gettext.extract --check-up-to-date - - name: Run codebase check run: mix codebase diff --git a/test/nimble_template/addons/variants/gettext_test.exs b/test/nimble_template/addons/variants/gettext_test.exs index 4fdcaeed..af59c172 100644 --- a/test/nimble_template/addons/variants/gettext_test.exs +++ b/test/nimble_template/addons/variants/gettext_test.exs @@ -13,7 +13,13 @@ defmodule NimbleTemplate.Addons.Phoenix.GettextTest do assert_file("mix.exs", fn file -> assert file =~ """ - "gettext.extract-and-merge": ["gettext.extract --merge --no-fuzzy"], + codebase: [ + "gettext.extract --check-up-to-date", + """ + + assert file =~ """ + "codebase.fix": [ + "gettext.extract --merge --no-fuzzy", """ end) end) From 9f12197933b8e4fe5f65c1c91eb3f538cc58d73b Mon Sep 17 00:00:00 2001 From: Andy Duong Date: Tue, 29 Nov 2022 13:40:50 +0700 Subject: [PATCH 22/43] Add postcss-scss --- lib/nimble_template/addons/variants/phoenix/web/post_css.ex | 3 ++- .../addons/variants/phoenix/web/post_css_test.exs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/nimble_template/addons/variants/phoenix/web/post_css.ex b/lib/nimble_template/addons/variants/phoenix/web/post_css.ex index deb82e1a..f99a4240 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/post_css.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/post_css.ex @@ -27,7 +27,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PostCSS do """, """ "devDependencies": { - "postcss": "8.4.12", + "postcss": "8.4.19", + "postcss-scss": "4.0.6", "postcss-cli": "9.1.0", "postcss-load-config": "3.1.4", "autoprefixer": "10.4.5", diff --git a/test/nimble_template/addons/variants/phoenix/web/post_css_test.exs b/test/nimble_template/addons/variants/phoenix/web/post_css_test.exs index 77ae0e67..2d30edb3 100644 --- a/test/nimble_template/addons/variants/phoenix/web/post_css_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/post_css_test.exs @@ -55,7 +55,8 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PostCSSTest do assert_file("assets/package.json", fn file -> assert file =~ """ "devDependencies": { - "postcss": "8.4.12", + "postcss": "8.4.19", + "postcss-scss": "4.0.6", "postcss-cli": "9.1.0", "postcss-load-config": "3.1.4", "autoprefixer": "10.4.5", From 9f8957089bddfa4d848163d7d9d70ffc3e0cfa20 Mon Sep 17 00:00:00 2001 From: Andy Duong Date: Wed, 30 Nov 2022 09:52:11 +0700 Subject: [PATCH 23/43] Correct the codeowners --- .github/CODEOWNERS | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index b2ace1bf..564b2b28 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,8 +1,5 @@ -# Team Lead -* @byhbt - # Team Members -* @andyduong1920 @bterone @hanam1ni @longnd @rosle @topnimble @Nihisil @nvminhtue @liamstevens111 +* @byhbt @andyduong1920 @bterone @hanam1ni @longnd @rosle @topnimble @Nihisil @nvminhtue @liamstevens111 # Engineering Leads CODEOWNERS @nimblehq/engineering-leads From b45a4350e4979c49e5f907765713a004e88ed831 Mon Sep 17 00:00:00 2001 From: topnimble <90754900+topnimble@users.noreply.github.com> Date: Wed, 30 Nov 2022 14:50:08 +0700 Subject: [PATCH 24/43] Add `async: false` to view home page test --- .../test/features/home_page/view_home_page_test.exs.eex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/priv/templates/nimble_template/test/features/home_page/view_home_page_test.exs.eex b/priv/templates/nimble_template/test/features/home_page/view_home_page_test.exs.eex index 70868f65..0f1ac282 100644 --- a/priv/templates/nimble_template/test/features/home_page/view_home_page_test.exs.eex +++ b/priv/templates/nimble_template/test/features/home_page/view_home_page_test.exs.eex @@ -1,5 +1,5 @@ defmodule <%= web_module %>.HomePage.ViewHomePageTest do - use <%= web_module %>.FeatureCase + use <%= web_module %>.FeatureCase, async: false feature "view home page", %{session: session} do visit(session, Routes.page_path(<%= web_module %>.Endpoint, :index)) From d6f35c8a52d3aff87c2446347c7a9480c511a106 Mon Sep 17 00:00:00 2001 From: Liam Stevens <8955671+liamstevens111@users.noreply.github.com> Date: Wed, 23 Nov 2022 13:18:33 +0700 Subject: [PATCH 25/43] Remove gettext compiler --- lib/nimble_template/templates/variants/phoenix/template.ex | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/nimble_template/templates/variants/phoenix/template.ex b/lib/nimble_template/templates/variants/phoenix/template.ex index 5e4c5e17..a8512590 100644 --- a/lib/nimble_template/templates/variants/phoenix/template.ex +++ b/lib/nimble_template/templates/variants/phoenix/template.ex @@ -46,9 +46,6 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do # credo:disable-for-next-line Credo.Check.Refactor.ABCSize defp apply_phoenix_common_setup(%Project{} = project) do - # TODO: Remove me after the Phoenix generator fix releases: https://github.com/phoenixframework/phoenix/pull/4894 - remove_mix_compiler_config!() - project |> apply_default_common_phoenix_addons() |> apply_optional_common_phoenix_addons() @@ -143,7 +140,4 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do defp apply_phoenix_variant_setup(%Project{web_project?: true, live_project?: true} = project), do: LiveTemplate.apply!(project) - - defp remove_mix_compiler_config!(), - do: Generator.delete_content!("mix.exs", "compilers: [:gettext] ++ Mix.compilers(),") end From afa8080c888889507b3b80997005fd09152a4cf9 Mon Sep 17 00:00:00 2001 From: Liam Stevens <8955671+liamstevens111@users.noreply.github.com> Date: Wed, 23 Nov 2022 13:19:09 +0700 Subject: [PATCH 26/43] Idea for change on suppressing credo warnings depending on project type' --- lib/nimble_template/templates/template.ex | 35 +++++++++++++++++------ 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/nimble_template/templates/template.ex b/lib/nimble_template/templates/template.ex index bbfdffd4..5ab4617a 100644 --- a/lib/nimble_template/templates/template.ex +++ b/lib/nimble_template/templates/template.ex @@ -32,14 +32,15 @@ defmodule NimbleTemplate.Templates.Template do defp post_apply!(%Project{mix_project?: true} = project) do order_dependencies!() fetch_and_install_elixir_dependencies() - suppress_necessary_credo_warnings(project) + suppress_credo_warnings_for_base_project(project) format_codebase() end defp post_apply!(%Project{api_project?: true} = project) do order_dependencies!() fetch_and_install_elixir_dependencies() - suppress_necessary_credo_warnings(project) + suppress_credo_warnings_for_base_project(project) + suppress_credo_warnings_for_project_type(project) format_codebase() end @@ -47,7 +48,8 @@ defmodule NimbleTemplate.Templates.Template do order_dependencies!() fetch_and_install_elixir_dependencies() fetch_and_install_node_dependencies() - suppress_necessary_credo_warnings(project) + suppress_credo_warnings_for_base_project(project) + suppress_credo_warnings_for_project_type(project) format_codebase() end @@ -60,15 +62,28 @@ defmodule NimbleTemplate.Templates.Template do Mix.shell().cmd("npm install --prefix assets") end - defp suppress_necessary_credo_warnings(%Project{ - base_module: base_module, + defp suppress_credo_warnings_for_base_project(%Project{base_module: base_module}) do + CredoHelper.disable_rule( + "lib/#{Macro.underscore(base_module)}.ex", + "CompassCredoPlugin.Check.DoSingleExpression" + ) + end + + defp suppress_credo_warnings_for_project_type(%Project{web_project?: true} = project) do + suppress_credo_warnings_for_phoenix_project(project) + end + + defp suppress_credo_warnings_for_project_type(%Project{api_project?: true} = project) do + suppress_credo_warnings_for_phoenix_project(project) + suppress_credo_warnings_for_phoenix_api_project(project) + end + + defp suppress_credo_warnings_for_phoenix_project(%Project{ base_path: base_path, - web_path: web_path, - web_test_path: web_test_path + web_path: web_path }) do Enum.each( [ - "lib/#{Macro.underscore(base_module)}.ex", "#{web_path}/controllers/page_controller.ex", "#{web_path}/telemetry.ex", "#{web_path}/views/error_view.ex", @@ -78,7 +93,11 @@ defmodule NimbleTemplate.Templates.Template do CredoHelper.disable_rule(file_path, "CompassCredoPlugin.Check.DoSingleExpression") end ) + end + defp suppress_credo_warnings_for_phoenix_api_project(%Project{ + web_test_path: web_test_path + }) do Enum.each( [ "#{web_test_path}/views/api/error_view_test.exs", From 937329a7d33def5b84719e4fadf2f02ec983e908 Mon Sep 17 00:00:00 2001 From: Liam Stevens <8955671+liamstevens111@users.noreply.github.com> Date: Wed, 23 Nov 2022 13:40:59 +0700 Subject: [PATCH 27/43] Remove unused alias' --- lib/nimble_template/templates/variants/phoenix/template.ex | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/nimble_template/templates/variants/phoenix/template.ex b/lib/nimble_template/templates/variants/phoenix/template.ex index a8512590..0c50bdf2 100644 --- a/lib/nimble_template/templates/variants/phoenix/template.ex +++ b/lib/nimble_template/templates/variants/phoenix/template.ex @@ -3,7 +3,6 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do import NimbleTemplate.{AddonHelper, GithubHelper} - alias NimbleTemplate.{Addons, Generator} alias NimbleTemplate.Addons.Phoenix, as: PhoenixAddons alias NimbleTemplate.Addons.Phoenix.Web, as: WebAddons alias NimbleTemplate.Projects.Project From 44cabf13a1eca50b69fad84cd4182a60200336b3 Mon Sep 17 00:00:00 2001 From: Liam Stevens <8955671+liamstevens111@users.noreply.github.com> Date: Wed, 23 Nov 2022 13:44:10 +0700 Subject: [PATCH 28/43] Remove unused alias --- lib/nimble_template/templates/variants/phoenix/template.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/nimble_template/templates/variants/phoenix/template.ex b/lib/nimble_template/templates/variants/phoenix/template.ex index 0c50bdf2..b5f7c884 100644 --- a/lib/nimble_template/templates/variants/phoenix/template.ex +++ b/lib/nimble_template/templates/variants/phoenix/template.ex @@ -3,6 +3,7 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do import NimbleTemplate.{AddonHelper, GithubHelper} + alias NimbleTemplate.Addons alias NimbleTemplate.Addons.Phoenix, as: PhoenixAddons alias NimbleTemplate.Addons.Phoenix.Web, as: WebAddons alias NimbleTemplate.Projects.Project From 143c06175b1a4482ff89655596449ae6b50849df Mon Sep 17 00:00:00 2001 From: Liam Stevens <8955671+liamstevens111@users.noreply.github.com> Date: Wed, 30 Nov 2022 11:30:45 +0700 Subject: [PATCH 29/43] Add gettext compiler back --- .../templates/variants/phoenix/template.ex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/nimble_template/templates/variants/phoenix/template.ex b/lib/nimble_template/templates/variants/phoenix/template.ex index b5f7c884..5e4c5e17 100644 --- a/lib/nimble_template/templates/variants/phoenix/template.ex +++ b/lib/nimble_template/templates/variants/phoenix/template.ex @@ -3,7 +3,7 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do import NimbleTemplate.{AddonHelper, GithubHelper} - alias NimbleTemplate.Addons + alias NimbleTemplate.{Addons, Generator} alias NimbleTemplate.Addons.Phoenix, as: PhoenixAddons alias NimbleTemplate.Addons.Phoenix.Web, as: WebAddons alias NimbleTemplate.Projects.Project @@ -46,6 +46,9 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do # credo:disable-for-next-line Credo.Check.Refactor.ABCSize defp apply_phoenix_common_setup(%Project{} = project) do + # TODO: Remove me after the Phoenix generator fix releases: https://github.com/phoenixframework/phoenix/pull/4894 + remove_mix_compiler_config!() + project |> apply_default_common_phoenix_addons() |> apply_optional_common_phoenix_addons() @@ -140,4 +143,7 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do defp apply_phoenix_variant_setup(%Project{web_project?: true, live_project?: true} = project), do: LiveTemplate.apply!(project) + + defp remove_mix_compiler_config!(), + do: Generator.delete_content!("mix.exs", "compilers: [:gettext] ++ Mix.compilers(),") end From 5936ca2b928d386b0ff0cebd8d23d182834b8da7 Mon Sep 17 00:00:00 2001 From: Liam Stevens <8955671+liamstevens111@users.noreply.github.com> Date: Wed, 30 Nov 2022 11:32:17 +0700 Subject: [PATCH 30/43] Remove further pattern match function added to call the removal of credo checks explicitly depending on type --- lib/nimble_template/templates/template.ex | 36 +++++++++++------------ 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/nimble_template/templates/template.ex b/lib/nimble_template/templates/template.ex index 5ab4617a..930402c4 100644 --- a/lib/nimble_template/templates/template.ex +++ b/lib/nimble_template/templates/template.ex @@ -39,8 +39,7 @@ defmodule NimbleTemplate.Templates.Template do defp post_apply!(%Project{api_project?: true} = project) do order_dependencies!() fetch_and_install_elixir_dependencies() - suppress_credo_warnings_for_base_project(project) - suppress_credo_warnings_for_project_type(project) + suppress_credo_warnings_for_phoenix_api_project(project) format_codebase() end @@ -48,8 +47,7 @@ defmodule NimbleTemplate.Templates.Template do order_dependencies!() fetch_and_install_elixir_dependencies() fetch_and_install_node_dependencies() - suppress_credo_warnings_for_base_project(project) - suppress_credo_warnings_for_project_type(project) + suppress_credo_warnings_for_phoenix_project(project) format_codebase() end @@ -69,19 +67,14 @@ defmodule NimbleTemplate.Templates.Template do ) end - defp suppress_credo_warnings_for_project_type(%Project{web_project?: true} = project) do - suppress_credo_warnings_for_phoenix_project(project) - end - - defp suppress_credo_warnings_for_project_type(%Project{api_project?: true} = project) do - suppress_credo_warnings_for_phoenix_project(project) - suppress_credo_warnings_for_phoenix_api_project(project) - end + defp suppress_credo_warnings_for_phoenix_project( + %Project{ + base_path: base_path, + web_path: web_path + } = project + ) do + suppress_credo_warnings_for_base_project(project) - defp suppress_credo_warnings_for_phoenix_project(%Project{ - base_path: base_path, - web_path: web_path - }) do Enum.each( [ "#{web_path}/controllers/page_controller.ex", @@ -95,9 +88,14 @@ defmodule NimbleTemplate.Templates.Template do ) end - defp suppress_credo_warnings_for_phoenix_api_project(%Project{ - web_test_path: web_test_path - }) do + defp suppress_credo_warnings_for_phoenix_api_project( + %Project{ + web_test_path: web_test_path + } = project + ) do + suppress_credo_warnings_for_base_project(project) + suppress_credo_warnings_for_phoenix_project(project) + Enum.each( [ "#{web_test_path}/views/api/error_view_test.exs", From f31ebd3b36bd7e532bd744d07b11e41c16a86042 Mon Sep 17 00:00:00 2001 From: Andy Duong Date: Wed, 7 Dec 2022 11:12:34 +0700 Subject: [PATCH 31/43] Excluded MultiAliasImportRequireUse rule on some files --- lib/nimble_template/addons/credo.ex | 9 +++++++-- priv/templates/nimble_template/.credo.exs | 21 +++++++++++++++------ test/nimble_template/addons/credo_test.exs | 15 ++++++++++++++- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/lib/nimble_template/addons/credo.ex b/lib/nimble_template/addons/credo.ex index 78077774..4a7158c4 100644 --- a/lib/nimble_template/addons/credo.ex +++ b/lib/nimble_template/addons/credo.ex @@ -10,8 +10,13 @@ defmodule NimbleTemplate.Addons.Credo do |> edit_files!() end - defp copy_files!(%Project{} = project) do - Generator.copy_file!([{:text, ".credo.exs", ".credo.exs"}]) + defp copy_files!(%Project{web_path: web_path, base_path: base_path} = project) do + binding = [ + base_entry_path: "#{base_path}.ex", + web_entry_path: "#{web_path}.ex" + ] + + Generator.copy_file!([{:eex, ".credo.exs", ".credo.exs"}], binding) project end diff --git a/priv/templates/nimble_template/.credo.exs b/priv/templates/nimble_template/.credo.exs index cb69e197..dcc365dc 100644 --- a/priv/templates/nimble_template/.credo.exs +++ b/priv/templates/nimble_template/.credo.exs @@ -157,12 +157,21 @@ # Controversial and experimental checks (opt-in, just replace `false` with `[]`) # {Credo.Check.Readability.StrictModuleLayout, - [ - order: - ~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, []}, + [ + order: + ~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, + files: %{ + excluded: [ + "<%= base_entry_path %>", + "<%= web_entry_path %>", + "test/support/conn_case.ex", + "test/support/data_case.ex", + "test/support/feature_case.ex" + ] + }}, {Credo.Check.Consistency.UnusedVariableNames, false}, {Credo.Check.Design.DuplicatedCode, files: %{excluded: ["**/*_test.exs"]}}, {Credo.Check.Readability.AliasAs, false}, diff --git a/test/nimble_template/addons/credo_test.exs b/test/nimble_template/addons/credo_test.exs index 2d4a5440..7d9a9a23 100644 --- a/test/nimble_template/addons/credo_test.exs +++ b/test/nimble_template/addons/credo_test.exs @@ -12,7 +12,20 @@ defmodule NimbleTemplate.Addons.CredoTest do in_test_project!(test_project_path, fn -> Addons.Credo.apply!(project) - assert_file(".credo.exs") + assert_file(".credo.exs", fn file -> + assert file =~ """ + {Credo.Check.Consistency.MultiAliasImportRequireUse, + files: %{ + excluded: [ + "lib/nimble_template.ex", + "lib/nimble_template_web.ex", + "test/support/conn_case.ex", + "test/support/data_case.ex", + "test/support/feature_case.ex" + ] + }}, + """ + end) end) end From fe17acdb3ad4ccfe73f24a3917a2241315ac1eca Mon Sep 17 00:00:00 2001 From: Andy Duong Date: Wed, 7 Dec 2022 11:15:44 +0700 Subject: [PATCH 32/43] Minor fix indent --- priv/templates/nimble_template/.credo.exs | 20 ++++++++++---------- test/nimble_template/addons/credo_test.exs | 18 +++++++++--------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/priv/templates/nimble_template/.credo.exs b/priv/templates/nimble_template/.credo.exs index dcc365dc..03ede894 100644 --- a/priv/templates/nimble_template/.credo.exs +++ b/priv/templates/nimble_template/.credo.exs @@ -162,16 +162,16 @@ ~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, - files: %{ - excluded: [ - "<%= base_entry_path %>", - "<%= web_entry_path %>", - "test/support/conn_case.ex", - "test/support/data_case.ex", - "test/support/feature_case.ex" - ] - }}, + {Credo.Check.Consistency.MultiAliasImportRequireUse, + files: %{ + excluded: [ + "<%= base_entry_path %>", + "<%= web_entry_path %>", + "test/support/conn_case.ex", + "test/support/data_case.ex", + "test/support/feature_case.ex" + ] + }}, {Credo.Check.Consistency.UnusedVariableNames, false}, {Credo.Check.Design.DuplicatedCode, files: %{excluded: ["**/*_test.exs"]}}, {Credo.Check.Readability.AliasAs, false}, diff --git a/test/nimble_template/addons/credo_test.exs b/test/nimble_template/addons/credo_test.exs index 7d9a9a23..a1d6717f 100644 --- a/test/nimble_template/addons/credo_test.exs +++ b/test/nimble_template/addons/credo_test.exs @@ -15,15 +15,15 @@ defmodule NimbleTemplate.Addons.CredoTest do assert_file(".credo.exs", fn file -> assert file =~ """ {Credo.Check.Consistency.MultiAliasImportRequireUse, - files: %{ - excluded: [ - "lib/nimble_template.ex", - "lib/nimble_template_web.ex", - "test/support/conn_case.ex", - "test/support/data_case.ex", - "test/support/feature_case.ex" - ] - }}, + files: %{ + excluded: [ + "lib/nimble_template.ex", + "lib/nimble_template_web.ex", + "test/support/conn_case.ex", + "test/support/data_case.ex", + "test/support/feature_case.ex" + ] + }}, """ end) end) From 2ba3a996b8cd472971cc2cf66ba371c0f6f7cb21 Mon Sep 17 00:00:00 2001 From: Andy Duong Date: Wed, 7 Dec 2022 11:30:11 +0700 Subject: [PATCH 33/43] Separate the credo file for mix and web projects --- lib/nimble_template/addons/credo.ex | 10 +- priv/templates/nimble_template/.credo.exs | 18 +- priv/templates/nimble_template/.credo.mix.exs | 198 ++++++++++++++++++ test/nimble_template/addons/credo_test.exs | 24 ++- 4 files changed, 230 insertions(+), 20 deletions(-) create mode 100644 priv/templates/nimble_template/.credo.mix.exs diff --git a/lib/nimble_template/addons/credo.ex b/lib/nimble_template/addons/credo.ex index 4a7158c4..d9e4be12 100644 --- a/lib/nimble_template/addons/credo.ex +++ b/lib/nimble_template/addons/credo.ex @@ -10,7 +10,15 @@ defmodule NimbleTemplate.Addons.Credo do |> edit_files!() end - defp copy_files!(%Project{web_path: web_path, base_path: base_path} = project) do + defp copy_files!(%Project{mix_project?: true} = project) do + Generator.copy_file!([{:text, ".credo.mix.exs", ".credo.exs"}]) + + project + end + + defp copy_files!( + %Project{web_path: web_path, base_path: base_path, mix_project?: false} = project + ) do binding = [ base_entry_path: "#{base_path}.ex", web_entry_path: "#{web_path}.ex" diff --git a/priv/templates/nimble_template/.credo.exs b/priv/templates/nimble_template/.credo.exs index 03ede894..15cdac1d 100644 --- a/priv/templates/nimble_template/.credo.exs +++ b/priv/templates/nimble_template/.credo.exs @@ -163,15 +163,15 @@ ignore: ~w/callback_impl/a ]}, {Credo.Check.Consistency.MultiAliasImportRequireUse, - files: %{ - excluded: [ - "<%= base_entry_path %>", - "<%= web_entry_path %>", - "test/support/conn_case.ex", - "test/support/data_case.ex", - "test/support/feature_case.ex" - ] - }}, + files: %{ + excluded: [ + "<%= base_entry_path %>", + "<%= web_entry_path %>", + "test/support/conn_case.ex", + "test/support/data_case.ex", + "test/support/feature_case.ex" + ] + }}, {Credo.Check.Consistency.UnusedVariableNames, false}, {Credo.Check.Design.DuplicatedCode, files: %{excluded: ["**/*_test.exs"]}}, {Credo.Check.Readability.AliasAs, false}, diff --git a/priv/templates/nimble_template/.credo.mix.exs b/priv/templates/nimble_template/.credo.mix.exs new file mode 100644 index 00000000..978b8a1d --- /dev/null +++ b/priv/templates/nimble_template/.credo.mix.exs @@ -0,0 +1,198 @@ +# This file contains the configuration for Credo and you are probably reading +# this after creating it with `mix credo.gen.config`. +# +# If you find anything wrong or unclear in this file, please report an +# issue on GitHub: https://github.com/rrrene/credo/issues +# +%{ + # + # You can have as many configs as you like in the `configs:` field. + configs: [ + %{ + # + # Run any config using `mix credo -C `. If no config name is given + # "default" is used. + # + name: "default", + # + # These are the files included in the analysis: + files: %{ + # + # You can give explicit globs or simply directories. + # In the latter case `**/*.{ex,exs}` will be used. + # + included: [ + "lib/", + "src/", + "test/", + "web/", + "apps/*/lib/", + "apps/*/src/", + "apps/*/test/", + "apps/*/web/" + ], + excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"] + }, + # + # Load and configure plugins here: + # + plugins: [], + # + # If you create your own checks, you must specify the source files for + # them here, so they can be loaded by Credo before running the analysis. + # + requires: [], + # + # If you want to enforce a style guide and need a more traditional linting + # experience, you can change `strict` to `true` below: + # + strict: false, + # + # To modify the timeout for parsing files, change this value: + # + parse_timeout: 5000, + # + # If you want to use uncolored output by default, you can change `color` + # to `false` below: + # + color: true, + # + # You can customize the parameters of any check by adding a second element + # to the tuple. + # + # To disable a check put `false` as second element: + # + # {Credo.Check.Design.DuplicatedCode, false} + # + checks: [ + # + ## Consistency Checks + # + {Credo.Check.Consistency.ExceptionNames, []}, + {Credo.Check.Consistency.LineEndings, []}, + {Credo.Check.Consistency.ParameterPatternMatching, []}, + {Credo.Check.Consistency.SpaceAroundOperators, []}, + {Credo.Check.Consistency.SpaceInParentheses, []}, + {Credo.Check.Consistency.TabsOrSpaces, []}, + + # + ## Design Checks + # + # You can customize the priority of any check + # Priority values are: `low, normal, high, higher` + # + {Credo.Check.Design.AliasUsage, + [priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]}, + # You can also customize the exit_status of each check. + # If you don't want TODO comments to cause `mix credo` to fail, just + # set this value to 0 (zero). + # + {Credo.Check.Design.TagTODO, [exit_status: 0]}, + {Credo.Check.Design.TagFIXME, []}, + + # + ## Readability Checks + # + {Credo.Check.Readability.AliasOrder, []}, + {Credo.Check.Readability.FunctionNames, []}, + {Credo.Check.Readability.LargeNumbers, []}, + {Credo.Check.Readability.MaxLineLength, [priority: :low, max_length: 100]}, + {Credo.Check.Readability.ModuleAttributeNames, []}, + {Credo.Check.Readability.ModuleDoc, false}, + {Credo.Check.Readability.ModuleNames, []}, + {Credo.Check.Readability.ParenthesesInCondition, []}, + {Credo.Check.Readability.ParenthesesOnZeroArityDefs, []}, + {Credo.Check.Readability.PredicateFunctionNames, []}, + {Credo.Check.Readability.PreferImplicitTry, []}, + {Credo.Check.Readability.RedundantBlankLines, []}, + {Credo.Check.Readability.Semicolons, []}, + {Credo.Check.Readability.SpaceAfterCommas, []}, + {Credo.Check.Readability.StringSigils, []}, + {Credo.Check.Readability.TrailingBlankLine, []}, + {Credo.Check.Readability.TrailingWhiteSpace, []}, + {Credo.Check.Readability.UnnecessaryAliasExpansion, []}, + {Credo.Check.Readability.VariableNames, []}, + + # + ## Refactoring Opportunities + # + {Credo.Check.Refactor.CondStatements, []}, + {Credo.Check.Refactor.CyclomaticComplexity, []}, + {Credo.Check.Refactor.FunctionArity, []}, + {Credo.Check.Refactor.LongQuoteBlocks, []}, + {Credo.Check.Refactor.MapInto, []}, + {Credo.Check.Refactor.MatchInCondition, []}, + {Credo.Check.Refactor.NegatedConditionsInUnless, []}, + {Credo.Check.Refactor.NegatedConditionsWithElse, []}, + {Credo.Check.Refactor.Nesting, []}, + {Credo.Check.Refactor.UnlessWithElse, []}, + {Credo.Check.Refactor.WithClauses, []}, + + # + ## Warnings + # + {Credo.Check.Warning.BoolOperationOnSameValues, []}, + {Credo.Check.Warning.ExpensiveEmptyEnumCheck, []}, + {Credo.Check.Warning.IExPry, []}, + {Credo.Check.Warning.IoInspect, []}, + {Credo.Check.Warning.LazyLogging, []}, + {Credo.Check.Warning.MixEnv, false}, + {Credo.Check.Warning.OperationOnSameValues, []}, + {Credo.Check.Warning.OperationWithConstantResult, []}, + {Credo.Check.Warning.RaiseInsideRescue, []}, + {Credo.Check.Warning.UnusedEnumOperation, []}, + {Credo.Check.Warning.UnusedFileOperation, []}, + {Credo.Check.Warning.UnusedKeywordOperation, []}, + {Credo.Check.Warning.UnusedListOperation, []}, + {Credo.Check.Warning.UnusedPathOperation, []}, + {Credo.Check.Warning.UnusedRegexOperation, []}, + {Credo.Check.Warning.UnusedStringOperation, []}, + {Credo.Check.Warning.UnusedTupleOperation, []}, + {Credo.Check.Warning.UnsafeExec, []}, + + # + # Checks scheduled for next check update (opt-in for now, just replace `false` with `[]`) + + # + # Controversial and experimental checks (opt-in, just replace `false` with `[]`) + # + {Credo.Check.Readability.StrictModuleLayout, + [ + order: + ~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, false}, + {Credo.Check.Design.DuplicatedCode, files: %{excluded: ["**/*_test.exs"]}}, + {Credo.Check.Readability.AliasAs, false}, + {Credo.Check.Readability.MultiAlias, false}, + {Credo.Check.Readability.Specs, false}, + {Credo.Check.Readability.SinglePipe, []}, + {Credo.Check.Readability.WithCustomTaggedTuple, []}, + {Credo.Check.Refactor.ABCSize, []}, + {Credo.Check.Refactor.AppendSingleItem, []}, + {Credo.Check.Refactor.DoubleBooleanNegation, []}, + {Credo.Check.Refactor.ModuleDependencies, false}, + {Credo.Check.Refactor.NegatedIsNil, []}, + {Credo.Check.Refactor.PipeChainStart, []}, + {Credo.Check.Refactor.VariableRebinding, []}, + {Credo.Check.Warning.LeakyEnvironment, []}, + {Credo.Check.Warning.MapGetUnsafePass, []}, + {Credo.Check.Warning.UnsafeToAtom, []}, + + # + ## Checks from CompassCredoPlugin + # + {CompassCredoPlugin.Check.DefdelegateOrder, []}, + {CompassCredoPlugin.Check.SingleModuleFile, []}, + {CompassCredoPlugin.Check.RepeatingFragments, []}, + {CompassCredoPlugin.Check.DoSingleExpression, []} + + # + # Custom checks can be created using `mix credo.gen.check`. + # + ] + } + ] +} diff --git a/test/nimble_template/addons/credo_test.exs b/test/nimble_template/addons/credo_test.exs index a1d6717f..49174c9b 100644 --- a/test/nimble_template/addons/credo_test.exs +++ b/test/nimble_template/addons/credo_test.exs @@ -15,15 +15,15 @@ defmodule NimbleTemplate.Addons.CredoTest do assert_file(".credo.exs", fn file -> assert file =~ """ {Credo.Check.Consistency.MultiAliasImportRequireUse, - files: %{ - excluded: [ - "lib/nimble_template.ex", - "lib/nimble_template_web.ex", - "test/support/conn_case.ex", - "test/support/data_case.ex", - "test/support/feature_case.ex" - ] - }}, + files: %{ + excluded: [ + "lib/nimble_template.ex", + "lib/nimble_template_web.ex", + "test/support/conn_case.ex", + "test/support/data_case.ex", + "test/support/feature_case.ex" + ] + }}, """ end) end) @@ -75,7 +75,11 @@ defmodule NimbleTemplate.Addons.CredoTest do in_test_project!(test_project_path, fn -> Addons.Credo.apply!(project) - assert_file(".credo.exs") + assert_file(".credo.exs", fn file -> + assert file =~ """ + {Credo.Check.Consistency.MultiAliasImportRequireUse, []}, + """ + end) end) end From f0c8d9427887822188a4c5d3bbe06edef65d06fc Mon Sep 17 00:00:00 2001 From: Thanh Huynh Date: Wed, 28 Dec 2022 09:03:39 +0700 Subject: [PATCH 34/43] [gh-307] Refactor the template.ex structure --- lib/nimble_template/helpers/credo.ex | 65 +++++++++++++++++++++++ lib/nimble_template/templates/template.ex | 61 +++------------------ 2 files changed, 72 insertions(+), 54 deletions(-) diff --git a/lib/nimble_template/helpers/credo.ex b/lib/nimble_template/helpers/credo.ex index c49a508d..2bbe8fba 100644 --- a/lib/nimble_template/helpers/credo.ex +++ b/lib/nimble_template/helpers/credo.ex @@ -1,5 +1,9 @@ defmodule NimbleTemplate.CredoHelper do alias NimbleTemplate.Generator + alias NimbleTemplate.Projects.Project + + @do_single_expression_rule_name "CompassCredoPlugin.Check.DoSingleExpression" + @single_module_file_rule_name "CompassCredoPlugin.Check.SingleModuleFile" @spec disable_rule(String.t(), String.t()) :: :ok | {:error, :failed_to_read_file} def disable_rule(file_path, rule) do @@ -7,4 +11,65 @@ defmodule NimbleTemplate.CredoHelper do # credo:disable-for-this-file #{rule} """) end + + @spec disable_do_single_expression_rule(list()) :: :ok | {:error, :failed_to_read_file} + def disable_do_single_expression_rule(file_paths) do + Enum.each(file_paths, fn file_path -> + disable_rule(file_path, @do_single_expression_rule_name) + end) + end + + @spec disable_single_module_file_rule(list()) :: :ok | {:error, :failed_to_read_file} + def disable_single_module_file_rule(file_paths) do + Enum.each(file_paths, fn file_path -> + disable_rule(file_path, @single_module_file_rule_name) + end) + end + + def suppress_credo_warnings_for_base_project(%Project{base_module: base_module}) do + disable_do_single_expression_rule(["lib/#{Macro.underscore(base_module)}.ex"]) + end + + def suppress_credo_warnings_for_phoenix_project( + %Project{ + base_path: base_path, + web_path: web_path + } = project + ) do + suppress_credo_warnings_for_base_project(project) + + single_expression_files = [ + "#{web_path}/controllers/page_controller.ex", + "#{web_path}/telemetry.ex", + "#{web_path}/views/error_view.ex", + "#{base_path}/release_tasks.ex" + ] + + disable_do_single_expression_rule(single_expression_files) + end + + def suppress_credo_warnings_for_phoenix_api_project( + %Project{ + web_test_path: web_test_path, + base_path: base_path, + web_path: web_path + } = project + ) do + suppress_credo_warnings_for_base_project(project) + + single_module_files = [ + "#{web_test_path}/views/api/error_view_test.exs", + "#{web_test_path}/params/params_validator_test.exs" + ] + + disable_single_module_file_rule(single_module_files) + + single_expression_files = [ + "#{base_path}/release_tasks.ex", + "#{web_path}/telemetry.ex", + "#{web_path}/views/error_view.ex" + ] + + disable_do_single_expression_rule(single_expression_files) + end end diff --git a/lib/nimble_template/templates/template.ex b/lib/nimble_template/templates/template.ex index 930402c4..ab776d9a 100644 --- a/lib/nimble_template/templates/template.ex +++ b/lib/nimble_template/templates/template.ex @@ -2,9 +2,9 @@ defmodule NimbleTemplate.Templates.Template do @moduledoc false import NimbleTemplate.DependencyHelper + import NimbleTemplate.CredoHelper alias NimbleTemplate.Addons.ExUnit - alias NimbleTemplate.CredoHelper alias NimbleTemplate.Projects.Project alias NimbleTemplate.Templates.Mix.Template, as: MixTemplate alias NimbleTemplate.Templates.Phoenix.Template, as: PhoenixTemplate @@ -31,82 +31,35 @@ defmodule NimbleTemplate.Templates.Template do defp post_apply!(%Project{mix_project?: true} = project) do order_dependencies!() - fetch_and_install_elixir_dependencies() + install_elixir_dependencies() suppress_credo_warnings_for_base_project(project) format_codebase() end defp post_apply!(%Project{api_project?: true} = project) do order_dependencies!() - fetch_and_install_elixir_dependencies() + install_elixir_dependencies() suppress_credo_warnings_for_phoenix_api_project(project) format_codebase() end defp post_apply!(%Project{web_project?: true} = project) do order_dependencies!() - fetch_and_install_elixir_dependencies() - fetch_and_install_node_dependencies() + install_elixir_dependencies() + install_node_dependencies() suppress_credo_warnings_for_phoenix_project(project) format_codebase() end - defp fetch_and_install_elixir_dependencies() do + defp install_elixir_dependencies() do Mix.shell().cmd("MIX_ENV=dev mix do deps.get, deps.compile") Mix.shell().cmd("MIX_ENV=test mix do deps.get, deps.compile") end - defp fetch_and_install_node_dependencies() do + defp install_node_dependencies() do Mix.shell().cmd("npm install --prefix assets") end - defp suppress_credo_warnings_for_base_project(%Project{base_module: base_module}) do - CredoHelper.disable_rule( - "lib/#{Macro.underscore(base_module)}.ex", - "CompassCredoPlugin.Check.DoSingleExpression" - ) - end - - defp suppress_credo_warnings_for_phoenix_project( - %Project{ - base_path: base_path, - web_path: web_path - } = project - ) do - suppress_credo_warnings_for_base_project(project) - - Enum.each( - [ - "#{web_path}/controllers/page_controller.ex", - "#{web_path}/telemetry.ex", - "#{web_path}/views/error_view.ex", - "#{base_path}/release_tasks.ex" - ], - fn file_path -> - CredoHelper.disable_rule(file_path, "CompassCredoPlugin.Check.DoSingleExpression") - end - ) - end - - defp suppress_credo_warnings_for_phoenix_api_project( - %Project{ - web_test_path: web_test_path - } = project - ) do - suppress_credo_warnings_for_base_project(project) - suppress_credo_warnings_for_phoenix_project(project) - - Enum.each( - [ - "#{web_test_path}/views/api/error_view_test.exs", - "#{web_test_path}/params/params_validator_test.exs" - ], - fn file_path -> - CredoHelper.disable_rule(file_path, "CompassCredoPlugin.Check.SingleModuleFile") - end - ) - end - defp format_codebase() do Mix.shell().cmd("mix codebase.fix") end From 6afa9944fbe653cbfe89ce27c5e38b677512ce4e Mon Sep 17 00:00:00 2001 From: Thanh Huynh Date: Wed, 28 Dec 2022 10:09:29 +0700 Subject: [PATCH 35/43] [gh-307] Address Credo feedback --- lib/nimble_template/templates/template.ex | 3 +-- lib/nimble_template/templates/variants/phoenix/template.ex | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/nimble_template/templates/template.ex b/lib/nimble_template/templates/template.ex index ab776d9a..560391ad 100644 --- a/lib/nimble_template/templates/template.ex +++ b/lib/nimble_template/templates/template.ex @@ -1,8 +1,7 @@ defmodule NimbleTemplate.Templates.Template do @moduledoc false - import NimbleTemplate.DependencyHelper - import NimbleTemplate.CredoHelper + import NimbleTemplate.{CredoHelper, DependencyHelper} alias NimbleTemplate.Addons.ExUnit alias NimbleTemplate.Projects.Project diff --git a/lib/nimble_template/templates/variants/phoenix/template.ex b/lib/nimble_template/templates/variants/phoenix/template.ex index 5e4c5e17..08ff5c6d 100644 --- a/lib/nimble_template/templates/variants/phoenix/template.ex +++ b/lib/nimble_template/templates/variants/phoenix/template.ex @@ -44,7 +44,6 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do end end - # credo:disable-for-next-line Credo.Check.Refactor.ABCSize defp apply_phoenix_common_setup(%Project{} = project) do # TODO: Remove me after the Phoenix generator fix releases: https://github.com/phoenixframework/phoenix/pull/4894 remove_mix_compiler_config!() From abc238f3bfdbe2bcf5a2dca73c2ab9552569d3e0 Mon Sep 17 00:00:00 2001 From: Thanh Huynh Date: Wed, 28 Dec 2022 11:00:47 +0700 Subject: [PATCH 36/43] [gh-307] Add checking file exist --- lib/nimble_template/helpers/credo.ex | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/nimble_template/helpers/credo.ex b/lib/nimble_template/helpers/credo.ex index 2bbe8fba..e07d1a8b 100644 --- a/lib/nimble_template/helpers/credo.ex +++ b/lib/nimble_template/helpers/credo.ex @@ -7,9 +7,11 @@ defmodule NimbleTemplate.CredoHelper do @spec disable_rule(String.t(), String.t()) :: :ok | {:error, :failed_to_read_file} def disable_rule(file_path, rule) do - Generator.prepend_content(file_path, """ - # credo:disable-for-this-file #{rule} - """) + if File.exists?(file_path) do + Generator.prepend_content(file_path, """ + # credo:disable-for-this-file #{rule} + """) + end end @spec disable_do_single_expression_rule(list()) :: :ok | {:error, :failed_to_read_file} @@ -38,38 +40,39 @@ defmodule NimbleTemplate.CredoHelper do ) do suppress_credo_warnings_for_base_project(project) - single_expression_files = [ + files_contain_single_expression = [ "#{web_path}/controllers/page_controller.ex", "#{web_path}/telemetry.ex", "#{web_path}/views/error_view.ex", "#{base_path}/release_tasks.ex" ] - disable_do_single_expression_rule(single_expression_files) + disable_do_single_expression_rule(files_contain_single_expression) end def suppress_credo_warnings_for_phoenix_api_project( %Project{ - web_test_path: web_test_path, base_path: base_path, - web_path: web_path + web_path: web_path, + web_test_path: web_test_path } = project ) do suppress_credo_warnings_for_base_project(project) - single_module_files = [ + files_contain_multiple_module = [ "#{web_test_path}/views/api/error_view_test.exs", "#{web_test_path}/params/params_validator_test.exs" ] - disable_single_module_file_rule(single_module_files) + disable_single_module_file_rule(files_contain_multiple_module) - single_expression_files = [ + files_contain_single_expression = [ + "#{web_path}/controllers/page_controller.ex", "#{base_path}/release_tasks.ex", "#{web_path}/telemetry.ex", "#{web_path}/views/error_view.ex" ] - disable_do_single_expression_rule(single_expression_files) + disable_do_single_expression_rule(files_contain_single_expression) end end From 91ad5f408cbe5b5ca4cd4eebaa89cc370db1081c Mon Sep 17 00:00:00 2001 From: Thanh Huynh Date: Wed, 28 Dec 2022 12:03:50 +0700 Subject: [PATCH 37/43] [gh-307] Extracting list of files --- lib/nimble_template/helpers/credo.ex | 53 +++++++++++++--------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/lib/nimble_template/helpers/credo.ex b/lib/nimble_template/helpers/credo.ex index e07d1a8b..8bfda21b 100644 --- a/lib/nimble_template/helpers/credo.ex +++ b/lib/nimble_template/helpers/credo.ex @@ -32,47 +32,44 @@ defmodule NimbleTemplate.CredoHelper do disable_do_single_expression_rule(["lib/#{Macro.underscore(base_module)}.ex"]) end - def suppress_credo_warnings_for_phoenix_project( - %Project{ - base_path: base_path, - web_path: web_path - } = project - ) do + def suppress_credo_warnings_for_phoenix_project(project) do suppress_credo_warnings_for_base_project(project) - files_contain_single_expression = [ - "#{web_path}/controllers/page_controller.ex", - "#{web_path}/telemetry.ex", - "#{web_path}/views/error_view.ex", - "#{base_path}/release_tasks.ex" - ] - - disable_do_single_expression_rule(files_contain_single_expression) + project + |> get_files_contain_single_expression() + |> disable_do_single_expression_rule() end - def suppress_credo_warnings_for_phoenix_api_project( - %Project{ - base_path: base_path, - web_path: web_path, - web_test_path: web_test_path - } = project - ) do + def suppress_credo_warnings_for_phoenix_api_project(project) do suppress_credo_warnings_for_base_project(project) - files_contain_multiple_module = [ - "#{web_test_path}/views/api/error_view_test.exs", - "#{web_test_path}/params/params_validator_test.exs" - ] + project + |> get_files_contain_multiple_modules() + |> disable_single_module_file_rule() - disable_single_module_file_rule(files_contain_multiple_module) + project + |> get_files_contain_single_expression() + |> disable_do_single_expression_rule() + end - files_contain_single_expression = [ + defp get_files_contain_single_expression(%Project{ + base_path: base_path, + web_path: web_path + }) do + [ "#{web_path}/controllers/page_controller.ex", "#{base_path}/release_tasks.ex", "#{web_path}/telemetry.ex", "#{web_path}/views/error_view.ex" ] + end - disable_do_single_expression_rule(files_contain_single_expression) + defp get_files_contain_multiple_modules(%Project{ + web_test_path: web_test_path + }) do + [ + "#{web_test_path}/views/api/error_view_test.exs", + "#{web_test_path}/params/params_validator_test.exs" + ] end end From d057912c57110d4c1a6a9885f00b4723c4b991e9 Mon Sep 17 00:00:00 2001 From: byhbt Date: Thu, 29 Dec 2022 04:03:37 +0000 Subject: [PATCH 38/43] Bump version to 4.6.0 --- README.md | 2 +- mix.exs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a02a445f..cbfdd45c 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Step 2: Add `nimble_template` dependency to `mix.exs`: ```elixir def deps do [ - {:nimble_template, "~> 4.5.0", only: :dev, runtime: false}, + {:nimble_template, "~> 4.6.0", only: :dev, runtime: false}, # other dependencies ... ] end diff --git a/mix.exs b/mix.exs index 9d8e3aa3..8fba427f 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule NimbleTemplate.MixProject do def project do [ app: :nimble_template, - version: "4.5.0", + version: "4.6.0", description: "Phoenix/Mix template for projects at [Nimble](https://nimblehq.co/).", elixir: "~> 1.14.0", elixirc_paths: elixirc_paths(Mix.env()), From ce27c66a70f9c83889b6fe91e171cd5a03d244e4 Mon Sep 17 00:00:00 2001 From: Thanh Huynh Date: Thu, 29 Dec 2022 13:48:11 +0700 Subject: [PATCH 39/43] [gh-307] Refactor the disable rule method --- lib/nimble_template/helpers/credo.ex | 48 +++++++++-------------- lib/nimble_template/templates/template.ex | 8 +--- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/lib/nimble_template/helpers/credo.ex b/lib/nimble_template/helpers/credo.ex index 8bfda21b..dabdb014 100644 --- a/lib/nimble_template/helpers/credo.ex +++ b/lib/nimble_template/helpers/credo.ex @@ -5,39 +5,15 @@ defmodule NimbleTemplate.CredoHelper do @do_single_expression_rule_name "CompassCredoPlugin.Check.DoSingleExpression" @single_module_file_rule_name "CompassCredoPlugin.Check.SingleModuleFile" - @spec disable_rule(String.t(), String.t()) :: :ok | {:error, :failed_to_read_file} - def disable_rule(file_path, rule) do - if File.exists?(file_path) do - Generator.prepend_content(file_path, """ - # credo:disable-for-this-file #{rule} - """) - end - end - - @spec disable_do_single_expression_rule(list()) :: :ok | {:error, :failed_to_read_file} - def disable_do_single_expression_rule(file_paths) do - Enum.each(file_paths, fn file_path -> - disable_rule(file_path, @do_single_expression_rule_name) - end) - end - - @spec disable_single_module_file_rule(list()) :: :ok | {:error, :failed_to_read_file} - def disable_single_module_file_rule(file_paths) do - Enum.each(file_paths, fn file_path -> - disable_rule(file_path, @single_module_file_rule_name) - end) - end - - def suppress_credo_warnings_for_base_project(%Project{base_module: base_module}) do - disable_do_single_expression_rule(["lib/#{Macro.underscore(base_module)}.ex"]) - end + def suppress_credo_warnings_for_base_project(%Project{base_module: base_module}), + do: disable_rules(["lib/#{Macro.underscore(base_module)}.ex"], @do_single_expression_rule_name) def suppress_credo_warnings_for_phoenix_project(project) do suppress_credo_warnings_for_base_project(project) project |> get_files_contain_single_expression() - |> disable_do_single_expression_rule() + |> disable_rules(@do_single_expression_rule_name) end def suppress_credo_warnings_for_phoenix_api_project(project) do @@ -45,11 +21,11 @@ defmodule NimbleTemplate.CredoHelper do project |> get_files_contain_multiple_modules() - |> disable_single_module_file_rule() + |> disable_rules(@single_module_file_rule_name) project |> get_files_contain_single_expression() - |> disable_do_single_expression_rule() + |> disable_rules(@do_single_expression_rule_name) end defp get_files_contain_single_expression(%Project{ @@ -72,4 +48,18 @@ defmodule NimbleTemplate.CredoHelper do "#{web_test_path}/params/params_validator_test.exs" ] end + + defp disable_rules(file_paths, rule_name) do + Enum.each(file_paths, fn file_path -> + disable_rule(file_path, rule_name) + end) + end + + defp disable_rule(file_path, rule) do + if File.exists?(file_path) do + Generator.prepend_content(file_path, """ + # credo:disable-for-this-file #{rule} + """) + end + end end diff --git a/lib/nimble_template/templates/template.ex b/lib/nimble_template/templates/template.ex index 560391ad..593e435f 100644 --- a/lib/nimble_template/templates/template.ex +++ b/lib/nimble_template/templates/template.ex @@ -55,11 +55,7 @@ defmodule NimbleTemplate.Templates.Template do Mix.shell().cmd("MIX_ENV=test mix do deps.get, deps.compile") end - defp install_node_dependencies() do - Mix.shell().cmd("npm install --prefix assets") - end + defp install_node_dependencies(), do: Mix.shell().cmd("npm install --prefix assets") - defp format_codebase() do - Mix.shell().cmd("mix codebase.fix") - end + defp format_codebase(), do: Mix.shell().cmd("mix codebase.fix") end From f7d31b3ee4771b9d6184611317292ae51192af82 Mon Sep 17 00:00:00 2001 From: Thanh Huynh Date: Thu, 29 Dec 2022 14:14:25 +0700 Subject: [PATCH 40/43] [gh-307] Change import to alias --- lib/nimble_template/templates/template.ex | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/nimble_template/templates/template.ex b/lib/nimble_template/templates/template.ex index 593e435f..25b003aa 100644 --- a/lib/nimble_template/templates/template.ex +++ b/lib/nimble_template/templates/template.ex @@ -1,9 +1,8 @@ defmodule NimbleTemplate.Templates.Template do @moduledoc false - import NimbleTemplate.{CredoHelper, DependencyHelper} - alias NimbleTemplate.Addons.ExUnit + alias NimbleTemplate.{CredoHelper, DependencyHelper} alias NimbleTemplate.Projects.Project alias NimbleTemplate.Templates.Mix.Template, as: MixTemplate alias NimbleTemplate.Templates.Phoenix.Template, as: PhoenixTemplate @@ -29,24 +28,24 @@ defmodule NimbleTemplate.Templates.Template do end defp post_apply!(%Project{mix_project?: true} = project) do - order_dependencies!() + DependencyHelper.order_dependencies!() install_elixir_dependencies() - suppress_credo_warnings_for_base_project(project) + CredoHelper.suppress_credo_warnings_for_base_project(project) format_codebase() end defp post_apply!(%Project{api_project?: true} = project) do - order_dependencies!() + DependencyHelper.order_dependencies!() install_elixir_dependencies() - suppress_credo_warnings_for_phoenix_api_project(project) + CredoHelper.suppress_credo_warnings_for_phoenix_api_project(project) format_codebase() end defp post_apply!(%Project{web_project?: true} = project) do - order_dependencies!() + DependencyHelper.order_dependencies!() install_elixir_dependencies() install_node_dependencies() - suppress_credo_warnings_for_phoenix_project(project) + CredoHelper.suppress_credo_warnings_for_phoenix_project(project) format_codebase() end From 23aba82e6277ef246fcfbfee2dca39796285321c Mon Sep 17 00:00:00 2001 From: Thanh Huynh Date: Thu, 29 Dec 2022 14:42:39 +0700 Subject: [PATCH 41/43] [gh-307] Update the test --- lib/nimble_template/helpers/credo.ex | 19 +++++++++++-------- test/nimble_template/helpers/credo_test.exs | 15 +++++++++------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/nimble_template/helpers/credo.ex b/lib/nimble_template/helpers/credo.ex index dabdb014..15d062fd 100644 --- a/lib/nimble_template/helpers/credo.ex +++ b/lib/nimble_template/helpers/credo.ex @@ -5,14 +5,17 @@ defmodule NimbleTemplate.CredoHelper do @do_single_expression_rule_name "CompassCredoPlugin.Check.DoSingleExpression" @single_module_file_rule_name "CompassCredoPlugin.Check.SingleModuleFile" - def suppress_credo_warnings_for_base_project(%Project{base_module: base_module}), - do: disable_rules(["lib/#{Macro.underscore(base_module)}.ex"], @do_single_expression_rule_name) + def suppress_credo_warnings_for_base_project(%Project{base_module: base_module}) do + base_module_path = "lib/#{Macro.underscore(base_module)}.ex" + + disable_rule(base_module_path, @do_single_expression_rule_name) + end def suppress_credo_warnings_for_phoenix_project(project) do suppress_credo_warnings_for_base_project(project) project - |> get_files_contain_single_expression() + |> get_files_containing_single_expression() |> disable_rules(@do_single_expression_rule_name) end @@ -20,27 +23,27 @@ defmodule NimbleTemplate.CredoHelper do suppress_credo_warnings_for_base_project(project) project - |> get_files_contain_multiple_modules() + |> get_files_containing_multiple_modules() |> disable_rules(@single_module_file_rule_name) project - |> get_files_contain_single_expression() + |> get_files_containing_single_expression() |> disable_rules(@do_single_expression_rule_name) end - defp get_files_contain_single_expression(%Project{ + defp get_files_containing_single_expression(%Project{ base_path: base_path, web_path: web_path }) do [ - "#{web_path}/controllers/page_controller.ex", "#{base_path}/release_tasks.ex", + "#{web_path}/controllers/page_controller.ex", "#{web_path}/telemetry.ex", "#{web_path}/views/error_view.ex" ] end - defp get_files_contain_multiple_modules(%Project{ + defp get_files_containing_multiple_modules(%Project{ web_test_path: web_test_path }) do [ diff --git a/test/nimble_template/helpers/credo_test.exs b/test/nimble_template/helpers/credo_test.exs index d60663e3..ac502037 100644 --- a/test/nimble_template/helpers/credo_test.exs +++ b/test/nimble_template/helpers/credo_test.exs @@ -3,22 +3,25 @@ defmodule NimbleTemplate.CredoHelperTest do alias NimbleTemplate.CredoHelper - describe "disable_rule/2" do + describe "suppress_credo_warnings_for_base_project/1" do test "prepends credo rule disabling in the given file", %{ - test_project_path: test_project_path + test_project_path: test_project_path, + project: project } do in_test_project!(test_project_path, fn -> - File.write!("sample_module.exs", """ + sample_module_file = "lib/nimble_template.ex" + + File.write!(sample_module_file, """ defmodule SampleModule do def foo, do: "bar" end """) - CredoHelper.disable_rule("sample_module.exs", "Credo.Check.Readability.RedundantBlankLines") + CredoHelper.suppress_credo_warnings_for_base_project(project) - assert_file("sample_module.exs", fn file -> + assert_file(sample_module_file, fn file -> assert file == """ - # credo:disable-for-this-file Credo.Check.Readability.RedundantBlankLines + # credo:disable-for-this-file CompassCredoPlugin.Check.DoSingleExpression defmodule SampleModule do def foo, do: "bar" end From 791a7a2e9f6f570f839db3a5494007e2cd04164e Mon Sep 17 00:00:00 2001 From: Thanh Huynh Date: Thu, 29 Dec 2022 15:43:20 +0700 Subject: [PATCH 42/43] [gh-307] Add test for single and multiple files --- test/nimble_template/helpers/credo_test.exs | 45 +++++++++++++++------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/test/nimble_template/helpers/credo_test.exs b/test/nimble_template/helpers/credo_test.exs index ac502037..7eb37645 100644 --- a/test/nimble_template/helpers/credo_test.exs +++ b/test/nimble_template/helpers/credo_test.exs @@ -9,22 +9,43 @@ defmodule NimbleTemplate.CredoHelperTest do project: project } do in_test_project!(test_project_path, fn -> - sample_module_file = "lib/nimble_template.ex" + CredoHelper.suppress_credo_warnings_for_base_project(project) - File.write!(sample_module_file, """ - defmodule SampleModule do - def foo, do: "bar" - end - """) + assert_file("#{test_project_path}/lib/nimble_template.ex", fn file -> + assert file =~ """ + # credo:disable-for-this-file CompassCredoPlugin.Check.DoSingleExpression + """ + end) + end) + end + end - CredoHelper.suppress_credo_warnings_for_base_project(project) + describe "suppress_credo_warnings_for_phoenix_project/1" do + test "prepends credo rule disabling in the given file", %{ + test_project_path: test_project_path, + project: project + } do + in_test_project!(test_project_path, fn -> + CredoHelper.suppress_credo_warnings_for_phoenix_project(project) + + assert_file( + "#{test_project_path}/lib/nimble_template_web/controllers/page_controller.ex", + fn file -> + assert file =~ """ + # credo:disable-for-this-file CompassCredoPlugin.Check.DoSingleExpression + """ + end + ) + + assert_file("#{test_project_path}/lib/nimble_template_web/telemetry.ex", fn file -> + assert file =~ """ + # credo:disable-for-this-file CompassCredoPlugin.Check.DoSingleExpression + """ + end) - assert_file(sample_module_file, fn file -> - assert file == """ + assert_file("#{test_project_path}/lib/nimble_template_web/views/error_view.ex", fn file -> + assert file =~ """ # credo:disable-for-this-file CompassCredoPlugin.Check.DoSingleExpression - defmodule SampleModule do - def foo, do: "bar" - end """ end) end) From 9e2123513c43c302c31db1f1586ce821e8aa395f Mon Sep 17 00:00:00 2001 From: Thanh Huynh Date: Fri, 30 Dec 2022 08:53:03 +0700 Subject: [PATCH 43/43] [gh-307] Add typespec --- lib/nimble_template/helpers/credo.ex | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/nimble_template/helpers/credo.ex b/lib/nimble_template/helpers/credo.ex index 15d062fd..ae9a6b5d 100644 --- a/lib/nimble_template/helpers/credo.ex +++ b/lib/nimble_template/helpers/credo.ex @@ -5,12 +5,14 @@ defmodule NimbleTemplate.CredoHelper do @do_single_expression_rule_name "CompassCredoPlugin.Check.DoSingleExpression" @single_module_file_rule_name "CompassCredoPlugin.Check.SingleModuleFile" + @spec suppress_credo_warnings_for_base_project(Project.t()) :: :ok def suppress_credo_warnings_for_base_project(%Project{base_module: base_module}) do base_module_path = "lib/#{Macro.underscore(base_module)}.ex" disable_rule(base_module_path, @do_single_expression_rule_name) end + @spec suppress_credo_warnings_for_phoenix_project(Project.t()) :: :ok def suppress_credo_warnings_for_phoenix_project(project) do suppress_credo_warnings_for_base_project(project) @@ -19,6 +21,7 @@ defmodule NimbleTemplate.CredoHelper do |> disable_rules(@do_single_expression_rule_name) end + @spec suppress_credo_warnings_for_phoenix_api_project(Project.t()) :: :ok def suppress_credo_warnings_for_phoenix_api_project(project) do suppress_credo_warnings_for_base_project(project)