nvmrc-wizard
Version: 
Automatically generate and manage .nvmrc based on your framework's Node.js compatibility
80 lines (56 loc) ⢠1.97 kB
Markdown
# nvmrc-wizard
š Automatically generate and manage `.nvmrc` based on your framework's Node.js compatibility.
Supports **Angular**, **React**, and **Vue** with comprehensive compatibility matrices.
## Features
- ā
 Auto-detects your framework and version
- ā
 Recommends the most compatible Node.js version
- ā
 Creates or updates `.nvmrc` file
- ā
 Optionally switches Node version using NVM
- ā
 Works on Windows, macOS, and Linux
- ā
 Shows NVM installation guide if needed if nvm is not installed
## Usage
```bash
# Run in your project directory
npx nvmrc-wizard
```
## What it does
1. **Detects your framework** from `package.json` (Angular/React/Vue)
2. **Finds the most compatible Node.js version** based on your framework version
3. **Creates `.nvmrc`** if it doesn't exist
4. **Prompts to update** if `.nvmrc` exists but has a different version
5. **Switches to the recommended version** (if NVM is installed and you confirm)
## Example output
```
š Analyzing Node.js version compatibility...
š¦ Detected: Angular v17.2.0
šÆ Most compatible Node.js version: v20.19.1
š No .nvmrc file found.
ā
 Created .nvmrc with recommended Node.js v20.19.1
š Switching to Node.js v20.19.1 as specified in .nvmrc...
ā
 Successfully switched to Node.js v20.19.1
```
## Supported Frameworks
- **Angular** 13.x - 20.x
- **React** 14.x - 19.x
- **Vue** 2.6.x - 3.5.x
For native JavaScript projects, it uses the latest LTS version.
## Requirements
- Node.js >= 14
- (Optional) NVM for automatic version switching
## Use with Husky
Add to `.husky/pre-commit`:
```bash
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
# Guid to auto-generate .nvmrc if missing
if [ ! -f .nvmrc ]; then
  echo "ā ERROR: .nvmrc file is missing!"
  echo ""
  echo "š Please create .nvmrc by running:"
  echo "   npx nvmrc-wizard"
  echo ""
  exit 1
fi
```
## License
MIT