UNPKG

1.24 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3// External modules
4var node_path = require('path');
5var node_fs = require('fs');
6var _ = require('lodash');
7var iconv = require('iconv-lite');
8var rimraf = require('rimraf');
9
10
11var sync = module.exports = {};
12
13// explode built-in fs methods to `fs-more`
14// sync.__proto__ = node_fs;
15
16
17// Process specified wildcard glob patterns or filenames against a
18// callback, excluding and uniquing files in the result set.
19function processPatterns(patterns, fn) {
20
21 // Filepaths to return.
22 var result = [];
23 // Iterate over flattened patterns array.
24 _.flatten(patterns).forEach(function(pattern) {
25 // If the first character is ! it should be omitted
26 var exclusion = pattern.indexOf('!') === 0;
27 // If the pattern is an exclusion, remove the !
28 if (exclusion) {
29 pattern = pattern.slice(1);
30 }
31 // Find all matching files for this pattern.
32 var matches = fn(pattern);
33
34 if (exclusion) {
35 // If an exclusion, remove matching files.
36 result = _.difference(result, matches);
37 } else {
38 // Otherwise add matching files.
39 result = _.union(result, matches);
40 }
41 });
42
43 return result;
44};