-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
53 lines (44 loc) · 1.46 KB
/
Copy pathindex.js
File metadata and controls
53 lines (44 loc) · 1.46 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const fs = require('fs');
const path = require('path');
const filepath = require('./lib/FilePath.js');
var Crawler = require('./lib/Crawler.js');
var CrawlerSync = require('./lib/CrawlerSync.js');
/**
* Gets list of files and folders using crawler object.
*/
function FilesList() {
}
/**
* Get the list of files and folders asynchronously
* including subfolder and files of the given directory.
* @param {String} directory Name of the directory being crawled
* @return {Array} list List of files and folders
*/
FilesList.prototype.getFilesList = function (dirname) {
var self = this;
var crawler = new Crawler();
dirname = filepath.normalisePath(dirname);
return new Promise(function(resolve, reject) {
var isParentDir = true;
crawler.crawl(dirname, isParentDir)
.then(crawler.getData.bind(crawler, resolve))
.catch(function(e) {
console.error(e);
reject();
});
});
};
/**
* Get the list of files and folders synchronously
* including subfolder and files of the given directory.
* @param {String} directory Name of the directory being crawled
* @return {Array} list List of files and folders
*/
FilesList.prototype.getFilesListSync = function (dirname) {
var self = this;
var crawler = new CrawlerSync();
dirname = filepath.normalisePath(dirname);
return crawler.getData(dirname);
};
var filesList = new FilesList();
module.exports = filesList;