Newer
Older
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
#!/usr/bin/env node
"use strict";
const fs = require("fs");
const browserify = require("browserify");
// Handle home page
const b = browserify();
b.add(`${process.cwd()}/src/main.js`)
.bundle()
.pipe(fs.createWriteStream(`${process.cwd()}/public/main.js`));
// Handle subpages
function getPageHtml(pagename) {
return `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Kuadrado Software - ${pagename}</title>
<link href="../../style/style.css" rel="stylesheet" />
</head>
<body>
<main></main>
</body>
<script type="text/javascript" src="./${pagename}.js"></script>
</html>
`;
}
const files = fs.readdirSync(`${process.cwd()}/src/pages`);
for (const f of files) {
const fPath = `${process.cwd()}/src/pages/${f}`;
const targetDirPath = `${process.cwd()}/public/${f}`;
if (!fs.existsSync(targetDirPath)) {
fs.mkdirSync(targetDirPath);
}
const b = browserify();
b.add(fPath)
.bundle()
.pipe(fs.createWriteStream(`${targetDirPath}/${f}.js`));
const page = fs.createWriteStream(`${targetDirPath}/index.html`);
page.write(getPageHtml(f));
}