Skip to content

Commit 496107b

Browse files
committed
[gh315] Remove Tailwind config
1 parent 25fd192 commit 496107b

File tree

2 files changed

+207
-119
lines changed

2 files changed

+207
-119
lines changed

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

Lines changed: 206 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -3,153 +3,241 @@ 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";
4863
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";
64+
import "phoenix_html"
65+
"""
66+
)
5867

59-
# import "phoenix_html"
60-
# """
61-
# )
68+
project
69+
end
6270

63-
# project
64-
# end
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";
6580
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";
81+
import "phoenix_html"
82+
"""
83+
)
7584

76-
# import "phoenix_html"
77-
# """
78-
# )
85+
project
86+
end
7987

80-
# project
81-
# end
88+
defp edit_app_scss!(project, %{with_nimble_css_addon: true}), do: project
8289

83-
# defp edit_app_scss!(project, %{with_nimble_css_addon: true}), do: project
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";
8498
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";
99+
@import './vendor/';
100+
"""
101+
)
93102

94-
# @import './vendor/';
95-
# """
96-
# )
103+
project
104+
end
97105

98-
# project
99-
# end
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+
////////////////////////////////
100113
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-
# ////////////////////////////////
114+
////////////////////////////////
115+
// Custom Bootstrap variables //
116+
////////////////////////////////
117+
"""
118+
)
108119

109-
# ////////////////////////////////
110-
# // Custom Bootstrap variables //
111-
# ////////////////////////////////
112-
# """
113-
# )
120+
project
121+
end
114122

115-
# project
116-
# end
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+
////////////////////////////////
117130
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-
# ////////////////////////////////
131+
////////////////////////////////
132+
// Custom Bootstrap variables //
133+
////////////////////////////////
134+
"""
135+
)
125136

126-
# ////////////////////////////////
127-
# // Custom Bootstrap variables //
128-
# ////////////////////////////////
129-
# """
130-
# )
137+
project
138+
end
131139

132-
# project
133-
# end
140+
defp edit_vendor_index!(project, %{with_nimble_css_addon: true}) do
141+
Generator.append_content!("assets/css/vendor/_index.scss", "@import './bootstrap';")
134142

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

138-
# project
139-
# 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';")
140149

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';")
150+
project
151+
end
144152

145-
# project
146-
# 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+
])
147157

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-
# ])
158+
project
159+
end
152160

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