Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move components and update CoreComponents handling #5

Merged
merged 4 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions lib/mix/tasks/station_ui.install.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Mix.Tasks.StationUi.Install do

@assets_subpath "assets"

@station_ui_subpath "station_ui"
@station_ui_subpath "components/station_ui"

@sources_root_path __DIR__ |> Path.join("../../../sources") |> Path.expand()

Expand Down Expand Up @@ -131,7 +131,7 @@ defmodule Mix.Tasks.StationUi.Install do
end

defp template_source_destination_file_path(context, source_file_path) do
installer_lib = Path.join(@sources_root_path, "lib/station_ui")
installer_lib = Path.join(@sources_root_path, "lib/components/station_ui")
relative_source_path = Path.relative_to(source_file_path, installer_lib)

Path.join([context.web_path, @station_ui_subpath, relative_source_path])
Expand Down Expand Up @@ -205,27 +205,32 @@ defmodule Mix.Tasks.StationUi.Install do

web_app_ex_path = PathContext.web_app_ex_path(context)
web_app_ex_content = File.read!(web_app_ex_path)
core_components_import = "import #{context.web_app_name}.CoreComponents"

web_app_ex_content =
String.replace(
web_app_ex_content,
"import #{context.web_app_name}.CoreComponents",
"use #{context.web_app_name}.StationUI.HTML"
core_components_import,
"# #{core_components_import}\n use #{context.web_app_name}.StationUI.HTML"
)

File.write!(web_app_ex_path, web_app_ex_content)
IO.puts("Updated #{web_app_ex_path}")

core_components_path = Path.join(context.web_path, "components/core_components.ex")
[first | rest] = File.read!(core_components_path) |> String.trim() |> String.split("\n")
last = List.last(rest)
File.rm!(core_components_path)

File.write(
core_components_path,
Enum.join([first, " # Replaced by StationUI components", last], "\n")
)
if Mix.shell().yes?(
"StationUI is designed to replace the default Phoenix CoreComponents. Ok to clear out the existing CoreComponents file? Unless you made custom changes to this file that you still want, this should be fine to do."
) do
core_components_path = Path.join(context.web_path, "components/core_components.ex")
[first | rest] = File.read!(core_components_path) |> String.trim() |> String.split("\n")
last = List.last(rest)
File.rm!(core_components_path)

File.write(
core_components_path,
Enum.join([first, " # Replaced by StationUI components, do not remove or phoenix generators will recreate the full file", last], "\n")
)

IO.puts("Replaced #{core_components_path}")
TheFirstAvenger marked this conversation as resolved.
Show resolved Hide resolved
IO.puts("Replaced #{core_components_path}")
end
end
end
144 changes: 0 additions & 144 deletions sources/lib/station_ui/HTML/icon_buttons.ex

This file was deleted.

Loading