2020-04-07 00:19:58 +02:00
|
|
|
'use strict';
|
|
|
|
const fs = require('fs');
|
2021-03-30 01:45:48 +02:00
|
|
|
const upath = require('upath');
|
2020-04-07 00:19:58 +02:00
|
|
|
const pug = require('pug');
|
|
|
|
const sh = require('shelljs');
|
|
|
|
const prettier = require('prettier');
|
|
|
|
|
|
|
|
module.exports = function renderPug(filePath) {
|
|
|
|
const destPath = filePath.replace(/src\/pug\//, 'dist/').replace(/\.pug$/, '.html');
|
2021-03-30 01:45:48 +02:00
|
|
|
const srcPath = upath.resolve(upath.dirname(__filename), '../src');
|
2020-04-07 00:19:58 +02:00
|
|
|
|
|
|
|
console.log(`### INFO: Rendering ${filePath} to ${destPath}`);
|
|
|
|
const html = pug.renderFile(filePath, {
|
|
|
|
doctype: 'html',
|
|
|
|
filename: filePath,
|
|
|
|
basedir: srcPath
|
|
|
|
});
|
|
|
|
|
2021-03-30 01:45:48 +02:00
|
|
|
const destPathDirname = upath.dirname(destPath);
|
2020-04-07 00:19:58 +02:00
|
|
|
if (!sh.test('-e', destPathDirname)) {
|
|
|
|
sh.mkdir('-p', destPathDirname);
|
|
|
|
}
|
|
|
|
|
|
|
|
const prettified = prettier.format(html, {
|
|
|
|
printWidth: 1000,
|
|
|
|
tabWidth: 4,
|
|
|
|
singleQuote: true,
|
|
|
|
proseWrap: 'preserve',
|
|
|
|
endOfLine: 'lf',
|
2020-06-18 20:03:24 +02:00
|
|
|
parser: 'html',
|
|
|
|
htmlWhitespaceSensitivity: 'ignore'
|
2020-04-07 00:19:58 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
fs.writeFileSync(destPath, prettified);
|
2021-03-30 01:45:48 +02:00
|
|
|
};
|