All files / generators/cdk-app create-project-configuration.ts

100% Statements 10/10
100% Branches 1/1
100% Functions 1/1
100% Lines 9/9

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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 1702x 2x   2x     2x       32x   32x                                                                                                                                                                                                                                                                         32x 16x                                         32x    
import { joinPathFragments, ProjectConfiguration } from '@nx/devkit';
import { ProjectType } from '@nx/workspace';
import { NormalizedProjectOptionsApplication } from '../../utils/normalize-project-options';
import { AppType } from './app-type';
import { CdkAppSchema } from './schema';
 
export const createProjectConfiguration = (
  options: CdkAppSchema,
  projectOptions: NormalizedProjectOptionsApplication,
): ProjectConfiguration => {
  const { projectRoot } = projectOptions;
 
  const projectConfiguration: ProjectConfiguration = {
    root: projectRoot,
    sourceRoot: joinPathFragments(projectRoot, 'cdk'),
    projectType: ProjectType.Application,
    implicitDependencies: [],
    targets: {
      cdk: {
        executor: 'nx-serverless-cdk:cdk',
        options: {},
      },
      deploy: {
        executor: 'nx-serverless-cdk:cdk',
        defaultConfiguration: 'dev',
        options: {},
        configurations: {
          dev: {
            predefinedArguments: ['deploy', 'Dev/*'],
          },
          stage: {
            predefinedArguments: ['deploy', 'Stage/*'],
          },
          prod: {
            predefinedArguments: ['deploy', 'Prod/*'],
          },
        },
      },
      'deploy-all': {
        executor: 'nx-serverless-cdk:cdk',
        defaultConfiguration: 'dev',
        dependsOn: [
          {
            dependencies: true,
            params: 'forward',
            target: 'deploy-all',
          },
        ],
        options: {},
        configurations: {
          dev: {
            predefinedArguments: ['deploy', 'Dev/*'],
          },
          stage: {
            predefinedArguments: ['deploy', 'Stage/*'],
          },
          prod: {
            predefinedArguments: ['deploy', 'Prod/*'],
          },
        },
      },
      destroy: {
        executor: 'nx-serverless-cdk:cdk',
        defaultConfiguration: 'dev',
        options: {},
        configurations: {
          dev: {
            predefinedArguments: ['destroy', 'Dev/*', '--force'],
          },
          stage: {
            predefinedArguments: ['destroy', 'Stage/*', '--force'],
          },
          prod: {
            predefinedArguments: ['destroy', 'Prod/*', '--force'],
          },
        },
      },
      diff: {
        executor: 'nx-serverless-cdk:cdk',
        defaultConfiguration: 'dev',
        options: {},
        configurations: {
          dev: {
            predefinedArguments: ['diff', 'Dev/*'],
          },
          stage: {
            predefinedArguments: ['diff', 'Stage/*'],
          },
          prod: {
            predefinedArguments: ['diff', 'Prod/*'],
          },
        },
      },
      ls: {
        executor: 'nx-serverless-cdk:cdk',
        defaultConfiguration: 'dev',
        options: {},
        configurations: {
          dev: {
            predefinedArguments: ['ls', 'Dev/*'],
          },
          stage: {
            predefinedArguments: ['ls', 'Stage/*'],
          },
          prod: {
            predefinedArguments: ['ls', 'Prod/*'],
          },
        },
      },
      synth: {
        executor: 'nx-serverless-cdk:cdk',
        defaultConfiguration: 'dev',
        options: {},
        configurations: {
          dev: {
            predefinedArguments: ['synth', 'Dev/*'],
          },
          stage: {
            predefinedArguments: ['synth', 'Stage/*'],
          },
          prod: {
            predefinedArguments: ['synth', 'Prod/*'],
          },
        },
      },
      watch: {
        executor: 'nx-serverless-cdk:cdk',
        defaultConfiguration: 'dev',
        options: {},
        configurations: {
          dev: {
            predefinedArguments: ['watch', 'Dev/*'],
          },
          stage: {
            predefinedArguments: ['watch', 'Stage/*'],
          },
          prod: {
            predefinedArguments: ['watch', 'Prod/*'],
          },
        },
      },
    },
    tags: ['cdk-app'],
  };
 
  if (options.type === AppType.lambda) {
    projectConfiguration.targets = {
      ...projectConfiguration.targets,
      'generate-event': {
        executor: 'nx-serverless-cdk:generate-event',
        options: {},
      },
      invoke: {
        executor: 'nx-serverless-cdk:invoke',
        options: {},
      },
      'start-api': {
        executor: 'nx-serverless-cdk:start-api',
        options: {},
      },
      'start-lambda': {
        executor: 'nx-serverless-cdk:start-lambda',
        options: {},
      },
    };
  }
 
  return projectConfiguration;
};