-
Notifications
You must be signed in to change notification settings - Fork 9
/
prepare.js
62 lines (50 loc) · 2.05 KB
/
prepare.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
const {
rmSync,
mkdirSync,
readdirSync,
readFileSync,
writeFileSync,
copyFileSync
} = require("fs")
const {join} = require("path")
const {renderFile} = require("pug")
const {compile} = require("handlebars")
const viewsBase = join(__dirname, "views")
const assetsBase = join(__dirname, "assets")
const confBase = join(__dirname, "conf")
const wombatBase = join(__dirname, "node_modules", "@webrecorder", "wombat", "dist")
const outputBase = join(__dirname, "output")
const generatedConfBase = join(__dirname, "generated-conf")
module.exports = context => {
console.log("Cleaning previous files...")
rmSync(outputBase, {force: true, recursive: true})
rmSync(generatedConfBase, {force: true, recursive: true})
mkdirSync(outputBase, {recursive: true})
mkdirSync(generatedConfBase, {recursive: true})
console.log("Preparing assets and templates...")
const views = readdirSync(viewsBase)
const assets = readdirSync(assetsBase)
const conf = readdirSync(confBase)
for (const entry of views) {
if (entry.startsWith("_") || !entry.endsWith(".pug"))
continue
const output = renderFile(join(viewsBase, entry), {basedir: viewsBase, ...context})
writeFileSync(join(outputBase, entry.replace(/\.pug$/, ".html")), output)
console.log("Processed view", entry)
}
for (const entry of assets) {
copyFileSync(join(assetsBase, entry), join(outputBase, entry))
console.log("Copied asset", entry)
}
for (const entry of conf) {
if (entry.startsWith("_") || !entry.endsWith(".hbs"))
continue
const input = readFileSync(join(confBase, entry), "utf-8")
const output = compile(input)(context)
writeFileSync(join(generatedConfBase, entry.slice(0, -4)), output)
console.log("Processed configuration", entry)
}
copyFileSync(join(wombatBase, "wombat.js"), join(outputBase, "wombat.js"))
copyFileSync(join(wombatBase, "wombatWorkers.js"), join(outputBase, "wombatWorkers.js"))
console.log("Copied Wombat scripts")
}