Skip to content

Commit 10c6dc0

Browse files
committed
[gh315] Remove Tailwind config
1 parent 25fd192 commit 10c6dc0

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+
defp edit_files!(%Project{} = project, opts) do
24+
project
25+
|> edit_assets_package!()
26+
|> edit_app_js!(opts)
27+
|> edit_app_scss!(opts)
28+
|> edit_vendor_index!(opts)
29+
|> edit_css_variables!(opts)
30+
end
1731

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
32+
defp copy_files!(%Project{} = project) do
33+
copy_bootstrap_vendor!(project)
2634

27-
# defp copy_files!(%Project{} = project) do
28-
# copy_bootstrap_vendor!(project)
35+
project
36+
end
2937

30-
# project
31-
# end
38+
defp edit_assets_package!(%Project{} = project) do
39+
Generator.replace_content!(
40+
"assets/package.json",
41+
"""
42+
"dependencies": {
43+
""",
44+
"""
45+
"dependencies": {
46+
"@popperjs/core": "2.11.5",
47+
"bootstrap": "5.1.3",
48+
"""
49+
)
3250

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-
# )
51+
project
52+
end
4553

46-
# project
47-
# end
54+
defp edit_app_js!(project, %{with_nimble_js_addon: true}) do
55+
Generator.replace_content!(
56+
"assets/js/app.js",
57+
"""
58+
import "phoenix_html"
59+
""",
60+
"""
61+
// Bootstrap
62+
import "bootstrap/dist/js/bootstrap";
63+
64+
import "phoenix_html"
65+
"""
66+
)
67+
68+
project
69+
end
4870

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";
71+
defp edit_app_js!(project, %{with_nimble_js_addon: false}) do
72+
Generator.replace_content!(
73+
"assets/js/app.js",
74+
"""
75+
import "phoenix_html"
76+
""",
77+
"""
78+
// Bootstrap
79+
import "bootstrap/dist/js/bootstrap";
5880
59-
# import "phoenix_html"
60-
# """
61-
# )
81+
import "phoenix_html"
82+
"""
83+
)
6284

63-
# project
64-
# end
85+
project
86+
end
6587

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";
88+
defp edit_app_scss!(project, %{with_nimble_css_addon: true}), do: project
7589

76-
# import "phoenix_html"
77-
# """
78-
# )
90+
defp edit_app_scss!(project, %{with_nimble_css_addon: false}) do
91+
Generator.replace_content!(
92+
"assets/css/app.scss",
93+
"""
94+
@import "./phoenix.css";
95+
""",
96+
"""
97+
@import "./phoenix.css";
7998
80-
# project
81-
# end
99+
@import './vendor/';
100+
"""
101+
)
82102

83-
# defp edit_app_scss!(project, %{with_nimble_css_addon: true}), do: project
103+
project
104+
end
84105

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";
106+
defp edit_css_variables!(project, %{with_nimble_css_addon: false}) do
107+
Generator.create_file!(
108+
"assets/css/_variables.scss",
109+
"""
110+
////////////////////////////////
111+
// Shared variables //
112+
////////////////////////////////
93113
94-
# @import './vendor/';
95-
# """
96-
# )
114+
////////////////////////////////
115+
// Custom Bootstrap variables //
116+
////////////////////////////////
117+
"""
118+
)
97119

98-
# project
99-
# end
120+
project
121+
end
100122

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-
# ////////////////////////////////
123+
defp edit_css_variables!(project, %{with_nimble_css_addon: true}) do
124+
Generator.append_content!(
125+
"assets/css/_variables.scss",
126+
"""
127+
////////////////////////////////
128+
// Shared variables //
129+
////////////////////////////////
108130
109-
# ////////////////////////////////
110-
# // Custom Bootstrap variables //
111-
# ////////////////////////////////
112-
# """
113-
# )
131+
////////////////////////////////
132+
// Custom Bootstrap variables //
133+
////////////////////////////////
134+
"""
135+
)
114136

115-
# project
116-
# end
137+
project
138+
end
117139

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-
# ////////////////////////////////
140+
defp edit_vendor_index!(project, %{with_nimble_css_addon: true}) do
141+
Generator.append_content!("assets/css/vendor/_index.scss", "@import './bootstrap';")
125142

126-
# ////////////////////////////////
127-
# // Custom Bootstrap variables //
128-
# ////////////////////////////////
129-
# """
130-
# )
143+
project
144+
end
131145

132-
# project
133-
# end
146+
defp edit_vendor_index!(project, %{with_nimble_css_addon: false}) do
147+
Generator.make_directory!("assets/css/vendor/", false)
148+
Generator.create_file!("assets/css/vendor/_index.scss", "@import './bootstrap';")
134149

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

138-
# project
139-
# end
153+
defp copy_bootstrap_vendor!(%Project{} = project) do
154+
Generator.copy_file!([
155+
{:text, "assets/bootstrap_css/vendor/_bootstrap.scss", "assets/css/vendor/_bootstrap.scss"}
156+
])
140157

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';")
158+
project
159+
end
144160

145-
# project
146-
# end
161+
def remove_tailwind_config_file!(project) do
162+
File.rm!("assets/tailwind.config.js")
147163

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-
# ])
164+
project
165+
end
152166

153-
# project
154-
# end
167+
def remove_tailwind_config!(project) do
168+
Generator.delete_content!(
169+
"config/config.exs",
170+
"""
171+
# Configure tailwind (the version is required)
172+
config :tailwind,
173+
version: "3.2.4",
174+
default: [
175+
args: ~w(
176+
--config=tailwind.config.js
177+
--input=css/app.css
178+
--output=../priv/static/assets/app.css
179+
),
180+
cd: Path.expand("../assets", __DIR__)
181+
]
182+
"""
183+
)
184+
185+
project
186+
end
187+
188+
def remove_tailwind_dev_config!(project) do
189+
Generator.replace_content!(
190+
"config/dev.exs",
191+
"""
192+
esbuild: {Esbuild, :install_and_run, [:app, ~w(--sourcemap=inline --watch)]},
193+
tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]}
194+
""",
195+
"""
196+
esbuild: {Esbuild, :install_and_run, [:app, ~w(--sourcemap=inline --watch)]}
197+
"""
198+
)
199+
200+
project
201+
end
202+
203+
def remove_tailwind_mix!(project) do
204+
Generator.replace_content!(
205+
"mix.exs",
206+
"""
207+
{:tailwind, "~> 0.1.8", runtime: Mix.env() == :dev},
208+
{:swoosh, "~> 1.3"},
209+
""",
210+
"""
211+
{:swoosh, "~> 1.3"},
212+
"""
213+
)
214+
215+
Generator.replace_content!(
216+
"mix.exs",
217+
"""
218+
"assets.setup": ["tailwind.install --if-missing", "esbuild.install --if-missing"],
219+
"assets.build": ["tailwind default", "esbuild app"],
220+
"assets.deploy": [
221+
"tailwind default --minify",
222+
"esbuild app --minify",
223+
"sass app --no-source-map --style=compressed",
224+
"cmd npm run postcss --prefix assets",
225+
"phx.digest"
226+
]
227+
""",
228+
"""
229+
"assets.setup": ["esbuild.install --if-missing"],
230+
"assets.build": ["esbuild app"],
231+
"assets.deploy": [
232+
"esbuild app --minify",
233+
"sass app --no-source-map --style=compressed",
234+
"cmd npm run postcss --prefix assets",
235+
"phx.digest"
236+
]
237+
"""
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)