forked from neslinesli93/elm-vs-yew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.js
51 lines (39 loc) · 1.27 KB
/
view.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
const fs = require("fs");
const path = require("path");
function getScripts() {
const elmPath = "./elm/build/static/js";
const elmFiles = readFiles(elmPath, "elm");
copyFiles(elmFiles);
const yewPath = "./yew/dist";
const yewFiles = readFiles(yewPath, "yew");
copyFiles(yewFiles);
const cssFiles = readFiles("./style", "style");
copyFiles(cssFiles, true);
const scripts = elmFiles
.concat(yewFiles)
.filter((f) => filesForTemplate(f.name))
.map((f) => path.join(f.publicPath, f.name));
const shynet = process.env.SHYNET_ENABLED !== undefined;
return { scripts, shynet };
}
function readFiles(filesPath, publicPath) {
return fs.readdirSync(filesPath).map((s) => ({
name: s,
publicPath,
distPath: path.join("dist", publicPath),
path: path.join(filesPath, s),
}));
}
function copyFiles(files, skipFilter) {
fs.mkdirSync(files[0].distPath, { recursive: true });
files
.filter((f) => skipFilter || filesForApplication(f.name))
.forEach((f) => fs.copyFileSync(f.path, path.join(f.distPath, f.name)));
}
function filesForApplication(f) {
return f.endsWith(".js") || f.endsWith(".wasm");
}
function filesForTemplate(f) {
return (f.startsWith("elm") || f.startsWith("yew")) && f.endsWith(".js");
}
module.exports = { getScripts };