Skip to content

Commit 0bbd241

Browse files
committed
[gh315] Remove Tailwind config
1 parent 0fc9f5a commit 0bbd241

File tree

2 files changed

+206
-119
lines changed

2 files changed

+206
-119
lines changed

lib/nimble_template/addons/variants/phoenix/web/bootstrap.ex

Lines changed: 205 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -3,153 +3,240 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.Bootstrap do
33

44
use NimbleTemplate.Addons.Addon
55

6+
# @impl true
7+
# def do_apply!(%Project{} = project, _opts) do
8+
# project
9+
# end
10+
11+
# TODO: Enable Bootstrap on the next PR
612
@impl true
7-
def do_apply!(%Project{} = project, _opts) do
13+
def do_apply!(%Project{} = project, opts) do
814
project
15+
|> edit_files!(opts)
16+
|> copy_files!()
17+
|> remove_tailwind_mix!()
18+
|> remove_tailwind_dev_config!()
19+
|> remove_tailwind_config_file!()
20+
|> remove_tailwind_config!()
921
end
1022

11-
# TODO: Enable Bootstrap on the next PR
12-
# def do_apply!(%Project{} = project, opts) do
13-
# project
14-
# |> edit_files!(opts)
15-
# |> copy_files!()
16-
# end
23+
def remove_tailwind_config_file!(project) do
24+
File.rm!("assets/tailwind.config.js")
1725

18-
# defp edit_files!(%Project{} = project, opts) do
19-
# project
20-
# |> edit_assets_package!()
21-
# |> edit_app_js!(opts)
22-
# |> edit_app_scss!(opts)
23-
# |> edit_vendor_index!(opts)
24-
# |> edit_css_variables!(opts)
25-
# end
26+
project
27+
end
2628

27-
# defp copy_files!(%Project{} = project) do
28-
# copy_bootstrap_vendor!(project)
29+
def remove_tailwind_config!(project) do
30+
Generator.delete_content!(
31+
"config/config.exs",
32+
"""
33+
# Configure tailwind (the version is required)
34+
config :tailwind,
35+
version: "3.2.4",
36+
default: [
37+
args: ~w(
38+
--config=tailwind.config.js
39+
--input=css/app.css
40+
--output=../priv/static/assets/app.css
41+
),
42+
cd: Path.expand("../assets", __DIR__)
43+
]
44+
"""
45+
)
2946

30-
# project
31-
# end
47+
project
48+
end
3249

33-
# defp edit_assets_package!(%Project{} = project) do
34-
# Generator.replace_content!(
35-
# "assets/package.json",
36-
# """
37-
# "dependencies": {
38-
# """,
39-
# """
40-
# "dependencies": {
41-
# "@popperjs/core": "2.11.5",
42-
# "bootstrap": "5.1.3",
43-
# """
44-
# )
50+
def remove_tailwind_dev_config!(project) do
51+
Generator.replace_content!(
52+
"config/dev.exs",
53+
"""
54+
esbuild: {Esbuild, :install_and_run, [:app, ~w(--sourcemap=inline --watch)]},
55+
tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]}
56+
""",
57+
"""
58+
esbuild: {Esbuild, :install_and_run, [:app, ~w(--sourcemap=inline --watch)]}
59+
"""
60+
)
4561

46-
# project
47-
# end
62+
project
63+
end
4864

49-
# defp edit_app_js!(project, %{with_nimble_js_addon: true}) do
50-
# Generator.replace_content!(
51-
# "assets/js/app.js",
52-
# """
53-
# import "phoenix_html"
54-
# """,
55-
# """
56-
# // Bootstrap
57-
# import "bootstrap/dist/js/bootstrap";
65+
def remove_tailwind_mix!(project) do
66+
Generator.replace_content!(
67+
"mix.exs",
68+
"""
69+
{:tailwind, "~> 0.1.8", runtime: Mix.env() == :dev},
70+
{:swoosh, "~> 1.3"},
71+
""",
72+
"""
73+
{:swoosh, "~> 1.3"},
74+
"""
75+
)
76+
77+
Generator.replace_content!(
78+
"mix.exs",
79+
"""
80+
"assets.setup": ["tailwind.install --if-missing", "esbuild.install --if-missing"],
81+
"assets.build": ["tailwind default", "esbuild app"],
82+
"assets.deploy": [
83+
"tailwind default --minify",
84+
"esbuild app --minify",
85+
"sass app --no-source-map --style=compressed",
86+
"cmd npm run postcss --prefix assets",
87+
"phx.digest"
88+
]
89+
""",
90+
"""
91+
"assets.setup": ["esbuild.install --if-missing"],
92+
"assets.build": ["esbuild app"],
93+
"assets.deploy": [
94+
"esbuild app --minify",
95+
"sass app --no-source-map --style=compressed",
96+
"cmd npm run postcss --prefix assets",
97+
"phx.digest"
98+
]
99+
"""
100+
)
58101

59-
# import "phoenix_html"
60-
# """
61-
# )
102+
project
103+
end
62104

63-
# project
64-
# end
105+
defp edit_files!(%Project{} = project, opts) do
106+
project
107+
|> edit_assets_package!()
108+
|> edit_app_js!(opts)
109+
|> edit_app_scss!(opts)
110+
|> edit_vendor_index!(opts)
111+
|> edit_css_variables!(opts)
112+
end
65113

66-
# defp edit_app_js!(project, %{with_nimble_js_addon: false}) do
67-
# Generator.replace_content!(
68-
# "assets/js/app.js",
69-
# """
70-
# import "phoenix_html"
71-
# """,
72-
# """
73-
# // Bootstrap
74-
# import "bootstrap/dist/js/bootstrap";
114+
defp copy_files!(%Project{} = project) do
115+
copy_bootstrap_vendor!(project)
75116

76-
# import "phoenix_html"
77-
# """
78-
# )
117+
project
118+
end
79119

80-
# project
81-
# end
120+
defp edit_assets_package!(%Project{} = project) do
121+
Generator.replace_content!(
122+
"assets/package.json",
123+
"""
124+
"dependencies": {
125+
""",
126+
"""
127+
"dependencies": {
128+
"@popperjs/core": "2.11.5",
129+
"bootstrap": "5.1.3",
130+
"""
131+
)
82132

83-
# defp edit_app_scss!(project, %{with_nimble_css_addon: true}), do: project
133+
project
134+
end
84135

85-
# defp edit_app_scss!(project, %{with_nimble_css_addon: false}) do
86-
# Generator.replace_content!(
87-
# "assets/css/app.scss",
88-
# """
89-
# @import "./phoenix.css";
90-
# """,
91-
# """
92-
# @import "./phoenix.css";
136+
defp edit_app_js!(project, %{with_nimble_js_addon: true}) do
137+
Generator.replace_content!(
138+
"assets/js/app.js",
139+
"""
140+
import "phoenix_html"
141+
""",
142+
"""
143+
// Bootstrap
144+
import "bootstrap/dist/js/bootstrap";
93145
94-
# @import './vendor/';
95-
# """
96-
# )
146+
import "phoenix_html"
147+
"""
148+
)
97149

98-
# project
99-
# end
150+
project
151+
end
100152

101-
# defp edit_css_variables!(project, %{with_nimble_css_addon: false}) do
102-
# Generator.create_file!(
103-
# "assets/css/_variables.scss",
104-
# """
105-
# ////////////////////////////////
106-
# // Shared variables //
107-
# ////////////////////////////////
153+
defp edit_app_js!(project, %{with_nimble_js_addon: false}) do
154+
Generator.replace_content!(
155+
"assets/js/app.js",
156+
"""
157+
import "phoenix_html"
158+
""",
159+
"""
160+
// Bootstrap
161+
import "bootstrap/dist/js/bootstrap";
108162
109-
# ////////////////////////////////
110-
# // Custom Bootstrap variables //
111-
# ////////////////////////////////
112-
# """
113-
# )
163+
import "phoenix_html"
164+
"""
165+
)
114166

115-
# project
116-
# end
167+
project
168+
end
117169

118-
# defp edit_css_variables!(project, %{with_nimble_css_addon: true}) do
119-
# Generator.append_content!(
120-
# "assets/css/_variables.scss",
121-
# """
122-
# ////////////////////////////////
123-
# // Shared variables //
124-
# ////////////////////////////////
170+
defp edit_app_scss!(project, %{with_nimble_css_addon: true}), do: project
125171

126-
# ////////////////////////////////
127-
# // Custom Bootstrap variables //
128-
# ////////////////////////////////
129-
# """
130-
# )
172+
defp edit_app_scss!(project, %{with_nimble_css_addon: false}) do
173+
Generator.replace_content!(
174+
"assets/css/app.scss",
175+
"""
176+
@import "./phoenix.css";
177+
""",
178+
"""
179+
@import "./phoenix.css";
131180
132-
# project
133-
# end
181+
@import './vendor/';
182+
"""
183+
)
134184

135-
# defp edit_vendor_index!(project, %{with_nimble_css_addon: true}) do
136-
# Generator.append_content!("assets/css/vendor/_index.scss", "@import './bootstrap';")
185+
project
186+
end
137187

138-
# project
139-
# end
188+
defp edit_css_variables!(project, %{with_nimble_css_addon: false}) do
189+
Generator.create_file!(
190+
"assets/css/_variables.scss",
191+
"""
192+
////////////////////////////////
193+
// Shared variables //
194+
////////////////////////////////
140195
141-
# defp edit_vendor_index!(project, %{with_nimble_css_addon: false}) do
142-
# Generator.make_directory!("assets/css/vendor/", false)
143-
# Generator.create_file!("assets/css/vendor/_index.scss", "@import './bootstrap';")
196+
////////////////////////////////
197+
// Custom Bootstrap variables //
198+
////////////////////////////////
199+
"""
200+
)
144201

145-
# project
146-
# end
202+
project
203+
end
147204

148-
# defp copy_bootstrap_vendor!(%Project{} = project) do
149-
# Generator.copy_file!([
150-
# {:text, "assets/bootstrap_css/vendor/_bootstrap.scss", "assets/css/vendor/_bootstrap.scss"}
151-
# ])
205+
defp edit_css_variables!(project, %{with_nimble_css_addon: true}) do
206+
Generator.append_content!(
207+
"assets/css/_variables.scss",
208+
"""
209+
////////////////////////////////
210+
// Shared variables //
211+
////////////////////////////////
152212
153-
# project
154-
# end
213+
////////////////////////////////
214+
// Custom Bootstrap variables //
215+
////////////////////////////////
216+
"""
217+
)
218+
219+
project
220+
end
221+
222+
defp edit_vendor_index!(project, %{with_nimble_css_addon: true}) do
223+
Generator.append_content!("assets/css/vendor/_index.scss", "@import './bootstrap';")
224+
225+
project
226+
end
227+
228+
defp edit_vendor_index!(project, %{with_nimble_css_addon: false}) do
229+
Generator.make_directory!("assets/css/vendor/", false)
230+
Generator.create_file!("assets/css/vendor/_index.scss", "@import './bootstrap';")
231+
232+
project
233+
end
234+
235+
defp copy_bootstrap_vendor!(%Project{} = project) do
236+
Generator.copy_file!([
237+
{:text, "assets/bootstrap_css/vendor/_bootstrap.scss", "assets/css/vendor/_bootstrap.scss"}
238+
])
239+
240+
project
241+
end
155242
end

lib/nimble_template/addons/variants/phoenix/web/core_js.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.CoreJS do
1616
""",
1717
"""
1818
"dependencies": {
19-
"core-js": "3.22.0"
19+
"core-js": "3.29.1"
2020
"""
2121
)
2222

0 commit comments

Comments
 (0)