127.0.0.1:8000 budget / master webpack / utils.js
master

Tree @master (Download .tar.gz)

utils.js @masterraw · history · blame

/* Author: Seva Luchianov */

const fs = require('fs');
const path = require('path');
global.PROJECT_ROOT = path.resolve(__dirname, "../");
global.JS_ROOT = "./src/js/";

module.exports = {
    getEntriesInFolder: function(folderPath, exceptions) {
        const {
            include = [], exclude = []
        } = (exceptions || {});

        return fs.readdirSync(
            path.join(global.PROJECT_ROOT, folderPath)
        ).reduce(function(entries, fileName) {
            if ([".js"].includes(path.extname(fileName)) || include.includes(fileName)) {
                if (exclude.includes(fileName)) {
                    return entries;
                }
                entries.push([folderPath, fileName]);
            }
            return entries;
        }, []);
    }
};