module SvelteOnRails::Installer::Utils
def self.add_route(route)
def self.add_route(route) file_path = 'config/routes.rb' # Read the file content content = File.read(file_path) # Split content into lines lines = content.lines # Find the index of Rails.application.routes.draw do ind = -1 lines.each_with_index do |line, i| if line.match?(/^\s*Rails.application.routes.draw\s*do[\s\S]+$/) ind = i end end # Insert if ind >= 0 lines.insert(ind + 1, route) else raise "ERROR: Could not find Rails.application.routes.draw do" end # Write the modified content back to the file begin File.write(file_path, lines.map { |l| l.gsub(/\n/, '') }.join("\n")) puts "Successfully inserted «root '#{route}'» into '#{file_path}'" rescue => e raise "Error writing to #{file_path} => «#{e.message}»" end end