File tree 3 files changed +37
-1
lines changed 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,9 @@ class InstallGenerator < ::Rails::Generators::Base
11
11
12
12
# Setup HTMX
13
13
def setup
14
- if importmap?
14
+ if bun_configured?
15
+ setup_bun
16
+ elsif importmap?
15
17
setup_importmap
16
18
elsif webpacker?
17
19
setup_webpacker
@@ -24,6 +26,10 @@ def setup
24
26
25
27
private
26
28
29
+ def bun_configured?
30
+ Pathname . new ( destination_root ) . join ( 'bun.config.js' ) . exist?
31
+ end
32
+
27
33
def webpacker?
28
34
!!defined? ( Webpacker )
29
35
end
@@ -40,6 +46,17 @@ def manifest(javascript_dir)
40
46
Pathname . new ( destination_root ) . join ( javascript_dir , 'application.js' )
41
47
end
42
48
49
+ def setup_bun
50
+ run 'bun add htmx.org'
51
+
52
+ manifest = manifest ( 'app/javascript' )
53
+ if manifest . exist?
54
+ append_file manifest , "\n #{ IMPORTMAP_SETUP } "
55
+ else
56
+ create_file manifest , IMPORTMAP_SETUP
57
+ end
58
+ end
59
+
43
60
def setup_importmap
44
61
run 'bin/importmap pin htmx.org'
45
62
Original file line number Diff line number Diff line change 114
114
end
115
115
end
116
116
117
+ context 'with bun configured' do
118
+ before do
119
+ generate_bun_config
120
+ end
121
+
122
+ it 'updates file with htmx import' do
123
+ run_generator
124
+ assert_file (
125
+ 'app/javascript/application.js' ,
126
+ "\n #{ Htmx ::Generators ::InstallGenerator ::IMPORTMAP_SETUP } "
127
+ )
128
+ end
129
+ end
130
+
117
131
context 'with no asset pipeline' do
118
132
before do
119
133
hide_const ( 'Webpacker' )
Original file line number Diff line number Diff line change @@ -7,5 +7,10 @@ def generate_application_js(location_folder)
7
7
FileUtils . mkdir_p ( pathname )
8
8
File . write ( "#{ pathname } /application.js" , '' )
9
9
end
10
+
11
+ def generate_bun_config
12
+ FileUtils . mkdir_p ( destination_root )
13
+ File . write ( "#{ destination_root } /bun.config.js" , "// Some JS\n " )
14
+ end
10
15
end
11
16
end
You can’t perform that action at this time.
0 commit comments