common/index.js
function serviceConfig() {

    var arg = ld.values(arguments), cfg = {};

    // try to load file from global directory
    if(typeof arg[0] === 'string') {
        var path = arg.shift();
        try {
            cfg = require('/etc/paukan/'+path+'.json');
        } catch (err) { // try to load file directly if global fails
            try {
                cfg = require(path);
            } catch (err) {}
        }
    }

    // append default settings
    var localCfg = arg.shift();
    if(!ld.isPlainObject(localCfg)) {
        throw new Error('at least local config should be specified');
    }
    ld.defaults(cfg, localCfg);

    // load specific field from package.json
    var packageCfg = arg.shift();
    if(ld.isPlainObject(packageCfg)) {
        ld.defaults(cfg, ld.pick(packageCfg, ['version', 'description', 'homepage', 'author']));
    }

    return cfg;
}
function serviceConfig() {

    var arg = ld.values(arguments), cfg = {};

    // try to load file from global directory
    if(typeof arg[0] === 'string') {
        var path = arg.shift();
        try {
            cfg = require('/etc/paukan/'+path+'.json');
        } catch (err) { // try to load file directly if global fails
            try {
                cfg = require(path);
            } catch (err) {}
        }
    }

    // append default settings
    var localCfg = arg.shift();
    if(!ld.isPlainObject(localCfg)) {
        throw new Error('at least local config should be specified');
    }
    ld.defaults(cfg, localCfg);

    // load specific field from package.json
    var packageCfg = arg.shift();
    if(ld.isPlainObject(packageCfg)) {
        ld.defaults(cfg, ld.pick(packageCfg, ['version', 'description', 'homepage', 'author']));
    }

    return cfg;
}
function serviceConfig ( ) { var arg = ld . values ( arguments ) , cfg = { } ; // try to load file from global directory if ( typeof arg [ 0 ] === 'string' ) { var path = arg . shift ( ) ; try { cfg = require ( '/etc/paukan/' + path + '.json' ) ; } catch ( err ) { // try to load file directly if global fails try { cfg = require ( path ) ; } catch ( err ) { } } } // append default settings var localCfg = arg . shift ( ) ; if ( ! ld . isPlainObject ( localCfg ) ) { throw new Error ( 'at least local config should be specified' ) ; } ld . defaults ( cfg , localCfg ) ; // load specific field from package.json var packageCfg = arg . shift ( ) ; if ( ld . isPlainObject ( packageCfg ) ) { ld . defaults ( cfg , ld . pick ( packageCfg , [ 'version' , 'description' , 'homepage' , 'author' ] ) ) ; } return cfg ; }
Take configuration files and service specific info from package.json

@params {string|object}
- if first parameter is string - will be added config from /etc/paukan/<name>.json
- second parameter is confguration object with default settings
- last (third, or second if name is not specified - object from package.json where service-specific info will be taken)
Take configuration files and service specific info from package . json