@@ -3,25 +3,31 @@ 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 ) ) {
1412 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' )
13+ return version
2214 }
2315 if ( dirName === pathe . dirname ( dirName ) ) break
2416 dirName = pathe . dirname ( dirName )
2517 }
26- return `Cannot determine puya-ts version`
18+ return 'unknown'
19+ }
20+
21+ export function appVersion ( options ?: { name ?: string ; withAVMVersion ?: boolean } ) : string {
22+ const name = options ?. name ?? 'puya-ts'
23+ const withAVMVersion = options ?. withAVMVersion ?? true
24+
25+ const version = packageVersion ( )
26+ return [ `${ name } ${ version } ` ]
27+ . concat (
28+ withAVMVersion
29+ ? [ '' , 'Targets:' , `puya ${ Constants . targetedPuyaVersion } ` , `AVM ${ Constants . supportedAvmVersions . join ( ', ' ) } ` ]
30+ : [ `puya ${ Constants . targetedPuyaVersion } ` ] ,
31+ )
32+ . join ( '\r\n' )
2733}
0 commit comments