Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ConfigAggregator

Aggregate global and local project config files, as well as environment variables for sfdx-config.json. The resolution happens in the following bottom-up order:

  1. Environment variables (SFDX_LOG_LEVEL)
  2. Workspace settings (<workspace-root>/.sfdx/sfdx-config.json)
  3. Global settings ($HOME/.sfdx/sfdx-config.json)

Use ConfigAggregator.create to instantiate the aggregator.

const aggregator = await ConfigAggregator.create();
console.log(aggregator.getPropertyValue('defaultusername'));

Hierarchy

  • AsyncOptionalCreatable<JsonMap>
    • ConfigAggregator

Index

Methods

getConfig

  • getConfig(): JsonMap

getConfigInfo

  • Get all resolved config property keys, values, locations, and paths.

    > console.log(aggregator.getConfigInfo());
    [
        { key: 'logLevel', val: 'INFO', location: 'Environment', path: '$SFDX_LOG_LEVEL'}
        { key: 'defaultusername', val: '<username>', location: 'Local', path: './.sfdx/sfdx-config.json'}
    ]

    Returns ConfigInfo[]

getEnvVars

  • getEnvVars(): Map<string, string>

getGlobalConfig

getInfo

getLocalConfig

getLocation

  • getLocation(key: string): Optional<Location>
  • Gets a resolved config property location.

    For example, getLocation('logLevel') will return:

    1. Location.GLOBAL if resolved to an environment variable.
    2. Location.LOCAL if resolved to local project config.
    3. Location.ENVIRONMENT if resolved to the global config.

    Parameters

    • key: string

      The key of the property.

    Returns Optional<Location>

getPath

  • getPath(key: string): Optional<string>
  • Get a resolved file path or environment variable name of the property.

    For example, getPath('logLevel') will return:

    1. $SFDX_LOG_LEVEL if resolved to an environment variable.
    2. ./.sfdx/sfdx-config.json if resolved to the local config.
    3. ~/.sfdx/sfdx-config.json if resolved to the global config.
    4. undefined, if not resolved.

    Note: that the path returned may be the absolute path instead of relative paths such as ./ and ~/.

    Parameters

    • key: string

      The key of the property.

    Returns Optional<string>

getPropertyValue

  • getPropertyValue(key: string): Optional<AnyJson>
  • Get a resolved config property.

    Throws SfdxError{ name: 'UnknownConfigKey' } An attempt to get a property that's not supported.

    Parameters

    • key: string

      The key of the property.

    Returns Optional<AnyJson>

init

  • init(): Promise<void>
  • Initialize this instances async dependencies.

    Returns Promise<void>

reload

Static create

  • create<P, T>(this: object, options?: P): Promise<T>
  • Asynchronously constructs and initializes a new instance of a concrete subclass with the optional options.

    Type parameters

    • P

    • T: AsyncOptionalCreatable<P>

    Parameters

    • this: object
    • Optional options: P

      An options object providing initialization params to the async constructor.

    Returns Promise<T>