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 diff --git a/.github/wiki/Contribution.md b/.github/wiki/Contribution.md index fe99c471..5ea39d62 100644 --- a/.github/wiki/Contribution.md +++ b/.github/wiki/Contribution.md @@ -18,17 +18,17 @@ 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`. -Then call `NimbleTemplate.Addons.Phoenix.Web.SampleAddon.apply(project)` inside `lib/nimble_template/templates/variants/phoenix/web/template.ex` file which will be executed on Terminal prompt. +Then call `NimbleTemplate.Addons.Phoenix.Web.SampleAddon.apply!(project)` inside `lib/nimble_template/templates/variants/phoenix/web/template.ex` file which will be executed on Terminal prompt. ## Functions @@ -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/.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/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/config/config.exs b/config/config.exs index 95a3373f..93ba4cb4 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,3 +1,9 @@ import Config config :phoenix, :json_library, Jason + +config :nimble_template, hex_package_resource: NimbleTemplate.Hex.Package + +if File.exists?("config/#{config_env()}.exs") do + import_config "#{config_env()}.exs" +end diff --git a/config/test.exs b/config/test.exs new file mode 100644 index 00000000..44e37c1b --- /dev/null +++ b/config/test.exs @@ -0,0 +1,3 @@ +import Config + +config :nimble_template, hex_package_resource: NimbleTemplate.Hex.PackageMock 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..b50ba3aa 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,22 @@ 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) - |> ProjectHelper.append_installed_addon(__MODULE__) + do_apply!(project, opts) 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 + defp latest_package_version(package), + do: "~> " <> hex_package_resource().get_latest_version(package) + + # 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 + 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..d9e4be12 100644 --- a/lib/nimble_template/addons/credo.ex +++ b/lib/nimble_template/addons/credo.ex @@ -4,26 +4,39 @@ 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{mix_project?: true} = project) do + Generator.copy_file!([{:text, ".credo.mix.exs", ".credo.exs"}]) project end - defp edit_files(%Project{} = project) do + 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" + ] + + Generator.copy_file!([{:eex, ".credo.exs", ".credo.exs"}], binding) + + project + end + + 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 +45,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..cb45cbfa 100644 --- a/lib/nimble_template/addons/variants/phoenix/gettext.ex +++ b/lib/nimble_template/addons/variants/phoenix/gettext.ex @@ -4,19 +4,30 @@ 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.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/lib/nimble_template/addons/variants/phoenix/health_plug.ex b/lib/nimble_template/addons/variants/phoenix/health_plug.ex index 1e98a9f6..b24ad494 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,24 @@ 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( + 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( + Generator.replace_content!( "#{web_path}/router.ex", """ # coveralls-ignore-start @@ -137,8 +136,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..f99a4240 100644 --- a/lib/nimble_template/addons/variants/phoenix/web/post_css.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/post_css.ex @@ -4,37 +4,38 @@ 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": { """, """ "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", """ ) - Generator.replace_content( + Generator.replace_content!( "assets/package.json", """ "scripts": { @@ -49,8 +50,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 +68,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 +87,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..b2228dbd 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,18 +28,18 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Wallaby do project end - defp copy_files( + defp copy_files!( %Project{ 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 = [ @@ -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/exception/mock_hex_package_required.ex b/lib/nimble_template/exception/mock_hex_package_required.ex new file mode 100644 index 00000000..187fa786 --- /dev/null +++ b/lib/nimble_template/exception/mock_hex_package_required.ex @@ -0,0 +1,3 @@ +defmodule NimbleTemplate.Exception.MockHexPackageRequiredException do + defexception [:message] +end diff --git a/lib/nimble_template/helpers/addon.ex b/lib/nimble_template/helpers/addon.ex index be699552..2e1cc324 100644 --- a/lib/nimble_template/helpers/addon.ex +++ b/lib/nimble_template/helpers/addon.ex @@ -1,4 +1,22 @@ defmodule NimbleTemplate.AddonHelper do - def install_addon_prompt?(addon), - do: Mix.shell().yes?("\nWould you like to add the #{addon} addon?") + 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 + Project.prepend_optional_addon(project, addon) + else + project + end + end + + defp build_addon_label(addon, nil) do + addon + |> Module.split() + |> List.last() + end + + defp build_addon_label(_addon, addon_label), do: addon_label end diff --git a/lib/nimble_template/helpers/credo.ex b/lib/nimble_template/helpers/credo.ex index c49a508d..ae9a6b5d 100644 --- a/lib/nimble_template/helpers/credo.ex +++ b/lib/nimble_template/helpers/credo.ex @@ -1,10 +1,71 @@ defmodule NimbleTemplate.CredoHelper do alias NimbleTemplate.Generator + alias NimbleTemplate.Projects.Project - @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} - """) + @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) + + project + |> get_files_containing_single_expression() + |> 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) + + project + |> get_files_containing_multiple_modules() + |> disable_rules(@single_module_file_rule_name) + + project + |> get_files_containing_single_expression() + |> disable_rules(@do_single_expression_rule_name) + end + + defp get_files_containing_single_expression(%Project{ + base_path: base_path, + web_path: web_path + }) do + [ + "#{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_containing_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 + + 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/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/helpers/project.ex b/lib/nimble_template/helpers/project.ex deleted file mode 100644 index 756d91fe..00000000 --- a/lib/nimble_template/helpers/project.ex +++ /dev/null @@ -1,10 +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 -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..59cc6ede --- /dev/null +++ b/lib/nimble_template/hex/package_mock.ex @@ -0,0 +1,15 @@ +defmodule NimbleTemplate.Hex.PackageMock do + @moduledoc false + + @behaviour NimbleTemplate.Hex.PackageBehaviour + + 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: + "Requires to mock Hex package with `@describetag mock_latest_package_versions: [{#{package}, :version}]`" + ) + end +end diff --git a/lib/nimble_template/projects/project.ex b/lib/nimble_template/projects/project.ex index 1fac9dc4..0898b83e 100644 --- a/lib/nimble_template/projects/project.ex +++ b/lib/nimble_template/projects/project.ex @@ -24,7 +24,7 @@ defmodule NimbleTemplate.Projects.Project do live_project?: false, web_project?: false, mix_project?: false, - installed_addons: [] + optional_addons: [] @type t :: %__MODULE__{ base_module: String.t() | nil, @@ -43,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() @@ -55,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() @@ -80,6 +80,13 @@ 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]) + 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/template.ex b/lib/nimble_template/templates/template.ex index 4ac13364..25b003aa 100644 --- a/lib/nimble_template/templates/template.ex +++ b/lib/nimble_template/templates/template.ex @@ -1,92 +1,60 @@ defmodule NimbleTemplate.Templates.Template do @moduledoc false - import NimbleTemplate.DependencyHelper - alias NimbleTemplate.Addons.ExUnit - alias NimbleTemplate.CredoHelper + alias NimbleTemplate.{CredoHelper, DependencyHelper} alias NimbleTemplate.Projects.Project 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 + project + |> MixTemplate.pre_apply() + |> MixTemplate.apply!() - 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 + project + |> PhoenixTemplate.pre_apply() + |> PhoenixTemplate.apply!() - ExUnit.apply(project) + ExUnit.apply!(project) - post_apply(project) + post_apply!(project) end - defp post_apply(%Project{mix_project?: true} = project) do - order_dependencies!() - fetch_and_install_elixir_dependencies() - suppress_necessary_credo_warnings(project) + defp post_apply!(%Project{mix_project?: true} = project) do + DependencyHelper.order_dependencies!() + install_elixir_dependencies() + CredoHelper.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) + defp post_apply!(%Project{api_project?: true} = project) do + DependencyHelper.order_dependencies!() + install_elixir_dependencies() + CredoHelper.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() - suppress_necessary_credo_warnings(project) + defp post_apply!(%Project{web_project?: true} = project) do + DependencyHelper.order_dependencies!() + install_elixir_dependencies() + install_node_dependencies() + CredoHelper.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 - Mix.shell().cmd("npm install --prefix assets") - end - - defp suppress_necessary_credo_warnings(%Project{ - base_module: base_module, - base_path: base_path, - web_path: web_path, - web_test_path: web_test_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", - "#{base_path}/release_tasks.ex" - ], - fn file_path -> - CredoHelper.disable_rule(file_path, "CompassCredoPlugin.Check.DoSingleExpression") - end - ) + defp install_node_dependencies(), do: Mix.shell().cmd("npm install --prefix assets") - 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 + defp format_codebase(), do: Mix.shell().cmd("mix codebase.fix") end diff --git a/lib/nimble_template/templates/variants/mix/template.ex b/lib/nimble_template/templates/variants/mix/template.ex index 25bda993..3af00fb8 100644 --- a/lib/nimble_template/templates/variants/mix/template.ex +++ b/lib/nimble_template/templates/variants/mix/template.ex @@ -6,7 +6,9 @@ defmodule NimbleTemplate.Templates.Mix.Template do alias NimbleTemplate.Addons alias NimbleTemplate.Projects.Project - def apply(%Project{} = project) do + def pre_apply(%Project{} = project), do: install_addon_prompt(project, Addons.Mimic) + + def apply!(%Project{} = project) do project |> apply_default_mix_addons() |> apply_optional_mix_addons() @@ -14,36 +16,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 + 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}) + 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 +53,7 @@ defmodule NimbleTemplate.Templates.Mix.Template do }) end - if install_addon_prompt?("Mimic"), 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/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..08ff5c6d 100644 --- a/lib/nimble_template/templates/variants/phoenix/template.ex +++ b/lib/nimble_template/templates/variants/phoenix/template.ex @@ -5,21 +5,48 @@ 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 alias NimbleTemplate.Templates.Phoenix.Web.Template, as: WebTemplate - def apply(%Project{} = project) do + 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 - # credo:disable-for-next-line Credo.Check.Refactor.ABCSize + defp pre_apply_variant_prompt(%Project{web_project?: true} = project) do + 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 + 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 +61,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 @@ -71,32 +98,32 @@ 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{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 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 +131,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..d080a007 100644 --- a/lib/nimble_template/templates/variants/phoenix/web/template.ex +++ b/lib/nimble_template/templates/variants/phoenix/web/template.ex @@ -1,12 +1,10 @@ defmodule NimbleTemplate.Templates.Phoenix.Web.Template do @moduledoc false - import NimbleTemplate.AddonHelper - 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,58 +12,35 @@ 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?("Dart Sass") do - Web.DartSass.apply(project) - - apply_dart_sass_requires_addons(project) - else - if install_addon_prompt?("Nimble JS"), do: Web.NimbleJS.apply(project) - end - - project - end + 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 - # 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) + 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) - 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 optional_addons, do: - Web.Bootstrap.apply(project, %{ - with_nimble_css_addon: with_nimble_css_addon, - with_nimble_js_addon: with_nimble_js_addon + Web.Bootstrap.apply!(project, %{ + with_nimble_css_addon: with_nimble_css_addon?, + with_nimble_js_addon: with_nimble_js_addon? }) + + project end end 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/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()), diff --git a/priv/templates/nimble_template/.credo.exs b/priv/templates/nimble_template/.credo.exs index cb69e197..15cdac1d 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/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/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/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)) diff --git a/test/nimble_template/addons/asdf_tool_version_test.exs b/test/nimble_template/addons/asdf_tool_version_test.exs index eb996779..3605f6df 100644 --- a/test/nimble_template/addons/asdf_tool_version_test.exs +++ b/test/nimble_template/addons/asdf_tool_version_test.exs @@ -2,15 +2,14 @@ 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 + 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 -> + AsdfToolVersion.apply!(project) assert_file(".tool-versions", fn file -> assert file =~ """ @@ -21,28 +20,17 @@ 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 + 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 -> + AsdfToolVersion.apply!(project) assert_file(".tool-versions", fn file -> assert file =~ """ @@ -56,15 +44,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 -> + 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..49174c9b 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,10 +9,23 @@ 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") + 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 @@ -20,8 +33,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 +48,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,19 +63,23 @@ 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 mock_latest_package_versions: [{:credo, "1.4"}, {:compass_credo_plugin, "1.0.0"}] @describetag required_addons: [:TestEnv] test "copies the .credo.exs", %{ 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") + assert_file(".credo.exs", fn file -> + assert file =~ """ + {Credo.Check.Consistency.MultiAliasImportRequireUse, []}, + """ + end) end) end @@ -70,8 +87,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 +101,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..af59c172 100644 --- a/test/nimble_template/addons/variants/gettext_test.exs +++ b/test/nimble_template/addons/variants/gettext_test.exs @@ -1,19 +1,25 @@ 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 =~ """ - "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) diff --git a/test/nimble_template/addons/variants/health_plug_test.exs b/test/nimble_template/addons/variants/health_plug_test.exs index feeb0b47..1fbd35ce 100644 --- a/test/nimble_template/addons/variants/health_plug_test.exs +++ b/test/nimble_template/addons/variants/health_plug_test.exs @@ -1,15 +1,16 @@ 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"] + @describetag mock_latest_package_versions: [{:excoveralls, "0.12.2"}] 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 +20,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 +33,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 =~ """ @@ -55,8 +56,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/helpers/router_helper.ex", fn file -> assert file =~ """ @@ -72,8 +73,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/helpers/router_helper_test.exs", fn file -> assert file =~ """ @@ -97,8 +98,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 +112,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..8cae3214 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", @@ -9,10 +9,11 @@ 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 -> - 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 +26,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 +46,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 +64,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 +84,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 +100,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 +122,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", @@ -133,10 +134,11 @@ 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 -> - 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 +151,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 +171,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 +189,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 +209,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 +225,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..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 @@ -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,13 +49,14 @@ 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 =~ """ "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", @@ -68,8 +69,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 +86,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..4edbe8e3 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,17 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.WallabyTest do use NimbleTemplate.AddonCase, async: false - describe "#apply/2" do + alias NimbleTemplate.Projects.Project + + 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 +45,10 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.WallabyTest do project: project, test_project_path: test_project_path } do - in_test_project(test_project_path, fn -> - project = ProjectHelper.append_installed_addon(project, NimbleTemplate.Addons.Phoenix.ExVCR) + in_test_project!(test_project_path, fn -> + project = Project.prepend_optional_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 +83,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 +94,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 +111,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 +131,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 +148,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 +171,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/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/helpers/credo_test.exs b/test/nimble_template/helpers/credo_test.exs index 9ab90441..7eb37645 100644 --- a/test/nimble_template/helpers/credo_test.exs +++ b/test/nimble_template/helpers/credo_test.exs @@ -3,25 +3,49 @@ 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", """ - defmodule SampleModule do - def foo, do: "bar" - end - """) + in_test_project!(test_project_path, fn -> + CredoHelper.suppress_credo_warnings_for_base_project(project) - CredoHelper.disable_rule("sample_module.exs", "Credo.Check.Readability.RedundantBlankLines") + 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 + + 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.exs", fn file -> - assert file == """ - # credo:disable-for-this-file Credo.Check.Readability.RedundantBlankLines - defmodule SampleModule do - def foo, do: "bar" - end + 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 """ end) end) 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/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 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..cb5b193a --- /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.Exception.MockHexPackageRequiredException + alias NimbleTemplate.Hex.PackageMock + + 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/nimble_template/projects/project_test.exs b/test/nimble_template/projects/project_test.exs index d27190a8..f65bf31d 100644 --- a/test/nimble_template/projects/project_test.exs +++ b/test/nimble_template/projects/project_test.exs @@ -3,12 +3,12 @@ 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 } 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" @@ -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 diff --git a/test/nimble_template/version_test.exs b/test/nimble_template/version_test.exs index a631404b..d53f24f9 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", %{ + test_project_path: test_project_path + } do + in_test_project!(test_project_path, fn -> + current_version = Mix.Project.config()[:version] - 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() - 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(".") - # 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 Version.bump(new_version) == :ok + assert_file("mix.exs", fn file -> + assert file =~ "version: \"#{new_version}\"" + refute file =~ "version: \"#{current_version}\"" + end) - 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}," - 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}," + 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 + describe "upgrade_stack!/1" do + 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..8f493ec1 100644 --- a/test/support/addon_case.ex +++ b/test/support/addon_case.ex @@ -6,8 +6,9 @@ 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 + 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, "") @@ -74,21 +60,21 @@ 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) + 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? @@ -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..48e5212b --- /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 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)