Skip to content

Commit

Permalink
improvement: automatically add sources to assets/tailwind.config.js
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Jan 27, 2025
1 parent 8058503 commit de66810
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
erlang 27.0.1
elixir 1.17.2-otp-27
elixir 1.18.2
6 changes: 6 additions & 0 deletions documentation/tutorials/ui-overrides.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ Generates sign in, registration and reset forms for a resource.

Generates a default registration form.

* `:button_text` - Text for the submit button.

* `:disable_button_text` - Text for the submit button when the request is happening.

* `:form_class` - CSS class for the `form` element.
Expand All @@ -140,6 +142,8 @@ Generates a default registration form.

Generates a default sign in form.

* `:button_text` - Text for the submit button.

* `:disable_button_text` - Text for the submit button when the request is happening.

* `:form_class` - CSS class for the `form` element.
Expand Down Expand Up @@ -191,6 +195,8 @@ Generates a default password reset form.

Generates a default password reset form.

* `:button_text` - Tex for the submit button.

* `:disable_button_text` - Text for the submit button when the request is happening.

* `:form_class` - CSS class for the `form` element.
Expand Down
36 changes: 34 additions & 2 deletions lib/mix/tasks/ash_authentication_phoenix.install.ex
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ if Code.ensure_loaded?(Igniter) do
|> Igniter.Project.Formatter.import_dep(:ash_authentication_phoenix)
|> Igniter.compose_task("igniter.add_extension", ["phoenix"])
|> warn_on_missing_modules(options, argv, install?)
|> explain_tailwind_changes()
|> do_or_explain_tailwind_changes()
|> use_authentication_phoenix_router(router)
|> create_auth_controller()
|> create_overrides_module(overrides)
Expand Down Expand Up @@ -341,6 +341,38 @@ if Code.ensure_loaded?(Igniter) do
end)
end

@tailwind_prefix """
module.exports = {
content: [
"""

defp do_or_explain_tailwind_changes(igniter) do
if Igniter.exists?(igniter, "assets/tailwind.config.js") do
igniter = Igniter.include_glob(igniter, "assets/tailwind.config.js")
source = Rewrite.source!(igniter.rewrite, "assets/tailwind.config.js")
content = Rewrite.Source.get(source, :content)

case String.split(content, @tailwind_prefix, parts: 2) do
[prefix, suffix] ->
insert = " \"../deps/ash_authentication_phoenix/**/*.*ex\",\n"

source =
Rewrite.Source.update(
source,
:content,
prefix <> @tailwind_prefix <> insert <> suffix
)

%{igniter | rewrite: Rewrite.update!(igniter.rewrite, source)}

_ ->
explain_tailwind_changes(igniter)
end
else
explain_tailwind_changes(igniter)
end
end

defp explain_tailwind_changes(igniter) do
Igniter.add_notice(igniter, """
Modify your `tailwind.config.js` file, to add the ash_authentication_phoenix
Expand All @@ -351,7 +383,7 @@ if Code.ensure_loaded?(Igniter) do
"./js/**/*.js",
"../lib/*_web.ex",
"../lib/*_web/**/*.*ex",
"../deps/ash_authentication_phoenix/**/*.*ex", // <-- Add this line
],
...
}
Expand Down

0 comments on commit de66810

Please sign in to comment.