A utility for generating file maps and contents for directories. This tool helps in creating structured representations of directory contents, which can be useful to feed into an AI system
- Generate detailed file maps of directories
- TypeScript support
- Comprehensive test coverage
- Easy-to-use API
npm install
To build the project:
npm run build
To run the main script:
npm run start -- --dir /path/to/directory
npm run start -- --dir /path/to/directory --output ./custom-output.md
npm run start -- --dir /path/to/directory --ignore node_modules dist .git
npm run start -- --dir /path/to/directory --append-ignore custom-folder "*.log"
The main functionality is provided through the generateFileMap
function. Here's how to use it:
import { generateFileMap } from './fileMapper';
// Basic usage - just specify the directory
const result = generateFileMap('./path/to/your/directory');
// Advanced usage with options
const result = generateFileMap('./path/to/your/directory', {
outputPath: './output.md', // Save results to a markdown file
ignorePatterns: [
'node_modules', // Ignore node_modules directory
'*.log', // Ignore all log files
'.git', // Ignore git directory
'*.tmp' // Ignore temporary files
]
});
// The result object contains:
console.log(result.fileMap); // String representation of directory structure
console.log(result.fileContents); // Contents of all files
console.log(result.tokenCount); // Token count statistics
-
outputPath
(optional): Path where the results should be saved as a markdown file. The markdown file will include:- Directory structure
- File contents
- Token count statistics
-
ignorePatterns
(optional): Array of patterns to ignore. Supports:- Exact matches (e.g., 'node_modules')
- Glob patterns (e.g., '*.log')
Run tests:
npm test
Run tests in watch mode:
npm run test:watch
fileMapper.ts
- Core functionality for mapping files and directoriesfileMapper.test.ts
- Test suite for the file mappermain.ts
- Entry point scriptdist/
- Compiled JavaScript outputtsconfig.json
- TypeScript configurationvitest.config.ts
- Vitest test runner configuration
- TypeScript
- Node.js
- tsx (for running TypeScript files)
- Vitest (for testing)
MIT