Skip to content

Instantly share code, notes, and snippets.

@t2
Created January 24, 2025 23:25
Show Gist options
  • Save t2/8ab0ab7b64265e128f233714fb786f59 to your computer and use it in GitHub Desktop.
Save t2/8ab0ab7b64265e128f233714fb786f59 to your computer and use it in GitHub Desktop.
Consolidate React Native Project Code
require 'fileutils'
PROJECT_NAME = 'your_project_name'
TARGETS_TO_CONSOLIDATE = %w[
app/apollo
app/components
app/context
app/graphql
app/hooks
app/navigation
app/screens
app/styles
app/types
app/utils
android/app/src/main
]
SPECIFIC_FILES = %w[
ios/PROJECT_NAME/AppDelegate.h
ios/PROJECT_NAME/AppDelegate.mm
ios/Podfile.lock
ios/PROJECT_NAME.xcodeproj/project.pbxproj
android/app/build.gradle
android/build.gradle
android/gradle.properties
fastlane/Fastfile
fastlane/Appfile
].map { |path| path.gsub('PROJECT_NAME', PROJECT_NAME) }
FILE_EXTENSIONS = %w[.js .jsx .tsx .ts .json .rb .kt .swift .java]
OUTPUT_DIR = "consolidated_files"
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