All files / migrations/standalone 0005-migrate-angular-json-assets.ts

95.12% Statements 39/41
83.33% Branches 5/6
100% Functions 1/1
95.12% Lines 39/41

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 421x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
import { type Project } from "ts-morph";
import type { CliOptions } from "../../../types/cli-options";
import { saveFileChanges } from "../../utils/log-utils";
 
/**
 * Migrates the assets in angular.json to remove copying the ionicons svg assets.
 */
export const migrateAngularJsonAssets = async (
  project: Project,
  cliOptions: CliOptions,
) => {
  const angularJsonSourceFile = project
    .getSourceFiles()
    .find((sourceFile) => sourceFile.getFilePath().endsWith("angular.json"));
 
  if (angularJsonSourceFile === undefined) {
    return;
  }
 
  const angularJson = JSON.parse(angularJsonSourceFile.getText());
 
  for (const project of Object.keys(angularJson.projects)) {
    const assets = angularJson.projects[project].architect.build.options
      .assets as string[];
    const assetsToRemove = assets.filter((asset: string | any) => {
      return (
        typeof asset === "object" &&
        asset.input === "node_modules/ionicons/dist/ionicons/svg"
      );
    });
 
    assetsToRemove.forEach((assetToRemove) => {
      const index = assets.indexOf(assetToRemove);
      assets.splice(index, 1);
    });
  }
 
  angularJsonSourceFile.replaceWithText(JSON.stringify(angularJson, null, 2));
 
  return await saveFileChanges(angularJsonSourceFile, cliOptions);
};