All files / generators/init generator.ts

100% Statements 17/17
100% Branches 1/1
100% Functions 2/2
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 724x             4x 4x 4x     4x 91x                                         4x       91x   91x   91x                 91x                   91x   91x 1x     91x     4x  
import {
  addDependenciesToPackageJson,
  formatFiles,
  GeneratorCallback,
  runTasksInSerial,
  Tree,
} from '@nx/devkit';
import { jestInitGenerator } from '@nx/jest';
import { initGenerator as jsInitGenerator } from '@nx/js';
import { getVersions, Versions } from '../../utils/versions';
import { InitSchema } from './schema';
 
const addInitDependencies = (tree: Tree, versions: Versions) => {
  return addDependenciesToPackageJson(
    tree,
    {
      // CDK dependencies
      'aws-cdk-lib': versions['aws-cdk-lib'],
      constructs: versions['constructs'],
      'source-map-support': versions['source-map-support'],
      // TypeScript dependencies
      tslib: versions.tslib,
    },
    {
      // CDK development dependencies
      'aws-cdk': versions['aws-cdk'],
      'tsconfig-paths': versions['tsconfig-paths'],
      'ts-node': versions['ts-node'],
      // TypeScript development dependencies
      '@types/node': versions['@types/node'],
    },
  );
};
 
export const initGenerator = async (
  tree: Tree,
  options: InitSchema,
): Promise<GeneratorCallback> => {
  const versions = getVersions();
 
  const tasks: GeneratorCallback[] = [];
 
  tasks.push(
    await jsInitGenerator(tree, {
      js: false,
      skipFormat: true,
      skipPackageJson: false,
      tsConfigName: 'tsconfig.base.json',
    }),
  );
 
  tasks.push(
    await jestInitGenerator(tree, {
      compiler: 'tsc',
      js: false,
      skipPackageJson: false,
      testEnvironment: 'node',
      rootProject: false,
    }),
  );
 
  tasks.push(addInitDependencies(tree, versions));
 
  if (!options.skipFormat) {
    await formatFiles(tree);
  }
 
  return runTasksInSerial(...tasks);
};
 
export default initGenerator;