@@ -6,15 +6,29 @@ import * as path from 'path';
66import printTableFromInp from './src/service' ;
77
88// Read package.json to get version
9- const packageJson = JSON . parse (
10- fs . readFileSync ( path . join ( __dirname , 'package.json' ) , 'utf8' )
11- ) ;
9+ let packageVersion = '0.0.0-dev' ; // More descriptive default version
10+ try {
11+ // Try to read from dist's parent directory first (for global installs)
12+ const packagePath = path . join ( __dirname , '..' , 'package.json' ) ;
13+ const packageJson = JSON . parse ( fs . readFileSync ( packagePath , 'utf8' ) ) ;
14+ packageVersion = packageJson . version ;
15+ } catch ( error ) {
16+ try {
17+ // Fallback to current directory (for development)
18+ const packagePath = path . join ( __dirname , 'package.json' ) ;
19+ const packageJson = JSON . parse ( fs . readFileSync ( packagePath , 'utf8' ) ) ;
20+ packageVersion = packageJson . version ;
21+ } catch ( error ) {
22+ // More descriptive warning message
23+ console . warn ( 'Warning: Could not find package.json in either dist parent directory or current directory. Using default version.' ) ;
24+ }
25+ }
1226
1327export function runCLI ( argv : string [ ] = process . argv ) {
1428 const program = new Command ( ) ;
1529
1630 program
17- . version ( packageJson . version , '-v, --version' , 'output the current version' )
31+ . version ( packageVersion , '-v, --version' , 'output the current version' )
1832 . option ( '-i, --input <value>' , 'input string' )
1933 . option ( '-s, --stdin' , 'read input from stdin' )
2034 . option ( '-t, --tableOptions <value>' , 'table options in JSON format' )
0 commit comments