All files / packages/sds-release-manager/src config.ts

100% Statements 11/11
100% Branches 20/20
100% Functions 2/2
100% Lines 11/11

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          8x   8x 8x 8x 8x   8x 8x 8x                                             2x 2x         2x                        
import os from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import dotenv from 'dotenv';
 
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
 
export const ENV_PATH = path.join(packageRoot, '.env');
export const DEFAULT_GITCORE_HOST = 'gitcore.soma.salesforce.com';
export const DEFAULT_SLDS_SCS_GH_HOST = 'git.soma.salesforce.com';
export const DEFAULT_SLDS_SCS_REPO = 'aura/slds-scs';
export const DEFAULT_NEXUS_SLDS_SCS_BASE =
  'https://nexus-proxy.repo.local.sfdc.net/nexus/content/groups/public/org/sfs/slds-scs';
export const DEFAULT_PIN_VERSION_FILE = 'third_party/dependencies/org_sfs.bzl';
export const DEFAULT_PIN_CATALOG_FILE = 'third_party/dependencies/pinned_catalog/org_sfs.bzl';
 
export type ReleaseManagerConfig = {
  gitcoreHost: string;
  sldsScsGhHost: string;
  sldsScsRepo: string;
  nexusSldsScsBase: string;
  pinVersionFile: string;
  pinCatalogFile: string;
  // Optional; Workspace-backed commands only.
  sfwAlias?: string;
  sfwCorePath: string;
  sshConfigFile: string;
};
 
export type LoadEnvResult = {
  path: string;
  // True when `.env` existed and was loaded.
  used: boolean;
};
 
// Load this package's `.env` into process.env.
export function loadEnv(envPath = ENV_PATH): LoadEnvResult {
  const result = dotenv.config({ path: envPath, quiet: true });
  return { path: envPath, used: result.error == null };
}
 
// Read configuration from environment variables (after `loadEnv`).
export function loadConfiguration(env: NodeJS.ProcessEnv = process.env): ReleaseManagerConfig {
  return {
    gitcoreHost: env.GITCORE_HOST || DEFAULT_GITCORE_HOST,
    sldsScsGhHost: env.SLDS_SCS_GH_HOST || DEFAULT_SLDS_SCS_GH_HOST,
    sldsScsRepo: env.SLDS_SCS_REPO || DEFAULT_SLDS_SCS_REPO,
    nexusSldsScsBase: env.NEXUS_SLDS_SCS_BASE || DEFAULT_NEXUS_SLDS_SCS_BASE,
    pinVersionFile: env.PIN_VERSION_FILE || DEFAULT_PIN_VERSION_FILE,
    pinCatalogFile: env.PIN_CATALOG_FILE || DEFAULT_PIN_CATALOG_FILE,
    sfwAlias: env.SFW_ALIAS || undefined,
    sfwCorePath: env.SFW_CORE_PATH || '/opt/workspace/core-public/core',
    sshConfigFile: env.SFW_SSH_CONFIG || path.join(os.homedir(), '.ssh', 'workspaces-config'),
  };
}