Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[gh315] Support Phoenix 1.7.x #318

Draft
wants to merge 51 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
0abae0b
[gh315] Upgrade the template dependencies and Phoenix to 1.7.0
andyduong1920 Feb 27, 2023
f4c0e85
[gh315] Remove Phoenix view
andyduong1920 Feb 27, 2023
f2da7a0
[gh315] Upgrade to Phoenix 1.7.1
andyduong1920 Mar 10, 2023
29121fa
[gh315] Upgrade the docs
andyduong1920 Mar 10, 2023
ec3d4b8
[gh315] Do not need --no-live when the --no-html is given
andyduong1920 Mar 10, 2023
8285a95
[gh315] Update - 1
andyduong1920 Mar 10, 2023
e0f71d3
[gh315] Update - 2
andyduong1920 Mar 10, 2023
898d053
[gh315] Format
andyduong1920 Mar 10, 2023
e5c6bac
[gh315] Format
andyduong1920 Mar 10, 2023
8fafd23
[gh315] Fix the gettext
andyduong1920 Mar 10, 2023
d711e97
[gh315] Fix linting
andyduong1920 Mar 10, 2023
993f8bf
[gh315] Fix the wallaby with httppoison
andyduong1920 Mar 10, 2023
21f9553
[gh315] Fix format
andyduong1920 Mar 10, 2023
e01a3a9
[gh315] Fix wallaby
andyduong1920 Mar 10, 2023
ba9d749
[gh315] Fix wallaby
andyduong1920 Mar 10, 2023
a7067d6
[gh315] Disable SVG
andyduong1920 Mar 10, 2023
cfee357
[gh315] Fix the CoreComponents
andyduong1920 Mar 10, 2023
d58e92a
[gh315] Fix the CoreComponents
andyduong1920 Mar 10, 2023
9963795
[gh315] Fix the CoreComponents
andyduong1920 Mar 10, 2023
33e0727
[gh315] Disable the EmptyBodyParamsPlugTest
andyduong1920 Mar 10, 2023
cbf2e4f
[gh315] Remove the httppoison as Wallaby released the new version
andyduong1920 Mar 14, 2023
20a369e
Remove the CoreComponent
andyduong1920 Mar 15, 2023
d91d395
[gh315] Fix the credo on the web entry point
andyduong1920 Mar 15, 2023
d8fd6aa
[gh315] Fix the credo and the feature test
andyduong1920 Mar 15, 2023
766e541
[gh315] Fix the credo and the feature test
andyduong1920 Mar 15, 2023
9890876
[gh315] Skip test on the core_components
andyduong1920 Mar 15, 2023
ad453cc
[gh315] Fix credo helper
andyduong1920 Mar 15, 2023
87b59ce
[gh315] Fix credo helper
andyduong1920 Mar 15, 2023
0b73dc2
Initial
liamstevens111 Mar 15, 2023
f8225ad
Remove duplicate code introduced
liamstevens111 Mar 16, 2023
47bdea3
Change IconHelper tests to pipe |> syntax
liamstevens111 Mar 16, 2023
25fd192
Merge pull request #320 from nimblehq/feature/incorporate-verified-ro…
andyduong1920 Mar 16, 2023
614792e
Initial conversion from ErrorView to ErrorJSON view
liamstevens111 Mar 17, 2023
a9d9325
Change to match pre-existing custom error output and tests
liamstevens111 Mar 17, 2023
9baa1c5
Add Plug.Conn.Status alias
liamstevens111 Mar 17, 2023
4a0c259
Add test for non-exisitant error code
liamstevens111 Mar 17, 2023
3e26ff0
Include changeset error output and tests
liamstevens111 Mar 19, 2023
b496595
Disable singlemodulefile CompassCredoCheck for test file
liamstevens111 Mar 19, 2023
d9a3c6c
Add test for ensuring file exists for ErrorJSON in template
liamstevens111 Mar 19, 2023
116856a
Fix webmodule name for Gettext
liamstevens111 Mar 19, 2023
2bd1e00
Add ErrorJSON to multiple module disable rule
liamstevens111 Mar 19, 2023
33b9e63
Use translate_error/1 from CoreComponents instead of redefining
liamstevens111 Mar 20, 2023
c725541
Change to use ErrorJSON in Fallback Controller and check_empty_body_p…
liamstevens111 Mar 20, 2023
4e7621b
Fix CoreComponent webmodule prefix for translate
liamstevens111 Mar 20, 2023
2887ee6
Fix CoreComponent import again
liamstevens111 Mar 20, 2023
31aea20
Add back translate_errors as CoreComponents cant be found
liamstevens111 Mar 20, 2023
8d6bb13
Update ViewCase although it doesn't seem to be used
liamstevens111 Mar 21, 2023
d408554
Update ViewCase although it doesn't seem to be used
liamstevens111 Mar 21, 2023
334c0da
Remove TODO and RouteHelper from feature_case and view_case
liamstevens111 Apr 4, 2023
dece778
Remove RouteHelper from tests
liamstevens111 Apr 4, 2023
0fc9f5a
Merge pull request #323 from nimblehq/feature/revisit-error-view
andyduong1920 Apr 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/wiki/Generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
5. Edit `mix.exs` file and add this line to the dependencies.

```elixir
{:nimble_template, "~> 3.0", path: "~/elixir-templates", only: :dev, runtime: false}
{:nimble_template, "~> 4.7", path: "~/elixir-templates", only: :dev, runtime: false}
```

Modify the path to locate the `elixir-templates` directory. For example `~/elixir-templates` if inside the home directory.
Expand All @@ -36,7 +36,7 @@ Modify the path to locate the `elixir-templates` directory. For example `~/elixi

- Web project: `make create_phoenix_project PROJECT_DIRECTORY=sample_project OPTIONS="--no-live"`
- Live project: `make create_phoenix_project PROJECT_DIRECTORY=sample_project OPTIONS=""`
- API project: `make create_phoenix_project PROJECT_DIRECTORY=sample_project OPTIONS="--no-html --no-assets --no-live"`
- API project: `make create_phoenix_project PROJECT_DIRECTORY=sample_project OPTIONS="--no-html --no-assets"`

3. Answer the prompt `Fetch and install dependencies? [Yn]` with `n` (not install)

Expand Down
6 changes: 3 additions & 3 deletions .github/wiki/Testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ mix phx.new awesome_project
- API variants do NOT support HTML and Assets configuration.

```bash
mix phx.new awesome_project --no-html --no-assets --no-live
mix phx.new awesome_project --no-html --no-assets
```

- Custom project variants allow us to modify the app name or module name.
Expand All @@ -108,8 +108,8 @@ Web project

API project

- Standard (`mix phx.new awesome_project --no-html --no-assets --no-live`)
- Custom (`mix phx.new awesome_project --no-html --no-assets --no-live --module=CustomModuleName --app=custom_otp_app_name`)
- Standard (`mix phx.new awesome_project --no-html --no-assets`)
- Custom (`mix phx.new awesome_project --no-html --no-assets --module=CustomModuleName --app=custom_otp_app_name`)

LiveView project

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/apply_api_variant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ jobs:
name: Test on a Standard API project
uses: ./.github/workflows/reusable_phoenix_project.yml
with:
new_project_options: "--no-html --no-assets --no-live"
new_project_options: "--no-html --no-assets"
variant: "api"

long_custom_name_api_project:
name: Test on a long custom name API project
uses: ./.github/workflows/reusable_phoenix_project.yml
with:
new_project_options: "--no-html --no-assets --no-live --module=SampleCustomModule --app=sample_custom_app"
new_project_options: "--no-html --no-assets --module=SampleCustomModule --app=sample_custom_app"
variant: "api"

short_custom_name_api_project:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
type: string

env:
PHOENIX_VERSION: 1.6.11
PHOENIX_VERSION: 1.7.1
MIX_ENV: test

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable_phoenix_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
type: string

env:
PHOENIX_VERSION: 1.6.11
PHOENIX_VERSION: 1.7.1
BASE_PROJECT_DIRECTORY: sample_project
DB_HOST: localhost
MIX_ENV: dev
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Test template
on: push

env:
PHOENIX_VERSION: 1.6.11
PHOENIX_VERSION: 1.7.1
MIX_ENV: test

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upgrade_stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ on:
type: string

env:
PHOENIX_VERSION: 1.6.11
PHOENIX_VERSION: 1.7.1
MIX_ENV: test

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/verify_release_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- 'release/**'

env:
PHOENIX_VERSION: 1.6.11
PHOENIX_VERSION: 1.7.1
MIX_ENV: test

jobs:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ nimble_template-*.tar
nimble_template.iml

**/tmp

# The sample generated project on local
sample_project/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ NimbleTemplate has been developed and actively tested with the below environment
- Mix 1.13.3
- Elixir 1.14.0
- Erlang/OTP 25.0.4
- Phoenix 1.6.11
- Phoenix 1.7.1
- Node 16.15.0

## Installation
Expand Down
18 changes: 1 addition & 17 deletions lib/nimble_template/addons/variants/phoenix/api/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,16 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.Config do
edit_files!(project)
end

def edit_config_prod!(%Project{otp_app: otp_app, web_module: web_module} = project) do
def edit_config_prod!(%Project{} = project) do
Generator.delete_content!(
"config/prod.exs",
"""
# For production, don't forget to configure the url host
# to something meaningful, Phoenix uses this information
# when generating URLs.
#
# Note we also include the path to a cache manifest
# containing the digested version of static files. This
# manifest is generated by the `mix phx.digest` task,
# which you should run after static files are built and
# before starting your production server.
"""
)

Generator.delete_content!(
"config/prod.exs",
"config :#{otp_app}, #{web_module}.Endpoint,"
)

Generator.delete_content!(
"config/prod.exs",
"cache_static_manifest: \"priv/static/cache_manifest.json\""
)

project
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,56 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.EmptyBodyParamsPlug do

@impl true
def do_apply!(%Project{} = project, _opts) do
# TODO: Revisit on the next PR
project
|> copy_files!()
|> edit_files!()
end

defp copy_files!(
%Project{
web_module: web_module,
web_path: web_path,
web_test_path: web_test_path
} = project
) do
binding = [
web_module: web_module
]

files = [
{:eex, "lib/otp_app_web/plugs/check_empty_body_params_plug.ex.eex",
"#{web_path}/plugs/check_empty_body_params_plug.ex"},
{:eex, "test/otp_app_web/plugs/check_empty_body_params_plug_test.exs.eex",
"#{web_test_path}/plugs/check_empty_body_params_plug_test.exs"}
]

Generator.copy_file!(files, binding)

project
end

defp edit_files!(%Project{web_path: web_path, web_module: web_module} = project) do
Generator.replace_content!(
"#{web_path}/router.ex",
"""
pipeline :api do
plug :accepts, ["json"]
end
""",
"""
pipeline :api do
plug :accepts, ["json"]
plug #{web_module}.CheckEmptyBodyParamsPlug
end
"""
)

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

# defp copy_files!(
# %Project{
# web_module: web_module,
# web_path: web_path,
# web_test_path: web_test_path
# } = project
# ) do
# binding = [
# web_module: web_module
# ]

# files = [
# {:eex, "lib/otp_app_web/plugs/check_empty_body_params_plug.ex.eex",
# "#{web_path}/plugs/check_empty_body_params_plug.ex"},
# {:eex, "test/otp_app_web/plugs/check_empty_body_params_plug_test.exs.eex",
# "#{web_test_path}/plugs/check_empty_body_params_plug_test.exs"}
# ]

# Generator.copy_file!(files, binding)

# project
# end

# defp edit_files!(%Project{web_path: web_path, web_module: web_module} = project) do
# Generator.replace_content!(
# "#{web_path}/router.ex",
# """
# pipeline :api do
# plug :accepts, ["json"]
# end
# """,
# """
# pipeline :api do
# plug :accepts, ["json"]
# plug #{web_module}.CheckEmptyBodyParamsPlug
# end
# """
# )

# project
# end
end
44 changes: 44 additions & 0 deletions lib/nimble_template/addons/variants/phoenix/api/error_json.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
defmodule NimbleTemplate.Addons.Phoenix.Api.ErrorJSON do
@moduledoc false

use NimbleTemplate.Addons.Addon

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

defp delete_files!(%Project{web_path: web_path, web_test_path: web_test_path} = project) do
File.rm!("#{web_path}/controllers/error_json.ex")
File.rm!("#{web_test_path}/controllers/error_json_test.exs")

project
end

defp copy_files!(
%Project{
base_module: base_module,
web_module: web_module,
web_path: web_path,
web_test_path: web_test_path
} = project
) do
binding = [
web_module: web_module,
base_module: base_module
]

files = [
{:eex, "lib/otp_app_web/controllers/error_json.ex.eex",
"#{web_path}/controllers/error_json.ex"},
{:eex, "test/otp_app_web/controllers/error_json_test.exs.eex",
"#{web_test_path}/controllers/error_json_test.exs"}
]

Generator.copy_file!(files, binding)

project
end
end
46 changes: 0 additions & 46 deletions lib/nimble_template/addons/variants/phoenix/api/error_view.ex

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,26 @@ defmodule NimbleTemplate.Addons.Phoenix.Api.FallbackController do
"""
def controller do
quote do
use Phoenix.Controller, namespace: #{web_module}
use Phoenix.Controller,
formats: [:html, :json],
layouts: [html: #{web_module}.Layouts]

import Plug.Conn
import #{web_module}.Gettext

alias #{web_module}.ParamsValidator
alias #{web_module}.Router.Helpers, as: Routes
""",
"""
def controller do
quote do
use Phoenix.Controller, namespace: #{web_module}
use Phoenix.Controller,
formats: [:html, :json],
layouts: [html: #{web_module}.Layouts]

import Plug.Conn
import #{web_module}.Gettext

alias #{web_module}.ParamsValidator
alias #{web_module}.Router.Helpers, as: Routes

action_fallback #{web_module}.Api.FallbackController
"""
Expand Down
Loading