File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
vite_rails/lib/vite_rails
vite_ruby/lib/vite_ruby/cli Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ def setup_app_files
31
31
replace_first_line config . config_path , "app/frontend" , %( "sourceCodeDir": "#{ dir } ",)
32
32
end
33
33
setup_content_security_policy root . join ( "config/initializers/content_security_policy.rb" )
34
- append root . join ( "Procfile.dev" ) , "web: bin/rails s"
34
+ append_if_no_web_entry root . join ( "Procfile.dev" ) , "web: bin/rails s"
35
35
end
36
36
37
37
# Internal: Configure CSP rules that allow to load @vite/client correctly.
@@ -56,6 +56,18 @@ def setup_content_security_policy(csp_file)
56
56
CSP
57
57
end
58
58
59
+ # Internal: Append a line to a file only if no line starts with 'web:'
60
+ # @param path [Pathname] The path to the file
61
+ # @param contents [String] The line to append
62
+ def append_if_no_web_entry ( path , contents )
63
+ content = read_lines ( path )
64
+
65
+ # Check if any line starts with 'web:'
66
+ return if content . any? { |line | line . strip . start_with? ( "web:" ) }
67
+
68
+ append root . join ( "Procfile.dev" ) , "web: bin/rails s"
69
+ end
70
+
59
71
# Override: Create a sample JS file and attempt to inject it in an HTML template.
60
72
def install_sample_files
61
73
unless config . resolved_entrypoints_dir . join ( "application.js" ) . exist?
Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ def install_sample_files
61
61
62
62
def_delegators "ViteRuby" , :config
63
63
64
- %i[ append cp inject_line_after inject_line_after_last inject_line_before replace_first_line write ] . each do |util |
64
+ %i[ append read_lines cp inject_line_after inject_line_after_last inject_line_before replace_first_line write ] . each do |util |
65
65
define_method ( util ) { |*args |
66
66
ViteRuby ::CLI ::FileUtils . send ( util , *args ) rescue nil
67
67
}
You can’t perform that action at this time.
0 commit comments