@@ -3,25 +3,30 @@ import { fileURLToPath } from 'node:url'
33import pathe from 'pathe'
44import { Constants } from '../constants'
55
6- export function appVersion ( options ?: { name ?: string ; withAVMVersion ?: boolean } ) : string {
6+ export function packageVersion ( ) : string {
77 let dirName = pathe . dirname ( fileURLToPath ( import . meta. url ) )
8- const name = options ?. name ?? 'puya-ts'
9- const withAVMVersion = options ?. withAVMVersion ?? true
108
119 while ( true ) {
1210 const packageJsonPath = pathe . join ( dirName , 'package.json' )
1311 if ( fs . existsSync ( packageJsonPath ) ) {
14- const version = JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf8' ) ) . version
15- return [ `${ name } ${ version } ` ]
16- . concat (
17- withAVMVersion
18- ? [ '' , 'Targets:' , `puya ${ Constants . targetedPuyaVersion } ` , `AVM ${ Constants . supportedAvmVersions . join ( ', ' ) } ` ]
19- : [ `puya ${ Constants . targetedPuyaVersion } ` ] ,
20- )
21- . join ( '\r\n' )
12+ return JSON . parse ( fs . readFileSync ( packageJsonPath , 'utf8' ) ) . version
2213 }
2314 if ( dirName === pathe . dirname ( dirName ) ) break
2415 dirName = pathe . dirname ( dirName )
2516 }
26- return `Cannot determine puya-ts version`
17+ return 'unknown'
18+ }
19+
20+ export function appVersion ( options ?: { name ?: string ; withAVMVersion ?: boolean } ) : string {
21+ const name = options ?. name ?? 'puya-ts'
22+ const withAVMVersion = options ?. withAVMVersion ?? true
23+
24+ const version = packageVersion ( )
25+ return [ `${ name } ${ version } ` ]
26+ . concat (
27+ withAVMVersion
28+ ? [ '' , 'Targets:' , `puya ${ Constants . targetedPuyaVersion } ` , `AVM ${ Constants . supportedAvmVersions . join ( ', ' ) } ` ]
29+ : [ `puya ${ Constants . targetedPuyaVersion } ` ] ,
30+ )
31+ . join ( '\n' )
2732}
0 commit comments