package-version-info
v0.0.6
Published
Generate version info from package.json for TypeScript projects
Downloads
836
Maintainers
Readme
Package Version Info
A blazingly fast CLI tool written in Zig that generates TypeScript version information files from your package.json. Perfect for embedding version, build date, and git information into your applications.
✨ Features
- 🚀 Fast: Written in Zig for maximum performance
- 📦 Zero Dependencies: No runtime dependencies required
- 👤 Author Information: Extracts author details from package.json
- 🌿 Git Integration: Automatically extracts branch and commit information
- ⚡ TypeScript Output: Generates type-safe TypeScript constants
- 🎯 Graceful Degradation: Works with or without a git repository or author info
- 🔧 Configurable: Customize input and output paths
🚀 Quick Start
Installation
npm install package-version-info --save-dev
# or
yarn add package-version-info --devUsage
# Generate version-info.ts from package.json
npx package-version-info
# Show version
npx package-version-info --version
# Custom paths
npx package-version-info --input package.json --output src/version-info.tsOutput Example
Full Output (with author and git):
export const VERSION_INFO = {
version: "1.0.0",
date: "2025-12-26T16:00:00.000Z",
author: {
name: "Dominik Hladík",
email: "[email protected]",
url: "https://github.com/Celtian",
},
git: {
branch: "master",
commit: "324822ac3893dd6159ab8cb4477d45edeacf11f6",
},
};Minimal Output (without author and git):
export const VERSION_INFO = {
version: "1.0.0",
date: "2025-12-26T16:00:00.000Z",
};📖 Usage in Your Application
Once generated, import and use the version info in your application:
import { VERSION_INFO } from "./version-info";
console.log(`Version: ${VERSION_INFO.version}`);
console.log(`Build Date: ${VERSION_INFO.date}`);
if (VERSION_INFO.author) {
console.log(`Author: ${VERSION_INFO.author.name}`);
console.log(`Email: ${VERSION_INFO.author.email}`);
console.log(`URL: ${VERSION_INFO.author.url}`);
}
if (VERSION_INFO.git) {
console.log(`Branch: ${VERSION_INFO.git.branch}`);
console.log(`Commit: ${VERSION_INFO.git.commit}`);
}🔧 CLI Options
| Option | Alias | Default | Description |
| ----------- | ----- | ----------------- | ------------------------------ |
| --version | -v | - | Display version information |
| --input | -i | package.json | Path to package.json file |
| --output | -o | version-info.ts | Path to output TypeScript file |
🛠️ Integration with Build Tools
NPM Scripts
Add to your package.json:
{
"scripts": {
"prebuild": "package-version-info",
"build": "your-build-command"
}
}With TypeScript Projects
{
"scripts": {
"version-info": "package-version-info --output src/version-info.ts",
"prebuild": "npm run version-info",
"build": "tsc"
}
}🏗️ Development
This project is written in Zig. To build from source:
Prerequisites
- Zig >= 0.15.2
Build Commands
# Build the executable
zig build
# Run the executable
zig build run
# Run with arguments
zig build run -- --input package.json --output version-info.ts
# Run tests
zig build test
# Clean build artifacts
rm -rf zig-cache zig-out🎯 Why Zig?
- Performance: Compiled binary with minimal overhead
- Size: Small executable footprint
- Cross-platform: Easy to build for multiple platforms
- Memory Safety: No runtime exceptions or undefined behavior
📦 Dependencies
None - This is a standalone binary with zero runtime dependencies.
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
🪪 License
Copyright © 2025 Dominik Hladik
All contents are licensed under the MIT license.
