-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.js
60 lines (53 loc) · 1.63 KB
/
runner.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
57
58
59
60
/*
* runner.js: start a new localhost http server on port 300.
* makes it easy to see the generated site.
*
* to run: node runner.js
*/
var express = require('express');
var app = express();
var fs = require('fs');
//process.chdir(__dirname + "/..");
app.get('/', function (req, res) {
let dir = fs.readdirSync(".");
let list = [];
dir.filter(function (file) {
var stat = fs.statSync(file);
if (!(stat && stat.isDirectory())) {
return;
}
if ([".git", "libraries", "node_modules", "new-blank", "images"].includes(file)) {
return;
}
list.push(file);
})
list = list.map(file => {
let subdir = fs.readdirSync("./" + file);
subdir = subdir.filter(s => s.startsWith("sketch"));
console.log(subdir);
let responseString = `<li>`;
responseString += `<a href="${file}/">${file}</a>`
responseString += `<ul>`;
subdir.map(s => {
let num = s.replace("sketch", "").replace(".js", "");
responseString += `<li><a href="${file}/#${num}">${s}</a></li>`
});
responseString += `</ul>`;
responseString += `</li>`;
return responseString;
})
res.send("<ul>" + list.join("\n") + "</ul>")
});
app.get('*', function (req, res) {
var path = process.cwd() + req.path;
if (fs.existsSync(path)) {
res.sendFile(path);
} else {
res.sendFile(path + '.html');
}
});
var server = app.listen(8989, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Listening at http://%s:%s', host, port);
});