utils/index.js
function env(file, inject) {
    const envs = {};
    if (!path.isAbsolute(file)) {
        file = path.resolve(process.cwd(), file);
    }
    if (fs.existsSync(file) && fs.lstatSync(file).isFile()) {
        const content = fs.readFileSync(file, 'utf8');
        content.split('\n').forEach(line => {
            const kv = line.match(/^\s*([\w.-]+)\s*=\s*(.*)?\s*$/);
            if (kv) {
                const k = kv[1];
                let v = kv[2] || '';
                if (
                    v &&
                    v.length > 0 &&
                    v.charAt(0) === '"' &&
                    v.charAt(v.length - 1) === '"'
                ) {
                    v = v.replace(/\\n/gm, '\n');
                }
                v = v.replace(/(^['"]|['"]$)/g, '').trim();
                envs[k] = v;
            }
        });
    }

    if (inject) {
        Object.keys(envs).forEach(k => {
            if (!(k in process.env)) {
                process.env[k] = envs[k];
            }
        });
    }

    return envs;
}
function env(file, inject) {
    const envs = {};
    if (!path.isAbsolute(file)) {
        file = path.resolve(process.cwd(), file);
    }
    if (fs.existsSync(file) && fs.lstatSync(file).isFile()) {
        const content = fs.readFileSync(file, 'utf8');
        content.split('\n').forEach(line => {
            const kv = line.match(/^\s*([\w.-]+)\s*=\s*(.*)?\s*$/);
            if (kv) {
                const k = kv[1];
                let v = kv[2] || '';
                if (
                    v &&
                    v.length > 0 &&
                    v.charAt(0) === '"' &&
                    v.charAt(v.length - 1) === '"'
                ) {
                    v = v.replace(/\\n/gm, '\n');
                }
                v = v.replace(/(^['"]|['"]$)/g, '').trim();
                envs[k] = v;
            }
        });
    }

    if (inject) {
        Object.keys(envs).forEach(k => {
            if (!(k in process.env)) {
                process.env[k] = envs[k];
            }
        });
    }

    return envs;
}
function env ( file , inject ) { const envs = { } ; if ( ! path . isAbsolute ( file ) ) { file = path . resolve ( process . cwd ( ) , file ) ; } if ( fs . existsSync ( file ) && fs . lstatSync ( file ) . isFile ( ) ) { const content = fs . readFileSync ( file , 'utf8' ) ; content . split ( '\n' ) . forEach ( line => { const kv = line . match ( / ^\s*([\w.-]+)\s*=\s*(.*)?\s*$ / ) ; if ( kv ) { const k = kv [ 1 ] ; let v = kv [ 2 ] || '' ; if ( v && v . length > 0 && v . charAt ( 0 ) === '"' && v . charAt ( v . length - 1 ) === '"' ) { v = v . replace ( / \\n / gm , '\n' ) ; } v = v . replace ( / (^['"]|['"]$) / g , '' ) . trim ( ) ; envs [ k ] = v ; } } ) ; } if ( inject ) { Object . keys ( envs ) . forEach ( k => { if ( ! ( k in process . env ) ) { process . env [ k ] = envs [ k ] ; } } ) ; } return envs ; }
Read envs from file path

@param {string} file
@param {boolean} [inject]
@returns {{[x: string]: string}}
Read envs from file path