All files / src app.constants.ts

53.33% Statements 8/15
84.38% Branches 27/32
66.67% Functions 2/3
46.15% Lines 6/13

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                            1x 2x 1x         10x                     10x     1x                                                                            
type Commands =
  | '--wss'
  | '--secret'
  | '--port'
  | '--label'
  | '--random-port'
  | '--runner-type'
  | '--send-response-to-server'
  | '--systemctl'
  | '--systemctl-name'
  | '--systemctl-description'
  | '--systemctl-executable'
  | '--nat-ip';
 
export const includes = (i: Commands) =>
  process.argv.toString().includes(i);
export const nextOrDefault = (
  i: Commands,
  fb: unknown = true,
  type = (p) => p,
) => {
  Iif (process.argv.toString().includes(i)) {
    const isNextArgumentPresent =
      process.argv[process.argv.indexOf(i) + 1];
    if (!isNextArgumentPresent) {
      return fb;
    }
    if (isNextArgumentPresent.includes('--')) {
      return fb;
    }
    return type(isNextArgumentPresent);
  }
  return fb;
};
 
export const Environment = {
  GRAPHQL_RUNNER_SUBSCRIPTION_URI:
    process.env.GRAPHQL_RUNNER_SUBSCRIPTION_URI ||
    nextOrDefault('--wss', ''),
  GRAPHQL_RUNNER_SECRET:
    process.env.GRAPHQL_RUNNER_SECRET ||
    nextOrDefault('--secret', ''),
  GRAPHQL_RUNNER_API_PORT:
    process.env.GRAPHQL_RUNNER_API_PORT ||
    nextOrDefault('--port', '42043'),
  GRAPHQL_SYSTEM_SERVICE:
    process.env.GRAPHQL_SYSTEM_SERVICE ||
    nextOrDefault('--systemctl', false),
  GRAPHQL_SYSTEM_SERVICE_NAME:
    process.env.GRAPHQL_SYSTEM_SERVICE_NAME ||
    nextOrDefault('--systemctl-name', false),
  GRAPHQL_SYSTEM_SERVICE_DESCRIPTION:
    process.env.GRAPHQL_SYSTEM_SERVICE_DESCRIPTION ||
    nextOrDefault('--systemctl-description', false),
  GRAPHQL_SYSTEM_SERVICE_EXECUTABLE:
    process.env.GRAPHQL_SYSTEM_SERVICE_EXECUTABLE ||
    nextOrDefault('--systemctl-executable', ''),
  GRAPHQL_RUNNER_RANDOM_PORT:
    process.env.GRAPHQL_RUNNER_RANDOM_PORT ||
    includes('--random-port'),
  GRAPHQL_RUNNER_TYPE:
    process.env.GRAPHQL_RUNNER_TYPE ||
    nextOrDefault('--runner-type'),
  GRAPHQL_RUNNER_LABEL:
    process.env.GRAPHQL_RUNNER_LABEL ||
    nextOrDefault('--label', ''),
  GRAPHQL_RUNNER_SEND_RETURN_RESPONSE:
    process.env.GRAPHQL_RUNNER_SEND_RETURN_RESPONSE ||
    includes('--send-response-to-server'),
  GRAPHQL_RUNNER_NAT_IP:
    process.env.GRAPHQL_RUNNER_NAT_IP ||
    nextOrDefault('--nat-ip', ''),
};