Herr Bischoff

How to Convert Pug Templates to HTML via Command Line

Hot on the heels of my previous post regarding NODE_PATH, here’s a tiny little script for when you need to convert batches of Pug templates via the command line. Pug itself does not provide a CLI and it’s easy to see why. Creating one fitting your needs is trivial.

#!/usr/bin/env node

const prettier = require("prettier");
const pug = require("pug");

var args = process.argv.slice(2);

html = pug.renderFile(args[0]);

console.log(prettier.format(html, { parser: "html" }));

It requires Node.js as well as Pug and Prettier to be globally installed and that’s it: npm install -g pug prettier