-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.js
56 lines (45 loc) · 1.51 KB
/
load.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const { resolve } = require("path");
const { glob } = require("glob");
const camelCase = require("./camelcase");
const loadFunctions = (folder, exports, group = false, extension = ".f.js") => {
if (group) {
const folders = glob.sync(`./*/`, {
cwd: resolve(folder),
ignore: "./node_modules/**",
});
for (let i = 0; i < folders.length; i++) {
const fol = folders[i];
const folderName = fol.split(".").join("").split("/").join("");
const folderFiles = glob.sync(`./**/*${extension}`, {
cwd: resolve(fol),
ignore: "./node_modules/**",
});
const ex = {};
for (let y = 0; y < folderFiles.length; y++) {
const file = folderFiles[y];
const functionName = camelCase(
file.split(extension).join("").split("/").join("_")
); // Strip off '.f.js'
const mod = require(resolve(fol, file));
ex[functionName] = mod.default || mod;
}
if (Object.keys(ex).length) {
exports[folderName] = ex;
}
}
} else {
const files = glob.sync(`./**/*${extension}`, {
cwd: resolve(folder),
ignore: "./node_modules/**",
});
for (let f = 0, fl = files.length; f < fl; f++) {
const file = files[f];
const functionName = camelCase(
file.split(extension).join("").split("/").join("_")
); // Strip off '.f.js'
const mod = require(resolve(folder, file));
exports[functionName] = mod.default || mod;
}
}
};
exports.loadFunctions = loadFunctions;