module SvelteOnRails::Installer::Utils

def self.remove_line_from_file(file_path, string_to_find, force: false)

def self.remove_line_from_file(file_path, string_to_find, force: false)
  # Read the file content
  content = File.read(file_path)
  # Split content into lines
  lines = content.lines
  found_lines = []
  modified_content = []
  lines.each do |line|
    if line.match(/^[\s\S]+#{string_to_find}[\s\S]+$/)
      found_lines.push(line)
    else
      modified_content.push(line)
    end
  end
  utils = SvelteOnRails::Installer::Utils
  if found_lines.present?
    return if !force && utils.ask_yn("Remove lines\n#{found_lines.join("\n  • ")}\n from #{file_path}?")
    # Write the modified content back to the file
    begin
      File.write(file_path, modified_content.map { |l| l.gsub(/\n/, '') }.join("\n"))
      puts "Successfully removed #{found_lines.length} #{'line'.pluralize(found_lines.length)}."
    rescue => e
      raise "Error writing to #{file_path} => «#{e.message}»"
    end
  else
  end
end