Sha256: d592d0f226362b05eaf4f36a826ad63ea31863e79b881dc1b118e08dcc3959f5
Contents?: true
Size: 1.43 KB
Versions: 43
Compression:
Stored size: 1.43 KB
Contents
/** * @fileoverview Module for loading rules from files and directories. * @author Michael Ficarra */ "use strict"; //------------------------------------------------------------------------------ // Requirements //------------------------------------------------------------------------------ const fs = require("fs"), path = require("path"); const rulesDirCache = {}; //------------------------------------------------------------------------------ // Public Interface //------------------------------------------------------------------------------ /** * Load all rule modules from specified directory. * @param {string} [relativeRulesDir] Path to rules directory, may be relative. Defaults to `lib/rules`. * @param {string} cwd Current working directory * @returns {Object} Loaded rule modules by rule ids (file names). */ module.exports = function(relativeRulesDir, cwd) { const rulesDir = relativeRulesDir ? path.resolve(cwd, relativeRulesDir) : path.join(__dirname, "rules"); // cache will help performance as IO operation are expensive if (rulesDirCache[rulesDir]) { return rulesDirCache[rulesDir]; } const rules = Object.create(null); fs.readdirSync(rulesDir).forEach(file => { if (path.extname(file) !== ".js") { return; } rules[file.slice(0, -3)] = path.join(rulesDir, file); }); rulesDirCache[rulesDir] = rules; return rules; };
Version data entries
43 entries across 43 versions & 1 rubygems