npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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)

  1. Clone or download the repository.
  2. Navigate to the project directory:
    cd /path/to/prompt-concator
  3. 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!