Sha256: 524883bdda528f8ebf28ece1fd3d5a97e3735895f2e114102b6c5ac3484cc9bb

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

#!/usr/bin/env ruby

require 'fileutils'

app_root = Dir.pwd
app_name = File.basename(app_root)

# Create tmp directory
tmp_dir = File.join(app_root, 'tmp')
FileUtils.mkdir_p(tmp_dir)

# Define directories and file patterns to include in the search, excluding specific files and directories
include_patterns = [
  File.join(app_root, 'bin', '**', '*'),
  File.join(app_root, 'lib', '**', '*'),
  File.join(app_root, 'spec', '**', '*'),
  File.join(app_root, '.github', '**', '*'),
  File.join(app_root, '*.{md,rss,json,rb,gemspec,lock,yml,gitignore,rspec,tool-versions,Appraisals,Rakefile}')
]

# Find all matching files
files = include_patterns.flat_map { |pattern| Dir.glob(pattern, File::FNM_DOTMATCH) }
files.select! { |f| File.file?(f) }

# Exclude the gemfiles directory and the top-level Gemfile.lock
files.reject! do |file|
  file.start_with?(File.join(app_root, 'gemfiles')) || file == File.join(app_root, 'Gemfile.lock')
end

# Output file
output_file = File.join(tmp_dir, "#{app_name}_flat_file.txt")

File.open(output_file, 'w') do |file|
  files.each do |file_path|
    relative_path = file_path.sub("#{app_root}/", '')
    extension = File.extname(file_path).delete_prefix('.')

    file.puts "#{relative_path}:"

    content = File.read(file_path)
    if extension == 'md'
      file.puts content
    else
      file.puts "```#{extension}"
      file.puts content
      file.puts "```"
    end

    file.puts ""
  end
end

# Print the path to the generated flat file
puts "Flat file created at: #{output_file}"

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_recall-2.1.0 bin/flatten