You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1017 B
35 lines
1017 B
'use strict'; |
|
const fs = require('fs'); |
|
const path = require('path'); |
|
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'); |
|
const srcPath = path.resolve(path.dirname(__filename), '../src'); |
|
|
|
console.log(`### INFO: Rendering ${filePath} to ${destPath}`); |
|
const html = pug.renderFile(filePath, { |
|
doctype: 'html', |
|
filename: filePath, |
|
basedir: srcPath |
|
}); |
|
|
|
const destPathDirname = path.dirname(destPath); |
|
if (!sh.test('-e', destPathDirname)) { |
|
sh.mkdir('-p', destPathDirname); |
|
} |
|
|
|
const prettified = prettier.format(html, { |
|
printWidth: 1000, |
|
tabWidth: 4, |
|
singleQuote: true, |
|
proseWrap: 'preserve', |
|
endOfLine: 'lf', |
|
parser: 'html', |
|
htmlWhitespaceSensitivity: 'ignore' |
|
}); |
|
|
|
fs.writeFileSync(destPath, prettified); |
|
}; |