All files / src/utils/backbase api-extractor.ts

100% Statements 17/17
100% Branches 5/5
100% Functions 4/4
100% Lines 16/16

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 18 19 20 21 22 23 24 25 26 27 28 29 30 31  2x   2x           13x 3x     10x 10x   10x 20x 20x 20x   20x 20x   10x     2x 3x 3x  
import { Tree } from '@angular-devkit/schematics';
import { JSONFile } from '../angular/json-utils';
 
export function updateAddApiExtractorToLib(
  host: Tree,
  rootPackageJsonPath: string,
  isPublicLib: boolean,
  libName: string,
): void {
  if (!isPublicLib || !host.exists(rootPackageJsonPath)) {
    return;
  }
 
  const rootPackageJson = new JSONFile(host, rootPackageJsonPath);
  const libPath = `libs/${libName}`;
 
  ['api:check', 'api:extract'].forEach((scriptKey) => {
    const scriptWithLib = `${scriptKey}:${libName}`;
    const path = ['scripts', scriptKey];
    const value = rootPackageJson.get(path);
 
    rootPackageJson.modify(['scripts', scriptWithLib], `cd ${libPath} && npm run ${scriptKey}`);
    rootPackageJson.modify(path, value ? `${value} && npm run ${scriptWithLib}` : `npm run ${scriptWithLib}`);
  });
  return;
}
 
export const updateAddApiExtractorToLibRule =
  (rootPackageJsonPath: string, isPublicLib: boolean, libName: string) => (host: Tree) =>
    updateAddApiExtractorToLib(host, rootPackageJsonPath, isPublicLib, libName);