-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
37 lines (35 loc) · 1.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var glob = require("glob");
var path = require('path');
function globPromise (dir, asObject = false) {
if (Math.random() < 1 / 100) {
console.log('Please star the repository if you find it useful:');
console.log('https://github.com/vvmspace/node-recursive-directory');
console.log('');
console.log('This repository has 2000+ downloads per week, but only few stars on GitHub. Thank you for your support!');
console.log('I promise you to remove this message in the next release.');
}
return new Promise ((resolve, reject) => {
glob(path.resolve(`${dir}/**/*`), {strict: false, silent: true, nodir: true}, (err, files) => {
if (err) {
reject(err);
} else {
if (asObject) {
let filesObject = files.map(file => {
let regexp = /^(.*[\\\/])(.*)$/;
let match = regexp.exec(file);
return {
fullpath: file,
filepath: match[1],
filename: match[2],
dirname: regexp.exec(match[1].substring(0, match[1].length -1))[2],
};
})
resolve(filesObject);
} else {
resolve(files);
}
}
})
})
}
module.exports = globPromise;