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
This commit is contained in:
parent
b01a9ea0e3
commit
fe7158600a
2 changed files with 23 additions and 3 deletions
|
|
@ -50,6 +50,9 @@ export {
|
||||||
getStatistics
|
getStatistics
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Export version utilities
|
||||||
|
export { getBrainyVersion } from './utils/version.js'
|
||||||
|
|
||||||
// Export embedding functionality
|
// Export embedding functionality
|
||||||
import {
|
import {
|
||||||
UniversalSentenceEncoder,
|
UniversalSentenceEncoder,
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,32 @@
|
||||||
* Version utilities for Brainy
|
* Version utilities for Brainy
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Package version - this should be updated during the build process
|
import { readFileSync } from 'fs'
|
||||||
const BRAINY_VERSION = '0.41.0'
|
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
|
* Get the current Brainy package version
|
||||||
* @returns The current version string
|
* @returns The current version string
|
||||||
*/
|
*/
|
||||||
export function getBrainyVersion(): string {
|
export function getBrainyVersion(): string {
|
||||||
return BRAINY_VERSION
|
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!
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue