module SvelteOnRails::Installer::Utils
def self.write_templates(template_paths)
def self.write_templates(template_paths) existing = template_paths.select { |p| File.exist?(p) } verb = 'Created' if existing.present? begin puts "#{'Template'.pluralize(existing.length)} already exists:\n#{existing.join("\n")}.\nOverwrite? (y/n)" continue = STDIN.gets.chomp.downcase[0] end until ['y', 'n'].include?(continue) if continue == 'n' puts "Skipping write #{'template'.pluralize(template_paths.length)}." return end verb = 'Overwrote' end template_paths.each do |p| source_path = File.expand_path('rails_template', __dir__) + '/' + p FileUtils.mkdir_p(File.dirname(p)) FileUtils.cp(source_path, p) end puts "#{verb} #{'file'.pluralize(template_paths.length)}:\n#{template_paths.join("\n")}" end