Skip to content

Phase 2 Implementation Complete ✅

Summary

The merge-files tool has been implemented and is ready for testing.

What It Does

Merges unique content from one markdown file into another:

  1. Creates backups (A.original, B.original)
  2. Parses both files into sections by heading
  3. Identifies unique sections in A (not in B)
  4. Merges unique sections into B under appropriate headings
  5. Updates TOC in B
  6. Updates all links pointing to A to redirect to B
  7. Removes A from VitePress config
  8. Preserves A, A.original, B.original for manual review

Features Implemented

Section parsing - Breaks files into sections by markdown headings
Duplicate detection - Identifies similar/duplicate content
Smart merging - Finds best-fit headings or creates new ones
TOC updates - Automatically updates Table of Contents
Link redirects - Updates all references from A → B
Config updates - Removes merged file from VitePress
Backup preservation - Keeps originals for review/undo
Edge cases - Handles empty files, identical files, etc.
Verbose mode - Shows detailed progress with -v flag

Files Created

notes/tools/
├── merge-files.ts                    # Main tool
└── docs/
    ├── test-merge.sh                 # Test runner
    └── test/
        └── merge-fixtures/           # Test files
            ├── file-a.md             # Source file
            ├── file-b.md             # Target file
            └── test-links.md         # File with links to A

Usage

Compile:

bash
cd /Users/sand/GitHub/webseriously/notes/tools
npx tsc

Run:

bash
node notes/tools/dist/merge-files.js A.md B.md       # Merge A into B
node notes/tools/dist/merge-files.js -v A.md B.md    # Verbose mode
node notes/tools/dist/merge-files.js --help          # Show help

Test

Run the test script:

bash
bash notes/tools/docs/test-merge.sh

This will:

  1. Reset test fixtures to original state
  2. Compile TypeScript
  3. Run merge tool on test files
  4. Show merged content and updated links
  5. List backup files created

Next Steps

  1. Test the tool - Run test-merge.sh
  2. Verify results - Check merged content, links, backups
  3. Mark Phase 2 complete - If tests pass
  4. Move to Phase 3 - Integration & documentation

Status: READY FOR TESTING 🚀