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
3131 replace_first_line config . config_path , "app/frontend" , %( "sourceCodeDir": "#{ dir } ",)
3232 end
3333 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"
3535 end
3636
3737 # Internal: Configure CSP rules that allow to load @vite/client correctly.
@@ -56,6 +56,18 @@ def setup_content_security_policy(csp_file)
5656 CSP
5757 end
5858
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 path , contents
69+ end
70+
5971 # Override: Create a sample JS file and attempt to inject it in an HTML template.
6072 def install_sample_files
6173 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
6161
6262 def_delegators "ViteRuby" , :config
6363
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 |
6565 define_method ( util ) { |*args |
6666 ViteRuby ::CLI ::FileUtils . send ( util , *args ) rescue nil
6767 }
You can’t perform that action at this time.
0 commit comments