generate-version-info
v0.0.2
Published
Generate version information files for different environments
Downloads
243
Maintainers
Readme
generate-version-info
A CLI tool and Node.js library for generating version information files with git information and build details.
🚀 What it does
generate-version-info creates a version.json file containing:
- Application version (from package.json)
- Git metadata (short SHA, commit date)
- Build timestamp (when the version file was generated)
Perfect for deployment pipelines, monitoring, and debugging in production environments.
📦 Installation
Global installation (recommended for CLI usage)
npm install -g generate-version-infoProject dependency
npm install generate-version-info🎯 Usage
CLI Usage
# Generate version.json in current directory
generate-version-infoProgrammatic Usage
import { generateVersion } from 'generate-version-info';
// Generate version.json in current directory
await generateVersion();📄 Output Example
{
"appVersion": "1.2.3",
"gitShortSha": "a1b2c3d",
"buildDate": "2026-03-12T17:46:54.164Z",
"releaseDate": "2026-03-12T15:11:59.000Z"
}🔧 Configuration
The tool generates version information by reading your project's package.json and git metadata. No additional configuration is required.
⚙️ API Reference
generateVersion()
Generates a version.json file in the current directory using the local package.json and git metadata.
Parameters: None
Returns: Promise
🧪 Testing
Test the CLI locally
Clone and build:
git clone https://github.com/MarceloBuenoMartinez/generate-version-info.git cd generate-version-info pnpm install pnpm buildTest the CLI:
# Test version generation node dist/bin/cli.js cat version.jsonTest programmatically:
node -e " const { generateVersion } = require('./dist/src/index.js'); generateVersion().then(result => console.log('Generated:', result) ); "
Integration Testing
Test in your project:
# Install globally and test
npm install -g generate-version-info
cd /path/to/your/project
generate-version-infoExpected behavior:
- ✅ Creates
version.jsonin current directory - ✅ Includes all 4 fields (appVersion, gitShortSha, buildDate, releaseDate)
- ✅ Works in any project with a package.json
- ✅ Consistent output format
📁 File Structure
generate-version-info/
├── bin/cli.ts # CLI entry point
├── src/index.ts # Main library code
├── dist/ # Compiled JavaScript
└── version.json # Generated output (when testing)🔄 Development Workflow
# Install dependencies
pnpm install
# Development mode
pnpm dev
# Build TypeScript
pnpm build
# Clean build artifacts
pnpm clean
# Test locally
node dist/bin/cli.js📝 Common Use Cases
- CI/CD pipelines: Add version info to build artifacts
- Deployment tracking: Know exactly what version is deployed
- Debugging: Correlate issues with specific builds/commits
- Monitoring: Display version info in health check endpoints
- Documentation: Embed version details in generated docs
🤝 Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes and test:
pnpm build && node dist/bin/cli.js - Commit:
git commit -m "feat: add amazing feature" - Push:
git push origin feature/amazing-feature - Open a Pull Request
📄 License
MIT License - see LICENSE file for details.
