UNPKG

@plugjs/plug

Version:
48 lines (46 loc) 1.95 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // plugs/filter.ts var filter_exports = {}; module.exports = __toCommonJS(filter_exports); var import_files = require("../files.cjs"); var import_paths = require("../paths.cjs"); var import_pipe = require("../pipe.cjs"); var import_match = require("../utils/match.cjs"); var import_options = require("../utils/options.cjs"); (0, import_pipe.install)("filter", class Filter { _globs; _options; constructor(...args) { const { params, options } = (0, import_options.parseOptions)(args, {}); this._options = options; this._globs = params; } pipe(files, context) { const { directory, ...options } = this._options; const dir = directory ? context.resolve(directory) : files.directory; const builder = import_files.Files.builder(dir); const matcher = (0, import_match.match)(this._globs, options); for (const file of files.absolutePaths()) { const relative = (0, import_paths.resolveRelativeChildPath)(builder.directory, file); if (relative && matcher(relative)) builder.add(relative); } const result = builder.build(); const discarded = files.length - result.length; context.log.debug("Filtered", result.length, "files (discarded", discarded, "files)"); return result; } }); //# sourceMappingURL=filter.cjs.map