@plugjs/plug
Version:
PlugJS Build System ===================
34 lines • 1.48 kB
JavaScript
import { Files } from "../files.js";
import { resolveRelativeChildPath } from "../paths.js";
import { install } from "../pipe.js";
import { match } from "../utils/match.js";
import { parseOptions } from "../utils/options.js";
/* ========================================================================== *
* INSTALLATION / IMPLEMENTATION *
* ========================================================================== */
/** Filter the current {@link Files} using globs. */
install('filter', class Filter {
_globs;
_options;
constructor(...args) {
const { params, 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 = Files.builder(dir);
const matcher = match(this._globs, options);
for (const file of files.absolutePaths()) {
const relative = 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.js.map