Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vite_rails/lib/vite_rails/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def setup_app_files
replace_first_line config.config_path, "app/frontend", %( "sourceCodeDir": "#{dir}",)
end
setup_content_security_policy root.join("config/initializers/content_security_policy.rb")
append root.join("Procfile.dev"), "web: bin/rails s"
append_unless_present root.join("Procfile.dev"), "web: bin/rails s", pattern: "web:"
end

# Internal: Configure CSP rules that allow to load @vite/client correctly.
Expand Down
9 changes: 8 additions & 1 deletion vite_ruby/lib/vite_ruby/cli/file_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ def cp(source, destination)
# @since 1.2.11
# @api private
def append(path, contents)
append_unless_present(path, contents, pattern: contents)
end

# Adds a new line at the bottom of the file, unless any line matches the pattern.
#
# @api private
def append_unless_present(path, contents, pattern:)
content = read_lines(path)
return if content.join.include?(contents)
return if content.any? { |line| line.include?(pattern) }

content << "\n" unless content.last&.end_with?("\n")
content << "#{contents}\n"
Expand Down
2 changes: 1 addition & 1 deletion vite_ruby/lib/vite_ruby/cli/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def install_sample_files

def_delegators "ViteRuby", :config

%i[append cp inject_line_after inject_line_after_last inject_line_before replace_first_line write].each do |util|
%i[append append_unless_present cp inject_line_after inject_line_after_last inject_line_before replace_first_line write].each do |util|
define_method(util) { |*args|
ViteRuby::CLI::FileUtils.send(util, *args) rescue nil
}
Expand Down
Loading