require 'find' class FileManager def copy_files_recursively(source_dir, destination_dir) if Dir.exist?(source_dir) Dir.glob(File.join(source_dir, '*')).each do |item| relative_path = Pathname.new(item).relative_path_from(Pathname.new(source_dir)).to_s destination_path = File.join(destination_dir, relative_path) if File.directory?(item) FileUtils.mkdir_p(destination_path) FileUtils.cp_r(File.join(item, '.'), destination_path) else FileUtils.mkdir_p(File.dirname(destination_path)) FileUtils.cp(item, destination_path) end Solara.logger.debug("🚗 Copied #{relative_path} \n\t↖️From: #{source_dir} \n\t↗️To: #{destination_dir}") end else Solara.logger.failure("#{source_dir} not found in Solara") end end def delete_folders_by_prefix(directory, folder_prefix) # Get a list of all folders in the directory folders = Dir.entries(directory).select { |entry| File.directory?(File.join(directory, entry)) && entry.start_with?(folder_prefix) } # Delete each folder folders.each do |folder| folder_path = File.join(directory, folder) FileUtils.rm_rf(folder_path) Solara.logger.debug("🧹 Deleted folder: #{folder_path}") end end def self.create_file_if_not_exist(file_path) unless File.exist?(file_path) FileUtils.mkdir_p(File.dirname(file_path)) File.open(file_path, 'w') {} Solara.logger.debug("✨ Created file: #{file_path}") end end def self.create_files_if_not_exist(file_paths) file_paths.each do |file_path| create_file_if_not_exist(file_path) end end def self.find_file_extesion(extension) files = [] Find.find(SolaraSettingsManager.instance.project_root) do |path| if FileTest.file?(path) && File.extname(path) == extension files << path end end files end def self.find_files_by_extension(directory, extension) Dir.glob(File.join(directory, "**", "*#{extension}")) end def self.find_files_by_name(directory, filename) Dir.glob(File.join(directory, "**", filename)).to_a end def self.get_relative_path(root_dir, sub_dir) Pathname(sub_dir).relative_path_from(Pathname(root_dir)).to_s rescue sub_dir end def self.get_relative_path_to_root(sub_dir) Pathname(sub_dir).relative_path_from(Pathname(FilePath.project_root)).to_s rescue sub_dir end def self.get_folders(source) # Fetches only directories in the specified source directory Dir.glob(File.join(source, '*')).select { |path| File.directory?(path) } end def self.delete_if_exists(path) FileUtils.rm_rf(path) if File.exist?(path) end end