brainy/src/utils/version.ts
David Snelling 197f99c1c3 fix: implement automatic version detection from package.json
- Replace hardcoded version string with dynamic reading from package.json
- Add version caching for performance
- Export getBrainyVersion function from main index
- Ensures version stays automatically synchronized with releases
2025-08-28 16:58:35 -07:00

43 lines
No EOL
1.1 KiB
TypeScript

/**
* Version utilities for Brainy
*/
import { readFileSync } from 'fs'
import { join, dirname } from 'path'
import { fileURLToPath } from 'url'
// Get package.json path relative to this file
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const packageJsonPath = join(__dirname, '../../package.json')
let cachedVersion: string | null = null
/**
* Get the current Brainy package version
* @returns The current version string
*/
export function getBrainyVersion(): string {
if (!cachedVersion) {
try {
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8'))
cachedVersion = packageJson.version
} catch {
// Fallback version if package.json can't be read
cachedVersion = '2.7.1'
}
}
return cachedVersion!
}
/**
* Get version information for augmentation metadata
* @param service The service/augmentation name
* @returns Version metadata object
*/
export function getAugmentationVersion(service: string): { augmentation: string; version: string } {
return {
augmentation: service,
version: getBrainyVersion()
}
}