diff --git a/.github/ISSUE_TEMPLATE/bug_template.md b/.github/ISSUE_TEMPLATE/bug_template.md new file mode 100644 index 00000000..adb94cc1 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_template.md @@ -0,0 +1,20 @@ +--- +name: "Bug Report" +about: "You found something that is not working. Report it so that it can be fixed. 👷‍" +title: "Fix: " +labels: "type : bug" +--- + +## Issue + +Describe the issue you are facing. Show us the implementation: screenshots, gif, etc. + +## Expected + +Describe what should be the correct behaviour. + +## Steps to reproduce + +1. +2. +3. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_template.md b/.github/ISSUE_TEMPLATE/feature_template.md new file mode 100644 index 00000000..1176d56e --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_template.md @@ -0,0 +1,14 @@ +--- +name: "Feature" +about: "Open a feature issue to add new functionalities." +title: "Add " +labels: "type : feature" +--- + +## Why + +Describe the big picture of the feature and why it's needed. + +## Who Benefits? + +Describe who will be the beneficiaries e.g. everyone, clients... \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/rfc_template.md b/.github/ISSUE_TEMPLATE/rfc_template.md new file mode 100644 index 00000000..bb67e96a --- /dev/null +++ b/.github/ISSUE_TEMPLATE/rfc_template.md @@ -0,0 +1,28 @@ +--- +name: "Request For Comments (RFC)" +about: "You have an idea on how to improve the template. Propose your idea so that the team can provide feedback." +title: "RFC: " +labels: "type : rfa" +--- + +## Issue + +Describe the issue from the template or generated project currently facing. Provide as much content as possible. + +## Solution + +Describe the solution you are prescribing for the issue. + +## Who Benefits? + +Describe who will be the beneficiaries e.g. everyone, clients... + +## What's Next? + +Provide an actionable list of things that must happen in order to implement the solution: + +- [ ] +- [ ] +- [ ] + +Using a poll is encouraged to gather feedback on the RFA 👉 Use this tool: https://gh-polls.com/ \ No newline at end of file diff --git a/.github/workflows/publish_to_hex_pm.yml b/.github/workflows/publish_to_hex_pm.yml index d5bc21a2..5614d9fb 100644 --- a/.github/workflows/publish_to_hex_pm.yml +++ b/.github/workflows/publish_to_hex_pm.yml @@ -11,14 +11,19 @@ on: workflow_dispatch: env: - OTP_VERSION: 23.2.1 - ELIXIR_VERSION: 1.11.3 + OTP_VERSION: 23.3 + ELIXIR_VERSION: 1.11.4 jobs: publish: runs-on: ubuntu-latest if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }} steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.8.0 + with: + access_token: ${{ github.token }} + - uses: actions/checkout@v2 with: ref: ${{ github.event.workflow_run.head_branch || github.ref }} diff --git a/.github/workflows/test_api_variant_on_custom_api_project.yml b/.github/workflows/test_api_variant_on_custom_api_project.yml index b17bec09..146f401e 100644 --- a/.github/workflows/test_api_variant_on_custom_api_project.yml +++ b/.github/workflows/test_api_variant_on_custom_api_project.yml @@ -3,8 +3,8 @@ name: "Test API variant on custom API project" on: push env: - OTP_VERSION: 23.2.1 - ELIXIR_VERSION: 1.11.3 + OTP_VERSION: 23.3 + ELIXIR_VERSION: 1.11.4 PHOENIX_VERSION: 1.5.7 jobs: @@ -24,6 +24,11 @@ jobs: --health-retries 5 steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.8.0 + with: + access_token: ${{ github.token }} + - uses: actions/checkout@v2 with: ref: ${{ github.head_ref }} @@ -43,7 +48,7 @@ jobs: restore-keys: | ${{ runner.os }}-mix- - - uses: nimblehq/elixir-templates@composite_1.1 + - uses: nimblehq/elixir-templates@composite_1.4 with: new_project_options: '--no-html --no-webpack --module=CustomModule --app=custom_app' variant: 'api' diff --git a/.github/workflows/test_api_variant_on_standard_api_project.yml b/.github/workflows/test_api_variant_on_standard_api_project.yml index 1b539f88..9841036c 100644 --- a/.github/workflows/test_api_variant_on_standard_api_project.yml +++ b/.github/workflows/test_api_variant_on_standard_api_project.yml @@ -3,8 +3,8 @@ name: "Test API variant on standard API project" on: push env: - OTP_VERSION: 23.2.1 - ELIXIR_VERSION: 1.11.3 + OTP_VERSION: 23.3 + ELIXIR_VERSION: 1.11.4 PHOENIX_VERSION: 1.5.7 jobs: @@ -24,6 +24,11 @@ jobs: --health-retries 5 steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.8.0 + with: + access_token: ${{ github.token }} + - uses: actions/checkout@v2 with: ref: ${{ github.head_ref }} @@ -43,7 +48,7 @@ jobs: restore-keys: | ${{ runner.os }}-mix- - - uses: nimblehq/elixir-templates@composite_1.1 + - uses: nimblehq/elixir-templates@composite_1.4 with: new_project_options: '--no-html --no-webpack' variant: 'api' diff --git a/.github/workflows/test_live_variant_on_custom_liveview_project.yml b/.github/workflows/test_live_variant_on_custom_liveview_project.yml index 21d24aad..5cc4dd99 100644 --- a/.github/workflows/test_live_variant_on_custom_liveview_project.yml +++ b/.github/workflows/test_live_variant_on_custom_liveview_project.yml @@ -3,8 +3,8 @@ name: "Test Live variant on custom LiveView project" on: push env: - OTP_VERSION: 23.2.1 - ELIXIR_VERSION: 1.11.3 + OTP_VERSION: 23.3 + ELIXIR_VERSION: 1.11.4 PHOENIX_VERSION: 1.5.7 NODE_VERSION: 14 @@ -25,6 +25,11 @@ jobs: --health-retries 5 steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.8.0 + with: + access_token: ${{ github.token }} + - uses: actions/checkout@v2 with: ref: ${{ github.head_ref }} @@ -34,7 +39,7 @@ jobs: otp-version: ${{ env.OTP_VERSION }} elixir-version: ${{ env.ELIXIR_VERSION }} - - uses: actions/setup-node@v2-beta + - uses: actions/setup-node@v2.1.5 with: node-version: ${{ env.NODE_VERSION }} @@ -47,23 +52,17 @@ jobs: key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} restore-keys: | ${{ runner.os }}-mix- - - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=yarn_cache_dir::$(yarn cache dir)" - - name: npm packages cache + - name: Cache Node npm uses: actions/cache@v2 with: path: | - ${{ steps.yarn-cache-dir-path.outputs.yarn_cache_dir }} - **/yarn.lock **/node_modules - key: ${{ runner.os }}-npm-packages-${{ hashFiles('**/package.json*') }} + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | - ${{ runner.os }}-npm-packages- + ${{ runner.os }}-node- - - uses: nimblehq/elixir-templates@composite_1.1 + - uses: nimblehq/elixir-templates@composite_1.4 with: new_project_options: '--live --module=CustomModule --app=custom_app' variant: 'live' diff --git a/.github/workflows/test_live_variant_on_standard_liveview_project.yml b/.github/workflows/test_live_variant_on_standard_liveview_project.yml index 9768b3f5..6ba329d5 100644 --- a/.github/workflows/test_live_variant_on_standard_liveview_project.yml +++ b/.github/workflows/test_live_variant_on_standard_liveview_project.yml @@ -3,8 +3,8 @@ name: "Test Live variant on standard LiveView project" on: push env: - OTP_VERSION: 23.2.1 - ELIXIR_VERSION: 1.11.3 + OTP_VERSION: 23.3 + ELIXIR_VERSION: 1.11.4 PHOENIX_VERSION: 1.5.7 NODE_VERSION: 14 @@ -25,6 +25,11 @@ jobs: --health-retries 5 steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.8.0 + with: + access_token: ${{ github.token }} + - uses: actions/checkout@v2 with: ref: ${{ github.head_ref }} @@ -34,7 +39,7 @@ jobs: otp-version: ${{ env.OTP_VERSION }} elixir-version: ${{ env.ELIXIR_VERSION }} - - uses: actions/setup-node@v2-beta + - uses: actions/setup-node@v2.1.5 with: node-version: ${{ env.NODE_VERSION }} @@ -47,23 +52,17 @@ jobs: key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} restore-keys: | ${{ runner.os }}-mix- - - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=yarn_cache_dir::$(yarn cache dir)" - - name: npm packages cache + - name: Cache Node npm uses: actions/cache@v2 with: path: | - ${{ steps.yarn-cache-dir-path.outputs.yarn_cache_dir }} - **/yarn.lock **/node_modules - key: ${{ runner.os }}-npm-packages-${{ hashFiles('**/package.json*') }} + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | - ${{ runner.os }}-npm-packages- + ${{ runner.os }}-node- - - uses: nimblehq/elixir-templates@composite_1.1 + - uses: nimblehq/elixir-templates@composite_1.4 with: new_project_options: '--live' variant: 'live' diff --git a/.github/workflows/test_mix_variant_on_custom_mix_project.yml b/.github/workflows/test_mix_variant_on_custom_mix_project.yml new file mode 100644 index 00000000..17c8767a --- /dev/null +++ b/.github/workflows/test_mix_variant_on_custom_mix_project.yml @@ -0,0 +1,55 @@ +name: "Test Mix variant on custom Mix project" + +on: push + +env: + OTP_VERSION: 23.3 + ELIXIR_VERSION: 1.11.4 + MIX_ENV: test + +jobs: + unit_test: + runs-on: ubuntu-latest + + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.8.0 + with: + access_token: ${{ github.token }} + + - uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + + - uses: erlef/setup-elixir@v1 + with: + otp-version: ${{ env.OTP_VERSION }} + elixir-version: ${{ env.ELIXIR_VERSION }} + + - name: Cache Elixir build + uses: actions/cache@v2 + with: + path: | + _build + deps + key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} + restore-keys: | + ${{ runner.os }}-mix- + + - name: Create Mix project + run: make create_mix_project PROJECT_DIRECTORY=sample_project OPTIONS="--module=CustomModule --app=custom_app" + + - name: Apply Mix template + run: make apply_mix_template PROJECT_DIRECTORY=sample_project + + - name: Install Elixir Dependencies + run: cd sample_project && mix deps.get + + - name: Compile dependencies + run: cd sample_project && mix compile --warnings-as-errors --all-warnings + + - name: Run mix codebase + run: cd sample_project && mix codebase + + - name: Run mix test + run: cd sample_project && mix test diff --git a/.github/workflows/test_mix_variant_on_custom_mix_project_with_supervision.yml b/.github/workflows/test_mix_variant_on_custom_mix_project_with_supervision.yml new file mode 100644 index 00000000..e240d59a --- /dev/null +++ b/.github/workflows/test_mix_variant_on_custom_mix_project_with_supervision.yml @@ -0,0 +1,55 @@ +name: "Test Mix variant on custom Mix project with --sup option" + +on: push + +env: + OTP_VERSION: 23.3 + ELIXIR_VERSION: 1.11.4 + MIX_ENV: test + +jobs: + unit_test: + runs-on: ubuntu-latest + + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.8.0 + with: + access_token: ${{ github.token }} + + - uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + + - uses: erlef/setup-elixir@v1 + with: + otp-version: ${{ env.OTP_VERSION }} + elixir-version: ${{ env.ELIXIR_VERSION }} + + - name: Cache Elixir build + uses: actions/cache@v2 + with: + path: | + _build + deps + key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} + restore-keys: | + ${{ runner.os }}-mix- + + - name: Create Mix project + run: make create_mix_project PROJECT_DIRECTORY=sample_project OPTIONS="--module=CustomModule --app=custom_app --sup" + + - name: Apply Mix template + run: make apply_mix_template PROJECT_DIRECTORY=sample_project + + - name: Install Elixir Dependencies + run: cd sample_project && mix deps.get + + - name: Compile dependencies + run: cd sample_project && mix compile --warnings-as-errors --all-warnings + + - name: Run mix codebase + run: cd sample_project && mix codebase + + - name: Run mix test + run: cd sample_project && mix test diff --git a/.github/workflows/test_mix_variant_on_standard_mix_project.yml b/.github/workflows/test_mix_variant_on_standard_mix_project.yml new file mode 100644 index 00000000..bd62d7ce --- /dev/null +++ b/.github/workflows/test_mix_variant_on_standard_mix_project.yml @@ -0,0 +1,55 @@ +name: "Test Mix variant on standard Mix project" + +on: push + +env: + OTP_VERSION: 23.3 + ELIXIR_VERSION: 1.11.4 + MIX_ENV: test + +jobs: + unit_test: + runs-on: ubuntu-latest + + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.8.0 + with: + access_token: ${{ github.token }} + + - uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + + - uses: erlef/setup-elixir@v1 + with: + otp-version: ${{ env.OTP_VERSION }} + elixir-version: ${{ env.ELIXIR_VERSION }} + + - name: Cache Elixir build + uses: actions/cache@v2 + with: + path: | + _build + deps + key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} + restore-keys: | + ${{ runner.os }}-mix- + + - name: Create Mix project + run: make create_mix_project PROJECT_DIRECTORY=sample_project OPTIONS="" + + - name: Apply Mix template + run: make apply_mix_template PROJECT_DIRECTORY=sample_project + + - name: Install Elixir Dependencies + run: cd sample_project && mix deps.get + + - name: Compile dependencies + run: cd sample_project && mix compile --warnings-as-errors --all-warnings + + - name: Run mix codebase + run: cd sample_project && mix codebase + + - name: Run mix test + run: cd sample_project && mix test diff --git a/.github/workflows/test_mix_variant_on_standard_mix_project_with_supervision.yml b/.github/workflows/test_mix_variant_on_standard_mix_project_with_supervision.yml new file mode 100644 index 00000000..6d515a2f --- /dev/null +++ b/.github/workflows/test_mix_variant_on_standard_mix_project_with_supervision.yml @@ -0,0 +1,55 @@ +name: "Test Mix variant on standard Mix project with --sup option" + +on: push + +env: + OTP_VERSION: 23.3 + ELIXIR_VERSION: 1.11.4 + MIX_ENV: test + +jobs: + unit_test: + runs-on: ubuntu-latest + + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.8.0 + with: + access_token: ${{ github.token }} + + - uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + + - uses: erlef/setup-elixir@v1 + with: + otp-version: ${{ env.OTP_VERSION }} + elixir-version: ${{ env.ELIXIR_VERSION }} + + - name: Cache Elixir build + uses: actions/cache@v2 + with: + path: | + _build + deps + key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} + restore-keys: | + ${{ runner.os }}-mix- + + - name: Create Mix project + run: make create_mix_project PROJECT_DIRECTORY=sample_project OPTIONS="--sup" + + - name: Apply Mix template + run: make apply_mix_template PROJECT_DIRECTORY=sample_project + + - name: Install Elixir Dependencies + run: cd sample_project && mix deps.get + + - name: Compile dependencies + run: cd sample_project && mix compile --warnings-as-errors --all-warnings + + - name: Run mix codebase + run: cd sample_project && mix codebase + + - name: Run mix test + run: cd sample_project && mix test diff --git a/.github/workflows/test_release_version.yml b/.github/workflows/test_release_version.yml index 00ec56da..5a48b40e 100644 --- a/.github/workflows/test_release_version.yml +++ b/.github/workflows/test_release_version.yml @@ -1,46 +1,53 @@ -name: "Test Release version" - -on: - push: - branches: - - 'release/**' - -env: - OTP_VERSION: 23.2.1 - ELIXIR_VERSION: 1.11.3 - PHOENIX_VERSION: 1.5.7 - -jobs: - release_version_test: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.head_ref }} - - - uses: erlef/setup-elixir@v1 - with: - otp-version: ${{ env.OTP_VERSION }} - elixir-version: ${{ env.ELIXIR_VERSION }} - - - name: Cache Elixir build - uses: actions/cache@v2 - with: - path: | - _build - deps - key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} - restore-keys: | - ${{ runner.os }}-mix- - - - name: Install Dependencies - run: mix deps.get +# name: "Test Release version" + +# on: +# push: +# branches: +# - 'release/**' + +# env: +# OTP_VERSION: 23.3 +# ELIXIR_VERSION: 1.11.4 +# PHOENIX_VERSION: 1.5.7 +# MIX_ENV: test + +# jobs: +# release_version_test: +# runs-on: ubuntu-latest + +# steps: +# - name: Cancel Previous Runs +# uses: styfle/cancel-workflow-action@0.8.0 +# with: +# access_token: ${{ github.token }} + +# - uses: actions/checkout@v2 +# with: +# ref: ${{ github.head_ref }} + +# - uses: erlef/setup-elixir@v1 +# with: +# otp-version: ${{ env.OTP_VERSION }} +# elixir-version: ${{ env.ELIXIR_VERSION }} + +# - name: Cache Elixir build +# uses: actions/cache@v2 +# with: +# path: | +# _build +# deps +# key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} +# restore-keys: | +# ${{ runner.os }}-mix- + +# - name: Install Dependencies +# run: mix deps.get + +# - name: Compile dependencies +# run: mix compile --warnings-as-errors --all-warnings - - name: Install Phoenix ${{ env.PHOENIX_VERSION }} - run: make install_phoenix PHOENIX_VERSION=${{ env.PHOENIX_VERSION }} +# - name: Install Phoenix ${{ env.PHOENIX_VERSION }} +# run: make install_phoenix PHOENIX_VERSION=${{ env.PHOENIX_VERSION }} - - name: Run Tests - run: mix test --only release_version - env: - MIX_ENV: test +# - name: Run Tests +# run: mix test --only release_version diff --git a/.github/workflows/test_template.yml b/.github/workflows/test_template.yml index 1763d628..6aff76c7 100644 --- a/.github/workflows/test_template.yml +++ b/.github/workflows/test_template.yml @@ -3,15 +3,21 @@ name: "Test template" on: push env: - OTP_VERSION: 23.2.1 - ELIXIR_VERSION: 1.11.3 + OTP_VERSION: 23.3 + ELIXIR_VERSION: 1.11.4 PHOENIX_VERSION: 1.5.7 + MIX_ENV: test jobs: unit_test: runs-on: ubuntu-latest steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.8.0 + with: + access_token: ${{ github.token }} + - uses: actions/checkout@v2 with: ref: ${{ github.head_ref }} @@ -33,7 +39,10 @@ jobs: - name: Install Dependencies run: mix deps.get - + + - name: Compile dependencies + run: mix compile --warnings-as-errors --all-warnings + - name: Install Phoenix ${{ env.PHOENIX_VERSION }} run: make install_phoenix PHOENIX_VERSION=${{ env.PHOENIX_VERSION }} @@ -41,6 +50,4 @@ jobs: run: mix codebase - name: Run Tests - run: mix do compile --warnings-as-errors, test - env: - MIX_ENV: test + run: mix test diff --git a/.github/workflows/test_variant_on_custom_project.yml b/.github/workflows/test_variant_on_custom_web_project.yml similarity index 71% rename from .github/workflows/test_variant_on_custom_project.yml rename to .github/workflows/test_variant_on_custom_web_project.yml index 338d4e61..c2796562 100644 --- a/.github/workflows/test_variant_on_custom_project.yml +++ b/.github/workflows/test_variant_on_custom_web_project.yml @@ -3,8 +3,8 @@ name: "Test variant on custom Web project" on: push env: - OTP_VERSION: 23.2.1 - ELIXIR_VERSION: 1.11.3 + OTP_VERSION: 23.3 + ELIXIR_VERSION: 1.11.4 PHOENIX_VERSION: 1.5.7 NODE_VERSION: 14 @@ -29,6 +29,11 @@ jobs: --health-retries 5 steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.8.0 + with: + access_token: ${{ github.token }} + - uses: actions/checkout@v2 with: ref: ${{ github.head_ref }} @@ -38,7 +43,7 @@ jobs: otp-version: ${{ env.OTP_VERSION }} elixir-version: ${{ env.ELIXIR_VERSION }} - - uses: actions/setup-node@v2-beta + - uses: actions/setup-node@v2.1.5 with: node-version: ${{ env.NODE_VERSION }} @@ -52,22 +57,16 @@ jobs: restore-keys: | ${{ runner.os }}-mix- - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=yarn_cache_dir::$(yarn cache dir)" - - - name: npm packages cache + - name: Cache Node npm uses: actions/cache@v2 with: path: | - ${{ steps.yarn-cache-dir-path.outputs.yarn_cache_dir }} - **/yarn.lock **/node_modules - key: ${{ runner.os }}-npm-packages-${{ hashFiles('**/package.json*') }} + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | - ${{ runner.os }}-npm-packages- + ${{ runner.os }}-node- - - uses: nimblehq/elixir-templates@composite_1.1 + - uses: nimblehq/elixir-templates@composite_1.4 with: new_project_options: '--module=CustomModule --app=custom_app' variant: ${{ matrix.variant }} diff --git a/.github/workflows/test_variant_on_standard_project.yml b/.github/workflows/test_variant_on_standard_web_project.yml similarity index 70% rename from .github/workflows/test_variant_on_standard_project.yml rename to .github/workflows/test_variant_on_standard_web_project.yml index b1c19807..0e365e40 100644 --- a/.github/workflows/test_variant_on_standard_project.yml +++ b/.github/workflows/test_variant_on_standard_web_project.yml @@ -3,8 +3,8 @@ name: "Test variant on standard Web project" on: push env: - OTP_VERSION: 23.2.1 - ELIXIR_VERSION: 1.11.3 + OTP_VERSION: 23.3 + ELIXIR_VERSION: 1.11.4 PHOENIX_VERSION: 1.5.7 NODE_VERSION: 14 @@ -29,6 +29,11 @@ jobs: --health-retries 5 steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.8.0 + with: + access_token: ${{ github.token }} + - uses: actions/checkout@v2 with: ref: ${{ github.head_ref }} @@ -38,7 +43,7 @@ jobs: otp-version: ${{ env.OTP_VERSION }} elixir-version: ${{ env.ELIXIR_VERSION }} - - uses: actions/setup-node@v2-beta + - uses: actions/setup-node@v2.1.5 with: node-version: ${{ env.NODE_VERSION }} @@ -52,22 +57,16 @@ jobs: restore-keys: | ${{ runner.os }}-mix- - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=yarn_cache_dir::$(yarn cache dir)" - - - name: npm packages cache + - name: Cache Node npm uses: actions/cache@v2 with: path: | - ${{ steps.yarn-cache-dir-path.outputs.yarn_cache_dir }} - **/yarn.lock **/node_modules - key: ${{ runner.os }}-npm-packages-${{ hashFiles('**/package.json*') }} + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | - ${{ runner.os }}-npm-packages- + ${{ runner.os }}-node- - - uses: nimblehq/elixir-templates@composite_1.1 + - uses: nimblehq/elixir-templates@composite_1.4 with: new_project_options: '' variant: ${{ matrix.variant }} diff --git a/.gitignore b/.gitignore index 967b8ce3..2e3f8871 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,7 @@ erl_crash.dump *.ez # Ignore package tarball (built via "mix hex.build"). -nimble_phx_gen_template-*.tar +nimble_template-*.tar # Ignore folder information and IDE-specific files .DS_Store diff --git a/.tool-versions b/.tool-versions index 5cf945fb..7bc7f2ef 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -erlang 23.2.1 -elixir 1.11.3-otp-23 +erlang 23.3 +elixir 1.11.4-otp-23 diff --git a/Makefile b/Makefile index 3b5edd18..97ab82f1 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,21 @@ -.PHONY: install_phoenix create_project apply_template remove_nimble_phx_gen_template +.PHONY: install_phoenix create_phoenix_project apply_phoenix_template create_mix_project apply_mix_template remove_nimble_template # Y - in response to Are you sure you want to install "phx_new-${PHOENIX_VERSION}.ez"? install_phoenix: printf "Y\n" | mix archive.install hex phx_new ${PHOENIX_VERSION} -create_project: +create_phoenix_project: mix phx.new ${PROJECT_DIRECTORY} ${OPTIONS} + +create_mix_project: + mix new ${PROJECT_DIRECTORY} ${OPTIONS} # Y - in response to Will you host this project on Github? # Y - in response to Do you want to generate the .github/ISSUE_TEMPLATE and .github/PULL_REQUEST_TEMPLATE? # Y - in response to Do you want to generate the Github Action workflow? # Y - in response to Would you like to add the Oban addon? -common_addon_prompts = Y\nY\nY\nY\n +# Y - in response to Would you like to add the ExVCR addon? +common_addon_prompts = Y\nY\nY\nY\nY\n web_addon_prompts = @@ -19,24 +23,41 @@ api_addon_prompts = live_addon_prompts = +# Y - in response to Will you host this project on Github? +# Y - in response to Do you want to generate the .github/ISSUE_TEMPLATE and .github/PULL_REQUEST_TEMPLATE? +# Y - in response to Do you want to generate the Github Action workflow? +# Y - in response to Would you like to add the Mimic addon? +mix_addon_prompts = Y\nY\nY\nY\n + # Y - in response to Fetch and install dependencies? post_setup_addon_prompts = Y\n -apply_template: +apply_phoenix_template: cd ${PROJECT_DIRECTORY} && \ - echo '{:nimble_phx_gen_template, path: "../", only: :dev, runtime: false},' > nimble_phx_gen_template.txt && \ - sed -i -e '/{:phoenix, "~> /r nimble_phx_gen_template.txt' mix.exs && \ - rm nimble_phx_gen_template.txt && \ - mix deps.get && \ + echo '{:nimble_template, path: "../", only: :dev, runtime: false},' > nimble_template.txt && \ + sed -i -e '/{:phoenix, "~> /r nimble_template.txt' mix.exs && \ + rm nimble_template.txt && \ + export MIX_ENV=dev && \ + mix do deps.get, deps.compile && \ mix format && \ if [ $(VARIANT) = web ]; then \ - printf "${common_addon_prompts}${web_addon_prompts}${post_setup_addon_prompts}" | mix nimble.phx.gen.template --web; \ + printf "${common_addon_prompts}${web_addon_prompts}${post_setup_addon_prompts}" | mix nimble_template.gen --web; \ elif [ $(VARIANT) = api ]; then \ - printf "${common_addon_prompts}${api_addon_prompts}${post_setup_addon_prompts}" | mix nimble.phx.gen.template --api; \ + printf "${common_addon_prompts}${api_addon_prompts}${post_setup_addon_prompts}" | mix nimble_template.gen --api; \ elif [ $(VARIANT) = live ]; then \ - printf "${common_addon_prompts}${web_addon_prompts}${live_addon_prompts}${post_setup_addon_prompts}" | mix nimble.phx.gen.template --live; \ + printf "${common_addon_prompts}${web_addon_prompts}${live_addon_prompts}${post_setup_addon_prompts}" | mix nimble_template.gen --live; \ fi; + +apply_mix_template: + cd ${PROJECT_DIRECTORY} && \ + echo '{:nimble_template, path: "../", only: :dev, runtime: false}' > nimble_template.txt && \ + sed -i -e '/# {:dep_from_git, /r nimble_template.txt' mix.exs && \ + rm nimble_template.txt && \ + export MIX_ENV=dev && \ + mix do deps.get, deps.compile && \ + mix format && \ + printf "${mix_addon_prompts}${post_setup_addon_prompts}" | mix nimble_template.gen --mix; \ -remove_nimble_phx_gen_template: +remove_nimble_template: cd ${PROJECT_DIRECTORY} && \ - sed -i -e 's/{:nimble_phx_gen_template, path: "..\/"},//' mix.exs + sed -i -e 's/{:nimble_template, path: "..\/"},//' mix.exs diff --git a/README.md b/README.md index 3231eb6e..67ff890e 100644 --- a/README.md +++ b/README.md @@ -1,114 +1,162 @@ -# NimblePhxGenTemplate +## Introduction -Project repository template to set up all public Phoenix projects at [Nimble](https://nimblehq.co/) +Phoenix/Mix template for projects at [Nimble](https://nimblehq.co/). + +## Prerequisites + +NimbleTemplate has been developed and actively tested with the below environment: + +- Mix 1.11.4 +- Elixir 1.11.4 +- Erlang/OTP 23.3 +- Phoenix 1.5.7 ## Installation -### Generate a new Phoenix project by using [mix phx.new](https://hexdocs.pm/phoenix/Mix.Tasks.Phx.New.html) +*Note:* NimbleTemplate only works on a _new_ Phoenix/Mix project, applying it to an existing Phoenix/Mix project might not work as expected. + +Step 1: Generate a new project ```bash -mix phx.new ... +# New Phoenix project +mix phx.new awesome_project + +# New Mix project +mix new awesome_project ``` -### Adding `nimble_phx_gen_template` into `mix.exs`: +Step 2: Add `nimble_template` dependency to `mix.exs`: ```elixir def deps do [ - {:nimble_phx_gen_template, "~> 2.2.0", only: :dev, runtime: false}, - ... + {:nimble_template, "~> 3.0", only: :dev, runtime: false}, + # other dependencies ... ] end ``` -Then run `mix do deps.get, deps.compile` to install NimblePhxGenTemplate. +Step 3: Fetch and install dependencies -*Note:* NimblePhxGenTemplate is only working on a new Phoenix project, applying NimblePhxGenTemplate to an existing Phoenix project might not work as expected. +Run this command in the root of the project directory to install NimbleTemplate. + +```bash +mix do deps.get, deps.compile +``` ## Usage -``` -mix nimble.phx.gen.template -v # Print the version -mix nimble.phx.gen.template --web # Apply the Web template -mix nimble.phx.gen.template --api # Apply the API template -mix nimble.phx.gen.template --live # Apply the LiveView template -``` -## Requirements +```bash +mix help nimble_template.gen # Print help -NimblePhxGenTemplate has been developed and actively tested with: -- Elixir 1.11.3 -- Erlang/OTP 23.2.1 -- Phoenix 1.5.7 +mix nimble_template.gen -v # Print the version -Running NimblePhxGenTemplate currently requires: -- Elixir 1.11.3 -- Erlang/OTP 23.2.1 -- Phoenix 1.5.7 +# Phoenix application +mix nimble_template.gen --web # Apply the Web template +mix nimble_template.gen --api # Apply the API template +mix nimble_template.gen --live # Apply the LiveView template -## Contributing +# Non-Phoenix application +mix nimble_template.gen --mix # Apply the Mix template +``` + +## Running tests -We appreciate any contribution to NimblePhxGenTemplate. +NimbleTemplate uses Github Action as the CI, the workflow files locate under [.github/workflows/](https://github.com/nimblehq/elixir-templates/tree/develop/.github/workflows) directory. -### Test +There are 2 types of test **Template test** and **Variant test** -NimblePhxGenTemplate is using Github Action, the workflow files are located under `.github/workflows/` folder, it's including the Template test and Variant test workflow. -#### 1/ Template test +### 1/ Template test -All files are located under `test/` folder. +All test files are located under `test/` directory. ``` . ├── ... ├── test │ ├── ... -│ ├── nimble.phx.gen.template +│ ├── nimble_template │ │ └── addons │ │ │ ├── ... │ │ │ ├── common_addon_test.exs │ │ │ └── variants -│ │ │ │ └── api -│ │ │ │ │ ├── ... -│ │ │ │ │ └── api_addon_test.exs -│ │ │ │ └── web +│ │ │ │ └── mix │ │ │ │ │ ├── ... -│ │ │ │ │ └── web_addon_test.exs +│ │ │ │ │ └── mix_addon_test.exs +│ │ │ │ └── phoenix +│ │ │ │ │ └── api +│ │ │ │ │ │ ├── ... +│ │ │ │ │ │ └── api_addon_test.exs +│ │ │ │ │ └── live +│ │ │ │ │ │ ├── ... +│ │ │ │ │ │ └── live_addon_test.exs +│ │ │ │ │ └── web +│ │ │ │ │ │ ├── ... +│ │ │ │ │ │ └── web_addon_test.exs ``` -#### 2/ Variant test +### 2/ Variant test -##### 2.1/ Variant +#### 2.1/ Variant -NimblePhxGenTemplate is supporting 3 variants: +NimbleTemplate supports 4 variants: - API -- Web - Live +- Web +- Mix -##### 2.2/ Phoenix project +#### 2.2/ Phoenix project -The Phoenix project could be either a Web project or API project. +The Phoenix project could be either a Web or API project. -- Web project is including HTML and Webpack configuration, which was generated by `mix phx.new AppName`. +- Web variant supports HTML and Webpack configuration. -- API project is NOT including HTML and Webpack configuration, which was generated by `mix phx.new AppName --no-html --no-webpack`. +```bash +mix phx.new awesome_project +``` -Aside from that, it could also be a Custom project, which contains the custom OTP app name or custom module name. +- LiveView project is including HTML and Webpack configuration. -- `mix phx.new AppName --module=CustomModuleName` -- `mix phx.new AppName --app=custom_otp_app_name` -- `mix phx.new AppName --module=CustomModuleName --app=custom_otp_app_name` +```bash +mix phx.new awesome_project --live +``` + +- API variant does NOT support HTML and Webpack configuration. + +```bash +mix phx.new awesome_project --no-html --no-webpack +``` + +- Custom project variant allow us to modify the app name or module name. + +```bash +# Use CustomModuleName +mix phx.new awesome_project --module=CustomModuleName + +# Use custom OTP app name +mix phx.new awesome_project --app=custom_otp_app_name + +# Use custom module and app name +mix phx.new awesome_project --module=CustomModuleName --app=custom_otp_app_name +``` So it ends up with 6 project types: -- Standard Web project (`mix phx.new AppName`) -- Custom Web project (`mix phx.new AppName --module=CustomModuleName --app=custom_otp_app_name`) -- Standard API project (`mix phx.new AppName --no-html --no-webpack`) -- Custom API project (`mix phx.new AppName --no-html --no-webpack --module=CustomModuleName --app=custom_otp_app_name`) -- Standard LiveView project (`mix phx.new AppName --live`) -- Custom LiveView project (`mix phx.new AppName --live --module=CustomModuleName --app=custom_otp_app_name`) +Web project +- Standard (`mix phx.new awesome_project`) +- Custom (`mix phx.new awesome_project --module=CustomModuleName --app=custom_otp_app_name`) + +API project +- Standard (`mix phx.new awesome_project --no-html --no-webpack`) +- Custom (`mix phx.new awesome_project --no-html --no-webpack --module=CustomModuleName --app=custom_otp_app_name`) + +LiveView project +- Standard (`mix phx.new awesome_project --live`) +- Custom (`mix phx.new awesome_project --live --module=CustomModuleName --app=custom_otp_app_name`) -Putting it all together, it is 8 variant test cases. +Putting it all together, there are 8 variants of test cases. - Applying the `API variant` to a `Standard Web project` - Applying the `API variant` to a `Custom Web project` @@ -119,20 +167,47 @@ Putting it all together, it is 8 variant test cases. - Applying the `Live variant` to a `Standard LiveView project` - Applying the `Live variant` to a `Custom LiveView project` +##### 2.2/ Mix project + +The Mix project could be either a Standard project or a Custom project. + +- `mix new awesome_project` +- `mix new awesome_project --module=CustomModuleName` +- `mix new awesome_project --app=custom_otp_app_name` +- `mix new awesome_project --module=CustomModuleName --app=custom_otp_app_name` + +Each project could be include the `supervision tree` or not. + +- `mix new awesome_project` +- `mix new awesome_project --sup` +- `mix new awesome_project --module=CustomModuleName --app=custom_otp_app_name` +- `mix new awesome_project --module=CustomModuleName --app=custom_otp_app_name --sup` + +Putting it all together, it will has 4 variant test cases. + +- Applying the `Mix variant` to a `Standard Mix project` +- Applying the `Mix variant` to a `Custom Mix project` +- Applying the `Mix variant` to a `Standard Mix project with the --sup option` +- Applying the `Mix variant` to a `Custom Mix project with the --sup option` + ### Release Set the `HEX_API_KEY` as a Github secret (skip this step if it has been done). -The release process follows the [Git flow](https://nimblehq.co/compass/development/version-control/#releases-). +The release process follows the [Git flow](https://nimblehq.co/compass/development/version-control/release-management). Once a `release/` is created, to publish the new version to Hex.pm, the version number in the `mix.ex` file needs to be updated on the release branch before merging. -Once the release branch is merged into the `master` branch, Github Action will automatically publish the template to https://hex.pm/packages/nimble_phx_gen_template. +Once the release branch is merged into the `master` branch, Github Action automatically publishes the template to [https://hex.pm/packages/nimble_template](https://hex.pm/packages/nimble_template). + + +## Contributing + +Contributions, issues, and feature requests are welcome!
Feel free to check [issues page](https://github.com/nimblehq/elixir-templates/issues). ## License -This project is Copyright (c) 2014-2021 Nimble. It is free software, -and may be redistributed under the terms specified in the [LICENSE] file. +This project is Copyright (c) 2014 and onwards. It is free software, and may be redistributed under the terms specified in the [LICENSE] file. [LICENSE]: /LICENSE @@ -146,4 +221,4 @@ We love open source and do our part in sharing our work with the community! See [our other projects][community] or [hire our team][hire] to help build your product. [community]: https://github.com/nimblehq -[hire]: https://nimblehq.co/ +[hire]: https://nimblehq.co diff --git a/action.yml b/action.yml index d07218c4..e8ee3237 100644 --- a/action.yml +++ b/action.yml @@ -7,7 +7,7 @@ inputs: runs: using: "composite" steps: - - name: Install Dependencies + - name: Install Elixir Dependencies run: mix deps.get shell: bash @@ -16,17 +16,23 @@ runs: shell: bash # Y - in response to Fetch and install dependencies? - - name: Create project - run: printf "Y\n" | make create_project PROJECT_DIRECTORY=sample_project OPTIONS="${{ inputs.new_project_options }}" + - name: Create Phoenix project + run: printf "Y\n" | make create_phoenix_project PROJECT_DIRECTORY=sample_project OPTIONS="${{ inputs.new_project_options }}" shell: bash - - name: Apply template - run: make apply_template PROJECT_DIRECTORY=sample_project VARIANT=${{ inputs.variant }} + - name: Apply Phoenix template + run: make apply_phoenix_template PROJECT_DIRECTORY=sample_project VARIANT=${{ inputs.variant }} shell: bash - name: Install Elixir Dependencies run: cd sample_project && mix deps.get shell: bash + + - name: Compile dependencies + run: cd sample_project && mix compile --warnings-as-errors --all-warnings + shell: bash + env: + MIX_ENV: test - name: Install Node Dependencies run: cd sample_project && npm install --prefix assets @@ -52,16 +58,16 @@ runs: env: MIX_ENV: test DB_HOST: localhost - + - name: Run mix test - run: cd sample_project && mix do compile --warnings-as-errors, coverage + run: cd sample_project && mix coverage shell: bash env: MIX_ENV: test DB_HOST: localhost - - name: Remove nimble_phx_gen_template - run: make remove_nimble_phx_gen_template PROJECT_DIRECTORY=sample_project + - name: Remove nimble_template + run: make remove_nimble_template PROJECT_DIRECTORY=sample_project shell: bash - name: Build release app diff --git a/lib/mix/tasks/nimble.phx.gen.template.ex b/lib/mix/tasks/nimble.phx.gen.template.ex deleted file mode 100644 index a539e8fa..00000000 --- a/lib/mix/tasks/nimble.phx.gen.template.ex +++ /dev/null @@ -1,39 +0,0 @@ -defmodule Mix.Tasks.Nimble.Phx.Gen.Template do - @shortdoc "Generates Nimble's Phoenix template" - - use Mix.Task - - alias Nimble.Phx.Gen.Template.{Project, Template} - - @version Mix.Project.config()[:version] - @variants [api: :boolean, web: :boolean, live: :boolean] - - def run([args]) when args in ~w(-v --version) do - Mix.shell().info("Nimble.Phx.Gen.Template v#{@version}") - end - - def run(args) do - if Mix.Project.umbrella?() do - Mix.raise("mix nimble.phx.gen.template can only be run inside an application directory") - end - - {opts, _params} = parse_opts(args) - - {:ok, _} = Application.ensure_all_started(:httpoison) - - Template.apply(Project.new(opts)) - end - - defp parse_opts(args) do - case OptionParser.parse(args, strict: @variants) do - {opts, args, []} -> - {opts, args} - - {_opts, _args, [switch | _]} -> - Mix.raise("Invalid option: " <> humanize_variant_option(switch)) - end - end - - defp humanize_variant_option({name, nil}), do: name - defp humanize_variant_option({name, val}), do: name <> "=" <> val -end diff --git a/lib/mix/tasks/nimble_template.gen.ex b/lib/mix/tasks/nimble_template.gen.ex new file mode 100644 index 00000000..85533749 --- /dev/null +++ b/lib/mix/tasks/nimble_template.gen.ex @@ -0,0 +1,59 @@ +defmodule Mix.Tasks.NimbleTemplate.Gen do + @shortdoc "Apply Nimble's Elixir/Phoenix template" + + @moduledoc """ + #{@shortdoc} + + - Hex package: https://hex.pm/packages/nimble_template + - Github: https://github.com/nimblehq/elixir-templates + + # Usage + + - mix help nimble_template.gen # Print help + - mix nimble_template.gen -v # Print the version + + ### Phoenix application + + - mix nimble_template.gen --api # Apply the Phoenix API template + - mix nimble_template.gen --live # Apply the Phoenix LiveView template + - mix nimble_template.gen --web # Apply the Phoenix Web template + + ### Non-Phoenix application + + - mix nimble_template.gen --mix # Apply the Mix template + """ + + use Mix.Task + + alias NimbleTemplate.{Project, Template} + + @version Mix.Project.config()[:version] + @variants [api: :boolean, web: :boolean, live: :boolean, mix: :boolean] + + def run([args]) when args in ~w(-v --version), do: Mix.shell().info("NimbleTemplate v#{@version}") + + def run(args) do + if Mix.Project.umbrella?() do + Mix.raise("mix nimble_template.gen can only be run inside an application directory") + end + + {opts, _params} = parse_opts(args) + + {:ok, _} = Application.ensure_all_started(:httpoison) + + Template.apply(Project.new(opts)) + end + + defp parse_opts(args) do + case OptionParser.parse(args, strict: @variants) do + {opts, args, []} -> + {opts, args} + + {_opts, _args, [switch | _]} -> + Mix.raise("Invalid option: " <> humanize_variant_option(switch)) + end + end + + defp humanize_variant_option({name, nil}), do: name + defp humanize_variant_option({name, val}), do: name <> "=" <> val +end diff --git a/lib/nimble.phx.gen.template/addons/elixir_version.ex b/lib/nimble.phx.gen.template/addons/elixir_version.ex deleted file mode 100644 index 66d463df..00000000 --- a/lib/nimble.phx.gen.template/addons/elixir_version.ex +++ /dev/null @@ -1,38 +0,0 @@ -defmodule Nimble.Phx.Gen.Template.Addons.ElixirVersion do - use Nimble.Phx.Gen.Template.Addon - - @impl true - def do_apply(%Project{} = project, _opts) do - project - |> copy_files() - |> edit_files() - end - - defp copy_files( - %Project{ - erlang_asdf_version: erlang_asdf_version, - elixir_asdf_version: elixir_asdf_version - } = project - ) do - Generator.copy_file([{:eex, ".tool-versions.eex", ".tool-versions"}], - erlang_asdf_version: erlang_asdf_version, - elixir_asdf_version: elixir_asdf_version - ) - - project - end - - defp edit_files(%Project{elixir_mix_version: elixir_mix_version} = project) do - Generator.replace_content( - "mix.exs", - """ - elixir: "~> 1.7", - """, - """ - elixir: "~> #{elixir_mix_version}", - """ - ) - - project - end -end diff --git a/lib/nimble.phx.gen.template/addons/github.ex b/lib/nimble.phx.gen.template/addons/github.ex deleted file mode 100644 index ac2d0fad..00000000 --- a/lib/nimble.phx.gen.template/addons/github.ex +++ /dev/null @@ -1,40 +0,0 @@ -defmodule Nimble.Phx.Gen.Template.Addons.Github do - use Nimble.Phx.Gen.Template.Addon - - @versions %{ - otp_version: "23.0.2", - elixir_version: "1.10.4" - } - - @impl true - def do_apply(%Project{} = project, opts) when is_map_key(opts, :github_template) do - files = [ - {:text, Path.join([".github", "ISSUE_TEMPLATE.md"]), - Path.join([".github", "ISSUE_TEMPLATE.md"])}, - {:text, Path.join([".github", "PULL_REQUEST_TEMPLATE.md"]), - Path.join([".github", "PULL_REQUEST_TEMPLATE.md"])} - ] - - Generator.copy_file(files) - - project - end - - @impl true - def do_apply(%Project{web_project?: web_project?} = project, opts) - when is_map_key(opts, :github_action) do - binding = [ - otp_version: @versions.otp_version, - elixir_version: @versions.elixir_version, - web_project?: web_project? - ] - - files = [ - {:eex, ".github/workflows/test.yml.eex", ".github/workflows/test.yml"} - ] - - Generator.copy_file(files, binding) - - project - end -end diff --git a/lib/nimble.phx.gen.template/addons/readme.ex b/lib/nimble.phx.gen.template/addons/readme.ex deleted file mode 100644 index 834ff6b4..00000000 --- a/lib/nimble.phx.gen.template/addons/readme.ex +++ /dev/null @@ -1,32 +0,0 @@ -defmodule Nimble.Phx.Gen.Template.Addons.Readme do - use Nimble.Phx.Gen.Template.Addon - - @impl true - def do_apply(%Project{} = project, _opts) do - project - |> delete_files() - |> copy_files() - end - - def delete_files(project) do - File.rm("README.md") - - project - end - - defp copy_files( - %Project{ - api_project?: api_project?, - erlang_asdf_version: erlang_asdf_version, - elixir_mix_version: elixir_mix_version - } = project - ) do - Generator.copy_file([{:eex, "README.md.eex", "README.md"}], - erlang_version: erlang_asdf_version, - elixir_version: elixir_mix_version, - web_project?: !api_project? - ) - - project - end -end diff --git a/lib/nimble.phx.gen.template/http_client/http_adapter.ex b/lib/nimble.phx.gen.template/http_client/http_adapter.ex deleted file mode 100644 index 1f177d9b..00000000 --- a/lib/nimble.phx.gen.template/http_client/http_adapter.ex +++ /dev/null @@ -1,3 +0,0 @@ -defmodule Nimble.Phx.Gen.Template.HttpClient.HttpAdapter do - use HTTPoison.Base -end diff --git a/lib/nimble.phx.gen.template/variants/api/template.ex b/lib/nimble.phx.gen.template/variants/api/template.ex deleted file mode 100644 index 60f3e0cf..00000000 --- a/lib/nimble.phx.gen.template/variants/api/template.ex +++ /dev/null @@ -1,7 +0,0 @@ -defmodule Nimble.Phx.Gen.Template.Api.Template do - alias Nimble.Phx.Gen.Template.Project - - def apply(%Project{} = project) do - project - end -end diff --git a/lib/nimble.phx.gen.template/variants/live/template.ex b/lib/nimble.phx.gen.template/variants/live/template.ex deleted file mode 100644 index 5d85d74b..00000000 --- a/lib/nimble.phx.gen.template/variants/live/template.ex +++ /dev/null @@ -1,10 +0,0 @@ -defmodule Nimble.Phx.Gen.Template.Live.Template do - alias Nimble.Phx.Gen.Template.Project - alias Nimble.Phx.Gen.Template.Web.Template, as: WebTemplate - - def apply(%Project{} = project) do - WebTemplate.apply(project) - - project - end -end diff --git a/lib/nimble.phx.gen.template/addon.ex b/lib/nimble_template/addon.ex similarity index 76% rename from lib/nimble.phx.gen.template/addon.ex rename to lib/nimble_template/addon.ex index dda68391..19d86f23 100644 --- a/lib/nimble.phx.gen.template/addon.ex +++ b/lib/nimble_template/addon.ex @@ -1,5 +1,7 @@ -defmodule Nimble.Phx.Gen.Template.Addon do - alias Nimble.Phx.Gen.Template.{Addon, Project} +defmodule NimbleTemplate.Addon do + @moduledoc false + + alias NimbleTemplate.{Addon, Project} @callback apply(%Project{}, %{}) :: %Project{} @callback do_apply(%Project{}, %{}) :: %Project{} @@ -8,8 +10,8 @@ defmodule Nimble.Phx.Gen.Template.Addon do quote location: :keep, bind_quoted: [opts: opts] do @behaviour Addon - alias Nimble.Phx.Gen.Template.{Generator, Project} - alias Nimble.Phx.Gen.Template.Hex.Package + alias NimbleTemplate.{Generator, Project} + alias NimbleTemplate.Hex.Package def apply(%Project{} = project, opts \\ %{}) when is_map(opts) do Generator.print_log("* applying ", inspect(__MODULE__)) diff --git a/lib/nimble.phx.gen.template/addons/credo.ex b/lib/nimble_template/addons/credo.ex similarity index 66% rename from lib/nimble.phx.gen.template/addons/credo.ex rename to lib/nimble_template/addons/credo.ex index 74e2139c..43be4a91 100644 --- a/lib/nimble.phx.gen.template/addons/credo.ex +++ b/lib/nimble_template/addons/credo.ex @@ -1,5 +1,7 @@ -defmodule Nimble.Phx.Gen.Template.Addons.Credo do - use Nimble.Phx.Gen.Template.Addon +defmodule NimbleTemplate.Addons.Credo do + @moduledoc false + + use NimbleTemplate.Addon @impl true def do_apply(%Project{} = project, _opts) do @@ -28,6 +30,20 @@ defmodule Nimble.Phx.Gen.Template.Addons.Credo do project end + defp edit_mix(%Project{mix_project?: true} = project) do + Generator.replace_content( + "mix.exs", + """ + codebase: ["deps.unlock --check-unused", "format --check-formatted"] + """, + """ + codebase: ["deps.unlock --check-unused", "format --check-formatted", "credo --strict"] + """ + ) + + project + end + defp edit_mix(project) do Generator.replace_content( "mix.exs", diff --git a/lib/nimble.phx.gen.template/addons/dialyxir.ex b/lib/nimble_template/addons/dialyxir.ex similarity index 69% rename from lib/nimble.phx.gen.template/addons/dialyxir.ex rename to lib/nimble_template/addons/dialyxir.ex index bc48310e..5e4098a5 100644 --- a/lib/nimble.phx.gen.template/addons/dialyxir.ex +++ b/lib/nimble_template/addons/dialyxir.ex @@ -1,5 +1,7 @@ -defmodule Nimble.Phx.Gen.Template.Addons.Dialyxir do - use Nimble.Phx.Gen.Template.Addon +defmodule NimbleTemplate.Addons.Dialyxir do + @moduledoc false + + use NimbleTemplate.Addon @impl true def do_apply(%Project{} = project, _opts) do diff --git a/lib/nimble.phx.gen.template/addons/docker.ex b/lib/nimble_template/addons/docker.ex similarity index 67% rename from lib/nimble.phx.gen.template/addons/docker.ex rename to lib/nimble_template/addons/docker.ex index b0040e19..8347650b 100644 --- a/lib/nimble.phx.gen.template/addons/docker.ex +++ b/lib/nimble_template/addons/docker.ex @@ -1,5 +1,7 @@ -defmodule Nimble.Phx.Gen.Template.Addons.Docker do - use Nimble.Phx.Gen.Template.Addon +defmodule NimbleTemplate.Addons.Docker do + @moduledoc false + + use NimbleTemplate.Addon @impl true def do_apply( @@ -7,8 +9,9 @@ defmodule Nimble.Phx.Gen.Template.Addons.Docker do web_project?: web_project?, otp_app: otp_app, base_module: base_module, - docker_build_base_image: docker_build_base_image, - docker_app_base_image: docker_app_base_image + alpine_version: alpine_version, + elixir_version: elixir_version, + erlang_version: erlang_version } = project, _opts ) do @@ -22,8 +25,9 @@ defmodule Nimble.Phx.Gen.Template.Addons.Docker do ], otp_app: otp_app, base_module: base_module, - docker_build_base_image: docker_build_base_image, - docker_app_base_image: docker_app_base_image, + alpine_version: alpine_version, + elixir_version: elixir_version, + erlang_version: erlang_version, web_project?: web_project? ) diff --git a/lib/nimble_template/addons/elixir_version.ex b/lib/nimble_template/addons/elixir_version.ex new file mode 100644 index 00000000..ae6b2af0 --- /dev/null +++ b/lib/nimble_template/addons/elixir_version.ex @@ -0,0 +1,21 @@ +defmodule NimbleTemplate.Addons.ElixirVersion do + @moduledoc false + + use NimbleTemplate.Addon + + @impl true + def do_apply( + %Project{ + erlang_version: erlang_version, + elixir_asdf_version: elixir_asdf_version + } = project, + _opts + ) do + Generator.copy_file([{:eex, ".tool-versions.eex", ".tool-versions"}], + erlang_version: erlang_version, + elixir_asdf_version: elixir_asdf_version + ) + + project + end +end diff --git a/lib/nimble.phx.gen.template/addons/ex_coveralls.ex b/lib/nimble_template/addons/ex_coveralls.ex similarity index 82% rename from lib/nimble.phx.gen.template/addons/ex_coveralls.ex rename to lib/nimble_template/addons/ex_coveralls.ex index 426e02c1..50c00f54 100644 --- a/lib/nimble.phx.gen.template/addons/ex_coveralls.ex +++ b/lib/nimble_template/addons/ex_coveralls.ex @@ -1,5 +1,7 @@ -defmodule Nimble.Phx.Gen.Template.Addons.ExCoveralls do - use Nimble.Phx.Gen.Template.Addon +defmodule NimbleTemplate.Addons.ExCoveralls do + @moduledoc false + + use NimbleTemplate.Addon @impl true def do_apply(%Project{} = project, _opts) do @@ -8,13 +10,28 @@ defmodule Nimble.Phx.Gen.Template.Addons.ExCoveralls do |> edit_files() end - defp copy_files(%Project{otp_app: otp_app} = project) do + defp copy_files(%Project{otp_app: otp_app, mix_project?: mix_project?} = project) do binding = [ otp_app: otp_app, minimum_coverage: 100 ] - Generator.copy_file([{:eex, "coveralls.json.eex", "coveralls.json"}], binding) + template_file_path = + if mix_project? do + "coveralls.json.mix.eex" + else + "coveralls.json.eex" + end + + Generator.copy_file([{:eex, template_file_path, "coveralls.json"}], binding) + + project + end + + defp edit_files(%Project{mix_project?: true} = project) do + project + |> inject_mix_dependency() + |> edit_mix() project end diff --git a/lib/nimble.phx.gen.template/addons/ex_machina.ex b/lib/nimble_template/addons/ex_machina.ex similarity index 95% rename from lib/nimble.phx.gen.template/addons/ex_machina.ex rename to lib/nimble_template/addons/ex_machina.ex index 0cc195d8..a4aeca95 100644 --- a/lib/nimble.phx.gen.template/addons/ex_machina.ex +++ b/lib/nimble_template/addons/ex_machina.ex @@ -1,5 +1,7 @@ -defmodule Nimble.Phx.Gen.Template.Addons.ExMachina do - use Nimble.Phx.Gen.Template.Addon +defmodule NimbleTemplate.Addons.ExMachina do + @moduledoc false + + use NimbleTemplate.Addon @impl true def do_apply(%Project{} = project, _opts) do diff --git a/lib/nimble_template/addons/ex_unit.ex b/lib/nimble_template/addons/ex_unit.ex new file mode 100644 index 00000000..50d02535 --- /dev/null +++ b/lib/nimble_template/addons/ex_unit.ex @@ -0,0 +1,22 @@ +defmodule NimbleTemplate.Addons.ExUnit do + @moduledoc false + + use NimbleTemplate.Addon + + @impl true + def do_apply(%Project{} = project, _opts), do: edit_test_helper(project) + + defp edit_test_helper(%Project{} = project) do + Generator.replace_content( + "test/test_helper.exs", + """ + ExUnit.start() + """, + """ + ExUnit.start(capture_log: true) + """ + ) + + project + end +end diff --git a/lib/nimble_template/addons/ex_vcr.ex b/lib/nimble_template/addons/ex_vcr.ex new file mode 100644 index 00000000..ed799752 --- /dev/null +++ b/lib/nimble_template/addons/ex_vcr.ex @@ -0,0 +1,75 @@ +defmodule NimbleTemplate.Addons.ExVCR do + @moduledoc false + + use NimbleTemplate.Addon + + @cassette_directory "test/support/fixtures/vcr_cassettes" + + @impl true + def do_apply(%Project{} = project, _opts) do + project + |> edit_files() + |> create_cassette_directory() + end + + defp edit_files(%Project{} = project) do + project + |> 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}) + + project + end + + defp edit_test_config(project) do + Generator.append_content( + "config/test.exs", + """ + + # Configurations for ExVCR + config :exvcr, + vcr_cassette_library_dir: "#{@cassette_directory}" + """ + ) + + project + end + + defp edit_case(project) do + Generator.inject_content( + "test/support/conn_case.ex", + """ + quote do + """, + """ + use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney + + """ + ) + + Generator.inject_content( + "test/support/data_case.ex", + """ + quote do + """, + """ + use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney + + """ + ) + + project + end + + defp create_cassette_directory(project) do + Generator.make_directory(@cassette_directory) + + project + end +end diff --git a/lib/nimble_template/addons/github.ex b/lib/nimble_template/addons/github.ex new file mode 100644 index 00000000..4878171e --- /dev/null +++ b/lib/nimble_template/addons/github.ex @@ -0,0 +1,54 @@ +defmodule NimbleTemplate.Addons.Github do + @moduledoc false + + use NimbleTemplate.Addon + + @impl true + def do_apply(%Project{} = project, opts) when is_map_key(opts, :github_template) do + files = [ + {:text, Path.join([".github", "ISSUE_TEMPLATE.md"]), + Path.join([".github", "ISSUE_TEMPLATE.md"])}, + {:text, Path.join([".github", "PULL_REQUEST_TEMPLATE.md"]), + Path.join([".github", "PULL_REQUEST_TEMPLATE.md"])} + ] + + Generator.copy_file(files) + + project + end + + @impl true + def do_apply( + %Project{ + web_project?: web_project?, + mix_project?: mix_project?, + erlang_version: erlang_version, + elixir_version: elixir_version, + node_version: node_version + } = project, + opts + ) + when is_map_key(opts, :github_action) do + binding = [ + erlang_version: erlang_version, + elixir_version: elixir_version, + node_version: node_version, + web_project?: web_project? + ] + + template_file_path = + if mix_project? do + ".github/workflows/test.yml.mix.eex" + else + ".github/workflows/test.yml.eex" + end + + files = [ + {:eex, template_file_path, ".github/workflows/test.yml"} + ] + + Generator.copy_file(files, binding) + + project + end +end diff --git a/lib/nimble.phx.gen.template/addons/makefile.ex b/lib/nimble_template/addons/makefile.ex similarity index 61% rename from lib/nimble.phx.gen.template/addons/makefile.ex rename to lib/nimble_template/addons/makefile.ex index 1154f4a5..b9c277f8 100644 --- a/lib/nimble.phx.gen.template/addons/makefile.ex +++ b/lib/nimble_template/addons/makefile.ex @@ -1,5 +1,7 @@ -defmodule Nimble.Phx.Gen.Template.Addons.Makefile do - use Nimble.Phx.Gen.Template.Addon +defmodule NimbleTemplate.Addons.Makefile do + @moduledoc false + + use NimbleTemplate.Addon @impl true def do_apply(%Project{} = project, _opts) do diff --git a/lib/nimble.phx.gen.template/addons/mimic.ex b/lib/nimble_template/addons/mimic.ex similarity index 87% rename from lib/nimble.phx.gen.template/addons/mimic.ex rename to lib/nimble_template/addons/mimic.ex index 2ff2ec5d..ccf17ca1 100644 --- a/lib/nimble.phx.gen.template/addons/mimic.ex +++ b/lib/nimble_template/addons/mimic.ex @@ -1,5 +1,7 @@ -defmodule Nimble.Phx.Gen.Template.Addons.Mimic do - use Nimble.Phx.Gen.Template.Addon +defmodule NimbleTemplate.Addons.Mimic do + @moduledoc false + + use NimbleTemplate.Addon @impl true def do_apply(%Project{} = project, _opts) do diff --git a/lib/nimble.phx.gen.template/addons/mix_release.ex b/lib/nimble_template/addons/mix_release.ex similarity index 96% rename from lib/nimble.phx.gen.template/addons/mix_release.ex rename to lib/nimble_template/addons/mix_release.ex index 258f5c49..ec815f1e 100644 --- a/lib/nimble.phx.gen.template/addons/mix_release.ex +++ b/lib/nimble_template/addons/mix_release.ex @@ -1,5 +1,7 @@ -defmodule Nimble.Phx.Gen.Template.Addons.MixRelease do - use Nimble.Phx.Gen.Template.Addon +defmodule NimbleTemplate.Addons.MixRelease do + @moduledoc false + + use NimbleTemplate.Addon @prod_secret_path "config/prod.secret.exs" diff --git a/lib/nimble.phx.gen.template/addons/oban.ex b/lib/nimble_template/addons/oban.ex similarity index 96% rename from lib/nimble.phx.gen.template/addons/oban.ex rename to lib/nimble_template/addons/oban.ex index 90228403..3c8f06fc 100644 --- a/lib/nimble.phx.gen.template/addons/oban.ex +++ b/lib/nimble_template/addons/oban.ex @@ -1,5 +1,7 @@ -defmodule Nimble.Phx.Gen.Template.Addons.Oban do - use Nimble.Phx.Gen.Template.Addon +defmodule NimbleTemplate.Addons.Oban do + @moduledoc false + + use NimbleTemplate.Addon @impl true def do_apply(%Project{} = project, _opts) do diff --git a/lib/nimble_template/addons/readme.ex b/lib/nimble_template/addons/readme.ex new file mode 100644 index 00000000..43297998 --- /dev/null +++ b/lib/nimble_template/addons/readme.ex @@ -0,0 +1,42 @@ +defmodule NimbleTemplate.Addons.Readme do + @moduledoc false + + use NimbleTemplate.Addon + + @impl true + def do_apply(%Project{} = project, _opts) do + project + |> delete_files() + |> copy_files() + end + + def delete_files(project) do + File.rm("README.md") + + project + end + + defp copy_files( + %Project{ + web_project?: web_project?, + mix_project?: mix_project?, + erlang_version: erlang_version, + elixir_version: elixir_version + } = project + ) do + template_file_path = + if mix_project? do + "README.md.mix.eex" + else + "README.md.eex" + end + + Generator.copy_file([{:eex, template_file_path, "README.md"}], + erlang_version: erlang_version, + elixir_version: elixir_version, + web_project?: web_project? + ) + + project + end +end diff --git a/lib/nimble.phx.gen.template/addons/test_env.ex b/lib/nimble_template/addons/test_env.ex similarity index 67% rename from lib/nimble.phx.gen.template/addons/test_env.ex rename to lib/nimble_template/addons/test_env.ex index f4e66a5b..1078d662 100644 --- a/lib/nimble.phx.gen.template/addons/test_env.ex +++ b/lib/nimble_template/addons/test_env.ex @@ -1,5 +1,15 @@ -defmodule Nimble.Phx.Gen.Template.Addons.TestEnv do - use Nimble.Phx.Gen.Template.Addon +defmodule NimbleTemplate.Addons.TestEnv do + @moduledoc false + + use NimbleTemplate.Addon + + @impl true + def do_apply(%Project{mix_project?: true} = project, _opts) do + project + |> edit_mix() + |> edit_formatter_exs() + |> edit_test_helper() + end @impl true def do_apply(%Project{} = project, _opts) do @@ -11,6 +21,42 @@ defmodule Nimble.Phx.Gen.Template.Addons.TestEnv do |> edit_test_support_cases() end + defp edit_mix(%Project{mix_project?: true} = project) do + Generator.replace_content( + "mix.exs", + """ + deps: deps() + """, + """ + elixirc_paths: elixirc_paths(Mix.env()), + aliases: aliases(), + deps: deps() + """ + ) + + Generator.replace_content( + "mix.exs", + """ + # Run "mix help deps" to learn about dependencies. + """, + """ + defp aliases do + [ + codebase: ["deps.unlock --check-unused", "format --check-formatted"] + ] + end + + # Specifies which paths to compile per environment. + defp elixirc_paths(:test), do: ["lib", "test/support"] + defp elixirc_paths(_), do: ["lib"] + + # Run "mix help deps" to learn about dependencies. + """ + ) + + project + end + defp edit_mix(project) do Generator.inject_content( "mix.exs", diff --git a/lib/nimble.phx.gen.template/addons/variants/api/.keep b/lib/nimble_template/addons/variants/mix/.keep similarity index 100% rename from lib/nimble.phx.gen.template/addons/variants/api/.keep rename to lib/nimble_template/addons/variants/mix/.keep diff --git a/lib/nimble.phx.gen.template/addons/variants/live/.keep b/lib/nimble_template/addons/variants/phoenix/api/.keep similarity index 100% rename from lib/nimble.phx.gen.template/addons/variants/live/.keep rename to lib/nimble_template/addons/variants/phoenix/api/.keep diff --git a/test/nimble.phx.gen.template/addons/variants/api/.keep b/lib/nimble_template/addons/variants/phoenix/live/.keep similarity index 100% rename from test/nimble.phx.gen.template/addons/variants/api/.keep rename to lib/nimble_template/addons/variants/phoenix/live/.keep diff --git a/lib/nimble.phx.gen.template/addons/variants/web/assets.ex b/lib/nimble_template/addons/variants/phoenix/web/assets.ex similarity index 91% rename from lib/nimble.phx.gen.template/addons/variants/web/assets.ex rename to lib/nimble_template/addons/variants/phoenix/web/assets.ex index 5cabe94e..7f921c92 100644 --- a/lib/nimble.phx.gen.template/addons/variants/web/assets.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/assets.ex @@ -1,5 +1,7 @@ -defmodule Nimble.Phx.Gen.Template.Addons.Web.Assets do - use Nimble.Phx.Gen.Template.Addon +defmodule NimbleTemplate.Addons.Phoenix.Web.Assets do + @moduledoc false + + use NimbleTemplate.Addon @impl true def do_apply(%Project{} = project, _opts) do diff --git a/lib/nimble.phx.gen.template/addons/variants/web/core_js.ex b/lib/nimble_template/addons/variants/phoenix/web/core_js.ex similarity index 92% rename from lib/nimble.phx.gen.template/addons/variants/web/core_js.ex rename to lib/nimble_template/addons/variants/phoenix/web/core_js.ex index 93e24d4b..54d044e5 100644 --- a/lib/nimble.phx.gen.template/addons/variants/web/core_js.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/core_js.ex @@ -1,5 +1,7 @@ -defmodule Nimble.Phx.Gen.Template.Addons.Web.CoreJS do - use Nimble.Phx.Gen.Template.Addon +defmodule NimbleTemplate.Addons.Phoenix.Web.CoreJS do + @moduledoc false + + use NimbleTemplate.Addon @impl true def do_apply(%Project{} = project, _opts) do diff --git a/lib/nimble.phx.gen.template/addons/variants/web/sobelow.ex b/lib/nimble_template/addons/variants/phoenix/web/sobelow.ex similarity index 90% rename from lib/nimble.phx.gen.template/addons/variants/web/sobelow.ex rename to lib/nimble_template/addons/variants/phoenix/web/sobelow.ex index 14854bd1..a597b610 100644 --- a/lib/nimble.phx.gen.template/addons/variants/web/sobelow.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/sobelow.ex @@ -1,5 +1,7 @@ -defmodule Nimble.Phx.Gen.Template.Addons.Web.Sobelow do - use Nimble.Phx.Gen.Template.Addon +defmodule NimbleTemplate.Addons.Phoenix.Web.Sobelow do + @moduledoc false + + use NimbleTemplate.Addon @impl true def do_apply(%Project{} = project, _opts) do diff --git a/lib/nimble.phx.gen.template/addons/variants/web/wallaby.ex b/lib/nimble_template/addons/variants/phoenix/web/wallaby.ex similarity index 96% rename from lib/nimble.phx.gen.template/addons/variants/web/wallaby.ex rename to lib/nimble_template/addons/variants/phoenix/web/wallaby.ex index 451d8481..2d489759 100644 --- a/lib/nimble.phx.gen.template/addons/variants/web/wallaby.ex +++ b/lib/nimble_template/addons/variants/phoenix/web/wallaby.ex @@ -1,5 +1,7 @@ -defmodule Nimble.Phx.Gen.Template.Addons.Web.Wallaby do - use Nimble.Phx.Gen.Template.Addon +defmodule NimbleTemplate.Addons.Phoenix.Web.Wallaby do + @moduledoc false + + use NimbleTemplate.Addon @impl true def do_apply(%Project{} = project, _opts) do diff --git a/lib/nimble.phx.gen.template/generator.ex b/lib/nimble_template/generator.ex similarity index 65% rename from lib/nimble.phx.gen.template/generator.ex rename to lib/nimble_template/generator.ex index ca035a3c..376ba90e 100644 --- a/lib/nimble.phx.gen.template/generator.ex +++ b/lib/nimble_template/generator.ex @@ -1,9 +1,11 @@ -defmodule Nimble.Phx.Gen.Template.Generator do - @template_resource "priv/templates/nimble.phx.gen.template" +defmodule NimbleTemplate.Generator do + @moduledoc false + + @template_resource "priv/templates/nimble_template" def copy_file(files, binding \\ []) do Mix.Phoenix.copy_from( - [:nimble_phx_gen_template], + [:nimble_template], @template_resource, binding, files @@ -54,6 +56,19 @@ defmodule Nimble.Phx.Gen.Template.Generator do end end + 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 + + print_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( "mix.exs", @@ -78,6 +93,18 @@ defmodule Nimble.Phx.Gen.Template.Generator do ) end + def make_directory(path, touch_directory \\ true) do + case File.mkdir_p(path) do + :ok -> + :ok + + {:error, reason} -> + Mix.raise(~s[Failed to make directory #{path} reason: #{Atom.to_string(reason)}]) + end + + create_keep_file(path, touch_directory) + end + def print_log(prefix, content \\ ""), do: Mix.shell().info([:green, prefix, :reset, content]) defp split_with_self(contents, text) do @@ -86,4 +113,16 @@ defmodule Nimble.Phx.Gen.Template.Generator do [_] -> :error end end + + defp create_keep_file(path, true) do + case File.touch("#{path}/.keep") do + :ok -> + :ok + + {:error, reason} -> + Mix.raise(~s[Failed to create .keep file at #{path}, reason: #{Atom.to_string(reason)}]) + end + end + + defp create_keep_file(_path, _touch_directory), do: :ok end diff --git a/lib/nimble.phx.gen.template/hex/hex_client.ex b/lib/nimble_template/hex/hex_client.ex similarity index 75% rename from lib/nimble.phx.gen.template/hex/hex_client.ex rename to lib/nimble_template/hex/hex_client.ex index d8b71703..3fd497ca 100644 --- a/lib/nimble.phx.gen.template/hex/hex_client.ex +++ b/lib/nimble_template/hex/hex_client.ex @@ -1,5 +1,7 @@ -defmodule Nimble.Phx.Gen.Template.Hex.HexClient do - alias Nimble.Phx.Gen.Template.HttpClient.HttpAdapter +defmodule NimbleTemplate.Hex.HexClient do + @moduledoc false + + alias NimbleTemplate.HttpClient.HttpAdapter @base_url "https://hex.pm/api/" diff --git a/lib/nimble.phx.gen.template/hex/package.ex b/lib/nimble_template/hex/package.ex similarity index 64% rename from lib/nimble.phx.gen.template/hex/package.ex rename to lib/nimble_template/hex/package.ex index e5a06296..402e9ed7 100644 --- a/lib/nimble.phx.gen.template/hex/package.ex +++ b/lib/nimble_template/hex/package.ex @@ -1,5 +1,7 @@ -defmodule Nimble.Phx.Gen.Template.Hex.Package do - alias Nimble.Phx.Gen.Template.Hex.HexClient +defmodule NimbleTemplate.Hex.Package do + @moduledoc false + + alias NimbleTemplate.Hex.HexClient def get_latest_version(package) do {:ok, package_info} = HexClient.get("packages/#{package}") diff --git a/lib/nimble_template/http_client/http_adapter.ex b/lib/nimble_template/http_client/http_adapter.ex new file mode 100644 index 00000000..e59660ba --- /dev/null +++ b/lib/nimble_template/http_client/http_adapter.ex @@ -0,0 +1,5 @@ +defmodule NimbleTemplate.HttpClient.HttpAdapter do + @moduledoc false + + use HTTPoison.Base +end diff --git a/lib/nimble.phx.gen.template/project.ex b/lib/nimble_template/project.ex similarity index 55% rename from lib/nimble.phx.gen.template/project.ex rename to lib/nimble_template/project.ex index 4616ded4..87844838 100644 --- a/lib/nimble.phx.gen.template/project.ex +++ b/lib/nimble_template/project.ex @@ -1,46 +1,44 @@ -defmodule Nimble.Phx.Gen.Template.Project do - # Erlang versions: asdf list all erlang - # Elixir versions: asdf list all elixir - @default_versions %{ - erlang_asdf_version: "23.2.1", - elixir_asdf_version: "1.11.3-otp-23", - elixir_mix_version: "1.11.3" - } - - # Elixir image tags: https://hub.docker.com/r/hexpm/elixir/tags - @docker_base_images %{ - build: "hexpm/elixir:1.11.3-erlang-23.2.1-alpine-3.12.1", - app: "alpine:3.12.1" - } - - defstruct otp_app: nil, - base_module: nil, +defmodule NimbleTemplate.Project do + @moduledoc false + + @alpine_version "3.13.2" + @elixir_version "1.11.4" + @erlang_version "23.3" + @node_version "14" + + defstruct base_module: nil, base_path: nil, base_test_path: nil, + otp_app: nil, web_module: nil, web_path: nil, web_test_path: nil, + # Dependency Versions + alpine_version: @alpine_version, + elixir_version: @elixir_version, + elixir_asdf_version: + "#{@elixir_version}-otp-#{@erlang_version |> String.split(".") |> List.first()}", + erlang_version: @erlang_version, + node_version: @node_version, + # Variants api_project?: false, - web_project?: false, live_project?: false, - erlang_asdf_version: @default_versions[:erlang_asdf_version], - elixir_asdf_version: @default_versions[:elixir_asdf_version], - elixir_mix_version: @default_versions[:elixir_mix_version], - docker_build_base_image: @docker_base_images[:build], - docker_app_base_image: @docker_base_images[:app] + web_project?: false, + mix_project?: false def new(opts \\ %{}) do %__MODULE__{ - api_project?: api_project?(opts), - web_project?: web_project?(opts), - live_project?: live_project?(opts), - otp_app: otp_app(), base_module: base_module(), base_path: "lib/" <> Atom.to_string(otp_app()), base_test_path: "test/" <> Atom.to_string(otp_app()), + otp_app: otp_app(), web_module: base_module() <> "Web", web_path: "lib/" <> Atom.to_string(otp_app()) <> "_web", - web_test_path: "test/" <> Atom.to_string(otp_app()) <> "_web" + web_test_path: "test/" <> Atom.to_string(otp_app()) <> "_web", + api_project?: api_project?(opts), + web_project?: web_project?(opts), + live_project?: live_project?(opts), + mix_project?: mix_project?(opts) } end @@ -50,6 +48,8 @@ defmodule Nimble.Phx.Gen.Template.Project do defp live_project?(opts), do: opts[:live] === true + defp mix_project?(opts), do: opts[:mix] === true + defp otp_app(), do: Mix.Phoenix.otp_app() defp base_module(), do: Mix.Phoenix.base() diff --git a/lib/nimble_template/template.ex b/lib/nimble_template/template.ex new file mode 100644 index 00000000..0db74daa --- /dev/null +++ b/lib/nimble_template/template.ex @@ -0,0 +1,37 @@ +defmodule NimbleTemplate.Template do + @moduledoc false + + alias NimbleTemplate.Mix.Template, as: MixTemplate + alias NimbleTemplate.Phoenix.Template, as: PhoenixTemplate + alias NimbleTemplate.Project + + def apply(%Project{mix_project?: true} = project) do + MixTemplate.apply(project) + + fetch_and_install_dependencies() + end + + def apply(%Project{} = project) do + PhoenixTemplate.apply(project) + + fetch_and_install_dependencies() + end + + def host_on_github?(), do: Mix.shell().yes?("\nWill you host this project on Github?") + + def generate_github_template?(), + do: + Mix.shell().yes?( + "\nDo you want to generate the .github/ISSUE_TEMPLATE and .github/PULL_REQUEST_TEMPLATE?" + ) + + def generate_github_action?(), + do: Mix.shell().yes?("\nDo you want to generate the Github Action workflow?") + + def install_addon_prompt?(addon), + do: Mix.shell().yes?("\nWould you like to add the #{addon} addon?") + + defp fetch_and_install_dependencies(), + do: + if(Mix.shell().yes?("\nFetch and install dependencies?"), do: Mix.shell().cmd("mix deps.get")) +end diff --git a/lib/nimble_template/variants/mix/template.ex b/lib/nimble_template/variants/mix/template.ex new file mode 100644 index 00000000..50067dd9 --- /dev/null +++ b/lib/nimble_template/variants/mix/template.ex @@ -0,0 +1,37 @@ +defmodule NimbleTemplate.Mix.Template do + @moduledoc false + + import NimbleTemplate.Template, + only: [ + host_on_github?: 0, + generate_github_template?: 0, + generate_github_action?: 0, + install_addon_prompt?: 1 + ] + + alias NimbleTemplate.{Addons, Project} + + def apply(%Project{} = project) do + project + |> Addons.ElixirVersion.apply() + |> Addons.Readme.apply() + |> Addons.TestEnv.apply() + |> Addons.Credo.apply() + |> Addons.Dialyxir.apply() + |> Addons.ExCoveralls.apply() + + if host_on_github?() do + if generate_github_template?(), + do: Addons.Github.apply(project, %{github_template: true}) + + if generate_github_action?(), + do: Addons.Github.apply(project, %{github_action: true}) + end + + if install_addon_prompt?("Mimic"), do: Addons.Mimic.apply(project) + + Addons.ExUnit.apply(project) + + project + end +end diff --git a/lib/nimble_template/variants/phoenix/api/template.ex b/lib/nimble_template/variants/phoenix/api/template.ex new file mode 100644 index 00000000..443bd77b --- /dev/null +++ b/lib/nimble_template/variants/phoenix/api/template.ex @@ -0,0 +1,9 @@ +defmodule NimbleTemplate.Phoenix.Api.Template do + @moduledoc false + + alias NimbleTemplate.Project + + def apply(%Project{} = project) do + project + end +end diff --git a/lib/nimble_template/variants/phoenix/live/template.ex b/lib/nimble_template/variants/phoenix/live/template.ex new file mode 100644 index 00000000..4175bbbe --- /dev/null +++ b/lib/nimble_template/variants/phoenix/live/template.ex @@ -0,0 +1,12 @@ +defmodule NimbleTemplate.Phoenix.Live.Template do + @moduledoc false + + alias NimbleTemplate.Phoenix.Web.Template, as: WebTemplate + alias NimbleTemplate.Project + + def apply(%Project{} = project) do + WebTemplate.apply(project) + + project + end +end diff --git a/lib/nimble.phx.gen.template/template.ex b/lib/nimble_template/variants/phoenix/template.ex similarity index 56% rename from lib/nimble.phx.gen.template/template.ex rename to lib/nimble_template/variants/phoenix/template.ex index a30e58e8..36b2fecf 100644 --- a/lib/nimble.phx.gen.template/template.ex +++ b/lib/nimble_template/variants/phoenix/template.ex @@ -1,18 +1,29 @@ -defmodule Nimble.Phx.Gen.Template.Template do - alias Nimble.Phx.Gen.Template.Api.Template, as: ApiTemplate - alias Nimble.Phx.Gen.Template.Live.Template, as: LiveTemplate - alias Nimble.Phx.Gen.Template.Web.Template, as: WebTemplate - alias Nimble.Phx.Gen.Template.{Addons, Project} +defmodule NimbleTemplate.Phoenix.Template do + @moduledoc false + + import NimbleTemplate.Template, + only: [ + host_on_github?: 0, + generate_github_template?: 0, + generate_github_action?: 0, + install_addon_prompt?: 1 + ] + + alias NimbleTemplate.Phoenix.Api.Template, as: ApiTemplate + alias NimbleTemplate.Phoenix.Live.Template, as: LiveTemplate + alias NimbleTemplate.Phoenix.Web.Template, as: WebTemplate + alias NimbleTemplate.{Addons, Project} def apply(%Project{} = project) do project |> common_setup() |> variant_setup() - if Mix.shell().yes?("\nFetch and install dependencies?"), do: Mix.shell().cmd("mix deps.get") + Addons.ExUnit.apply(project) + + project end - # Common setup for both API and Web projects defp common_setup(%Project{} = project) do project |> Addons.ElixirVersion.apply() @@ -36,6 +47,7 @@ defmodule Nimble.Phx.Gen.Template.Template do end if install_addon_prompt?("Oban"), do: Addons.Oban.apply(project) + if install_addon_prompt?("ExVCR"), do: Addons.ExVCR.apply(project) project end @@ -47,18 +59,4 @@ defmodule Nimble.Phx.Gen.Template.Template do defp variant_setup(%Project{web_project?: true, live_project?: true} = project), do: LiveTemplate.apply(project) - - defp host_on_github?(), do: Mix.shell().yes?("\nWill you host this project on Github?") - - defp generate_github_template?(), - do: - Mix.shell().yes?( - "\nDo you want to generate the .github/ISSUE_TEMPLATE and .github/PULL_REQUEST_TEMPLATE?" - ) - - defp generate_github_action?(), - do: Mix.shell().yes?("\nDo you want to generate the Github Action workflow?") - - defp install_addon_prompt?(addon), - do: Mix.shell().yes?("\nWould you like to add the #{addon} addon?") end diff --git a/lib/nimble.phx.gen.template/variants/web/template.ex b/lib/nimble_template/variants/phoenix/web/template.ex similarity index 55% rename from lib/nimble.phx.gen.template/variants/web/template.ex rename to lib/nimble_template/variants/phoenix/web/template.ex index 5403ed17..434d2319 100644 --- a/lib/nimble.phx.gen.template/variants/web/template.ex +++ b/lib/nimble_template/variants/phoenix/web/template.ex @@ -1,6 +1,8 @@ -defmodule Nimble.Phx.Gen.Template.Web.Template do - alias Nimble.Phx.Gen.Template.Addons.Web - alias Nimble.Phx.Gen.Template.Project +defmodule NimbleTemplate.Phoenix.Web.Template do + @moduledoc false + + alias NimbleTemplate.Addons.Phoenix.Web + alias NimbleTemplate.Project def apply(%Project{} = project) do project diff --git a/mix.exs b/mix.exs index fded33ed..a89d3519 100644 --- a/mix.exs +++ b/mix.exs @@ -1,12 +1,12 @@ -defmodule NimblePhxGenTemplate.MixProject do +defmodule NimbleTemplate.MixProject do use Mix.Project def project do [ - app: :nimble_phx_gen_template, - version: "2.2.1", - description: "Project repository template to set up all public Phoenix projects at Nimble", - elixir: "~> 1.11.3", + app: :nimble_template, + version: "3.0.0", + description: "Phoenix/Mix template for projects at [Nimble](https://nimblehq.co/).", + elixir: "~> 1.11.4", elixirc_paths: elixirc_paths(Mix.env()), start_permanent: Mix.env() == :prod, deps: deps(), @@ -30,12 +30,12 @@ defmodule NimblePhxGenTemplate.MixProject do # Run "mix help deps" to learn about dependencies. defp deps do [ - {:phoenix, "~> 1.5.7"}, - {:jason, "~> 1.2.2"}, - {:httpoison, "~> 1.7.0"}, - {:mimic, "~> 1.3.1", only: :test}, - {:credo, "~> 1.4.0", only: [:dev, :test], runtime: false}, - {:ex_doc, "~> 0.23.0", only: :dev, runtime: false} + {:credo, "~> 1.4", only: [:dev, :test], runtime: false}, + {:ex_doc, "~> 0.23", only: :dev, runtime: false}, + {:httpoison, "~> 1.7"}, + {:jason, "~> 1.2"}, + {:mimic, "~> 1.3", only: :test}, + {:phoenix, "~> 1.5.7"} ] end diff --git a/mix.lock b/mix.lock index 740450d5..c3d1ab37 100644 --- a/mix.lock +++ b/mix.lock @@ -1,26 +1,28 @@ %{ "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, - "certifi": {:hex, :certifi, "2.5.2", "b7cfeae9d2ed395695dd8201c57a2d019c0c43ecaf8b8bcb9320b40d6662f340", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "3b3b5f36493004ac3455966991eaf6e768ce9884693d9968055aeeeb1e575040"}, - "credo": {:hex, :credo, "1.4.0", "92339d4cbadd1e88b5ee43d427b639b68a11071b6f73854e33638e30a0ea11f5", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1fd3b70dce216574ce3c18bdf510b57e7c4c85c2ec9cad4bff854abaf7e58658"}, - "earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"}, - "ex_doc": {:hex, :ex_doc, "0.23.0", "a069bc9b0bf8efe323ecde8c0d62afc13d308b1fa3d228b65bca5cf8703a529d", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "f5e2c4702468b2fd11b10d39416ddadd2fcdd173ba2a0285ebd92c39827a5a16"}, - "hackney": {:hex, :hackney, "1.16.0", "5096ac8e823e3a441477b2d187e30dd3fff1a82991a806b2003845ce72ce2d84", [:rebar3], [{:certifi, "2.5.2", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.1", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.0", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.6", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "3bf0bebbd5d3092a3543b783bf065165fa5d3ad4b899b836810e513064134e18"}, - "httpoison": {:hex, :httpoison, "1.7.0", "abba7d086233c2d8574726227b6c2c4f6e53c4deae7fe5f6de531162ce9929a0", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "975cc87c845a103d3d1ea1ccfd68a2700c211a434d8428b10c323dc95dc5b980"}, - "idna": {:hex, :idna, "6.0.1", "1d038fb2e7668ce41fbf681d2c45902e52b3cb9e9c77b55334353b222c2ee50c", [:rebar3], [{:unicode_util_compat, "0.5.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "a02c8a1c4fd601215bb0b0324c8a6986749f807ce35f25449ec9e69758708122"}, + "certifi": {:hex, :certifi, "2.6.1", "dbab8e5e155a0763eea978c913ca280a6b544bfa115633fa20249c3d396d9493", [:rebar3], [], "hexpm", "524c97b4991b3849dd5c17a631223896272c6b0af446778ba4675a1dff53bb7e"}, + "credo": {:hex, :credo, "1.5.5", "e8f422026f553bc3bebb81c8e8bf1932f498ca03339856c7fec63d3faac8424b", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "dd8623ab7091956a855dc9f3062486add9c52d310dfd62748779c4315d8247de"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.12", "b245e875ec0a311a342320da0551da407d9d2b65d98f7a9597ae078615af3449", [:mix], [], "hexpm", "711e2cc4d64abb7d566d43f54b78f7dc129308a63bc103fbd88550d2174b3160"}, + "ex_doc": {:hex, :ex_doc, "0.24.2", "e4c26603830c1a2286dae45f4412a4d1980e1e89dc779fcd0181ed1d5a05c8d9", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "e134e1d9e821b8d9e4244687fb2ace58d479b67b282de5158333b0d57c6fb7da"}, + "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, + "hackney": {:hex, :hackney, "1.17.4", "99da4674592504d3fb0cfef0db84c3ba02b4508bae2dff8c0108baa0d6e0977c", [:rebar3], [{:certifi, "~>2.6.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "~>6.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "~>1.0.0", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:parse_trans, "3.3.1", [hex: :parse_trans, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "~>1.1.0", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}, {:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "de16ff4996556c8548d512f4dbe22dd58a587bf3332e7fd362430a7ef3986b16"}, + "httpoison": {:hex, :httpoison, "1.8.0", "6b85dea15820b7804ef607ff78406ab449dd78bed923a49c7160e1886e987a3d", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "28089eaa98cf90c66265b6b5ad87c59a3729bea2e74e9d08f9b51eb9729b3c3a"}, + "idna": {:hex, :idna, "6.1.1", "8a63070e9f7d0c62eb9d9fcb360a7de382448200fbbd1b106cc96d3d8099df8d", [:rebar3], [{:unicode_util_compat, "~>0.7.0", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "92376eb7894412ed19ac475e4a86f7b413c1b9fbb5bd16dccd57934157944cea"}, "jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"}, "makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.15.0", "98312c9f0d3730fde4049985a1105da5155bfe5c11e47bdc7406d88e01e4219b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "75ffa34ab1056b7e24844c90bfc62aaf6f3a37a15faa76b07bc5eba27e4a8b4a"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"}, + "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"}, - "mime": {:hex, :mime, "1.5.0", "203ef35ef3389aae6d361918bf3f952fa17a09e8e43b5aa592b93eba05d0fb8d", [:mix], [], "hexpm", "55a94c0f552249fc1a3dd9cd2d3ab9de9d3c89b559c2bd01121f824834f24746"}, + "mime": {:hex, :mime, "1.6.0", "dabde576a497cef4bbdd60aceee8160e02a6c89250d6c0b29e56c0dfb00db3d2", [:mix], [], "hexpm", "31a1a8613f8321143dde1dafc36006a17d28d02bdfecb9e95a880fa7aabd19a7"}, "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"}, - "mimic": {:hex, :mimic, "1.3.1", "ba1c90b851de9065db81b1e3a16f659e53dffb89d2f4d404db06f67d0b990deb", [:mix], [], "hexpm", "51b74ab8009e0673bf68beba6abfce0e5500c8bec3ad27033c4a8dacbc44d55e"}, + "mimic": {:hex, :mimic, "1.5.0", "ad33740f414412639006afa4092f7bf09f5ddeb51999f94181ff8ad9e5d5d675", [:mix], [], "hexpm", "0f4620b88623c3869a11bd7e5691cccc712290c4bcbf73bf07bfb37c3c6932a4"}, "nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"}, - "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"}, - "phoenix": {:hex, :phoenix, "1.5.7", "2923bb3af924f184459fe4fa4b100bd25fa6468e69b2803dfae82698269aa5e0", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 2.13", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.1.2 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "774cd64417c5a3788414fdbb2be2eb9bcd0c048d9e6ad11a0c1fd67b7c0d0978"}, + "parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"}, + "phoenix": {:hex, :phoenix, "1.5.8", "71cfa7a9bb9a37af4df98939790642f210e35f696b935ca6d9d9c55a884621a4", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_html, "~> 2.13", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.1.2 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "35ded0a32f4836168c7ab6c33b88822eccd201bcd9492125a9bea4c54332d955"}, "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.0.0", "a1ae76717bb168cdeb10ec9d92d1480fec99e3080f011402c0a2d68d47395ffb", [:mix], [], "hexpm", "c52d948c4f261577b9c6fa804be91884b381a7f8f18450c5045975435350f771"}, - "plug": {:hex, :plug, "1.11.0", "f17217525597628298998bc3baed9f8ea1fa3f1160aa9871aee6df47a6e4d38e", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2d9c633f0499f9dc5c2fd069161af4e2e7756890b81adcbb2ceaa074e8308876"}, - "plug_crypto": {:hex, :plug_crypto, "1.2.0", "1cb20793aa63a6c619dd18bb33d7a3aa94818e5fd39ad357051a67f26dfa2df6", [:mix], [], "hexpm", "a48b538ae8bf381ffac344520755f3007cc10bd8e90b240af98ea29b69683fc2"}, + "plug": {:hex, :plug, "1.11.1", "f2992bac66fdae679453c9e86134a4201f6f43a687d8ff1cd1b2862d53c80259", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "23524e4fefbb587c11f0833b3910bfb414bf2e2534d61928e920f54e3a1b881f"}, + "plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"}, - "telemetry": {:hex, :telemetry, "0.4.2", "2808c992455e08d6177322f14d3bdb6b625fbcfd233a73505870d8738a2f4599", [:rebar3], [], "hexpm", "2d1419bd9dda6a206d7b5852179511722e2b18812310d304620c7bd92a13fcef"}, - "unicode_util_compat": {:hex, :unicode_util_compat, "0.5.0", "8516502659002cec19e244ebd90d312183064be95025a319a6c7e89f4bccd65b", [:rebar3], [], "hexpm", "d48d002e15f5cc105a696cf2f1bbb3fc72b4b770a184d8420c8db20da2674b38"}, + "telemetry": {:hex, :telemetry, "0.4.3", "a06428a514bdbc63293cd9a6263aad00ddeb66f608163bdec7c8995784080818", [:rebar3], [], "hexpm", "eb72b8365ffda5bed68a620d1da88525e326cb82a75ee61354fc24b844768041"}, + "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"}, } diff --git a/priv/templates/nimble.phx.gen.template/Dockerfile.eex b/priv/templates/nimble.phx.gen.template/Dockerfile.eex deleted file mode 100644 index d8135612..00000000 --- a/priv/templates/nimble.phx.gen.template/Dockerfile.eex +++ /dev/null @@ -1,53 +0,0 @@ -FROM <%= docker_build_base_image %> AS build - -# install build dependencies -RUN apk add --no-cache build-base npm git && \ - mix local.hex --force && \ - mix local.rebar --force - -# prepare build dir -WORKDIR /app - -# set build ENV -ENV MIX_ENV=prod - -# install mix dependencies -COPY mix.exs mix.lock ./ -COPY config config -RUN mix do deps.get, deps.compile -<%= if web_project? do %> -# build assets -COPY assets/package.json assets/package-lock.json ./assets/ -RUN npm --prefix ./assets ci --progress=false --no-audit --loglevel=error - -COPY priv priv -COPY assets assets -RUN npm run --prefix ./assets deploy -RUN mix phx.digest -<% end %> -# compile and build release -COPY lib lib -# uncomment COPY if rel/ exists -# COPY rel rel -RUN mix do compile, release - -# prepare release image -FROM <%= docker_app_base_image %> AS app - -RUN apk add --no-cache openssl ncurses-libs - -WORKDIR /app - -# Setup non-root user -RUN addgroup -S app_group && \ - adduser -s /bin/sh -G app_group -D app_user && \ - chown app_user:app_group /app - -COPY --from=build --chown=app_user:app_group /app/_build/prod/rel/<%= otp_app %> ./ -COPY bin/start.sh ./bin/start.sh - -ENV HOME=/app - -USER app_user - -CMD bin/start.sh diff --git a/priv/templates/nimble.phx.gen.template/.credo.exs b/priv/templates/nimble_template/.credo.exs similarity index 100% rename from priv/templates/nimble.phx.gen.template/.credo.exs rename to priv/templates/nimble_template/.credo.exs diff --git a/priv/templates/nimble.phx.gen.template/.dockerignore b/priv/templates/nimble_template/.dockerignore similarity index 100% rename from priv/templates/nimble.phx.gen.template/.dockerignore rename to priv/templates/nimble_template/.dockerignore diff --git a/priv/templates/nimble.phx.gen.template/.github/ISSUE_TEMPLATE.md b/priv/templates/nimble_template/.github/ISSUE_TEMPLATE.md similarity index 100% rename from priv/templates/nimble.phx.gen.template/.github/ISSUE_TEMPLATE.md rename to priv/templates/nimble_template/.github/ISSUE_TEMPLATE.md diff --git a/priv/templates/nimble.phx.gen.template/.github/PULL_REQUEST_TEMPLATE.md b/priv/templates/nimble_template/.github/PULL_REQUEST_TEMPLATE.md similarity index 100% rename from priv/templates/nimble.phx.gen.template/.github/PULL_REQUEST_TEMPLATE.md rename to priv/templates/nimble_template/.github/PULL_REQUEST_TEMPLATE.md diff --git a/priv/templates/nimble.phx.gen.template/.github/workflows/test.yml.eex b/priv/templates/nimble_template/.github/workflows/test.yml.eex similarity index 77% rename from priv/templates/nimble.phx.gen.template/.github/workflows/test.yml.eex rename to priv/templates/nimble_template/.github/workflows/test.yml.eex index 5ac67879..a67a05e0 100644 --- a/priv/templates/nimble.phx.gen.template/.github/workflows/test.yml.eex +++ b/priv/templates/nimble_template/.github/workflows/test.yml.eex @@ -1,9 +1,13 @@ name: "Tests" + on: pull_request env: - OTP_VERSION: <%= inspect otp_version %> + OTP_VERSION: <%= inspect erlang_version %> ELIXIR_VERSION: <%= inspect elixir_version %> + NODE_VERSION: <%= inspect node_version %> + MIX_ENV: test + DB_HOST: localhost jobs: test: @@ -22,6 +26,11 @@ jobs: --health-retries 5 steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.8.0 + with: + access_token: ${{ github.token }} + - uses: actions/checkout@v2 with: ref: ${{ github.head_ref }} @@ -30,7 +39,11 @@ jobs: with: otp-version: ${{ env.OTP_VERSION }} elixir-version: ${{ env.ELIXIR_VERSION }} - + <%= if web_project? do %> + - uses: actions/setup-node@v2.1.5 + with: + node-version: ${{ env.NODE_VERSION }} + <% end %> - name: Cache Elixir build uses: actions/cache@v2 with: @@ -51,7 +64,10 @@ jobs: <% end %> - name: Install Dependencies run: mix deps.get - + + - name: Compile dependencies + run: mix compile --warnings-as-errors --all-warnings + <%= if web_project? do %> - name: Install node module run: npm --prefix assets install @@ -61,24 +77,15 @@ jobs: <% end %> - name: Create database run: mix ecto.create - env: - MIX_ENV: test - DB_HOST: localhost - name: Migrate database run: mix ecto.migrate - env: - MIX_ENV: test - DB_HOST: localhost - name: Run codebase check run: mix codebase - name: Run Tests - run: mix do compile --warnings-as-errors, coverage - env: - MIX_ENV: test - DB_HOST: localhost + run: mix coverage <%= if web_project? do %> - uses: actions/upload-artifact@v2 if: ${{ failure() }} diff --git a/priv/templates/nimble_template/.github/workflows/test.yml.mix.eex b/priv/templates/nimble_template/.github/workflows/test.yml.mix.eex new file mode 100644 index 00000000..7b466bf1 --- /dev/null +++ b/priv/templates/nimble_template/.github/workflows/test.yml.mix.eex @@ -0,0 +1,49 @@ +name: "Tests" + +on: pull_request + +env: + OTP_VERSION: <%= inspect erlang_version %> + ELIXIR_VERSION: <%= inspect elixir_version %> + MIX_ENV: test + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.8.0 + with: + access_token: ${{ github.token }} + + - uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + + - uses: erlef/setup-elixir@v1 + with: + otp-version: ${{ env.OTP_VERSION }} + elixir-version: ${{ env.ELIXIR_VERSION }} + + - name: Cache Elixir build + uses: actions/cache@v2 + with: + path: | + _build + deps + key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} + restore-keys: | + ${{ runner.os }}-mix- + + - name: Install Dependencies + run: mix deps.get + + - name: Compile dependencies + run: mix compile --warnings-as-errors --all-warnings + + - name: Run codebase check + run: mix codebase + + - name: Run Tests + run: mix coverage diff --git a/priv/templates/nimble.phx.gen.template/.sobelow-conf b/priv/templates/nimble_template/.sobelow-conf similarity index 100% rename from priv/templates/nimble.phx.gen.template/.sobelow-conf rename to priv/templates/nimble_template/.sobelow-conf diff --git a/priv/templates/nimble.phx.gen.template/.tool-versions.eex b/priv/templates/nimble_template/.tool-versions.eex similarity index 72% rename from priv/templates/nimble.phx.gen.template/.tool-versions.eex rename to priv/templates/nimble_template/.tool-versions.eex index bbe8bcb4..8d20812c 100644 --- a/priv/templates/nimble.phx.gen.template/.tool-versions.eex +++ b/priv/templates/nimble_template/.tool-versions.eex @@ -1,3 +1,3 @@ # Configuration file for https://github.com/asdf-vm/asdf -erlang <%= erlang_asdf_version %> +erlang <%= erlang_version %> elixir <%= elixir_asdf_version %> diff --git a/priv/templates/nimble_template/Dockerfile.eex b/priv/templates/nimble_template/Dockerfile.eex new file mode 100644 index 00000000..1afbd53e --- /dev/null +++ b/priv/templates/nimble_template/Dockerfile.eex @@ -0,0 +1,56 @@ +ARG ELIXIR_IMAGE_VERSION=<%= elixir_version %> +ARG ERLANG_IMAGE_VERSION=<%= erlang_version %> +ARG RELEASE_IMAGE_VERSION=<%= alpine_version %> + +FROM hexpm/elixir:${ELIXIR_IMAGE_VERSION}-erlang-${ERLANG_IMAGE_VERSION}-alpine-${RELEASE_IMAGE_VERSION} AS build + +RUN apk update && \ + apk upgrade --no-cache && \ + apk add --no-cache \ + nodejs \ + npm \ + git \ + build-base && \ + mix local.rebar --force && \ + mix local.hex --force + +WORKDIR /app + +COPY . . + +ENV MIX_ENV=prod + +RUN mix do deps.get, deps.compile, compile +<%= if web_project? do %> +RUN cd assets && \ + npm ci --progress=false --no-audit --loglevel=error && \ + npm run deploy && \ + cd - && \ + mix phx.digest +<% end %> + +RUN mix release + +# +# Release +# +FROM alpine:${RELEASE_IMAGE_VERSION} AS app + +RUN apk update && \ + apk add --no-cache \ + bash \ + openssl-dev + +WORKDIR /opt/app +EXPOSE 4000 + +RUN addgroup -g 1000 appuser && \ + adduser -u 1000 -G appuser -g appuser -s /bin/sh -D appuser && \ + chown 1000:1000 /opt/app + +COPY --from=build --chown=1000:1000 /app/_build/prod/rel/<%= otp_app %> ./ +COPY bin/start.sh ./bin/start.sh + +USER app_user + +CMD bin/start.sh diff --git a/priv/templates/nimble.phx.gen.template/Makefile b/priv/templates/nimble_template/Makefile similarity index 100% rename from priv/templates/nimble.phx.gen.template/Makefile rename to priv/templates/nimble_template/Makefile diff --git a/priv/templates/nimble.phx.gen.template/README.md.eex b/priv/templates/nimble_template/README.md.eex similarity index 74% rename from priv/templates/nimble.phx.gen.template/README.md.eex rename to priv/templates/nimble_template/README.md.eex index 65499ab8..c56769e6 100644 --- a/priv/templates/nimble.phx.gen.template/README.md.eex +++ b/priv/templates/nimble_template/README.md.eex @@ -8,11 +8,15 @@ ### Erlang & Elixir -* Erlang <%= erlang_version %> and Elixir <%= elixir_version %> +* Erlang <%= erlang_version %> + +* Elixir <%= elixir_version %> * Recommended version manager. - - [asdf](https://github.com/asdf-vm/asdf) Erlang & Elixir + - [asdf](https://github.com/asdf-vm/asdf) + - [asdf-erlang](https://github.com/asdf-vm/asdf-erlang) + - [asdf-elixir](https://github.com/asdf-vm/asdf-elixir) ### Development @@ -59,6 +63,12 @@ ```sh mix codebase ``` + +* Test coverage: + + ```sh + mix coverage + ``` ### Production diff --git a/priv/templates/nimble_template/README.md.mix.eex b/priv/templates/nimble_template/README.md.mix.eex new file mode 100644 index 00000000..1cb7f107 --- /dev/null +++ b/priv/templates/nimble_template/README.md.mix.eex @@ -0,0 +1,45 @@ +[![Build Status](CI_BADGE_URL goes here)](REPO_URL goes here) + +## Introduction + +> *App introduction goes here ...* + +## Project Setup + +### Erlang & Elixir + +* Erlang <%= erlang_version %> + +* Elixir <%= elixir_version %> + +* Recommended version manager. + + - [asdf](https://github.com/asdf-vm/asdf) + - [asdf-erlang](https://github.com/asdf-vm/asdf-erlang) + - [asdf-elixir](https://github.com/asdf-vm/asdf-elixir) + +### Development + +* Install Elixir dependencies: + + ```sh + mix deps.get + ``` + +* Run all tests: + + ```sh + mix test + ``` + +* Run all lint: + + ```sh + mix codebase + ``` + +* Test coverage: + + ```sh + mix coverage + ``` diff --git a/priv/templates/nimble.phx.gen.template/bin/start.sh.eex b/priv/templates/nimble_template/bin/start.sh.eex similarity index 100% rename from priv/templates/nimble.phx.gen.template/bin/start.sh.eex rename to priv/templates/nimble_template/bin/start.sh.eex diff --git a/priv/templates/nimble.phx.gen.template/config/runtime.exs.eex b/priv/templates/nimble_template/config/runtime.exs.eex similarity index 100% rename from priv/templates/nimble.phx.gen.template/config/runtime.exs.eex rename to priv/templates/nimble_template/config/runtime.exs.eex diff --git a/priv/templates/nimble.phx.gen.template/coveralls.json.eex b/priv/templates/nimble_template/coveralls.json.eex similarity index 100% rename from priv/templates/nimble.phx.gen.template/coveralls.json.eex rename to priv/templates/nimble_template/coveralls.json.eex diff --git a/priv/templates/nimble_template/coveralls.json.mix.eex b/priv/templates/nimble_template/coveralls.json.mix.eex new file mode 100644 index 00000000..ec9de978 --- /dev/null +++ b/priv/templates/nimble_template/coveralls.json.mix.eex @@ -0,0 +1,9 @@ +{ + "skip_files": [ + "lib/<%= otp_app %>/application.ex", + "test/support" + ], + "coverage_options": { + "minimum_coverage": <%= minimum_coverage %> + } +} diff --git a/priv/templates/nimble.phx.gen.template/docker-compose.dev.yml.eex b/priv/templates/nimble_template/docker-compose.dev.yml.eex similarity index 100% rename from priv/templates/nimble.phx.gen.template/docker-compose.dev.yml.eex rename to priv/templates/nimble_template/docker-compose.dev.yml.eex diff --git a/priv/templates/nimble.phx.gen.template/docker-compose.yml.eex b/priv/templates/nimble_template/docker-compose.yml.eex similarity index 100% rename from priv/templates/nimble.phx.gen.template/docker-compose.yml.eex rename to priv/templates/nimble_template/docker-compose.yml.eex diff --git a/priv/templates/nimble.phx.gen.template/lib/otp_app/release_tasks.ex.eex b/priv/templates/nimble_template/lib/otp_app/release_tasks.ex.eex similarity index 100% rename from priv/templates/nimble.phx.gen.template/lib/otp_app/release_tasks.ex.eex rename to priv/templates/nimble_template/lib/otp_app/release_tasks.ex.eex diff --git a/priv/templates/nimble.phx.gen.template/priv/repo/migrations/add_oban_jobs_table.exs.eex b/priv/templates/nimble_template/priv/repo/migrations/add_oban_jobs_table.exs.eex similarity index 100% rename from priv/templates/nimble.phx.gen.template/priv/repo/migrations/add_oban_jobs_table.exs.eex rename to priv/templates/nimble_template/priv/repo/migrations/add_oban_jobs_table.exs.eex diff --git a/priv/templates/nimble.phx.gen.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 similarity index 100% rename from priv/templates/nimble.phx.gen.template/test/features/home_page/view_home_page_test.exs.eex rename to priv/templates/nimble_template/test/features/home_page/view_home_page_test.exs.eex diff --git a/priv/templates/nimble.phx.gen.template/test/support/factory.ex.eex b/priv/templates/nimble_template/test/support/factory.ex.eex similarity index 75% rename from priv/templates/nimble.phx.gen.template/test/support/factory.ex.eex rename to priv/templates/nimble_template/test/support/factory.ex.eex index 20ce910f..b516332e 100644 --- a/priv/templates/nimble.phx.gen.template/test/support/factory.ex.eex +++ b/priv/templates/nimble_template/test/support/factory.ex.eex @@ -2,5 +2,5 @@ defmodule <%= base_module %>.Factory do use ExMachina.Ecto, repo: <%= base_module %>.Repo # Define your factories in /test/factories and declare it here, - # eg: `use <%base_module %>.Accounts.UserFactory` + # eg: `use <%= base_module %>.Accounts.UserFactory` end diff --git a/priv/templates/nimble.phx.gen.template/test/support/feature_case.ex.eex b/priv/templates/nimble_template/test/support/feature_case.ex.eex similarity index 100% rename from priv/templates/nimble.phx.gen.template/test/support/feature_case.ex.eex rename to priv/templates/nimble_template/test/support/feature_case.ex.eex diff --git a/test/nimble.phx.gen.template/addons/credo_test.exs b/test/nimble.phx.gen.template/addons/credo_test.exs deleted file mode 100644 index 0bb1235f..00000000 --- a/test/nimble.phx.gen.template/addons/credo_test.exs +++ /dev/null @@ -1,50 +0,0 @@ -defmodule Nimble.Phx.Gen.Template.Addons.CredoTest do - use Nimble.Phx.Gen.Template.AddonCase - - describe "#apply/2" do - @describetag mock_latest_package_versions: [{:credo, "1.4"}] - @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) - - assert_file(".credo.exs") - end) - end - - test "injects credo to mix dependency", %{ - project: project, - test_project_path: test_project_path - } do - in_test_project(test_project_path, fn -> - Addons.Credo.apply(project) - - assert_file("mix.exs", fn file -> - assert file =~ """ - defp deps do - [ - {:credo, \"~> 1.4\", [only: [:dev, :test], runtime: false]}, - """ - end) - end) - 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) - - assert_file("mix.exs", fn file -> - assert file =~ """ - defp aliases do - [ - codebase: [\"deps.unlock --check-unused\", \"format --check-formatted\", \"credo --strict\"], - """ - end) - end) - end - end -end diff --git a/test/nimble.phx.gen.template/addons/elixir_version_test.exs b/test/nimble.phx.gen.template/addons/elixir_version_test.exs deleted file mode 100644 index fb80b5ee..00000000 --- a/test/nimble.phx.gen.template/addons/elixir_version_test.exs +++ /dev/null @@ -1,34 +0,0 @@ -defmodule Nimble.Phx.Gen.Template.Addons.ElixirVersionTest do - use Nimble.Phx.Gen.Template.AddonCase - - describe "#apply/2" do - test "copies the .tool-versions", %{ - project: project, - test_project_path: test_project_path - } do - in_test_project(test_project_path, fn -> - Addons.ElixirVersion.apply(project) - - assert_file(".tool-versions", fn file -> - assert file =~ """ - erlang 23.2.1 - elixir 1.11.3-otp-23 - """ - end) - end) - end - - test "changes the minimum Elixir version", %{ - project: project, - test_project_path: test_project_path - } do - in_test_project(test_project_path, fn -> - Addons.ElixirVersion.apply(project) - - assert_file("mix.exs", fn file -> - assert file =~ "elixir: \"~> 1.11.3\"," - end) - end) - end - end -end diff --git a/test/nimble.phx.gen.template/addons/excoveralls_test.exs b/test/nimble.phx.gen.template/addons/excoveralls_test.exs deleted file mode 100644 index 8db52aa7..00000000 --- a/test/nimble.phx.gen.template/addons/excoveralls_test.exs +++ /dev/null @@ -1,68 +0,0 @@ -defmodule Nimble.Phx.Gen.Template.Addons.ExCoverallsTest do - use Nimble.Phx.Gen.Template.AddonCase - - 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) - - assert_file("coveralls.json") - end) - end - - test "injects excoveralls to mix dependency", %{ - project: project, - test_project_path: test_project_path - } do - in_test_project(test_project_path, fn -> - Addons.ExCoveralls.apply(project) - - assert_file("mix.exs", fn file -> - assert file =~ """ - defp deps do - [ - {:excoveralls, \"~> 0.12.2\", [only: :test]}, - """ - end) - end) - 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) - - assert_file("mix.exs", fn file -> - assert file =~ """ - deps: deps(), - test_coverage: [tool: ExCoveralls], - preferred_cli_env: [ - lint: :test, - coverage: :test, - coveralls: :test, - "coveralls.html": :test - ] - """ - end) - end) - 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) - - assert_file("mix.exs", fn file -> - assert file =~ """ - defp aliases do - [ - coverage: [\"coveralls.html --raise\"], - """ - end) - end) - end - end -end diff --git a/test/nimble.phx.gen.template/addons/github_test.exs b/test/nimble.phx.gen.template/addons/github_test.exs deleted file mode 100644 index b871101e..00000000 --- a/test/nimble.phx.gen.template/addons/github_test.exs +++ /dev/null @@ -1,65 +0,0 @@ -defmodule Nimble.Phx.Gen.Template.Addons.GithubTest do - use Nimble.Phx.Gen.Template.AddonCase - - 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}) - - assert_file(".github/ISSUE_TEMPLATE.md") - end) - end - - test "copies the .github/PULL_REQUEST_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}) - - assert_file(".github/PULL_REQUEST_TEMPLATE.md") - end) - end - end - - describe "#apply/2 with api_project and github_action option" do - test "copies the .credo.exs", %{ - 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: true}) - - assert_file(".github/workflows/test.yml", fn file -> - refute file =~ "assets/node_modules" - refute file =~ "npm --prefix assets install" - refute file =~ "npm run --prefix assets build:dev" - refute file =~ "wallaby_screenshots" - end) - end) - end - end - - describe "#apply/2 with web_project and github_action option" do - test "copies the .credo.exs", %{ - project: project, - test_project_path: test_project_path - } do - in_test_project(test_project_path, fn -> - Addons.Github.apply(project, %{github_action: true}) - - assert_file(".github/workflows/test.yml", fn file -> - assert file =~ "assets/node_modules" - assert file =~ "npm --prefix assets install" - assert file =~ "npm run --prefix assets build:dev" - assert file =~ "wallaby_screenshots" - end) - end) - end - end -end diff --git a/test/nimble.phx.gen.template/addons/readme_test.exs b/test/nimble.phx.gen.template/addons/readme_test.exs deleted file mode 100644 index 8d778435..00000000 --- a/test/nimble.phx.gen.template/addons/readme_test.exs +++ /dev/null @@ -1,55 +0,0 @@ -defmodule Nimble.Phx.Gen.Template.Addons.ReadmeTest do - use Nimble.Phx.Gen.Template.AddonCase - - 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) - - assert_file("README.md", fn file -> - assert file =~ """ - Erlang 23.2.1 and Elixir 1.11.3 - """ - - assert file =~ """ - * Install Node dependencies: - - ```sh - npm install --prefix assets - ``` - """ - end) - end) - end - end - - 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} - - in_test_project(test_project_path, fn -> - Addons.Readme.apply(project) - - assert_file("README.md", fn file -> - assert file =~ """ - Erlang 23.2.1 and Elixir 1.11.3 - """ - - refute file =~ """ - * Install Node dependencies: - - ```sh - npm install --prefix assets - ``` - """ - end) - end) - end - end -end diff --git a/test/nimble_template/addons/credo_test.exs b/test/nimble_template/addons/credo_test.exs new file mode 100644 index 00000000..ea468150 --- /dev/null +++ b/test/nimble_template/addons/credo_test.exs @@ -0,0 +1,98 @@ +defmodule NimbleTemplate.Addons.CredoTest do + use NimbleTemplate.AddonCase, async: false + + describe "#apply/2" do + @describetag mock_latest_package_versions: [{:credo, "1.4"}] + @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) + + assert_file(".credo.exs") + end) + end + + test "injects credo to mix dependency", %{ + project: project, + test_project_path: test_project_path + } do + in_test_project(test_project_path, fn -> + Addons.Credo.apply(project) + + assert_file("mix.exs", fn file -> + assert file =~ """ + defp deps do + [ + {:credo, \"~> 1.4\", [only: [:dev, :test], runtime: false]}, + """ + end) + end) + 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) + + assert_file("mix.exs", fn file -> + assert file =~ """ + defp aliases do + [ + codebase: [\"deps.unlock --check-unused\", \"format --check-formatted\", \"credo --strict\"], + """ + end) + end) + end + end + + describe "#apply/2 with mix_project" do + @describetag mix_project?: true + @describetag mock_latest_package_versions: [{:credo, "1.4"}] + @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) + + assert_file(".credo.exs") + end) + end + + test "injects credo to mix dependency", %{ + project: project, + test_project_path: test_project_path + } do + in_test_project(test_project_path, fn -> + Addons.Credo.apply(project) + + assert_file("mix.exs", fn file -> + assert file =~ """ + defp deps do + [ + {:credo, \"~> 1.4\", [only: [:dev, :test], runtime: false]}, + """ + end) + end) + 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) + + assert_file("mix.exs", fn file -> + assert file =~ """ + defp aliases do + [ + codebase: [\"deps.unlock --check-unused\", \"format --check-formatted\", \"credo --strict\"] + """ + end) + end) + end + end +end diff --git a/test/nimble.phx.gen.template/addons/dialyxir_test.exs b/test/nimble_template/addons/dialyxir_test.exs similarity index 85% rename from test/nimble.phx.gen.template/addons/dialyxir_test.exs rename to test/nimble_template/addons/dialyxir_test.exs index ae0ef75b..02ea4848 100644 --- a/test/nimble.phx.gen.template/addons/dialyxir_test.exs +++ b/test/nimble_template/addons/dialyxir_test.exs @@ -1,5 +1,5 @@ -defmodule Nimble.Phx.Gen.Template.Addons.DialyxirTest do - use Nimble.Phx.Gen.Template.AddonCase +defmodule NimbleTemplate.Addons.DialyxirTest do + use NimbleTemplate.AddonCase, async: false describe "#apply/2" do @describetag mock_latest_package_versions: [{:dialyxir, "1.0"}] diff --git a/test/nimble.phx.gen.template/addons/docker_test.exs b/test/nimble_template/addons/docker_test.exs similarity index 60% rename from test/nimble.phx.gen.template/addons/docker_test.exs rename to test/nimble_template/addons/docker_test.exs index 815f3a99..041b8d5a 100644 --- a/test/nimble.phx.gen.template/addons/docker_test.exs +++ b/test/nimble_template/addons/docker_test.exs @@ -1,5 +1,5 @@ -defmodule Nimble.Phx.Gen.Template.Addons.DockerTest do - use Nimble.Phx.Gen.Template.AddonCase +defmodule NimbleTemplate.Addons.DockerTest do + use NimbleTemplate.AddonCase, async: false describe "#apply/2" do test "copies the docker-compose.dev.yml", %{ @@ -16,10 +16,10 @@ defmodule Nimble.Phx.Gen.Template.Addons.DockerTest do services: db: image: postgres:12.3 - container_name: nimble_phx_gen_template_db + container_name: nimble_template_db environment: - POSTGRES_HOST_AUTH_METHOD=trust - - POSTGRES_DB=nimble_phx_gen_template_dev + - POSTGRES_DB=nimble_template_dev ports: - "5432:5432" """ @@ -57,17 +57,29 @@ defmodule Nimble.Phx.Gen.Template.Addons.DockerTest do Addons.Docker.apply(project) assert_file("Dockerfile", fn file -> - assert file =~ "FROM hexpm/elixir:1.11.3-erlang-23.2.1-alpine-3.12.1 AS build" - assert file =~ "FROM alpine:3.12.1 AS app" + assert file =~ """ + ARG ELIXIR_IMAGE_VERSION=1.11.4 + ARG ERLANG_IMAGE_VERSION=23.3 + ARG RELEASE_IMAGE_VERSION=3.13.2 - assert file =~ - "RUN npm --prefix ./assets ci --progress=false --no-audit --loglevel=error" + FROM hexpm/elixir:${ELIXIR_IMAGE_VERSION}-erlang-${ERLANG_IMAGE_VERSION}-alpine-${RELEASE_IMAGE_VERSION} AS build + """ + + assert file =~ "FROM alpine:${RELEASE_IMAGE_VERSION} AS app" - assert file =~ "adduser -s /bin/sh -G app_group -D app_user &&" + assert file =~ """ + RUN cd assets && \\ + \t\tnpm ci --progress=false --no-audit --loglevel=error && \\ + \t\tnpm run deploy && \\ + \t\tcd - && \\ + \t\tmix phx.digest + """ + + assert file =~ "adduser -u 1000 -G appuser -g appuser -s /bin/sh -D appuser" assert file =~ "USER app_user" assert file =~ - "COPY --from=build --chown=app_user:app_group /app/_build/prod/rel/nimble_phx_gen_template ./" + "COPY --from=build --chown=1000:1000 /app/_build/prod/rel/nimble_template ./" end) end) end @@ -81,9 +93,9 @@ defmodule Nimble.Phx.Gen.Template.Addons.DockerTest do assert_file("bin/start.sh", fn file -> assert file =~ """ - bin/nimble_phx_gen_template eval "NimblePhxGenTemplate.ReleaseTasks.migrate()" + bin/nimble_template eval "NimbleTemplate.ReleaseTasks.migrate()" - bin/nimble_phx_gen_template start + bin/nimble_template start """ end) end) @@ -101,8 +113,13 @@ defmodule Nimble.Phx.Gen.Template.Addons.DockerTest do Addons.Docker.apply(project) assert_file("Dockerfile", fn file -> - refute file =~ - "RUN npm --prefix ./assets ci --progress=false --no-audit --loglevel=error" + refute file =~ """ + RUN cd assets && \\ + \t\tnpm ci --progress=false --no-audit --loglevel=error && \\ + \t\tnpm run deploy && \\ + \t\tcd - && \\ + \t\tmix phx.digest + """ end) end) end diff --git a/test/nimble_template/addons/elixir_version_test.exs b/test/nimble_template/addons/elixir_version_test.exs new file mode 100644 index 00000000..5b833b1d --- /dev/null +++ b/test/nimble_template/addons/elixir_version_test.exs @@ -0,0 +1,21 @@ +defmodule NimbleTemplate.Addons.ElixirVersionTest do + use NimbleTemplate.AddonCase, async: false + + describe "#apply/2" do + test "copies the .tool-versions", %{ + project: project, + test_project_path: test_project_path + } do + in_test_project(test_project_path, fn -> + Addons.ElixirVersion.apply(project) + + assert_file(".tool-versions", fn file -> + assert file =~ """ + erlang 23.3 + elixir 1.11.4-otp-23 + """ + end) + end) + end + end +end diff --git a/test/nimble_template/addons/ex_coveralls_test.exs b/test/nimble_template/addons/ex_coveralls_test.exs new file mode 100644 index 00000000..0da13400 --- /dev/null +++ b/test/nimble_template/addons/ex_coveralls_test.exs @@ -0,0 +1,135 @@ +defmodule NimbleTemplate.Addons.ExCoverallsTest do + use NimbleTemplate.AddonCase, async: false + + 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) + + assert_file("coveralls.json") + end) + end + + test "injects excoveralls to mix dependency", %{ + project: project, + test_project_path: test_project_path + } do + in_test_project(test_project_path, fn -> + Addons.ExCoveralls.apply(project) + + assert_file("mix.exs", fn file -> + assert file =~ """ + defp deps do + [ + {:excoveralls, \"~> 0.12.2\", [only: :test]}, + """ + end) + end) + 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) + + assert_file("mix.exs", fn file -> + assert file =~ """ + deps: deps(), + test_coverage: [tool: ExCoveralls], + preferred_cli_env: [ + lint: :test, + coverage: :test, + coveralls: :test, + "coveralls.html": :test + ] + """ + end) + end) + 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) + + assert_file("mix.exs", fn file -> + assert file =~ """ + defp aliases do + [ + coverage: [\"coveralls.html --raise\"], + """ + end) + end) + end + end + + describe "#apply/2 with mix_project" do + @describetag mix_project?: true + @describetag required_addons: [:TestEnv] + @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) + + assert_file("coveralls.json") + end) + end + + test "injects excoveralls to mix dependency", %{ + project: project, + test_project_path: test_project_path + } do + in_test_project(test_project_path, fn -> + Addons.ExCoveralls.apply(project) + + assert_file("mix.exs", fn file -> + assert file =~ """ + defp deps do + [ + {:excoveralls, \"~> 0.12.2\", [only: :test]}, + """ + end) + end) + 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) + + assert_file("mix.exs", fn file -> + assert file =~ """ + deps: deps(), + test_coverage: [tool: ExCoveralls], + preferred_cli_env: [ + lint: :test, + coverage: :test, + coveralls: :test, + "coveralls.html": :test + ] + """ + end) + end) + 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) + + assert_file("mix.exs", fn file -> + assert file =~ """ + defp aliases do + [ + coverage: [\"coveralls.html --raise\"], + """ + end) + end) + end + end +end diff --git a/test/nimble.phx.gen.template/addons/ex_machina_test.exs b/test/nimble_template/addons/ex_machina_test.exs similarity index 88% rename from test/nimble.phx.gen.template/addons/ex_machina_test.exs rename to test/nimble_template/addons/ex_machina_test.exs index d7fa6065..2da75a0f 100644 --- a/test/nimble.phx.gen.template/addons/ex_machina_test.exs +++ b/test/nimble_template/addons/ex_machina_test.exs @@ -1,5 +1,5 @@ -defmodule Nimble.Phx.Gen.Template.Addons.ExMachinaTest do - use Nimble.Phx.Gen.Template.AddonCase +defmodule NimbleTemplate.Addons.ExMachinaTest do + use NimbleTemplate.AddonCase, async: false describe "#apply/2" do @describetag mock_latest_package_versions: [{:ex_machina, "2.4"}] @@ -66,15 +66,15 @@ defmodule Nimble.Phx.Gen.Template.Addons.ExMachinaTest do Addons.ExMachina.apply(project) assert_file("test/support/data_case.ex", fn file -> - assert file =~ "import NimblePhxGenTemplate.Factory" + assert file =~ "import NimbleTemplate.Factory" end) assert_file("test/support/channel_case.ex", fn file -> - assert file =~ "import NimblePhxGenTemplate.Factory" + assert file =~ "import NimbleTemplate.Factory" end) assert_file("test/support/conn_case.ex", fn file -> - assert file =~ "import NimblePhxGenTemplate.Factory" + assert file =~ "import NimbleTemplate.Factory" end) end) end diff --git a/test/nimble_template/addons/ex_unit_test.exs b/test/nimble_template/addons/ex_unit_test.exs new file mode 100644 index 00000000..3730c54c --- /dev/null +++ b/test/nimble_template/addons/ex_unit_test.exs @@ -0,0 +1,16 @@ +defmodule NimbleTemplate.Addons.ExUnitTest do + use NimbleTemplate.AddonCase, async: false + + 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) + + assert_file("test/test_helper.exs", fn file -> + assert file =~ "ExUnit.start(capture_log: true)" + end) + end) + end + end +end diff --git a/test/nimble_template/addons/ex_vcr_test.exs b/test/nimble_template/addons/ex_vcr_test.exs new file mode 100644 index 00000000..cfe7f8fe --- /dev/null +++ b/test/nimble_template/addons/ex_vcr_test.exs @@ -0,0 +1,62 @@ +defmodule NimbleTemplate.Addons.ExVCRTest do + use NimbleTemplate.AddonCase + + 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 -> + Addons.ExVCR.apply(project) + + assert_file("mix.exs", fn file -> + assert file =~ "{:exvcr, \"~> 0.12.2\", [only: :test]}" + end) + end) + end + + test "updates configurations for test env", %{ + project: project, + test_project_path: test_project_path + } do + in_test_project(test_project_path, fn -> + Addons.ExVCR.apply(project) + + assert_file("config/test.exs", fn file -> + assert file =~ """ + # Configurations for ExVCR + config :exvcr, + vcr_cassette_library_dir: "test/support/fixtures/vcr_cassettes" + """ + end) + end) + end + + test "updates test cases", %{project: project, test_project_path: test_project_path} do + in_test_project(test_project_path, fn -> + Addons.ExVCR.apply(project) + + assert_file("test/support/data_case.ex", fn file -> + assert file =~ "use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney" + end) + + assert_file("test/support/conn_case.ex", fn file -> + assert file =~ "use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney" + end) + end) + end + + test "creates cassettes directory with .keep file", %{ + project: project, + test_project_path: test_project_path + } do + in_test_project(test_project_path, fn -> + Addons.ExVCR.apply(project) + + assert(File.exists?("test/support/fixtures/vcr_cassettes/.keep")) == true + end) + end + end +end diff --git a/test/nimble_template/addons/github_test.exs b/test/nimble_template/addons/github_test.exs new file mode 100644 index 00000000..43157cfb --- /dev/null +++ b/test/nimble_template/addons/github_test.exs @@ -0,0 +1,126 @@ +defmodule NimbleTemplate.Addons.GithubTest do + use NimbleTemplate.AddonCase, async: false + + 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}) + + assert_file(".github/ISSUE_TEMPLATE.md") + end) + end + + test "copies the .github/PULL_REQUEST_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}) + + assert_file(".github/PULL_REQUEST_TEMPLATE.md") + end) + end + end + + 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}) + + assert_file(".github/ISSUE_TEMPLATE.md") + end) + end + + test "copies the .github/PULL_REQUEST_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}) + + assert_file(".github/PULL_REQUEST_TEMPLATE.md") + end) + end + end + + describe "#apply/2 with api_project and github_action 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: true}) + + assert_file(".github/workflows/test.yml", fn file -> + refute file =~ "assets/node_modules" + refute file =~ "npm --prefix assets install" + refute file =~ "npm run --prefix assets build:dev" + refute file =~ "wallaby_screenshots" + end) + end) + end + end + + describe "#apply/2 with web_project and github_action 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: true}) + + assert_file(".github/workflows/test.yml", fn file -> + assert file =~ "assets/node_modules" + assert file =~ "npm --prefix assets install" + assert file =~ "npm run --prefix assets build:dev" + assert file =~ "wallaby_screenshots" + end) + end) + end + end + + describe "#apply/2 with mix_project and github_action 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: true}) + + assert_file(".github/workflows/test.yml", fn file -> + refute file =~ "postgres" + refute file =~ "ecto.create" + refute file =~ "ecto.migrate" + end) + end) + end + + test "does NOT include 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: true}) + + assert_file(".github/workflows/test.yml", fn file -> + refute file =~ "assets/node_modules" + refute file =~ "npm --prefix assets install" + refute file =~ "npm run --prefix assets build:dev" + refute file =~ "wallaby_screenshots" + end) + end) + end + end +end diff --git a/test/nimble.phx.gen.template/addons/makefile_test.exs b/test/nimble_template/addons/makefile_test.exs similarity index 73% rename from test/nimble.phx.gen.template/addons/makefile_test.exs rename to test/nimble_template/addons/makefile_test.exs index 19ecc7a2..7ce8b7a0 100644 --- a/test/nimble.phx.gen.template/addons/makefile_test.exs +++ b/test/nimble_template/addons/makefile_test.exs @@ -1,5 +1,5 @@ -defmodule Nimble.Phx.Gen.Template.Addons.MakefileTest do - use Nimble.Phx.Gen.Template.AddonCase +defmodule NimbleTemplate.Addons.MakefileTest do + use NimbleTemplate.AddonCase, async: false describe "#apply/2" do test "copies the Makefile", %{project: project, test_project_path: test_project_path} do diff --git a/test/nimble.phx.gen.template/addons/mimic_test.exs b/test/nimble_template/addons/mimic_test.exs similarity index 91% rename from test/nimble.phx.gen.template/addons/mimic_test.exs rename to test/nimble_template/addons/mimic_test.exs index 7e250ced..61455435 100644 --- a/test/nimble.phx.gen.template/addons/mimic_test.exs +++ b/test/nimble_template/addons/mimic_test.exs @@ -1,5 +1,5 @@ -defmodule Nimble.Phx.Gen.Template.Addons.MimicTest do - use Nimble.Phx.Gen.Template.AddonCase +defmodule NimbleTemplate.Addons.MimicTest do + use NimbleTemplate.AddonCase, async: false describe "#apply/2" do @describetag mock_latest_package_versions: [{:mimic, "1.3.1"}] diff --git a/test/nimble.phx.gen.template/addons/mix_release_test.exs b/test/nimble_template/addons/mix_release_test.exs similarity index 81% rename from test/nimble.phx.gen.template/addons/mix_release_test.exs rename to test/nimble_template/addons/mix_release_test.exs index a1e3a58b..4ca1ec59 100644 --- a/test/nimble.phx.gen.template/addons/mix_release_test.exs +++ b/test/nimble_template/addons/mix_release_test.exs @@ -1,5 +1,5 @@ -defmodule Nimble.Phx.Gen.Template.Addons.MixReleaseTest do - use Nimble.Phx.Gen.Template.AddonCase +defmodule NimbleTemplate.Addons.MixReleaseTest do + use NimbleTemplate.AddonCase, async: false describe "#apply/2" do test "deletes the import_config \"prod.secret.exs\" in config/prod.exs", %{ @@ -47,17 +47,17 @@ defmodule Nimble.Phx.Gen.Template.Addons.MixReleaseTest do end) end - test "creates the lib/nimble_phx_gen_template/release_tasks.ex", %{ + 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 -> Addons.MixRelease.apply(project) - assert_file("lib/nimble_phx_gen_template/release_tasks.ex", fn file -> + assert_file("lib/nimble_template/release_tasks.ex", fn file -> assert file =~ """ - defmodule NimblePhxGenTemplate.ReleaseTasks do - @app :nimble_phx_gen_template + defmodule NimbleTemplate.ReleaseTasks do + @app :nimble_template def migrate do """ diff --git a/test/nimble.phx.gen.template/addons/oban_test.exs b/test/nimble_template/addons/oban_test.exs similarity index 83% rename from test/nimble.phx.gen.template/addons/oban_test.exs rename to test/nimble_template/addons/oban_test.exs index 7ab6dc4a..10b091b0 100644 --- a/test/nimble.phx.gen.template/addons/oban_test.exs +++ b/test/nimble_template/addons/oban_test.exs @@ -1,5 +1,5 @@ -defmodule Nimble.Phx.Gen.Template.Addons.ObanTest do - use Nimble.Phx.Gen.Template.AddonCase +defmodule NimbleTemplate.Addons.ObanTest do + use NimbleTemplate.AddonCase, async: false use Mimic describe "#apply/2" do @@ -33,7 +33,7 @@ defmodule Nimble.Phx.Gen.Template.Addons.ObanTest do assert_file("priv/repo/migrations/20201120074154_add_oban_jobs_table.exs", fn file -> assert file =~ """ - defmodule NimblePhxGenTemplate.Repo.Migrations.AddObanJobsTable do + defmodule NimbleTemplate.Repo.Migrations.AddObanJobsTable do use Ecto.Migration def up do @@ -58,7 +58,7 @@ defmodule Nimble.Phx.Gen.Template.Addons.ObanTest do in_test_project(test_project_path, fn -> Addons.Oban.apply(project) - assert_file("lib/nimble_phx_gen_template/application.ex", fn file -> + assert_file("lib/nimble_template/application.ex", fn file -> assert file =~ """ {Oban, oban_config()} """ @@ -66,7 +66,7 @@ defmodule Nimble.Phx.Gen.Template.Addons.ObanTest do assert file =~ """ # Conditionally disable crontab, queues, or plugins here. defp oban_config do - Application.get_env(:nimble_phx_gen_template, Oban) + Application.get_env(:nimble_template, Oban) end """ end) @@ -82,8 +82,8 @@ defmodule Nimble.Phx.Gen.Template.Addons.ObanTest do assert_file("config/config.exs", fn file -> assert file =~ """ - config :nimble_phx_gen_template, Oban, - repo: NimblePhxGenTemplate.Repo, + config :nimble_template, Oban, + repo: NimbleTemplate.Repo, plugins: [Oban.Plugins.Pruner], queues: [default: 10] """ @@ -100,7 +100,7 @@ defmodule Nimble.Phx.Gen.Template.Addons.ObanTest do assert_file("config/test.exs", fn file -> assert file =~ """ - config :nimble_phx_gen_template, Oban, crontab: false, queues: false, plugins: false + config :nimble_template, Oban, crontab: false, queues: false, plugins: false """ end) end) @@ -113,7 +113,7 @@ defmodule Nimble.Phx.Gen.Template.Addons.ObanTest do in_test_project(test_project_path, fn -> Addons.Oban.apply(project) - assert(File.dir?("lib/nimble_phx_gen_template_worker")) == true + assert(File.dir?("lib/nimble_template_worker")) == true end) end end diff --git a/test/nimble_template/addons/readme_test.exs b/test/nimble_template/addons/readme_test.exs new file mode 100644 index 00000000..36d415c6 --- /dev/null +++ b/test/nimble_template/addons/readme_test.exs @@ -0,0 +1,103 @@ +defmodule NimbleTemplate.Addons.ReadmeTest do + use NimbleTemplate.AddonCase, async: false + + 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) + + assert_file("README.md", fn file -> + assert file =~ "Erlang 23.3" + assert file =~ "Elixir 1.11.4" + + assert file =~ """ + * Install Node dependencies: + + ```sh + npm install --prefix assets + ``` + """ + + assert file =~ """ + * Start the Phoenix app + + ```sh + iex -S mix phx.server + ``` + """ + end) + end) + end + end + + 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) + + assert_file("README.md", fn file -> + assert file =~ "Erlang 23.3" + assert file =~ "Elixir 1.11.4" + + refute file =~ """ + * Install Node dependencies: + + ```sh + npm install --prefix assets + ``` + """ + + assert file =~ """ + * Start the Phoenix app + + ```sh + iex -S mix phx.server + ``` + """ + end) + end) + end + end + + 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) + + assert_file("README.md", fn file -> + assert file =~ "Erlang 23.3" + assert file =~ "Elixir 1.11.4" + + refute file =~ """ + * Install Node dependencies: + + ```sh + npm install --prefix assets + ``` + """ + + refute file =~ """ + * Start the Phoenix app + + ```sh + iex -S mix phx.server + ``` + """ + end) + end) + end + end +end diff --git a/test/nimble.phx.gen.template/addons/test_env_test.exs b/test/nimble_template/addons/test_env_test.exs similarity index 52% rename from test/nimble.phx.gen.template/addons/test_env_test.exs rename to test/nimble_template/addons/test_env_test.exs index 9d3a5d6c..000b8550 100644 --- a/test/nimble.phx.gen.template/addons/test_env_test.exs +++ b/test/nimble_template/addons/test_env_test.exs @@ -1,5 +1,5 @@ -defmodule Nimble.Phx.Gen.Template.Addons.TestEnvTest do - use Nimble.Phx.Gen.Template.AddonCase +defmodule NimbleTemplate.Addons.TestEnvTest do + use NimbleTemplate.AddonCase, async: false describe "#apply/2" do test "injects the DB_HOST ENV", %{project: project, test_project_path: test_project_path} do @@ -74,4 +74,73 @@ defmodule Nimble.Phx.Gen.Template.Addons.TestEnvTest do end) end end + + describe "#apply/2 with mix_project" do + @describetag mix_project?: true + + test "adds codebase alias", %{project: project, test_project_path: test_project_path} do + in_test_project(test_project_path, fn -> + Addons.TestEnv.apply(project) + + assert_file("mix.exs", fn file -> + assert file =~ "aliases: aliases()" + + assert file =~ """ + defp aliases do + [ + codebase: [\"deps.unlock --check-unused\", \"format --check-formatted\"] + ] + end + """ + end) + end) + 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) + + assert_file("mix.exs", fn file -> + assert file =~ "elixirc_paths: elixirc_paths(Mix.env())," + + assert file =~ """ + # Specifies which paths to compile per environment. + defp elixirc_paths(:test), do: ["lib", "test/support"] + defp elixirc_paths(_), do: ["lib"] + """ + end) + end) + end + + 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) + + assert_file("test/test_helper.exs", fn file -> + assert file =~ """ + Code.put_compiler_option(:warnings_as_errors, true) + + ExUnit.start() + """ + end) + end) + end + + test "sets line_length to 100 in .formatter.exs", %{ + project: project, + test_project_path: test_project_path + } do + in_test_project(test_project_path, fn -> + Addons.TestEnv.apply(project) + + assert_file(".formatter.exs", fn file -> + assert file =~ """ + [ + line_length: 100, + """ + end) + end) + end + end end diff --git a/test/nimble_template/addons/variants/mix/.keep b/test/nimble_template/addons/variants/mix/.keep new file mode 100644 index 00000000..e69de29b diff --git a/test/nimble_template/addons/variants/phoenix/api/.keep b/test/nimble_template/addons/variants/phoenix/api/.keep new file mode 100644 index 00000000..e69de29b diff --git a/test/nimble_template/addons/variants/phoenix/live/.keep b/test/nimble_template/addons/variants/phoenix/live/.keep new file mode 100644 index 00000000..e69de29b diff --git a/test/nimble.phx.gen.template/addons/variants/web/assets_test.exs b/test/nimble_template/addons/variants/phoenix/web/assets_test.exs similarity index 93% rename from test/nimble.phx.gen.template/addons/variants/web/assets_test.exs rename to test/nimble_template/addons/variants/phoenix/web/assets_test.exs index 43125917..96432b75 100644 --- a/test/nimble.phx.gen.template/addons/variants/web/assets_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/assets_test.exs @@ -1,5 +1,5 @@ -defmodule Nimble.Phx.Gen.Template.AddonsWeb.AssetsTest do - use Nimble.Phx.Gen.Template.AddonCase +defmodule NimbleTemplate.Addons.Phoenix.Web.AssetsTest do + use NimbleTemplate.AddonCase, async: false describe "#apply/2" do test "adds assets.compile alias", %{project: project, test_project_path: test_project_path} do diff --git a/test/nimble.phx.gen.template/addons/variants/web/core_js_test.exs b/test/nimble_template/addons/variants/phoenix/web/core_js_test.exs similarity index 89% rename from test/nimble.phx.gen.template/addons/variants/web/core_js_test.exs rename to test/nimble_template/addons/variants/phoenix/web/core_js_test.exs index 00c716b1..c6e4b466 100644 --- a/test/nimble.phx.gen.template/addons/variants/web/core_js_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/core_js_test.exs @@ -1,5 +1,5 @@ -defmodule Nimble.Phx.Gen.Template.AddonsWeb.CoreJSTest do - use Nimble.Phx.Gen.Template.AddonCase +defmodule NimbleTemplate.Addons.Phoenix.Web.CoreJSTest do + use NimbleTemplate.AddonCase, async: false describe "#apply/2" do test "adds core-js into package.json", %{ diff --git a/test/nimble.phx.gen.template/addons/variants/web/sobelow_test.exs b/test/nimble_template/addons/variants/phoenix/web/sobelow_test.exs similarity index 93% rename from test/nimble.phx.gen.template/addons/variants/web/sobelow_test.exs rename to test/nimble_template/addons/variants/phoenix/web/sobelow_test.exs index 9c7e4d72..91abc080 100644 --- a/test/nimble.phx.gen.template/addons/variants/web/sobelow_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/sobelow_test.exs @@ -1,5 +1,5 @@ -defmodule Nimble.Phx.Gen.Template.AddonsWeb.SobelowTest do - use Nimble.Phx.Gen.Template.AddonCase +defmodule NimbleTemplate.Addons.Phoenix.Web.SobelowTest do + use NimbleTemplate.AddonCase, async: false describe "#apply/2" do @describetag mock_latest_package_versions: [{:credo, "0.26.2"}, {:sobelow, "0.8"}] diff --git a/test/nimble.phx.gen.template/addons/variants/web/wallaby_test.exs b/test/nimble_template/addons/variants/phoenix/web/wallaby_test.exs similarity index 75% rename from test/nimble.phx.gen.template/addons/variants/web/wallaby_test.exs rename to test/nimble_template/addons/variants/phoenix/web/wallaby_test.exs index 4d3abbd3..c7f5bd70 100644 --- a/test/nimble.phx.gen.template/addons/variants/web/wallaby_test.exs +++ b/test/nimble_template/addons/variants/phoenix/web/wallaby_test.exs @@ -1,5 +1,5 @@ -defmodule Nimble.Phx.Gen.Template.AddonsWeb.WallabyTest do - use Nimble.Phx.Gen.Template.AddonCase +defmodule NimbleTemplate.Addons.Phoenix.Web.WallabyTest do + use NimbleTemplate.AddonCase, async: false describe "#apply/2" do @describetag mock_latest_package_versions: [{:wallaby, "0.26.2"}] @@ -13,16 +13,16 @@ defmodule Nimble.Phx.Gen.Template.AddonsWeb.WallabyTest do assert_file("test/support/feature_case.ex", fn file -> assert file =~ """ - defmodule NimblePhxGenTemplateWeb.FeatureCase do + defmodule NimbleTemplateWeb.FeatureCase do use ExUnit.CaseTemplate using do quote do use Wallaby.Feature - import NimblePhxGenTemplate.Factory + import NimbleTemplate.Factory - alias NimblePhxGenTemplateWeb.Router.Helpers, as: Routes + alias NimbleTemplateWeb.Router.Helpers, as: Routes end end end @@ -38,7 +38,7 @@ defmodule Nimble.Phx.Gen.Template.AddonsWeb.WallabyTest do in_test_project(test_project_path, fn -> AddonsWeb.Wallaby.apply(project) - assert_file("test/nimble_phx_gen_template_web/features/home_page/view_home_page_test.exs") + assert_file("test/nimble_template_web/features/home_page/view_home_page_test.exs") end) end @@ -71,26 +71,26 @@ defmodule Nimble.Phx.Gen.Template.AddonsWeb.WallabyTest do {:ok, _} = Application.ensure_all_started(:wallaby) ExUnit.start() - Ecto.Adapters.SQL.Sandbox.mode(NimblePhxGenTemplate.Repo, :manual) + Ecto.Adapters.SQL.Sandbox.mode(NimbleTemplate.Repo, :manual) - Application.put_env(:wallaby, :base_url, NimblePhxGenTemplateWeb.Endpoint.url()) + Application.put_env(:wallaby, :base_url, NimbleTemplateWeb.Endpoint.url()) """ end) end) end - test "updates lib/nimble_phx_gen_template_web/endpoint.ex", %{ + test "updates lib/nimble_template_web/endpoint.ex", %{ project: project, test_project_path: test_project_path } do in_test_project(test_project_path, fn -> AddonsWeb.Wallaby.apply(project) - assert_file("lib/nimble_phx_gen_template_web/endpoint.ex", fn file -> + assert_file("lib/nimble_template_web/endpoint.ex", fn file -> assert file =~ """ - use Phoenix.Endpoint, otp_app: :nimble_phx_gen_template + use Phoenix.Endpoint, otp_app: :nimble_template - if Application.get_env(:nimble_phx_gen_template, :sql_sandbox) do + if Application.get_env(:nimble_template, :sql_sandbox) do plug Phoenix.Ecto.SQL.Sandbox end """ @@ -107,14 +107,14 @@ defmodule Nimble.Phx.Gen.Template.AddonsWeb.WallabyTest do assert_file("config/test.exs", fn file -> assert file =~ """ - config :nimble_phx_gen_template, NimblePhxGenTemplateWeb.Endpoint, + config :nimble_template, NimbleTemplateWeb.Endpoint, http: [port: 4002], server: true - config :nimble_phx_gen_template, :sql_sandbox, true + config :nimble_template, :sql_sandbox, true config :wallaby, - otp_app: :nimble_phx_gen_template, + otp_app: :nimble_template, chromedriver: [headless: System.get_env("CHROME_HEADLESS", "true") === "true"], screenshot_dir: "tmp/wallaby_screenshots", screenshot_on_failure: true diff --git a/test/nimble.phx.gen.template/release_version_test.exs b/test/nimble_template/release_version_test.exs similarity index 55% rename from test/nimble.phx.gen.template/release_version_test.exs rename to test/nimble_template/release_version_test.exs index 37031d54..00fed614 100644 --- a/test/nimble.phx.gen.template/release_version_test.exs +++ b/test/nimble_template/release_version_test.exs @@ -1,12 +1,12 @@ -defmodule Nimble.Phx.Gen.Template.ReleaseVersionTest do +defmodule NimbleTemplate.ReleaseVersionTest do use ExUnit.Case, async: true - alias Nimble.Phx.Gen.Template.Hex.Package + alias NimbleTemplate.Hex.Package @tag :release_version test "the new version is greater than the hex version" do new_version = Mix.Project.config()[:version] - hex_version = Package.get_latest_version("nimble_phx_gen_template") + hex_version = Package.get_latest_version("nimble_template") assert new_version > hex_version end diff --git a/test/support/addon_case.ex b/test/support/addon_case.ex index c8d015ad..e5995e87 100644 --- a/test/support/addon_case.ex +++ b/test/support/addon_case.ex @@ -1,16 +1,16 @@ -defmodule Nimble.Phx.Gen.Template.AddonCase do +defmodule NimbleTemplate.AddonCase do use ExUnit.CaseTemplate use Mimic - alias Nimble.Phx.Gen.Template.Addons.Web, as: AddonsWeb - alias Nimble.Phx.Gen.Template.{Addons, Project} - alias Nimble.Phx.Gen.Template.Hex.Package + alias NimbleTemplate.Addons.Phoenix.Web, as: AddonsWeb + alias NimbleTemplate.{Addons, Project} + alias NimbleTemplate.Hex.Package using do quote do - alias Nimble.Phx.Gen.Template.Addons - alias Nimble.Phx.Gen.Template.Addons.Web, as: AddonsWeb + alias NimbleTemplate.Addons + alias NimbleTemplate.Addons.Phoenix.Web, as: AddonsWeb # 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 @@ -30,14 +30,21 @@ defmodule Nimble.Phx.Gen.Template.AddonCase do end setup context do - # Set Web Project as default, switch to either API or Live Project in each test case - # eg: project = %{project | api_project?: true, web_project?: false} - project = Project.new(web: true) - parent_test_project_path = Path.join(tmp_path(), parent_test_project_path()) - test_project_path = Path.join(parent_test_project_path, "/nimble_phx_gen_template") + test_project_path = Path.join(parent_test_project_path, "/nimble_template") + + project = + if context[:mix_project?] == true do + create_mix_test_project(test_project_path) - create_test_project(test_project_path) + Project.new(mix: true) + else + create_phoenix_test_project(test_project_path) + + # Set Web Project as default, switch to either API or Live Project in each test case + # eg: project = %{project | api_project?: true, web_project?: false} + Project.new(web: true) + end on_exit(fn -> File.rm_rf!(parent_test_project_path) @@ -59,10 +66,17 @@ defmodule Nimble.Phx.Gen.Template.AddonCase do defp mock_latest_package_version({_package, version}), do: expect(Package, :get_latest_version, fn _package -> version end) - defp create_test_project(test_project_path) do + defp create_phoenix_test_project(test_project_path) do + # N - in response to Fetch and install dependencies? + Mix.shell().cmd( + "printf \"N\n\" | make create_phoenix_project PROJECT_DIRECTORY=#{test_project_path} > /dev/null" + ) + end + + defp create_mix_test_project(test_project_path) do # N - in response to Fetch and install dependencies? Mix.shell().cmd( - "printf \"N\n\" | make create_project PROJECT_DIRECTORY=#{test_project_path} > /dev/null" + "printf \"N\n\" | make create_mix_project PROJECT_DIRECTORY=#{test_project_path} > /dev/null" ) end diff --git a/test/test_helper.exs b/test/test_helper.exs index e6701419..6fc0293f 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(Nimble.Phx.Gen.Template.Hex.Package) +Mimic.copy(NimbleTemplate.Hex.Package) -ExUnit.start() +ExUnit.start(capture_log: true) ExUnit.configure(exclude: :release_version)