import { isCorrectLogLevel , Logger } from "backfill-logger" ; import { getAzureBlobConfigFromSerializedOptions , getNpmConfigFromSerializedOptions , } from "./cacheConfig" ; import { isCorrectMode , Config } from "./index" ; export function getEnvConfig ( logger ) { const config = { } ; const cacheProvider = process . env [ "BACKFILL_CACHE_PROVIDER" ] ; const serializedCacheProviderOptions = process . env [ "BACKFILL_CACHE_PROVIDER_OPTIONS" ] ; if ( cacheProvider === "azure-blob" && serializedCacheProviderOptions ) { config [ "cacheStorageConfig" ] = getAzureBlobConfigFromSerializedOptions ( serializedCacheProviderOptions , logger ) ; } else if ( cacheProvider === "npm" && serializedCacheProviderOptions ) { config [ "cacheStorageConfig" ] = getNpmConfigFromSerializedOptions ( serializedCacheProviderOptions , logger ) ; } else if ( cacheProvider === "local" ) { } const internalCacheFolder = process . env [ "BACKFILL_INTERNAL_CACHE_FOLDER" ] ; if ( internalCacheFolder ) { config [ "internalCacheFolder" ] = internalCacheFolder ; } const logFolder = process . env [ "BACKFILL_LOG_FOLDER" ] ; if ( logFolder ) { config [ "logFolder" ] = logFolder ; } const mode = process . env [ "BACKFILL_MODE" ] ; if ( mode ) { if ( isCorrectMode ( mode ) ) { config [ "mode" ] = mode ; } else { throw `Backfill config option "BACKFILL_MODE" was set, but with the wrong value: "${ mode }".` ; } } const logLevel = process . env [ "BACKFILL_LOG_LEVEL" ] ; if ( logLevel ) { if ( isCorrectLogLevel ( logLevel ) ) { config [ "logLevel" ] = logLevel ; } else { throw `Backfill config option "BACKFILL_LOG_LEVEL" was set, but with the wrong value: "${ logLevel }".` ; } } const performanceReportName = process . env [ "BACKFILL_PERFORMANCE_REPORT_NAME" ] ; if ( performanceReportName ) { config [ "performanceReportName" ] = performanceReportName ; } const producePerformanceLogs = process . env [ "BACKFILL_PRODUCE_PERFORMANCE_LOGS" ] ; if ( producePerformanceLogs ) { config [ "producePerformanceLogs" ] = Boolean ( producePerformanceLogs === "true" ) ; } const validateOutput = process . env [ "BACKFILL_VALIDATE_OUTPUT" ] ; if ( validateOutput ) { config [ "validateOutput" ] = Boolean ( validateOutput === "true" ) ; } return config ; }