127.0.0.1:8000 personal-website / 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) {
            let addEntry = include.includes(fileName);
            if (path.extname(fileName) === ".js") {
                fileName = fileName.substr(0, fileName.length - 3);
                addEntry = true;
            }
            if (addEntry) {
                if (exclude.includes(fileName)) {
                    return entries;
                }
                entries.push([folderPath, fileName]);
            }
            return entries;
        }, []);
    }
};