-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
66 lines (55 loc) · 1.71 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const fs = require("fs");
const path = require("path");
const compiler = require("vue-template-compiler");
const yaml = require("yaml");
function main() {
createJson();
Promise.all([render(), compileStyles()]).then(([html, css]) => {
const out = fs
.readFileSync("./template.html", { encoding: "utf-8" })
.replace("<!-- content -->", html)
.replace("/* stylesheet */", css);
fs.writeFileSync("./index.html", out);
});
}
function createJson() {
// const data = require("./data.js");
// const str = JSON.stringify(data, null, 2);
// fs.writeFileSync("./martin-hanzel-cv.json", str);
// fs.writeFileSync("./martin-hanzel-cv.yml", yaml.stringify(data));
const data = yaml.parse(fs.readFileSync("./martin-hanzel-cv.yml", "utf-8"))
fs.writeFileSync("./martin-hanzel-cv.json", JSON.stringify(data, null, 2));
}
function compileStyles() {
const stylus = require("stylus");
return new Promise((resolve) => {
stylus.render(
fs.readFileSync("./main.styl", { encoding: "utf-8" }),
(err, css) => {
if (err) throw err;
resolve(css);
}
);
});
}
function requireVue(path) {
const sfc = compiler.parseComponent(
fs.readFileSync(`./components/${path}.vue`, { encoding: "utf-8" })
);
return { ...eval(sfc.script.content), template: sfc.template.content };
}
function render() {
const Vue = require("vue");
const renderer = require("vue-server-renderer").createRenderer();
global.requireVue = requireVue;
const data = require("./martin-hanzel-cv.json");
const app = new Vue({
data: { data },
components: {
App: requireVue("App"),
},
template: `<App :data="data" /></div>`,
});
return renderer.renderToString(app);
}
main();