All Projects → zerkalica → Node Config Loader

zerkalica / Node Config Loader

Licence: mit
Scan directories and loads config json and yaml files

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Config Loader

Imports Loader
Imports Loader
Stars: ✭ 500 (+9900%)
Mutual labels:  webpack-loader
Wasm Loader
✨ WASM webpack loader
Stars: ✭ 604 (+11980%)
Mutual labels:  webpack-loader
Apollo
Apollo is a reliable configuration management system suitable for microservice configuration management scenarios.
Stars: ✭ 26,052 (+520940%)
Mutual labels:  configuration-management
Expose Loader
Expose Loader
Stars: ✭ 531 (+10520%)
Mutual labels:  webpack-loader
Aconfmgr
A configuration manager for Arch Linux
Stars: ✭ 576 (+11420%)
Mutual labels:  configuration-management
Ohai
Ohai profiles your system and emits JSON
Stars: ✭ 641 (+12720%)
Mutual labels:  configuration-management
Inject Loader
💉📦 A Webpack loader for injecting code into modules via their dependencies.
Stars: ✭ 474 (+9380%)
Mutual labels:  webpack-loader
Opsmop
DISCONTINUED: permanent copy of fork lives at github.com/mpdehaan/opsmop
Stars: ✭ 725 (+14400%)
Mutual labels:  configuration-management
Enms
An enterprise-grade vendor-agnostic network automation platform.
Stars: ✭ 595 (+11800%)
Mutual labels:  configuration-management
Bundle Loader
Bundle Loader
Stars: ✭ 666 (+13220%)
Mutual labels:  webpack-loader
Comlink Loader
Webpack loader to offload modules to Worker threads seamlessly using Comlink.
Stars: ✭ 535 (+10600%)
Mutual labels:  webpack-loader
React Svg Loader
A loader for webpack, rollup, babel that loads svg as a React Component
Stars: ✭ 570 (+11300%)
Mutual labels:  webpack-loader
Ini Parser
Read/Write an INI file the easy way!
Stars: ✭ 643 (+12760%)
Mutual labels:  configuration-management
Nacos Spring Boot Project
Nacos ECO Project for Spring Boot
Stars: ✭ 508 (+10060%)
Mutual labels:  configuration-management
Yacs
YACS -- Yet Another Configuration System
Stars: ✭ 705 (+14000%)
Mutual labels:  configuration-management
Svg Inline Loader
Inline SVG loader with cleaning-up functionality
Stars: ✭ 490 (+9700%)
Mutual labels:  webpack-loader
Cache Loader
[DEPRECATED] Caches the result of following loaders on disk
Stars: ✭ 630 (+12500%)
Mutual labels:  webpack-loader
Raw Loader
A loader for webpack that allows importing files as a String
Stars: ✭ 800 (+15900%)
Mutual labels:  webpack-loader
Conf
Simple config handling for your app or module
Stars: ✭ 707 (+14040%)
Mutual labels:  configuration-management
Spring Cloud Config Admin
Spring Cloud Config的综合管理后台(简称:SCCA)
Stars: ✭ 645 (+12800%)
Mutual labels:  configuration-management

Node config loader Build Status

NPM

Scan directories, load, parse to js object and merge many configs into single file/object.

  • Highly customizable and composable: each component is a pure function and exposed to public: compose you own loaders
  • Used globby for files matching
  • Compatible with lorenwest node-config file loading scheme, but each file name can be prefixed by '#' separator
  • Default loader supports json and yml files via nodeca js-yaml (can be overrided)
  • Live reload support via webpack loader

Config merge example

# input1#dev.yaml
ns:
    to:
        name: test
testArr:
    - t1
    - t2
__push__: [testArray2]
testArray2:
    - test1
    - test2
# input2#dev.yaml

ns:
    to:
        email: test-email
testArr:
    - t3
testArray2:
    - test3

merged input1 + input2:

#output.yaml

ns:
    to:
        name: test
        email: test-email
testArr:
    - t3
testArray2:
    - test1
    - test2
    - test3

Usage

As common lib

//simple.js
import {loadConfig} from 'node-config-loader'
import os from 'os'

loadConfig({
    mask: [
        `${__dirname}/config/**/*.{json,yml,tml}`
        `/etc/myapp.d/**/*.{json,yml,tml}`
        `${process.env.HOME}/.config/myapp/**/*.{json,yml,tml}`
    ],
    instance = 'server',
    env = process.env.NODE_ENV,
    hostname = os.hostname(),
    tagSeparator = '#'
})
    .then(config => console.log(config))
    .catch(err => config.error(err.message))

As webpack loader

Config load order:

  1. .configloaderrc
  2. webpack.config.js configLoader section
  3. webpack loader query params
import config from 'node-config-loader/webpack?env=prod&instance=client!./.configloaderrc'
console.log(config)

Where .configloaderrc is

{
    "mask": [
        "{ROOT}/src/config/**/*.json"
    ],
    "instance": "client|server",
    "env": "prod|dev",
    "hostname" : "host",
    "tagSeparator": "#"
}

mask is required, all other params are optional.

Available env vars in mask:

  • {ROOT} - project root
  • {DIRNAME} - .configloaderrc directory
  • {PWD} - process.cwd()
  • any process.env variable

Via Webpack config

// webpack.config.js
module.exports = {
    plugins: [
        new LoaderOptionsPlugin({
            options: {
                configLoader: {
                    env: isProduction ? 'prod' : 'dev',
                    instance: process.env.APP_INSTANCE || 'client'
                }
            }
        }),
    ],
    module: {
        loaders: [
            {
                test: /.*\.configloaderrc$/,
                loader: 'node-config-loader/webpack'
            }
    }
}

Flowtype

npm install --save empty

.flowconfig

[options]
module.name_mapper='.*\(\.configloaderrc\)' -> 'empty/object'

Isomorphic friendly сlient with run-time config

// getConfig.js
import config from '../conf/.configloaderrc'
import {merge} from 'node-config-loader'

function getRuntimeConfig({settings, location, referrer}) {
    return {
        env: {
            origin: location.origin,
            hash: location.hash,
            pathname: location.pathname,
            search: location.search,
            referrer: referrer
        },
        config: {
            debug: settings.debug,
            sitePrefix: settings.sitePrefix,
            locale: {
                lang: settings.locale
            }
        }
    }
}

export default function getConfig(opts) {
    return merge(config, getRuntimeConfig(opts))
}
// index.js
import getConfig from './getConfig'

const config = getConfig({
    settings: window.settings || {},
    location: window.location,
    referrer: document.referrer
})

// config
init(config)

interfaces

// @flow

function merge(objects: Object[]): Object
function strMap(strs: string, templateArgs: {[id: string]: string}): string

interface CreateScannerOpts {
    merge?: (acc: Object, src: Object) => Object;
    parser?: (data: FileRec) => Promise<Object>;
    readFile?: (fileName: string) => Promise<Buffer>;
}

type Scanner = (files: string[]) => Promise<Object>

function createScanner(opts?: CreateScannerOpts): Scanner

interface CreateNodeFilterOpts {
    instance?: string;
    hostname?: string;
    tagSeparator?: string;
    env?: string;
    templates?: string[];
}
function createNodeFilter(opts: CreateNodeFilterOpts): (files: string[]) => string[]

interface GetFilesOptions extends CreateNodeFilterOpts {
    mask: string[];
    glob?: {
        cwd?: string;
        root?: string;
        dot?: string;
        nomount?: boolean;
        mark?: boolean;
        nosort?: boolean;
        stat?: boolean;
        readdir?: boolean;
        silent?: boolean;
        statCache?: Object;
        symlinks?: Object;
        debug?: boolean;
        nonull?: boolean;
        nounique?: boolean;
        nobrace?: boolean;
        noglobstar?: boolean;
        noext?: boolean;
        nocase?: boolean;
        matchBase?: boolean;
        nodir?: boolean;
        ignore?: string;
        follow?: boolean;
        realpath?: boolean;
        absolute?: boolean;
    }
}
function getFiles(opts: GetFilesOptions): Promise<string[]>;

interface LoadConfigOptions extends GetFilesOptions, CreateScannerOpts {
    mask: string[];

    instance?: string;
    hostname?: string;
    tagSeparator?: string;
    env?: string;
    templates?: string[];

    glob?: Object;

    merge?: (acc: Object, src: Object) => Object;
    parser?: (data: FileRec) => Promise<Object>;
    readFile?: (fileName: string) => Promise<Buffer>;
}
function loadConfig(opts: LoadConfigOptions): Promise<Object>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].