src/ConfigHelper.js
function _load(file, defaultConfig, dump) {

    const f = normalize(file);
    const b = f.base;
    const p = f.profile;
    const ext = f.ext;

    if (ext) {
        const p = b + ext;
        let r = loadSpecific(b, '.js', p, defaultConfig, dump);
        if (r) return r;

        if (defaultConfig) return defaultConfig;

        throw new Error('file not found: ' + p);
    }

    let r = loadSpecific(b, '.yml', p, defaultConfig, dump);
    if (r) return r;

    r = loadSpecific(b, '.yaml', p, defaultConfig, dump);
    if (r) return r;

    r = loadSpecific(b, '.json', p, defaultConfig, dump);
    if (r) return r;

    r = loadSpecific(b, '.js', p, defaultConfig, dump);
    if (r) return r;

    if (defaultConfig) return defaultConfig;

    throw new Error(`file not found: ${b}[.profile].yml( or .yaml/.json/.js)`);

}
function _load(file, defaultConfig, dump) {

    const f = normalize(file);
    const b = f.base;
    const p = f.profile;
    const ext = f.ext;

    if (ext) {
        const p = b + ext;
        let r = loadSpecific(b, '.js', p, defaultConfig, dump);
        if (r) return r;

        if (defaultConfig) return defaultConfig;

        throw new Error('file not found: ' + p);
    }

    let r = loadSpecific(b, '.yml', p, defaultConfig, dump);
    if (r) return r;

    r = loadSpecific(b, '.yaml', p, defaultConfig, dump);
    if (r) return r;

    r = loadSpecific(b, '.json', p, defaultConfig, dump);
    if (r) return r;

    r = loadSpecific(b, '.js', p, defaultConfig, dump);
    if (r) return r;

    if (defaultConfig) return defaultConfig;

    throw new Error(`file not found: ${b}[.profile].yml( or .yaml/.json/.js)`);

}
function _load ( file , defaultConfig , dump ) { const f = normalize ( file ) ; const b = f . base ; const p = f . profile ; const ext = f . ext ; if ( ext ) { const p = b + ext ; let r = loadSpecific ( b , '.js' , p , defaultConfig , dump ) ; if ( r ) return r ; if ( defaultConfig ) return defaultConfig ; throw new Error ( 'file not found: ' + p ) ; } let r = loadSpecific ( b , '.yml' , p , defaultConfig , dump ) ; if ( r ) return r ; r = loadSpecific ( b , '.yaml' , p , defaultConfig , dump ) ; if ( r ) return r ; r = loadSpecific ( b , '.json' , p , defaultConfig , dump ) ; if ( r ) return r ; r = loadSpecific ( b , '.js' , p , defaultConfig , dump ) ; if ( r ) return r ; if ( defaultConfig ) return defaultConfig ; throw new Error ( ` ${ b } ` ) ; }
Read a configuration file.

Support format: yaml, json, js.
Support extension: .yml, .yaml, .json, .js

@param {*} file 1) if it is a string, I will think it a full path
2) if it is a object, I will think it is structured as:
{
dir: '',  // directory name. optional, working dir by default
name: '', // file name, without ext. must.
ext: '', // force to be with this extension. optional.
}
@param defaultConfig default config if file not exists. optional
@param boolean dump true to dump the content
Read a configuration file .