-
Notifications
You must be signed in to change notification settings - Fork 1k
/
server.js
54 lines (47 loc) · 1.24 KB
/
server.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
/******************************************************************************
*
* Copyright (c) 2017, the Perspective Authors.
*
* This file is part of the Perspective library, distributed under the terms of
* the Apache License 2.0. The full license can be found in the LICENSE file.
*
*/
const fs = require("fs");
const {WebSocketServer} = require("@finos/perspective");
const template = (body) => `
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
</head>
<body>
<ul id="list">
${body}
</ul>
</body>
</html>
`;
const prod_template = (name) => `
<li>
<a href="src/${name}/index.html">local</a>
<a href="dist/${name}/index.html">dist</a>
${name}
</li>
`;
const dev_template = (name) => `
<li>
<a href="src/${name}/index.html">local</a>
${name}
</li>
`;
const gists = JSON.parse(fs.readFileSync("gists.json"));
const lis = [];
for (const key of fs.readdirSync("src")) {
if (!!gists[key]) {
lis.push(prod_template(key));
} else {
lis.push(dev_template(key));
}
}
fs.writeFileSync("dist/index.html", template(lis.join("\n")));
new WebSocketServer({assets: [__dirname, "dist", "../../"]});