UNPKG

webpack-entries-autodiscovery

Version:
58 lines 2.57 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var glob_1 = require("glob"); var fs_1 = require("fs"); var path_1 = require("path"); var EntriesDiscoverer = /** @class */ (function () { function EntriesDiscoverer() { } EntriesDiscoverer.prototype.discoverEntries = function (params) { this.params = params; this.validateConfig(); return this.discoverEntriesInPath(this.params.basePath); }; EntriesDiscoverer.prototype.discoverEntriesInPath = function (path) { var _this = this; var entries = {}; var entriesGlob = this.getEntriesGlob(path); glob_1.sync(entriesGlob).forEach(function (absoluteFilePath) { var _a = absoluteFilePath.split(_this.params.entriesDirName + "/"), baseDir = _a[0], entryPath = _a[1]; var entryName = path_1.dirname(entryPath); entries[entryName] = absoluteFilePath; }); return entries; }; EntriesDiscoverer.prototype.getEntriesGlob = function (basePath) { var _a = this.params, entriesDirName = _a.entriesDirName, entryFilename = _a.entryFilename, entryExtensions = _a.entryExtensions; return basePath + "/" + entriesDirName + "/**/" + entryFilename + ".+(" + entryExtensions.join('|') + ")"; }; EntriesDiscoverer.prototype.validateConfig = function () { if (!fs_1.existsSync(this.params.entriesPath)) { throw new EntriesDirDoesntExist(this.params.entriesPath); } }; return EntriesDiscoverer; }()); exports.EntriesDiscoverer = EntriesDiscoverer; var EntriesDirDoesntExist = /** @class */ (function (_super) { __extends(EntriesDirDoesntExist, _super); function EntriesDirDoesntExist(dirName) { return _super.call(this, "Entries dir " + dirName + " does not exists") || this; } return EntriesDirDoesntExist; }(Error)); exports.EntriesDirDoesntExist = EntriesDirDoesntExist; //# sourceMappingURL=discoverer.js.map