class providing configuration used by AFT and it's plugins for reading in configuration an aftconfig.json, aftconfig.js, aftconfig.cjs or aftconfig.mjs file at the project root. this configuration can be read as a top-level field using aftConfig.get('field_name') or aftConfig.get('field_name', defaultVal) and can also be set without actually modifying the values in your aftconfig.json using aftConfig.set('field_name', val). additionally, configuration classes can be read using AftConfig with the aftConfig.getSection(ConfigClass) which will read from your aftconfig.json file for a field named ConfigClass

NOTE:

  • when a new instance of AftConfig is created the dotenv package is run and any .env file found at your project root (process.cwd()) will be processed into your environment variables making it easier to load values when developing and testing locally.
  • if using a javascript aftconfig file, you must export the config object using module.exports = { ... }

Ex: with an aftconfig.json containing:

{
"SomeCustomClassConfig": {
"configField1": "%your_env_var%",
"configField2": "some-value",
"configField3": ["foo", true, 10]
}
}

and with the following environment variables set:

export your_env_var="an important value"

and a config class of:

export class SomeCustomClassConfig {
configField1: string = 'default_value_here';
configField2: string = 'another_default_value';
configField3: Array<string | boolean | number> = ['default_val'];
configField4: string = 'last_default_value';
}

can be accessed using an AftConfig instance as follows:

const config = aftConfig.getSection(SomeCustomClassConfig); // or new AftConfig().getSection(SomeCustomClassConfig);
config.configField1; // returns "an important value"
config.configField2; // returns "some-value"
config.configField3; // returns ["foo", true, 10] as an array
config.configField4; // returns "last_default_value"

and if you wish to entirely disregard the configuration specified in your aftconfig.json file you can use the following (still based on the above example):

const config = new AftConfig({
SomeCustomClassConfig: {
configField1: 'custom_value_here'
}
});
config.configField1; // returns "custom_value_here"
config.configField2; // returns "another_default_value"
config.configField3; // returns ["default_val"] as an array
config.configField4; // returns "last_default_value"

Hierarchy

  • AftConfig

Constructors

Properties

_sectionCache: Map<string, {}>

Type declaration

    _valueCache: Map<string, JsonValue>
    _fileCandidates: readonly string[] = ...

    Accessors

    • get logLevel(): "trace" | "debug" | "info" | "step" | "warn" | "pass" | "fail" | "error" | "none"
    • used by AftLogger to limit console output by importance

      Returns "trace" | "debug" | "info" | "step" | "warn" | "pass" | "fail" | "error" | "none"

      Default

      'warn'
      
    • get plugins(): (string | PluginLocator)[]
    • an array of plugin filenames (these must also match the lowercase plugin class name minus any -, _ and . characters) to load via the pluginLoader

      ex:

      // aftconfig.json
      {
      "plugins": [
      "my-plugin",
      {"name": "my-other-plugin", "searchDir": "/full/path/to/my-other-plugin/"}
      ]
      }

      would match with the following plugin classes

      // <project-root>/any/subdirectory/my-plugin.js
      export class MyPlugin extends Plugin {
      doStuff = () => 'stuff';
      }

      and

      // /full/path/to/my-other-plugin.js
      export class MyOtherPlugin extends Plugin {
      doOtherStuff = () => 'other stuff';
      }

      Returns (string | PluginLocator)[]

      Default

      []
      

    Methods

    • looks for a value in the aftconfig.json file at the top level and if found attempts to extract any environment variable set if the value matches a format of %some_var_name% before returning the value or the specified defaultVal if nothing was found

      Type Parameters

      Parameters

      • key: string

        the configuration key

      • Optional defaultVal: T

        a default value to return if no value is set for the specified key

      Returns T

      the value set in the aftconfig.json file for the specified key or undefined

    • looks for a top-level section in your aftconfig.json file with a name matching the passed in className and returns it or a new instance of the className type

      Type Parameters

      • T extends {}

      Parameters

      • className: string | Class<T>

        a class of type T where the name of the class and the section name must match

      Returns T

      the section from aftconfig.json matching the name of the passed in className or a new instance of the className type

    • attempts to get an environment variable value for a given key if the passed in input is in the format of %some_env_var_key%

      Parameters

      • input: string

        a string that might reference an environment var between two % characters like %some_env_var%

      Returns string

      the value of the environment variable

    • iterates over all properties for the passed in input object and if a property is a string it calls processEnvVars on the property

      Type Parameters

      • T extends {}

      Parameters

      • input: T

        an object that contains properties

      Returns T

      the input object with any string property values updated based on the result of calling processEnvVars

    • adds the passed in section to the ConfigManager cache of aftconfig.json sections so it will be used instead of the value from the actual JSON file

      Type Parameters

      • T extends {}

      Parameters

      • key: string

        adds the passed in section to the cache so it will be used instead of reading from aftconfig.json

      • section: T

        an object containing properties

      Returns void

    Generated using TypeDoc