0.0.6 • Published 8 years ago

@gik/tools-configurator v0.0.6

Weekly downloads
5
License
MIT
Repository
github
Last release
8 years ago

@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
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

▲ Top