Skip to content

Commit

Permalink
Merge pull request #310 from nimblehq/release/4.6.0
Browse files Browse the repository at this point in the history
Release - 4.6.0
  • Loading branch information
byhbt authored Jan 13, 2023
2 parents 6742751 + 0270300 commit 6e94e44
Show file tree
Hide file tree
Showing 134 changed files with 2,034 additions and 1,504 deletions.
5 changes: 1 addition & 4 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Team Lead
* @byhbt

# Team Members
* @andyduong1920 @bterone @hanam1ni @longnd @rosle @topnimble @Nihisil @nvminhtue @liamstevens111
* @byhbt @andyduong1920 @bterone @hanam1ni @longnd @rosle @topnimble @Nihisil @nvminhtue @liamstevens111

# Engineering Leads
CODEOWNERS @nimblehq/engineering-leads
46 changes: 23 additions & 23 deletions .github/wiki/Contribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,25 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SampleAddon do
use NimbleTemplate.Addons.Addon

@impl true
def do_apply(%Project{} = project, opts) do
def do_apply!(%Project{} = project, opts) do
project
end
end
```

The module should implement `do_apply` callbacks of a behaviour.
The module should implement `do_apply!` callbacks of a behaviour.

With a new corresponding test file at `test/nimble_template/addons/variants/phoenix/web/addon_test.exs`.

Then call `NimbleTemplate.Addons.Phoenix.Web.SampleAddon.apply(project)` inside `lib/nimble_template/templates/variants/phoenix/web/template.ex` file which will be executed on Terminal prompt.
Then call `NimbleTemplate.Addons.Phoenix.Web.SampleAddon.apply!(project)` inside `lib/nimble_template/templates/variants/phoenix/web/template.ex` file which will be executed on Terminal prompt.

## Functions

These are functions from `NimbleTemplate.Generator` which can be called.

---

`copy_directory(source_path, target_path, binding \\ [])`
`copy_directory!(source_path, target_path, binding \\ [])`

Copy a directory and its content from source path to target path.

Expand All @@ -48,12 +48,12 @@ Copy a directory and its content from source path to target path.

Example
```elixir
Generator.copy_directory("assets/nimble_js", "assets/js")
Generator.copy_directory!("assets/nimble_js", "assets/js")
```

---

`copy_file(files, binding \\ [])`
`copy_file!(files, binding \\ [])`

Copy a list of files from source path to target path.

Expand All @@ -64,15 +64,15 @@ Copy a list of files from source path to target path.

Example
```elixir
Generator.copy_file([
Generator.copy_file!([
{:eex, "bin/start.sh.eex", "bin/start.sh"},
{:text, "assets/bootstrap_css/vendor/_bootstrap.scss", "assets/css/vendor/_bootstrap.scss"}
])
```

---

`rename_file(old_path, new_path)`
`rename_file!(old_path, new_path)`

Rename a file from old path to new path.

Expand All @@ -83,12 +83,12 @@ Rename a file from old path to new path.

Example
```elixir
Generator.rename_file("assets/css/app.css", "assets/css/app.scss")
Generator.rename_file!("assets/css/app.css", "assets/css/app.scss")
```

---

`replace_content(file_path, anchor, content)`
`replace_content!(file_path, anchor, content)`

Find and replace specified content of an existing file.

Expand All @@ -100,7 +100,7 @@ Find and replace specified content of an existing file.

Example
```elixir
Generator.replace_content(
Generator.replace_content!(
"test/test_helper.exs",
"""
ExUnit.start()
Expand All @@ -113,7 +113,7 @@ Generator.replace_content(

---

`delete_content(file_path, anchor)`
`delete_content!(file_path, anchor)`

Find and remove specified content of an existing file.

Expand All @@ -124,7 +124,7 @@ Find and remove specified content of an existing file.

Example
```elixir
Generator.delete_content(
Generator.delete_content!(
"assets/js/app.js",
"""
// We import the CSS which is extracted to its own file by esbuild.
Expand All @@ -137,7 +137,7 @@ Generator.delete_content(

---

`inject_content(file_path, anchor, content)`
`inject_content!(file_path, anchor, content)`

Inject a specified content below a specified content of an existing file.

Expand All @@ -149,7 +149,7 @@ Inject a specified content below a specified content of an existing file.

Example
```elixir
Generator.inject_content(
Generator.inject_content!(
support_case_path,
"""
use ExUnit.CaseTemplate
Expand All @@ -163,7 +163,7 @@ Generator.inject_content(

---

`append_content(file_path, content)`
`append_content!(file_path, content)`

Append a specified content to the end of an existing file.

Expand All @@ -174,7 +174,7 @@ Append a specified content to the end of an existing file.

Example
```elixir
Generator.append_content(
Generator.append_content!(
"assets/css/_variables.scss",
"""
Content
Expand All @@ -184,7 +184,7 @@ Generator.append_content(

---

`inject_mix_dependency(dependency)`
`inject_mix_dependency!(dependency)`

Inject a new mix dependency into `mix.exs` file.

Expand All @@ -196,14 +196,14 @@ Inject a new mix dependency into `mix.exs` file.

Example
```elixir
Generator.inject_mix_dependency(
Generator.inject_mix_dependency!(
{:credo, latest_package_version(:credo), only: [:dev, :test], runtime: false}
)
```

---

`make_directory(path, touch_directory \\ true)`
`make_directory!(path, touch_directory \\ true)`

Create a new directory.

Expand All @@ -214,12 +214,12 @@ Create a new directory.

Example
```elixir
Generator.make_directory("assets/css/vendor/", false)
Generator.make_directory!("assets/css/vendor/", false)
```

---

`create_file(path, content)`
`create_file!(path, content)`

Create a new file with specified content.

Expand All @@ -230,7 +230,7 @@ Create a new file with specified content.

Example
```elixir
Generator.create_file(
Generator.create_file!(
"assets/css/_variables.scss",
"""
Content
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/reusable_mix_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:

env:
BASE_PROJECT_DIRECTORY: sample_project
MIX_ENV: test
MIX_ENV: dev

jobs:
unit_test:
Expand Down Expand Up @@ -62,6 +62,10 @@ jobs:

- name: Run mix codebase
run: cd $BASE_PROJECT_DIRECTORY && mix codebase
env:
MIX_ENV: test

- name: Run mix test
run: cd $BASE_PROJECT_DIRECTORY && mix test
env:
MIX_ENV: test
5 changes: 5 additions & 0 deletions .github/workflows/reusable_phoenix_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ env:
PHOENIX_VERSION: 1.6.11
BASE_PROJECT_DIRECTORY: sample_project
DB_HOST: localhost
MIX_ENV: dev

jobs:
unit_test:
Expand Down Expand Up @@ -94,9 +95,13 @@ jobs:

- name: Run mix codebase
run: cd $BASE_PROJECT_DIRECTORY && mix codebase
env:
MIX_ENV: test

- name: Run mix test
run: cd $BASE_PROJECT_DIRECTORY && mix coverage
env:
MIX_ENV: test

- name: Remove nimble_template dependency
run: make remove_nimble_template PROJECT_DIRECTORY=$BASE_PROJECT_DIRECTORY
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Step 2: Add `nimble_template` dependency to `mix.exs`:
```elixir
def deps do
[
{:nimble_template, "~> 4.5.0", only: :dev, runtime: false},
{:nimble_template, "~> 4.6.0", only: :dev, runtime: false},
# other dependencies ...
]
end
Expand Down
6 changes: 6 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import Config

config :phoenix, :json_library, Jason

config :nimble_template, hex_package_resource: NimbleTemplate.Hex.Package

if File.exists?("config/#{config_env()}.exs") do
import_config "#{config_env()}.exs"
end
3 changes: 3 additions & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Config

config :nimble_template, hex_package_resource: NimbleTemplate.Hex.PackageMock
2 changes: 1 addition & 1 deletion lib/mix/tasks/nimble_template.bump_version.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule Mix.Tasks.NimbleTemplate.BumpVersion do
def run(args) do
new_version = parse_opts(args)

Version.bump(new_version)
Version.bump!(new_version)
end

defp parse_opts(args) do
Expand Down
4 changes: 3 additions & 1 deletion lib/mix/tasks/nimble_template.gen.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ defmodule Mix.Tasks.NimbleTemplate.Gen do

{:ok, _} = Application.ensure_all_started(:httpoison)

Template.apply(Project.new(opts))
opts
|> Project.new()
|> Template.apply!()
end

defp parse_opts(args) do
Expand Down
2 changes: 1 addition & 1 deletion lib/mix/tasks/nimble_template.upgrade_stack.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule Mix.Tasks.NimbleTemplate.UpgradeStack do
def run(args) do
stack_versions = parse_opts(args)

Version.upgrade_stack(stack_versions)
Version.upgrade_stack!(stack_versions)
end

defp parse_opts(args) do
Expand Down
23 changes: 12 additions & 11 deletions lib/nimble_template/addons/addon.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ defmodule NimbleTemplate.Addons.Addon do
alias __MODULE__
alias NimbleTemplate.Projects.Project

@callback apply(%Project{}, %{}) :: %Project{}
@callback do_apply(%Project{}, %{}) :: %Project{}
@callback apply!(%Project{}, %{}) :: %Project{}
@callback do_apply!(%Project{}, %{}) :: %Project{}

defmacro __using__(opts) do
quote location: :keep, bind_quoted: [opts: opts] do
Expand All @@ -18,21 +18,22 @@ defmodule NimbleTemplate.Addons.Addon do
alias NimbleTemplate.Projects.Project
alias NimbleTemplate.ProjectHelper

def apply(%Project{} = project, opts \\ %{}) when is_map(opts) do
def apply!(%Project{} = project, opts \\ %{}) when is_map(opts) do
Generator.info_log("* applying ", inspect(__MODULE__))

project
|> do_apply(opts)
|> ProjectHelper.append_installed_addon(__MODULE__)
do_apply!(project, opts)
end

def do_apply(%Project{} = project, opts) when is_map(opts), do: project
def do_apply!(%Project{} = project, opts) when is_map(opts), do: project

defp latest_package_version(package) do
"~> " <> Package.get_latest_version(package)
end
defp latest_package_version(package),
do: "~> " <> hex_package_resource().get_latest_version(package)

# TODO: `Application.get_env(:nimble_template, :hex_package_resource)` returns nil on runtime, temporary fix by fallback to `Package`
defp hex_package_resource,
do: Application.get_env(:nimble_template, :hex_package_resource, Package)

defoverridable do_apply: 2
defoverridable do_apply!: 2
end
end
end
6 changes: 3 additions & 3 deletions lib/nimble_template/addons/asdf_tool_version.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule NimbleTemplate.Addons.AsdfToolVersion do
use NimbleTemplate.Addons.Addon

@impl true
def do_apply(
def do_apply!(
%Project{
erlang_version: erlang_version,
elixir_asdf_version: elixir_asdf_version,
Expand All @@ -13,13 +13,13 @@ defmodule NimbleTemplate.Addons.AsdfToolVersion do
} = project,
_opts
) do
Generator.copy_file([{:eex, ".tool-versions.eex", ".tool-versions"}],
Generator.copy_file!([{:eex, ".tool-versions.eex", ".tool-versions"}],
erlang_version: erlang_version,
elixir_asdf_version: elixir_asdf_version
)

if web_project? do
Generator.append_content(
Generator.append_content!(
".tool-versions",
"""
nodejs #{node_asdf_version}
Expand Down
Loading

0 comments on commit 6e94e44

Please sign in to comment.