1.0.0 • Published 6 years ago

ufp-lcars-config v1.0.0

Weekly downloads
1
License
GPL-3.0
Repository
-
Last release
6 years ago

ufp-lcars-config

This module is responsible for loading configuration from various sources and then combining them into a single runtime configuration.

examples

Two example "validator" objects exist: validators/allFeatures.js & validators/lcars.js.

The validators/lcars.js is intended to be used/extended by the main ufp-lcars project for which this module was created.

Executing the following code will:

1) Load files beginning with the name ".name" from the source code's directory, the user's home, and the current working directory. 2) After doing this it will map any config parameters detected in environment varibles; it will search for the values using environment variable names defined by a keyified sanitizers in a very specific order: for example with "knex.connection.filename" `export knex.connection.filename="one.db"; export KNEX_CONNECTION_FILENAME="two.db"; ./example/bin 2) "UNIX_LIKE_CAPS_AND_UNDERSCORE"

API

Table of Contents

environment

Maps environment variables to "config" obj.

Parameters

  • validators Object An ideal config tree of functions that validato & validate values.
  • env Object Environment variables as key/value.

Returns Object A configuration object with only settings from the environment present.

files

Parameters

  • validators
  • paths Array Array of string locations to search for ".lcars.js" & ".lcars-environment.js" configuration files.
  • fileNames
  • idealized Object config property tree with optional functions to validate/sanitize values.

Returns Object technically only the config specified; but since this is where defaults arise it'll be everything really.

options

Parameters

  • validators
  • argv {Array} Array of strings to be interpreted as options; process.argv without slicing 2 is fine & dealt with.

Returns Object Configration map of only options specified from command line.

unknown

boolean: "interactive", "terminal", "secure", "knex.debug", "secret" ,

Parameters

  • option

runtime

This constructs a singular configure object from the various sources.

Parameters

  • validators Object A tree of functions that define all keys; sanitize key values; and throw runtime errors on invalid key values.
  • argv Array Array of strings, it's fine to include the first elements of process.argv.
  • env Object Environment variables represented as a POJO
  • paths Array Array of strings that are paths to be searched for configuration.
  • fileNames Array Array of strings that are base names of files to be searched.

Returns object configuration object that is a mapped combination of these diverse sources.

validatorsToblank

Always returns an empty skeleton of a validators tree.

Parameters

  • validators

Returns Object configuration object

1.0.0

6 years ago