All files / src/migrations 2.16.2.ts

95.65% Statements 22/23
66.66% Branches 2/3
100% Functions 3/3
95.45% Lines 21/22

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 51 521x 1x 1x   1x 1x 1x 1x 1x   1x                                       1x 1x 1x   1x 1x 1x 1x 1x     1x 1x 1x 1x              
import { normalize } from '@angular-devkit/core';
import { Rule, Tree, SchematicsException } from '@angular-devkit/schematics';
import { createSourceFile, ScriptTarget } from 'typescript';
 
import { insertImport } from '../utils/angular/ast-utils';
import { getApps, getWorkspace, readFileOrThrow } from '../utils/backbase/package-utils';
import { addImportToModule, insert } from '../utils/nrwl/ast-utils';
import { tryRule } from './utils/rules';
import { updateDevDependency } from './utils/package-json';
 
const manualProcess = `
## Make sure the version of @bb-cli/bb-ang is 3.11.4
 
For that install it as a dev dependency using the following command:
$ npm install --save-dev @bb-cli/bb-ang@3.11.4
 
## Ensure \`HttpClientModule\` is included in the app module
 
As the data modules can no longer provide the \`HttpClientModule\` it must be
imported by the app module.
 
    import { HttpClientModule } from '@angular/common/http';
 
    @NgModule({
      imports: [
        HttpClientModule,
      ]
    })
    export class AppModule { }`;
 
export default function (): Rule {
  return tryRule(async (tree: Tree) => {
    updateDevDependency('@bb-cli/bb-ang', '~3.11.4');
 
    const workspace = await getWorkspace(tree);
    const apps = getApps(workspace);
    for (const name of apps) {
      const project = workspace.projects.get(name);
      Iif (!project || !project.sourceRoot) {
        throw new SchematicsException('Project (name) missing required "sourceRoot" property in angular.json');
      }
      const modulePath = normalize(`${project.sourceRoot}/app/app.module.ts`);
      const moduleSource = readFileOrThrow(tree, modulePath);
      const sourceFile = createSourceFile(modulePath, moduleSource, ScriptTarget.Latest, true);
      insert(tree, modulePath, [
        insertImport(sourceFile, modulePath, 'HttpClientModule', '@angular/common/http'),
        ...addImportToModule(sourceFile, modulePath, `HttpClientModule`),
      ]);
    }
  }, manualProcess);
}