LogoRelidocs

Merge

Merge command.

rse merge is a powerful rse's command which allows you to merge multiple text/code files into a single file or output stream. It supports both simple file merging and advanced template generation for mock structures. Built with love for developers who like clean structure.

Features

  • 🧠 Smart filtering: skips binary/media files automatically
  • 🧩 Flexible output: write to file or stream to stdout
  • 💬 Optional path headers/footers: add comments with relative paths
  • 🛠️ CI-friendly: use --batch to disable all prompts
  • 📜 Comment-aware: supports language-specific comment prefixes
  • 🪄 Interactive prompts if args are missing
  • 🔁 Custom separators between sections
  • 🎨 Template generation: create TypeScript templates for mock structures
  • 🔄 Template updates: modify existing templates with new content
  • 📝 Source map support: generate source maps for merged files
  • 🔒 Security: validates file permissions and handles conflicts
  • 📦 Package.json integration: supports special handling of package.json files
  • 🔍 Deduplication: option to remove duplicate content
  • 📋 File sorting: sort by name, path, or modification time

Installation

  • You can run it via bunx: bunx @reliverse/remege (usage: bunx @reliverse/remege --help)
  • Or by installing globally: bun i -g @reliverse/remege (usage: remege --help)
  • Or install locally: bun add -D @reliverse/remege (usage: bun remege --help)

Tip

You can automate the process by adding a script to your package.json:

"scripts": {
  // remege | bunx @reliverse/remege
  "merge": "remege --s src/**/*.ts --d dist/combined.ts",
  "template": "remege --s src/templates --d templates/my-template.ts --as-templates"
}

Usage

Use it interactively:

remege

Or via command line flags:

# Basic merge
remege \
  --s "src/**/*.ts" \
  --ignore "**/*.test.ts" \
  --d dist/merged.txt \
  --separator "\n\n" \
  --comment "// "

# Generate template
remege \
  --s "src/templates" \
  --d "templates/my-template.ts" \
  --as-templates \
  --whitelabel "MYAPP"

# Update existing template
remege \
  --s "src/templates" \
  --d "templates/my-template.ts" \
  --templates-update "REACT_DLER_TEMPLATE"

Integration with Mock Command

The merge command integrates with the mock command to create and update templates that can be used to generate mock project structures. Here's how they work together:

1 Create a template from existing files:

remege --s src/templates --d templates/my-template.ts --as-templates

2 Use the template to generate a mock structure:

dler mock --template-file templates/my-template.ts

3 Update an existing template:

remege --s src/templates --d templates/my-template.ts --templates-update REACT_DLER_TEMPLATE

Options

FlagTypeDescription
--sstring[]Input glob patterns (comma-separated or repeated)
--ignorestring[]Extra ignore patterns
--dstringOutput file path
--stdoutbooleanPrint merged result to stdout
--separatorstringCustom separator between sections (default: \n\n)
--commentstringCustom comment prefix (e.g. #, //)
--forceCommentbooleanUse your custom comment for all file types
--noPathbooleanSkip path footer (don't show file path after each section)
--pathAbovebooleanPrint file path above each file's content (default: true)
--formatstringFallback extension for autogenerated file (default: txt)
--batchbooleanDisable prompts (non-interactive mode)
--recursivebooleanRecursively process all files in subdirectories (default: true)
--preserveStructurebooleanPreserve source directory structure in output (default: true)
--incrementbooleanAttach incrementing index to output filenames if set
--concurrencynumberNumber of concurrent file operations (default: 8)
--sortstringSort files by: name, path, mtime, none (default: path)
--dryRunbooleanShow what would be done, but don't write files
--backupbooleanBackup output files before overwriting
--dedupebooleanRemove duplicate file contents in merge
--headerstringHeader text to add at the start of merged output
--footerstringFooter text to add at the end of merged output
--select-filesbooleanPrompt for file selection before merging
--interactivebooleanEnable interactive mode with prompts
--as-templatesbooleanGenerate a TypeScript file with template structure
--ctnstringCustom template name when using --as-templates
--whitelabelstringCustom prefix to use instead of 'DLER' in template generation
--sourcemapbooleanGenerate source map for the merged output
--templates-updatestringUpdate specific template in existing mock template file
--devbooleanGenerate template for development

How It Works

Basic Merge

  • You provide --s globs like src/**/*.ts
  • Optionally ignore files via --ignore
  • All matching files are collected (except binaries)
  • Each section is appended into the final output, optionally with a path header/footer

Template Generation

  • Files are collected and processed based on their type (text, json, binary)
  • Special handling for package.json and tsconfig.json files
  • Generates a TypeScript file with template structure
  • Supports custom template names and whitelabel prefixes

Template Updates

  • Updates existing templates while preserving structure
  • Handles file conflicts and permissions
  • Supports source map generation for debugging

Example

# Basic merge with custom separator
bunx @reliverse/remege --s "src/**/*.js" --stdout --noPath

# Generate template from existing files
bunx @reliverse/remege --s "src/templates" --d "templates/my-template.ts" --as-templates

# Update existing template
bunx @reliverse/remege --s "src/templates" --d "templates/my-template.ts" --templates-update REACT_DLER_TEMPLATE

Custom Separator Examples

--separator "\n\n"    # double newline
--separator "\n---\n" # markdown-style break
--separator "\n// -----\n" # JS-style

Use escaped characters like \n, \t. These will be converted to newlines, tabs, etc.

Binary Files That Are Skipped

File types like images, videos, fonts, compressed archives, and executables are skipped by default:

  • .png, .jpg, .gif, .mp4, .mp3, .pdf, .zip, .exe, .woff, .jar, etc.

Language-Specific Comment Prefixes

These are automatically selected based on file extensions:

ExtComment
ts//
py#
html<!--
sql--
css/*

You can override using --comment.

Use Cases Examples

  • You want to send the contents of several files to AI
  • Collecting code snippets into a teaching demo
  • Merging many markdown files into a single file
  • Creating templates for mock project structures
  • Updating existing templates with new content
  • Generating source maps for debugging

License

💖 2025 MIT blefnk Nazar Kornienko