@dileepadev/fetch-gitignore
v1.0.2
Published
A terminal/CLI tool using Node.js that allows developers to fetch official .gitignore templates from GitHub and save them to their project. This tool will simplify initializing projects with the correct .gitignore and improve developer productivity.
Maintainers
Readme
Fetch .gitignore 🛡️
A professional terminal/CLI tool built with Node.js that simplifies initializing projects with official .gitignore templates from the GitHub gitignore repository.
Stop manually searching and copy-pasting .gitignore content—fetch and save them directly from your terminal!
Table of Contents
- Fetch .gitignore 🛡️
- Table of Contents
- 🚀 Features
- 📦 Installation
- 🛠️ Usage
- 🧪 Local Development & Testing
- 🧪 Running Tests
- 🏗️ Architecture
- 🤝 Contributing
- 📜 License
- 🐛 Troubleshooting
- 🚀 Development Workflow
🚀 Features
- Dynamic Fetching: Pulls the latest templates directly from the official GitHub repository.
- Multiple Templates: Combine multiple
.gitignoretemplates (e.g.,Node,Python,Visual Studio Code). - Caching: Local caching of templates and list for faster access and offline use.
- Safety: Prevents accidental overwriting of existing
.gitignorefiles unless forced. - Append Mode: Easily add new rules to your existing
.gitignore. - Directory Support: Target any directory, whether it's your current path or a subproject.
- Rate Limit Handling: Smartly handles GitHub API rate limits and provides clear feedback on when to retry.
📦 Installation
To use fetch-gitignore as a global CLI tool, install it via npm:
npm install -g @dileepadev/fetch-gitignoreOr run it instantly using npx:
npx @dileepadev/fetch-gitignore list
npx @dileepadev/fetch-gitignore add Node🛠️ Usage
1. List Available Templates
To see all templates available in the official GitHub repository:
fetch-gitignore list2. Add a Template
To create a new .gitignore file for your project:
fetch-gitignore add <TemplateName>Example: fetch-gitignore add Node
3. Combine Multiple Templates
You can pass multiple template names to merge them into a single .gitignore file:
fetch-gitignore add Node Python Rust4. Options
| Option | Shorthand | Description | Default |
| :--- | :--- | :--- | :--- |
| --dir <path> | -d | Target directory where .gitignore will be saved. | . |
| --append | -a | Append content to an existing .gitignore file. | false |
| --force | -f | Force overwrite an existing .gitignore file. | false |
| --no-cache | - | Bypass local cache and fetch directly from GitHub. | false |
| --help | -h | Display help information. | - |
| --version | -V | Display the version number. | - |
💾 Cache Configuration
Templates and the template list are cached locally (usually in ~/.fetch-gitignore-cache) for 24 hours.
You can customize the Time-To-Live (TTL) using an environment variable:
# Set cache to expire after 1 hour (3600 seconds)
export FETCH_GITIGNORE_CACHE_TTL=3600To disable caching entirely, set it to 0:
export FETCH_GITIGNORE_CACHE_TTL=0🧪 Local Development & Testing
This guide explains how to test fetch-gitignore locally before publishing to npm.
📦 Prerequisites
- Node.js ≥ 18
- npm ≥ 9
Check your version:
node -v
npm -v🔧 1. Install Dependencies
From the project root:
npm installBuild the TypeScript sources:
npm run build🔗 2. Link the CLI Globally (Recommended)
This simulates installing the package globally via npm install -g.
npm linkThis creates a global symlink so you can run:
fetch-gitignorefrom anywhere on your system.
🧪 3. Test the CLI
Move to any test directory:
mkdir test-cli
cd test-cliThen try:
List available templates
fetch-gitignore listCreate a .gitignore file
fetch-gitignore add NodeAppend to existing .gitignore
fetch-gitignore add Python --appendOverwrite existing .gitignore
fetch-gitignore add Node --forceAdd multiple templates
fetch-gitignore add Node Python ReactSpecify target directory
fetch-gitignore add Node --dir ./backendForce a refresh (bypass cache)
fetch-gitignore list --no-cache
fetch-gitignore add Node --no-cache🧠 4. Run Without Linking (Alternative)
If you don’t want to use npm link, you can run the CLI directly:
node dist/bin/index.js listor
node dist/bin/index.js add Node📦 5. Test as a Packed npm Module (Production Simulation)
To simulate a real npm installation:
npm packThis generates a .tgz file like:
dileepadev-fetch-gitignore-1.0.2.tgzThen install it globally:
npm install -g ./dileepadev-fetch-gitignore-1.0.2.tgzNow test it as if it were published.
🧹 6. Unlink When Done
To remove the global symlink:
npm unlink -g @dileepadev/fetch-gitignore🧪 Running Tests
This project uses Vitest for unit and integration testing.
Run All Tests
npm testRun Tests in Watch Mode
npm run test:watchRun Tests with Coverage
npm run test:coverageTest Structure
| Test File | Module | Description |
| :--- | :--- | :--- |
| tests/utils.test.ts | resolveDirectory, mergeTemplates | Directory resolution, template merging, edge cases |
| tests/logger.test.ts | logSuccess, logError, logInfo | Stdout/stderr routing, message content |
| tests/fileManager.test.ts | writeGitignore | Create, overwrite, append, conflict errors |
| tests/cache.test.ts | saveToCache, getFromCache | Save/load, TTL logic, env var overrides |
| tests/fetcher.test.ts | fetchTemplate, listTemplates | Mocked HTTP: success, 404, rate limits, response parsing |
| tests/cli.test.ts | CLI binary | --help, --version, subcommands, error handling |
🏗️ Architecture
- TypeScript: Strict, type-safe codebase compiled to ESM.
- Commander.js: Powering the CLI command and argument parsing.
- Node-Fetch: Used to retrieve template data from GitHub APIs.
- Chalk & Ora: Creating a beautiful, interactive terminal experience.
- File System (fs): Reliable management of
.gitignorefiles and local caching. - Vitest: Fast, TypeScript-native test framework for unit and integration tests.
🤝 Contributing
Contributions are welcome! Please check our CONTRIBUTING.md for guidelines on how to get started.
📜 License
Distributed under the MIT License. See LICENSE for more information.
🐛 Troubleshooting
Command not found?
Make sure npm link ran successfully. You can verify it with:
which fetch-gitignorePermission issues (macOS/Linux)
Ensure your CLI entry file is executable:
chmod +x dist/bin/index.js🚀 Development Workflow
During development:
- Edit code
- Run
npm run build - Run
fetch-gitignore - Test behavior
- Repeat
Because npm link creates a symlink, changes apply immediately — no reinstall required.
