-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.js
41 lines (36 loc) · 983 Bytes
/
build.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
const fs = require("fs");
let src = "./src";
let list = [];
let readdir = (src) => {
let files = fs.readdirSync(src)
files.forEach(file => {
let path = `${src}/${file}`;
let stat = fs.lstatSync(path);
if (stat.isFile()) {
list.push({
name: file.replace(".js", ""),
path: path
});
}
if (stat.isDirectory()) {
readdir(path);
}
});
};
readdir(src);
let comment = `//Generated By build.js ${new Date()}\n`;
let requireContent = "";
let exportHeader = `\nmodule.exports.default = module.exports = {\n`;
let exportContent = "";
let exportFooter = `}`;
list.forEach((item, index) => {
requireContent += `const ${item.name} = require("${item.path}");\n`;
if (index === list.length - 1) {
exportContent += `\t${item.name}\n`;
} else {
exportContent += `\t${item.name},\n`;
}
});
fs.writeFile("./index.js", `${comment}${requireContent}${exportHeader}${exportContent}${exportFooter}`, (err) => {
Error();
})