Skip to content

Commit 9d2d8fc

Browse files
authored
fix: fixing ctp version (#363)
1 parent 0bc1cca commit 9d2d8fc

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

index.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,29 @@ import * as path from 'path';
66
import 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

1327
export 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

Comments
 (0)