All files / libs/tools/plugin/src/generators/heal generator.ts

96.07% Statements 49/51
66.66% Branches 2/3
100% Functions 1/1
96.07% Lines 49/51

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 26x 26x 26x 13x     13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 13x 26x 26x 26x 26x 1x 1x  
import {
  formatFiles,
  getProjects,
  readProjectConfiguration as readProjectConfigurationNx,
  type Generator,
  type ProjectConfiguration,
  type Tree,
} from '@nx/devkit';
 
import { readProjectConfiguration } from '../helpers/project-configuration';
 
import { useRootBabelConfig } from './healthpacks/babel-frontend';
import { removeBuildTargetFromLib } from './healthpacks/build-target';
import { updateCypressConfiguration } from './healthpacks/cypress-config';
import { updateEslintConfigurationFiles } from './healthpacks/eslint-config';
import { useJestConfigCts } from './healthpacks/jest-config';
import { updatePackageJson } from './healthpacks/package-json';
import { updateTsConfigs } from './healthpacks/ts-config';
import { type HealGeneratorSchema } from './schema.d';
 
export const healGenerator: Generator<HealGeneratorSchema> = async (tree: Tree, _options) => {
  const workspaceProjects = getProjects(tree);
 
  workspaceProjects.forEach(({ name, root }) => {
    if (!name) {
      return;
    }
 
    const projectConfiguration = readProjectConfiguration(tree, root) ?? readProjectConfigurationNx(tree, name);
 
    const projectConfigurationWithNameAndRoot: ProjectConfiguration = {
      ...projectConfiguration,
      name,
      root,
    };
 
    // This one is first because it moves the config.
    updatePackageJson(tree, projectConfigurationWithNameAndRoot);
 
    removeBuildTargetFromLib(tree, projectConfigurationWithNameAndRoot);
    updateCypressConfiguration(tree, projectConfigurationWithNameAndRoot);
    useJestConfigCts(tree, projectConfigurationWithNameAndRoot);
    useRootBabelConfig(tree, projectConfigurationWithNameAndRoot);
    updateTsConfigs(tree, projectConfigurationWithNameAndRoot);
    updateEslintConfigurationFiles(tree, projectConfigurationWithNameAndRoot);
  });
 
  await formatFiles(tree);
};
 
export default healGenerator;