All files / src/migrations 2.11.1.ts

95.23% Statements 20/21
100% Branches 0/0
100% Functions 4/4
95% Lines 19/20

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 511x 1x 1x 1x 1x   1x                                         1x 2x 2x 2x       2x 2x     2x 2x 2x   2x 2x       1x 2x    
import { Rule, chain, Tree, SchematicsException } from '@angular-devkit/schematics';
import { updateDevDependency } from './utils/package-json';
import { tryRule } from './utils/rules';
import { readJsonFile } from './utils/json';
import { getWorkspace, getApps } from '../utils/backbase/package-utils';
 
const manualProcess = `
## 1. Add the new configuration to the "angular.json"
 
    {
    ...
    "projects": {
      "example-app": {
        ...
        "architect": {
          ...
          "build": {
            builder: '@bb-cli/bb-ang:browser'
            ...
    ...
 
## 2. Upgrade the "bb-ang" dev dependency
 
Install it as a dev dependency using the following command:
 
    npm i --save-dev @bb-cli/bb-ang@3.8.0`;
 
const addBackbaseBuilderToAngularJson = (tree: Tree, projectName: string) => {
  const content = readJsonFile<any>(tree, 'angular.json');
  try {
    content.projects[projectName].architect.build.builder = '@bb-cli/bb-ang:browser';
  } catch (_) {
    throw new SchematicsException(`Could not find build for project ${projectName}`);
  }
  tree.overwrite('angular.json', JSON.stringify(content, null, 2));
  return tree;
};
 
const addBackbaseBuilderRule = async (tree: Tree) => {
  const workspace = await getWorkspace(tree);
  const apps = getApps(workspace);
 
  for (const name of apps) {
    addBackbaseBuilderToAngularJson(tree, name);
  }
};
 
export default function (): Rule {
  return tryRule(chain([addBackbaseBuilderRule, updateDevDependency('@bb-cli/bb-ang', '~3.8.0')]), manualProcess);
}