All files / helpers fileHelper.ts

100% Statements 17/17
100% Branches 2/2
100% Functions 1/1
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 181x 1x 1x 1x 1x 1x 1x 9x 9x 9x 9x 9x 9x 3x 3x 3x 9x  
import fs from 'fs';
import path from 'path';
 
import { getBotPath } from '@services/internal/configService';
import { getLog } from '@services/internal/logService';
 
export const getVersionNumFromPackageJson = (): string => {
  try {
    const packageJsonFile = path.join(getBotPath(), '../../package.json');
    const packageString = fs.readFileSync(packageJsonFile, 'utf8');
    const pkg = JSON.parse(packageString);
    return pkg.version;
  } catch (ex) {
    getLog().e(`Unable to get version from package.json. Err: ${ex}`);
    return '0.0.0';
  }
};