All files / utils get-samconfig-path.ts

100% Statements 20/20
100% Branches 15/15
100% Functions 1/1
100% Lines 18/18

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 484x   4x           62x 150x   150x 10x         4x   140x 34x   34x 28x   106x 10x         4x         62x 26x     36x   36x          
import { dirname, join, relative, resolve } from 'node:path';
 
export const getSamconfigPath = (
  argv: string[],
  projectRootResolved: string,
): string | undefined => {
  let templateValue: string | undefined;
 
  for (let i = 0; i < argv.length; i++) {
    const arg = argv[i];
 
    if (arg === '--template') {
      if (
        argv[i + 1] &&
        !argv[i + 1]?.startsWith('--') &&
        !argv[i + 1]?.startsWith('-')
      ) {
        templateValue = argv[i + 1];
      }
    } else if (arg?.startsWith('--template=')) {
      const value = arg?.slice('--template='.length);
 
      if (value) {
        templateValue = value;
      }
    } else if (arg === '-t') {
      if (
        argv[i + 1] &&
        !argv[i + 1]?.startsWith('--') &&
        !argv[i + 1]?.startsWith('-')
      ) {
        templateValue = argv[i + 1];
      }
    }
  }
 
  if (!templateValue) {
    return undefined;
  }
 
  const templatePathResolved = resolve(projectRootResolved, templateValue);
 
  return relative(
    dirname(templatePathResolved),
    join(projectRootResolved, 'samconfig.toml'),
  );
};