Created
January 24, 2025 23:23
-
-
Save t2/a51989d20746857d1ce571e59bbdc8e1 to your computer and use it in GitHub Desktop.
Consolidate Rails Project Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'fileutils' | |
# Add the folders you want to consolidate the files from. | |
TARGETS_TO_CONSOLIDATE = %w[ | |
app/controllers | |
app/models | |
app/commands | |
app/helpers | |
app/jobs | |
app/notifiers | |
app/policies | |
app/services | |
app/components | |
app/views | |
app/javascript | |
app/graphql | |
spec | |
] | |
SPECIFIC_FILES = %w[db/schema.rb] | |
FILE_EXTENSIONS = %w[.rb .js .erb] | |
OUTPUT_DIR = "output" | |
FileUtils.mkdir_p(OUTPUT_DIR) | |
def consolidate_folder(folder_path) | |
folder_name = File.basename(folder_path) | |
output_file = File.join(OUTPUT_DIR, "#{folder_name}.txt") | |
File.open(output_file, 'w') {} | |
return unless Dir.exist?(folder_path) | |
Dir.glob(File.join(folder_path, '**', '*')).each do |file| | |
next unless FILE_EXTENSIONS.include?(File.extname(file)) | |
File.open(output_file, 'a') do |output| | |
output.puts "===== #{file} =====" | |
output.puts File.read(file) | |
output.puts "\n\n" | |
end | |
end | |
end | |
def consolidate_file(file_path) | |
return unless File.exist?(file_path) | |
file_name = File.basename(file_path, '.*') + '.txt' | |
output_file = File.join(OUTPUT_DIR, file_name) | |
File.open(output_file, 'w') do |output| | |
output.puts "===== #{file_path} =====" | |
output.puts File.read(file_path) | |
end | |
end | |
TARGETS_TO_CONSOLIDATE.each { |folder| consolidate_folder(folder) } | |
SPECIFIC_FILES.each { |file| consolidate_file(file) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment