-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
32 lines (25 loc) · 871 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
const fs = require("fs");
const path = require("path");
const mapsDir = __dirname + "/mapy";
const indexPath = __dirname + '/mapy/index.html';
const files = getAllFilesFromFolder(mapsDir);
let out = "<ol>";
files.forEach((absPath) => {
const relPath = path.relative(mapsDir, absPath);
out += '<li><a href="' + relPath + '">' + relPath + "</a></li>\n";
});
out += '</ol>';
console.log(out);
fs.writeFileSync(indexPath, out);
// Source: https://stackoverflow.com/questions/20822273/best-way-to-get-folder-and-file-list-in-javascript
function getAllFilesFromFolder(dir) {
var results = [];
fs.readdirSync(dir).forEach(function (file) {
file = dir + "/" + file;
var stat = fs.statSync(file);
if (stat && stat.isDirectory()) {
results = results.concat(getAllFilesFromFolder(file));
} else results.push(file);
});
return results;
}