-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement: Migrate phoenix gen to igniter (#261)
- Loading branch information
1 parent
c89c97d
commit 63fa4c7
Showing
5 changed files
with
403 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Used by "mix format" | ||
[ | ||
import_deps: [:ash], | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] | ||
import_deps: [:ash, :phoenix], | ||
plugins: [Phoenix.LiveView.HTMLFormatter], | ||
inputs: ["{mix}.exs", "{config,lib,test}/**/*.{ex,exs,heex}"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,55 @@ | ||
defmodule Mix.Tasks.AshPhoenix.Gen.Live do | ||
use Igniter.Mix.Task | ||
|
||
@example "mix ash_phoenix.gen.live --domain ExistingDomainName --resource ExistingResourceName --resource-plural ExistingResourceNames" | ||
|
||
@shortdoc "Generates liveviews for a given domain and resource." | ||
|
||
# --domain | ||
# --resource | ||
# --resource-plural | ||
@moduledoc """ | ||
#{@shortdoc} | ||
Generates liveviews for a given domain and resource. | ||
The domain and resource must already exist, this task does not define them. | ||
#{AshPhoenix.Gen.docs()} | ||
For example: | ||
## Example | ||
```bash | ||
mix ash_phoenix.gen.live ExistingDomainName ExistingResourceName | ||
#{@example} | ||
``` | ||
## Options | ||
* `--domain` - Existing domain | ||
* `--resource` - Existing resource | ||
* `--resourceplural` - Plural resource name | ||
""" | ||
use Mix.Task | ||
|
||
@shortdoc "Generates liveviews for a resource" | ||
def run(argv) do | ||
Mix.Task.run("compile") | ||
def info(_argv, _composing_task) do | ||
%Igniter.Mix.Task.Info{ | ||
# Groups allow for overlapping arguments for tasks by the same author | ||
# See the generators guide for more. | ||
group: :ash_phoenix, | ||
example: @example, | ||
schema: [domain: :string, resource: :string, resourceplural: :string], | ||
# Default values for the options in the `schema`. | ||
defaults: [], | ||
# CLI aliases | ||
aliases: [], | ||
# A list of options in the schema that are required | ||
required: [:domain, :resource, :resourceplural] | ||
} | ||
end | ||
|
||
if Mix.Project.umbrella?() do | ||
Mix.raise( | ||
"mix phx.gen.live must be invoked from within your *_web application root directory" | ||
) | ||
end | ||
def igniter(igniter, argv) do | ||
# extract options according to `schema` and `aliases` above | ||
options = options!(argv) | ||
|
||
AshPhoenix.Gen.Live.generate_from_cli(argv) | ||
# Do your work here and return an updated igniter | ||
igniter | ||
|> AshPhoenix.Gen.Live.generate_from_cli(options) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.