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 🙏

© 2025 – Pkg Stats / Ryan Hefner

source-collector

v0.0.11-beta

Published

Utility to collect file content and generate output in txt or json format

Readme

File Collector

source-collector is a utility for collecting the contents of sources from a specified project directory. It offers flexible options for included/excluded directories and output formats. It is both a Node.js module and a CLI tool.

Features

  • Collect the content of all sources in a project directory.
  • Flexible options to include or exclude specific directories.
  • Output the results in either:
    • TXT format with source paths and contents.
    • JSON format as a structured object.
  • Use it programmatically in Node.js or directly via CLI.

Installation

From NPM (Global Install)

npm install -g source-collector

Local Development (Without Publishing to NPM)

  • Clone the repository or set up the package locally.
  • Compile the TypeScript sources:
npm run build
  • Link the package globally:
npm link

Development

Prerequisites

  • Install Node.js and npm.
  • Clone the repository:
git clone https://github.com/andyBobro/source-collector.git
cd source-collector

Install Dependencies

Install the required dependencies for development:

npm install

Compile TypeScript

Compile the TypeScript source code into JavaScript:

npm run build

Usage

CLI Usage

After installation or linking, you can run the source-collector command from your terminal.

Basic Command

source-collector --outputPath output.json

Options

| Option | Type | Default | Required | Description | | ---------------- | ---------- | ----------------- | -------- | -------------------------------------------------- | | --includeDirs | string[] | All directories | No | List of directories to include (relative to root). | | --excludeDirs | string[] | node_modules | No | List of directories to exclude (relative to root). | | --outputFormat | string | json | No | Output format: txt or json. | | --outputPath | string | None | Yes | Path to save the output file. |

Node.js Usage

Basic usage

import { FileCollector } from 'source-collector';

(async () => {
  const collector = new FileCollector(process.cwd(), {
    includeDirs: ['src', 'test'], // Directories to include
    excludeDirs: ['dist', 'node_modules'], // Directories to exclude
    outputFormat: 'json', // Output format: json or txt
  });

  // Generate the output as JSON or TXT
  const output = await collector.generateOutput();
  console.log(output);

  // Save the output to a source
  await collector.saveOutput('output.json');
})();

API

| Method | Parameters | Returns | Description | |----------------------------|-----------------------------------------------------------------------------------------------|--------------------------------------|-----------------------------------------------------------------------------| | constructor | rootDir: string - The root directory to start collecting sources. | FileCollector instance | Creates an instance of FileCollector with the given root directory and options. | | | options: { includeDirs?: string[], excludeDirs?: string[], outputFormat?: 'txt' | 'json' } | | Includes options for directory inclusion, exclusion, and output format. | | generateOutput | None | Promise<string> or Promise<Record<string, { path: string; content: string }>> | Collects source content and generates the output in memory as JSON or TXT. | | saveOutput | sourcePath: string - The path where the output will be saved. | Promise<void> | Saves the generated output (JSON or TXT) to the specified source path. |

Options

| Option | Type | Default | Required | Description | |-------------------|--------------|-------------------|----------|-----------------------------------------------------| | includeDirs | string[] | All directories | No | List of directories to include (relative to root). | | excludeDirs | string[] | node_modules | No | List of directories to exclude (relative to root). | | outputFormat | string | json | No | Output format: txt or json. |