index-generate
v0.0.3
Published
A CLI tool to generate index.ts files automatically for TypeScript projects
Maintainers
Readme
index-generate
A powerful CLI and library to automatically generate index.ts files for TypeScript projects.
It intelligently exports default exports, named exports, and types from your files and folders.
# ===========================================================
# 📦 Installation
# ===========================================================
npm install index-generate
yarn add index-generate
# Install globally (optional)
npm install -g index-generate
# ===========================================================
# ⚡ CLI Usage
# ===========================================================
# Generate index.ts files for a target directory
ts-index-gen <target-directory>
# If no directory is provided, it defaults to:
# src/components
# Example:
ts-index-gen src/components
# ===========================================================
# 🛠️ Programmatic Usage (TypeScript)
# ===========================================================
import { generateAllOptimized } from 'index-generate/dist/generateIndex';
import path from 'path';
const targetDir = path.join(process.cwd(), 'src/components');
generateAllOptimized(targetDir)
.then(() => console.log("Index files generated successfully!"))
.catch(err => console.error("Error:", err));
# ===========================================================
# 📝 Notes
# ===========================================================
# - Default exports are renamed to match the file name.
# - Named exports (functions, classes, const, enum...) are preserved.
# - Type exports (type, interface, enum) are included.
# - Files starting with _ or . are ignored.
# - Test files (*.test.ts, *.test.tsx) are skipped.
# - Declaration files (*.d.ts) are skipped.
# - The generator works recursively on all subdirectories.
# - Must be executed in a Node.js environment (uses fs + path).
# ===========================================================
# 🤝 Contributing
# ===========================================================
# Contributions are welcome!
# Please open an issue or create a pull request on GitHub.
# ===========================================================