All files / src/migrations/utils json.ts

100% Statements 8/8
100% Branches 1/1
100% Functions 1/1
100% Lines 8/8

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 1429x   29x 163x 163x 15x   148x 148x   3x      
import { SchematicsException, Tree } from '@angular-devkit/schematics';
 
export function readJsonFile<T>(tree: Tree, filePath: string): T {
  const buffer = tree.read(filePath);
  if (buffer === null) {
    throw new SchematicsException(`Could not read ${filePath}`);
  }
  try {
    return JSON.parse(buffer.toString());
  } catch (error) {
    throw new SchematicsException(`Invalid ${filePath}`);
  }
}