Intelligent version control system that analyzes Git commits and automates semantic versioning (SemVer).
Version Control automates semantic versioning of your project, eliminating the need to manually decide between MAJOR, MINOR, or PATCH.
Why was it created?
Manual versioning is error-prone and inconsistent across teams. This tool solves:
- β Forgetting to update `package.json`, `CHANGELOG.md`, or tags
- β Confusion about which version to use (MAJOR/MINOR/PATCH)
- β Incomplete or disorganized CHANGELOGs
- β Inconsistent commit messages
Solution:
- β Automatically analyzes commits and suggests the correct version
- β Updates all files at once
- β Generates organized and complete CHANGELOGs
- β Creates tags and pushes automatically
- π Intelligent Analysis: Analyzes commit messages and modified files
- π― Automatic Suggestion: Suggests MAJOR, MINOR, or PATCH based on changes
- π Automatic Update: Updates `package.json`, `CHANGELOG.md`, and code files
- π·οΈ Git Tags: Creates tags automatically and pushes to repository
- π€ Smart Commit: Generates commit messages following Conventional Commits
- π Intelligent CHANGELOG: Groups commits by type and removes duplicates
- π§ͺ Test Mode: Allows automatic rollback
- π Internationalization: Support for EN, PT, ES, FR
```bash yarn global add @ridiormf/version-control
npm install -g @ridiormf/version-control ```
```bash yarn add -D @ridiormf/version-control
npm install -D @ridiormf/version-control ```
```bash npx @ridiormf/version-control
yarn dlx @ridiormf/version-control ```
After making your changes and committing:
```bash version-control ```
Or with npx (without installing):
```bash npx @ridiormf/version-control ```
Intelligent commit with automatic message:
```bash git add . smart-commit ```
Example:
```bash Staged files: 2 β¨ src/newFeature.ts (+45/-0) π src/index.ts (+5/-2)
Generated commit message: feat(src): add newFeature
Options: [1] Commit [2] Edit [3] Cancel Choice: 1
β Commit created successfully! ```
Add a script to your `package.json`:
```json { "scripts": { "version": "version-control", "version:test": "version-control --test", "commit": "smart-commit" } } ```
And run:
```bash
yarn commit
yarn version
yarn version:test ```
Use the library in your custom scripts:
```typescript import { analyzeChanges, bumpVersion, getCurrentVersion, updatePackageJson, updateChangelog, executeGitCommands, } from "@ridiormf/version-control";
// 1. Get current version const currentVersion = getCurrentVersion(); // Returns: "1.2.3"
// 2. Analyze changes from last commit const analysis = analyzeChanges(); // Returns: { type: 'minor', reason: ['New feature added'], filesChanged: [...], commitMsg: '...' }
// 3. Calculate new version const newVersion = bumpVersion(currentVersion, analysis.type); // Returns: "1.3.0"
// 4. Update files updatePackageJson(newVersion); updateChangelog(newVersion, analysis.type, analysis);
// 5. Commit and create tag executeGitCommands(newVersion); ```
The system analyzes changes from the last Git commit and suggests the appropriate version based on Conventional Commits format and file changes.
Detected when the commit message contains keywords like:
- `breaking`, `break`, `incompatible`, `remove`, `delete`, `rewrite`
Example:
```bash git commit -m "breaking: remove deprecated API methods"
```
Detected when:
- Message contains: `add`, `new`, `feature`, `implement`, `create`
- New files are added to the project
- Configuration files are modified
Example:
```bash git commit -m "feat: add user authentication module"
```
Detected when the message contains:
- `fix`, `bug`, `error`
- Small changes without new files
Example:
```bash git commit -m "fix: resolve memory leak in cache"
```
``` Breaks existing code? ββ YES β π΄ MAJOR (X.0.0) ββ NO β Adds functionality? ββ YES β π‘ MINOR (x.Y.0) ββ NO β π’ PATCH (x.y.Z) ```
See more at semver.org
```bash git commit -m "feat: add new export functionality" version-control
```
- `analyzeChanges()` - Analyzes last commit and suggests version type
- `getCurrentVersion(projectRoot?)` - Returns current version from package.json
- `bumpVersion(currentVersion, type)` - Calculates new version
- `updatePackageJson(newVersion, projectRoot?)` - Updates package.json
- `updateIndexFile(newVersion, projectRoot?)` - Updates @version in code files
- `updateChangelog(version, type, analysis, projectRoot?)` - Updates CHANGELOG.md
- `executeGitCommands(version)` - Creates commit, tag, and pushes
- `getStagedChanges()` - Lists staged files
- `generateCommitMessage(changes)` - Generates automatic commit message
- `getConfiguredLanguage()` - Returns configured language
- `setLanguage(lang)` - Sets language manually
- `clearConfig()` - Removes configuration
Analyzes the last commit and returns an analysis of the changes.
Returns:
```typescript interface ChangeAnalysis { type: "major" | "minor" | "patch"; reason: string[]; filesChanged: string[]; commitMsg: string; } ```
Returns the current version from `package.json`.
Parameters:
- `projectRoot` (optional): Project root path (default: `process.cwd()`)
Calculates the new version based on the bump type.
Parameters:
- `currentVersion`: Current version (e.g., "1.2.3")
- `type`: Bump type (`'major'`, `'minor'`, or `'patch'`)
Example:
```typescript bumpVersion("1.2.3", "major"); // "2.0.0" bumpVersion("1.2.3", "minor"); // "1.3.0" bumpVersion("1.2.3", "patch"); // "1.2.4" ```
The tool automatically detects the system language and adjusts all messages accordingly.
- π¬π§ English (EN) - Default
- π§π· Portuguese (PT) - pt_BR, pt_PT
- πͺπΈ Spanish (ES) - es_ES, es_MX, etc.
- π«π· French (FR) - fr_FR, fr_CA, etc.
```bash
version-control config --lang pt
version-control config --lang en
version-control config --lang es
version-control config --lang fr
version-control config --clear
version-control config ```
The configuration is saved globally in `~/.version-control-config.json` and will be used in all projects.
- MAJOR: `breaking`, `remove`, `delete`, `rewrite`
- MINOR: `add`, `new`, `feature`, `implement`
- PATCH: `fix`, `bug`, `error`
Contributions are welcome! Feel free to:
- Fork the project
- Create a branch for your feature (`git checkout -b feature/AmazingFeature`)
- Commit your changes (`git commit -m 'feat: add some AmazingFeature'`)
- Push to the branch (`git push origin feature/AmazingFeature`)
- Open a Pull Request
This project is under the MIT license. See the LICENSE file for more details.
Ridio Ricardo
- GitHub: @ridioricardo
Based on Semantic Versioning 2.0.0 specifications