-
Notifications
You must be signed in to change notification settings - Fork 0
/
pugconfig.js
60 lines (44 loc) · 1.59 KB
/
pugconfig.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
/**
* This custom script is used to build/copy website sources for distribution:
* - copy specific assets such as style sheets or scripts (either 3rd party or custom ones)
* - compile specific pug templates and render to dist path
*/
const watch = process.argv.indexOf('--watch') > 1;
const fs = require('fs');
const path = require('path');
const copy = require('./copy.js');
const pug = require('pug');
const websiteDir = '.';
const distDir = './_site';
const entries = ['index.pug', 'docs/docs.pug'];
const assets = [
[websiteDir, distDir, ['css/*.css', 'js/*.js', 'img/*.{svg,png}', 'fonts/*', '*.{svg,png,ico,xml,json}'], ["package.json", "package-lock.json"], false],
[websiteDir + '/docs', distDir + '/docs', ['*/*'], [""], false]
];
var build_pending = false;
function build() {
process.env.NODE_ENV = 'production';
assets.forEach((asset) => copy(asset[0], asset[1], asset[2], asset[3], asset[4]));
entries.forEach((entry) => {
const src = path.join(websiteDir, entry);
const dst = path.join(distDir, path.basename(entry, path.extname(entry)) + '.html');
if (!fs.existsSync(src)) {
console.log('file not found:', entry);
return;
}
const html = pug.renderFile(src);
fs.writeFileSync(dst, html);
console.log('emitted:', dst);
});
build_pending = false;
}
build(); // trigger initial build
if (watch) {
fs.watch(websiteDir, { recursive: true }, function () {
if (build_pending) {
return;
}
build_pending = true;
setTimeout(build, 100);
});
}