Skip to content

Commit f94bee1

Browse files
author
Ondrej Machala
committed
fix: read CLI version from package.json dynamically
1 parent 1581e1e commit f94bee1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/cli.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
import { existsSync, rmSync } from 'node:fs';
1+
import { existsSync, readFileSync, rmSync } from 'node:fs';
2+
import path from 'node:path';
23
import { Command } from 'commander';
34
import { getProfilePath, setup } from './browser';
45
import { getConfigPath } from './configFile';
56
import { log, setVerbose } from './logger';
67
import { sync } from './sync';
78

9+
// Read version from package.json
10+
const packageJsonPath = path.join(import.meta.dirname, '..', 'package.json');
11+
const packageJson: unknown = JSON.parse(readFileSync(packageJsonPath, 'utf8'));
12+
const version =
13+
packageJson && typeof packageJson === 'object' && 'version' in packageJson
14+
? String(packageJson.version)
15+
: '0.0.0';
16+
817
const program = new Command();
918

1019
program
1120
.name('heroshot')
1221
.description('Define your screenshots once, update them forever with one command')
13-
.version('0.0.2-alpha.2')
22+
.version(version)
1423
.option('-v, --verbose', 'Show detailed output')
1524
.hook('preAction', () => {
1625
const options = program.opts<{ verbose?: boolean }>();

0 commit comments

Comments
 (0)