Giter Club home page Giter Club logo

elixir-templates's Introduction

Introduction

Phoenix/Mix template for projects at Nimble.

Prerequisites

NimbleTemplate has been developed and actively tested with the below environment:

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

Installation

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

# New Phoenix project
mix phx.new awesome_project

# New Mix project
mix new awesome_project

Step 2: Add nimble_template dependency to mix.exs:

def deps do
  [
    {:nimble_template, "~> 4.7.0", only: :dev, runtime: false},
    # other dependencies ...
  ]
end

Step 3: Fetch and install dependencies

Run this command in the root of the project directory to install NimbleTemplate.

mix do deps.get, deps.compile

Usage

mix help nimble_template.gen # Print help

mix nimble_template.gen -v # Print the version

# 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

# Non-Phoenix application
mix nimble_template.gen --mix # Apply the Mix template

Running tests

The testing documentation is on Wiki

Release process

The release documentation is on Wiki

Contributing

Contributions, issues, and feature requests are welcome!
Feel free to check issues page.

FAQ

1. Getting (Mix) The task "phx.new" could not be found error

The Phoenix application generator is missing. By solving this problem, you need to run

mix archive.install hex phx_new

or

mix archive.install hex phx_new #{specific-version}

2. Getting Wallaby can't find chromedriver error

Your OS is missing/not installing chromedriver, you need to run:

Homebrew

brew install --cask chromedriver

Debian/Ubuntu

apt install chromium-chromedriver

Or download the package on the official site: https://chromedriver.chromium.org/downloads

License

This project is Copyright (c) 2014 and onwards. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About

Nimble

This project is maintained and funded by Nimble.

We love open source and do our part in sharing our work with the community! See our other projects or hire our team to help build your product.

elixir-templates's People

Contributors

andyduong1920 avatar bterone avatar byhbt avatar hanam1ni avatar liamstevens111 avatar longnd avatar nihisil avatar nvminhtue avatar olivierobert avatar rafayet-monon avatar tolsee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

elixir-templates's Issues

Update the `Usage` section

Currently, we don't know how to use the template base on the current Usage content.

## Usage

Clone the repository

`git clone [email protected]:nimblehq/elixir-templates.git`

It's better if we could improve it to make it clear like what should we do after cloning the repo, do we need to run any script after that, ...

Thank you ๐Ÿš€

Add Prettier

Why

To refactor EEX files easily

Who Benefits?

Phoenix template users

Manual Ecto migrations addon

Following the https://dashbit.co/blog/automatic-and-manual-ecto-migrations it nice to have the manual_migration pre-setting

1/ Adding migrate_manual to the https://github.com/nimblehq/elixir-templates/blob/develop/priv/templates/nimble.phx.gen.template/lib/otp_app/release_tasks.ex.eex

  def migrate_manual do
    load_app()

    for repo <- repos() do
      run_migrations(repo, "priv/repo/manual_migrations")
    end
  end

2/ Adjust aliases in mix.ex file

defp aliases() do
  [
    "ecto.migrate_all": ["ecto.migrate --migrations-path=priv/repo/migrations --migrations-path=priv/repo/manual_migrations"],
    "ecto.setup": ["ecto.create", "ecto.migrate_all", "run priv/repo/seeds.exs"],
    test: ["ecto.create --quiet", "ecto.migrate_all --quiet", "test"],
    ...
  ]
end

RFC: Helpers directory

Issue

I checked the module NimbleTemplate.Template and I think some functions do not belong to this module. We can extract these functions into the helper module and group them in the Helpers directory.

image

Solution

Introduce the helpers directory and we can place all helper functions there.

image

Who Benefits?

Developers

What's Next?

  • Create refactoring NimbleTemplate.Template PR


JS and CSS Linters for the Web variant

Why

To enhance the Web variant of the template, we can extract the work done by @rosle in MindValley to set up CSS and JS linters:

The following can be added to mix.exs:

lint: [
  "format --check-formatted",
  "credo",
  "cmd ./assets/node_modules/.bin/eslint --color ./assets",
  "cmd ./assets/node_modules/.bin/stylelint --color ./assets/css"
],
"lint.fix": [
  "format",
  "cmd ./assets/node_modules/.bin/eslint --color --fix ./assets",
  "cmd ./assets/node_modules/.bin/stylelint --color --fix ./assets/css"
]

With the following NPM dependencies:

image

Who Benefits?

Developers ๐Ÿ’ฏ

Boostrap addon?

Why

To init the Boostrap on the new project

Acceptance Criteria

Create a Boostrap addon, this is the Optional addon, so the user can decide to have it or not.

This addon will do the following tasks

1/ Add "bootstrap": "^5.0.0", into the assets/package.json
2/ Create a assets/css/vendor/_boostrap.scss file

// Configuration
@import 'bootstrap/scss/functions';
@import 'bootstrap/scss/variables';
@import 'bootstrap/scss/mixins';
@import 'bootstrap/scss/utilities';

// Re-enable these if needed.
// Do not forget to check the order of import components before re-enable.

// Layout & components
@import 'bootstrap/scss/root';
@import 'bootstrap/scss/reboot';
@import 'bootstrap/scss/type';
// @import 'bootstrap/scss/images';
@import 'bootstrap/scss/containers';
@import 'bootstrap/scss/grid';
// @import 'bootstrap/scss/tables';
// @import 'bootstrap/scss/forms';
// @import 'bootstrap/scss/buttons';
// @import 'bootstrap/scss/transitions';
// @import 'bootstrap/scss/dropdown';
// @import 'bootstrap/scss/button-group';
// @import 'bootstrap/scss/nav';
// @import 'bootstrap/scss/navbar';
// @import 'bootstrap/scss/card';
// @import 'bootstrap/scss/accordion';
// @import 'bootstrap/scss/breadcrumb';
// @import 'bootstrap/scss/pagination';
// @import 'bootstrap/scss/badge';
// @import 'bootstrap/scss/alert';
// @import 'bootstrap/scss/progress';
// @import 'bootstrap/scss/list-group';
// @import 'bootstrap/scss/close';
// @import 'bootstrap/scss/toasts';
// @import 'bootstrap/scss/modal';
// @import 'bootstrap/scss/tooltip';
// @import 'bootstrap/scss/popover';
// @import 'bootstrap/scss/carousel';
// @import 'bootstrap/scss/spinners';
// @import 'bootstrap/scss/offcanvas';

// Helpers
// @import 'bootstrap/scss/helpers';

// Utilities
// @import 'bootstrap/scss/utilities/api';

3/ Add @import 'vendor/boostrap'; into the assets/css/app.scss

4/ Add

// Bootstrap
import "bootstrap/dist/js/bootstrap";

into the assets/js/app.js file, after the core-js

image

Remove cache_static_manifest file in the API project.

Why

For API project, we don't need the cache_static_manifest configuration

07:45:39.037 [info] Migrations already up
07:45:40.539 [info] Running TrustedDeviceWeb.Endpoint with cowboy 2.9.0 at :::4000 (http)
07:45:40.539 [error] Could not find static manifest at "/opt/app/lib/trusted_device-0.1.0/priv/static/cache_manifest.json". Run "mix phx.digest" after building your static files or remove the configuration from "config/prod.exs".
07:45:40.539 [info] Access TrustedDeviceWeb.Endpoint at http://example.com

Solution

image

Who Benefits?

New projects..

Mix project variant?

Currently, the template is supporting the Phoenix project (API and web variants), how about supporting the Mix project (for creating another Elixir lib) ๐Ÿค”

mix nimble.phx.gen.template --mix

We could consider changing the task name to nimble.gen.template so that doesn't contain the phx to make it clear

mix nimble.gen.template --mix

[RFC] Credo rules

Add/update credo rules based on best practices and our preferences. Though the credo comes with the default config, some of the rules are better updated/tuned properly to increase productivity and consistency.

Proposal

strict: true

Set strict mode to true so that we can enforce the style guide.

Credo.Check.Design.AliasUsage

Config:

{Credo.Check.Design.AliasUsage,
  [
    priority: :low,
    if_nested_deeper_than: 2,
    if_called_more_often_than: 1
    excluded_namespaces: ~w[Ecto]
  ]
}

Add Base setup for API projects

Why

For the API project, we need to set up some Plug, Param Validation, or Error View, we could inherit these configurations from our existing API projects.

Plan

  • Request Params Validation.
  • ErrorView return follow JSON API standard format.
  • Add fallback controller. (add action_fallback MODULE.Api.V1.FallbackController into web entry point)
  • Check empty request body params Plug.
  • Add jsonapi dependency to mix.exs.
  • Add alias MODULE.ParamsValidator into web entry point.

Who Benefits?

The new API project's developer ๐Ÿคž

Moving assets to `nimble_web`?

May I know the reason that we keep the assets folder in the root folder instead of putting it in the nimble_web folder, as I know, the mix phx.new xxx --umbrella command generates the `assets folder inside the xxx_web folder. Or it just for the case that we will have multiple web apps (like the public one and the admin one)

Remove repository template setting

As the repositories list, we can see it as the template repository, however I think it could confuse the developers because Template Repository is for a different purpose, according to the docs, the Template Repository for "generate new repositories with the same directory structure, branches, and files."

Reference: https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/creating-a-template-repository

Screen Shot 2021-03-28 at 4 25 23 PM

I would suggest we uncheck the Template Repository from the repository settings:
https://github.com/nimblehq/elixir-templates/settings

Screen Shot 2021-03-28 at 4 19 47 PM

Keeping the assets folder in the `root folder`?

May I know the reason that we keep the assets folder in the root folder instead of putting it in the nimble_web folder, as I know, the mix phx.new xxx --umbrella command generates the `assets folder inside the xxx_web folder. Or it just for the case that we will have multiple web apps (like the public one and the admin one)

Apply specific addon instead of the whole template

Currently, the template doesn't support to apply only specific addon yet, someone might use the template to add a few add-ons instead of the whole template.

For example:

mix nimble.phx.gen.template addon=credo # applying only credo addon to an existing project
mix nimble.phx.gen.template addon=wallaby # applying only wallaby addon to an existing project

Adding `Project README`

Why

Once we generate the project, we need some READ ME like how to set up, install the dependency, running test,...

Feature request

Create a PROJECT_README.md file for example, that contains some content like

  • Setup docker
  • Setup chromedriver,...
  • How to run test,...

And in the #14 we could remove the README.md (template readme) and rename the PROJECT_README.md to just README.md so the new project will have some initial useful README content

Setup test

Description

  • Add alias
    • Add/configure required dependencies
defp aliases do
    [
      lint: ["format --check-formatted", "credo"],
      "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
      "ecto.reset": ["ecto.drop", "ecto.setup"],
      test: ["ecto.create --quiet", "ecto.migrate", "test"],
      coverage: ["sobelow --config", "coveralls.html --raise"]
    ]
end
  • Github's actions
    • Run lint and test in actions for all PRs
  • Use ExMachina for factories
  • Add dialyzer

Dockerize the app

Feature request

  • Add dockerfile

  • Add docker-compose for dev/production

  • Check how the container deployment work

  • Create release.exs and remove prod.secret.exs

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.