-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetFilesList.js
39 lines (34 loc) · 861 Bytes
/
getFilesList.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
38
39
#! /usr/bin/env node
const fs = require("fs");
/**
* Return Widgets files dir. e.g:
* {
* "MyWidget.jsx": "/path/to/widget/MyWidget.jsx",
* "MyWidget2.jsx": "/path/to/widget/MyWidget2.jsx"
* ...
* }
*
* @param {*} widgetsFolder
* @returns
*/
const getFilesList = (widgetsFolder) => {
if (!widgetsFolder) {
return null;
}
return new Promise((resolve, reject) => {
const widgetsList = {};
fs.readdir(widgetsFolder, function (err, files) {
// Handling error
if (err) {
reject("Unable to scan directory: " + err)
return console.log("Unable to scan directory: " + err);
}
// Listing all files using forEach
files.forEach(function (file) {
widgetsList[file] = `${widgetsFolder}/${file}`;
});
resolve(widgetsList)
})
})
}
module.exports = getFilesList