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
Flag | Type | Description |
---|---|---|
--s | string[] | Input glob patterns (comma-separated or repeated) |
--ignore | string[] | Extra ignore patterns |
--d | string | Output file path |
--stdout | boolean | Print merged result to stdout |
--separator | string | Custom separator between sections (default: \n\n ) |
--comment | string | Custom comment prefix (e.g. # , // ) |
--forceComment | boolean | Use your custom comment for all file types |
--noPath | boolean | Skip path footer (don't show file path after each section) |
--pathAbove | boolean | Print file path above each file's content (default: true) |
--format | string | Fallback extension for autogenerated file (default: txt ) |
--batch | boolean | Disable prompts (non-interactive mode) |
--recursive | boolean | Recursively process all files in subdirectories (default: true) |
--preserveStructure | boolean | Preserve source directory structure in output (default: true) |
--increment | boolean | Attach incrementing index to output filenames if set |
--concurrency | number | Number of concurrent file operations (default: 8) |
--sort | string | Sort files by: name, path, mtime, none (default: path) |
--dryRun | boolean | Show what would be done, but don't write files |
--backup | boolean | Backup output files before overwriting |
--dedupe | boolean | Remove duplicate file contents in merge |
--header | string | Header text to add at the start of merged output |
--footer | string | Footer text to add at the end of merged output |
--select-files | boolean | Prompt for file selection before merging |
--interactive | boolean | Enable interactive mode with prompts |
--as-templates | boolean | Generate a TypeScript file with template structure |
--ctn | string | Custom template name when using --as-templates |
--whitelabel | string | Custom prefix to use instead of 'DLER' in template generation |
--sourcemap | boolean | Generate source map for the merged output |
--templates-update | string | Update specific template in existing mock template file |
--dev | boolean | Generate template for development |
How It Works
Basic Merge
- You provide
--s
globs likesrc/**/*.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:
Ext | Comment |
---|---|
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