prompt-concator
v1.2.5
Published
`prompt-concator` is a powerful Node.js tool for concatenating file contents into a single output file. It supports customizable options like excluding specific files or folders, matching files with patterns, and even opening the result in **TextEdit** (m
Downloads
713
Readme
Prompt Concator
prompt-concator
is a powerful Node.js tool for concatenating file contents into a single output file. It supports customizable options like excluding specific files or folders, matching files with patterns, and even opening the result in TextEdit (macOS) for immediate review. Designed for developers and enthusiasts, it’s perfect for managing and summarizing file contents in an efficient way.
Features
- Flexible File Matching: Use glob patterns to include or exclude specific files or folders.
- Customizable: Options can be passed via CLI or a
prompt.config.json
file. - TextEdit Integration: Automatically opens the output file in TextEdit (macOS) with
textEdit: true
. - Watch Mode: Monitor file changes in real-time and regenerate the output file on the fly.
Installation
Global Installation
npm install -g prompt-concator
Local Installation (for Testing)
- Clone or download the repository.
- Navigate to the project directory:
cd /path/to/prompt-concator
- Link the package locally:
npm link
Usage
Command-Line Interface (CLI)
1. Run Once
Concatenate files based on the default or provided options:
npx prompt-concator -prompt "Your custom prompt here"
2. Enable Watch Mode
Regenerate the output file automatically when changes are detected:
npx prompt-concator -prompt "Your custom prompt here" --watch
3. Open in TextEdit (macOS)
Use the --textEdit
flag to open the resulting file in TextEdit:
npx prompt-concator -prompt "Your custom prompt here" --textEdit
4. Combine Watch Mode and TextEdit
Monitor changes and open the file in TextEdit after updates:
npx prompt-concator -prompt "Your custom prompt here" --watch --textEdit
Programmatic API
Use prompt-concator
in your Node.js scripts:
const { promptConcater, watchAndConcatenate } = require('prompt-concator');
// Run Once
promptConcater('Your prompt text here', {
excludeFolders: ['node_modules', 'dist'],
excludeFiles: ['README.md'],
patterns: [{ src: './src/**/*.js' }],
textEdit: true
});
// Watch for Changes
watchAndConcatenate('Your prompt text here', {
excludeFolders: ['node_modules', 'dist'],
excludeFiles: ['README.md'],
patterns: [{ src: './src/**/*.js' }],
textEdit: true
});
Configuration File: prompt.config.json
The tool reads configuration options from a prompt.config.json
file in the project directory. Here's an example:
{
"excludeFolders": ["node_modules", "dist"],
"excludeFiles": ["README.md"],
"patterns": [{ "src": "./src/**/*.js" }],
"textEdit": true
}
Options
| Option | Type | Description |
|-------------------|------------|-----------------------------------------------------------|
| excludeFolders
| Array
| List of folder names to exclude from processing. |
| excludeFiles
| Array
| List of specific file names to exclude. |
| patterns
| Array
| List of glob patterns to match files. |
| textEdit
| Boolean
| Open the output file in TextEdit after generation. |
Examples
Basic Example
npx prompt-concator -prompt "Merge all source files"
Watch Mode with Custom Configuration
Create a prompt.config.json
file:
{
"excludeFolders": ["node_modules", "dist"],
"patterns": [{ "src": "./src/**/*.js" }],
"textEdit": true
}
Run the tool:
npx prompt-concator -prompt "Combine source files." --watch
Combining with Other Tools
You can incorporate output-prompt.txt
into a pipeline that feeds into other apps or scripts. On macOS, it’s even possible to pair this with tools that capture the top-most window’s content or selected text, appending it to output-prompt.txt
. Then, supply it to an LLM interface, ensuring you have the latest and most relevant context on hand.
Command-Line Overrides by Configuration
In addition to using a prompt.config.json
file, you can override specific settings directly via the command line. These overrides are useful for temporary or project-specific adjustments without modifying the configuration file.
Example Overrides
Exclude Additional Folders and Files
You can exclude specific folders or files in addition to those defined in the configuration file:
npx prompt-concator -prompt "Custom Prompt" --excludeFolders temp logs --excludeFiles "*.tmp" "*.bak"
Combine Watch Mode and Overrides
Use overrides to customize file matching while monitoring changes:
npx prompt-concator -prompt "Custom Prompt" --watch --excludeFolders "temp" --excludeFiles "*.log"
Command-line overrides are merged with defaults and configurations, so you can fine-tune the tool's behavior without losing global settings.
Personal Motivation
This tool can help you precisely control which files and folders are incorporated into prompts for your LLM. For example, you might only want to include specific files from certain directories rather than relying on glob patterns.
Using the --onlyPaths
Option
If you run the tool with the --onlyPaths
flag, it will ignore the default behavior of expanding glob patterns. Instead, it will treat all subsequent arguments as literal paths (both files and folders). Only the files that are not excluded will be concatenated into output-prompt.txt
.
Example:
npx prompt-concator --onlyPaths ./src/file1.js ./src/file2.js ./docs ./another-folder
This command will: • Include file1.js and file2.js from ./src if they are not excluded by your configuration. • Acknowledge ./docs and ./another-folder as folders, though they are not concatenated. • Produce output-prompt.txt containing the concatenated contents of the included files.
License
Buy Me a Beer License
Feel free to use this tool for personal and commercial purposes. If you find it helpful, you can buy me a beer 🍺. Cheers!