From 1551c7060fd5dd1125aabb2a06d26e572aa270e3 Mon Sep 17 00:00:00 2001 From: Reid Litkauo Date: Thu, 28 Apr 2022 10:50:46 -0700 Subject: [PATCH] Add -r option (write to stdout) I found this useful, maybe someone else will too. --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 84cbe42..161e208 100644 --- a/index.js +++ b/index.js @@ -30,6 +30,7 @@ program .usage('[options] [dir|file ...]') .option('-O, --obj ', 'JSON/JavaScript options object or file') .option('-o, --out ', 'output the rendered HTML or compiled JavaScript to ') + .option('-r, --print', 'print the rendered HTML to stdout') .option('-p, --path ', 'filename used to resolve includes') .option('-b, --basedir ', 'path used as root directory to resolve absolute includes') .option('-P, --pretty', 'compile pretty HTML output') @@ -286,8 +287,9 @@ function renderFile(path, rootPath) { var dir = resolve(dirname(path)); mkdirp.sync(dir); var output = options.client ? fn : fn(options); - fs.writeFileSync(path, output); - consoleLog(' ' + chalk.gray('rendered') + ' ' + chalk.cyan('%s'), normalize(path)); + if (!program.print) { fs.writeFileSync(path, output); } + else { process.stdout.write(output); } + if (!program.print) { consoleLog(' ' + chalk.gray('rendered') + ' ' + chalk.cyan('%s'), normalize(path)); } // Found directory } else if (stat.isDirectory()) { var files = fs.readdirSync(path);