@gik/tools-configurator

0.0.6 • Public • Published

@gik/tools-configurator 0.0.6

Imports configuration from a folder

Contributors
Supported platforms
  • linux
  • darwin

Table of contents

  • configurator Load data from json (compatible) files according to current environment.
    • Path Returns full paths for the directories declard con package.json
    • Env Returns the current environment.
    • WebpackResolverPlugin Allows to implement the same functionality of configurator

configurator

Load data from json (compatible) files according to current environment. when no environment is specified development is assumed.

As an added bonus, the contents of Path and Env will be available to you when populating the configuration.

Example

Assuming the following directory structure and process.env.NODE_ENV = 'production':

 └ etc
    ├ default.json -> {
    |    "a": {
    |        "a1": "one",
    |        "a2": "two",
    |        "aa": "${a.a1}${a.a2}"
    |    }
    | }
    └ default-production.json -> {
          "a": {
              "ab": "${a.aa}-b"
          },
          "b": "${Env}"
      }

The result would be:

{
    a: {
        a1: 'one',
        a2: 'two',
        aa: 'onetwo',
        ab: 'onetwo-b'
    },
    b: 'production'
}
Parameters
[settings] Object Settings to customize behaviour.
[settings.name] string | Array The name for the config files. if an array is sent, will process specified names in order. Default default
[settings.path] string The path where config files are located. Default Path.etc
[settings.ext] string The extension filter for config files. Default .json
[settings.delete] boolean Remove Path and Env after merging. Default true
Returns

Object - The result of the merge of the common and environment file.

Throws
  • ConfiguratorSettingsTypeError - When sent an invalid settings parameter.
  • ConfiguratorSettingsPathError - When settings.path cannot be found.
  • ConfiguratorFileError - When a file cannot be loaded.
  • ConfiguratorParseError - When an error occurs when loading a file.
Members

▲ Top


Path

Returns full paths for the directories declard con package.json

▲ Top


Env

Returns the current environment.

▲ Top


WebpackResolverPlugin

Allows to implement the same functionality of configurator to generate a module that will be internally resolved by webpack.

Example

Adding the following to your webpack config:

{ ...
  resolve: {
    plugins: [ WebpackResolverPlugin('#config', { path: './config' }) ]
  }
}

Would make the configuration available on a module, like the following:

// your webpack source
import Config from '#config';
console.log(Config); // would output the parsed config on `./config`
Parameters
id string The identifier that you'll use to import the module.
settings Object The settings to be passed to the configurator.

▲ Top


Readme

Keywords

none

Package Sidebar

Install

npm i @gik/tools-configurator

Weekly Downloads

1

Version

0.0.6

License

MIT

Last publish

Collaborators

  • etor