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

cat-ate-my-source-code

v1.0.0

Published

A pragmatic backup & restore CLI tool for code projects

Readme

cat-ate-my-source-code

A pragmatic backup & restore CLI tool for code projects, focused on disaster recovery and redundancy habits.

"The Cat Ate My Source Code" - Inspired by The Pragmatic Programmer, this tool helps you develop good backup habits and protect your code from disasters.

Features

  • Versioned Backups: Timestamped backups for easy tracking
  • Multiple Projects: Configure and backup multiple code projects
  • Exclude Patterns: Skip node_modules, .git, and other unnecessary files
  • Retention Policy: Automatically prune old backups
  • Dry-Run Mode: Preview what will be backed up
  • Cross-Platform: Works on macOS, Linux, and Windows
  • Config-Driven: Simple JSON configuration
  • 🔜 Remote Backups: Interface designed for rsync/SCP (implementation stubbed)

Installation

npm install
npm run build

For global installation:

npm link

Configuration

Create a configuration file in one of these locations:

  1. cat-ate-my-source-code.config.json in your current working directory
  2. ~/.cat-ate-my-source-code/config.json in your home directory

Example Configuration

{
  "projects": [
    {
      "name": "my-app",
      "path": "/Users/me/dev/my-app",
      "exclude": ["node_modules", ".git", "dist", "*.log"]
    }
  ],
  "backupTargets": [
    {
      "name": "local-disk",
      "type": "local",
      "path": "/Users/me/backups"
    }
  ],
  "retention": {
    "maxBackupsPerProject": 10
  }
}

Configuration Options

  • projects: Array of project configurations

    • name: Unique project identifier
    • path: Absolute or relative path to project directory
    • exclude: Array of glob patterns to exclude (e.g., ["node_modules", ".git"])
  • backupTargets: Array of backup destinations

    • name: Unique target identifier
    • type: "local" or "remote" (remote is stubbed)
    • path: Destination path for backups
    • ssh: (Remote only) SSH connection details
  • retention: Retention policy

    • maxBackupsPerProject: Maximum number of backups to keep per project (default: 10)
  • compression: Enable compression (not yet implemented, default: false)

Usage

Note: The example config file (cat-ate-my-source-code.config.json) contains placeholder paths. Update it with your actual project paths before use.

Backup Commands

After building (npm run build), use the compiled CLI:

node dist/cli.js backup --project my-app

Or during development with ts-node:

npm start -- backup --project my-app

Backup all projects:

node dist/cli.js backup --all

Dry-run to preview:

node dist/cli.js backup --project my-app --dry-run

List Backups

List all backups for a project:

node dist/cli.js list --project my-app

List backups for all projects:

node dist/cli.js list

Restore Commands

Restore a backup to a destination:

node dist/cli.js restore --project my-app --backup 2025-01-15T10-30-00Z --dest /tmp/restore-my-app

Note: The restore command will not overwrite existing directories by default. Choose a destination that doesn't exist, or use --in-place (not yet implemented) with confirmation.

Check Configuration

Validate your configuration file:

node dist/cli.js check

Global Options

  • --config <path>: Specify a custom config file path
  • --verbose or -v: Enable verbose output
  • --dry-run: Preview operations without making changes

Backup Structure

Backups are organized as follows:

backups/
  └── my-app/
      ├── 2025-01-15T10-30-00Z/
      │   └── [project files]
      ├── 2025-01-15T14-20-00Z/
      │   └── [project files]
      └── ...

Each backup is a timestamped directory containing a complete copy of the project (excluding specified patterns).

Retention Policy

After creating a new backup, the tool automatically removes the oldest backups that exceed maxBackupsPerProject. This keeps your backup storage manageable while maintaining a history of recent backups.

Development

Build

npm run build

Run in Development

npm start backup --project my-app

Test

npm test

Philosophy

This tool embodies the principles from The Pragmatic Programmer:

  • Always Use Version Control: While Git is essential, backups provide an additional safety net
  • Backup Early, Backup Often: Automated backups help you develop good habits
  • Design for Failure: Multiple backup targets and retention policies ensure redundancy
  • DRY (Don't Repeat Yourself): Config-driven approach means you define your projects once

The name "cat-ate-my-source-code" is a playful reference to the book's discussion about excuses and the importance of having backups. When disaster strikes (hardware failure, accidental deletion, etc.), you'll be glad you have backups.

Limitations & Future Work

  • Remote Backups: Interface is designed but implementation is stubbed. Future versions will support rsync/SCP.
  • Compression: Config option exists but compression is not yet implemented.
  • In-Place Restore: --in-place flag is designed but not yet implemented for safety.

License

MIT