UNPKG

mdast

Version:

Markdown processor powered by plugins

73 lines (61 loc) 1.46 kB
/** * @author Titus Wormer * @copyright 2015 Titus Wormer * @license MIT * @module mdast:cli:file-pipeline:stdout * @version 2.2.2 * @fileoverview Write a file to stdout(4). */ 'use strict'; /* eslint-env node */ /* * Dependencies. */ var debug = require('debug')('mdast:cli:file-pipeline:stdout'); /** * Write a virtual file to stdout(4). * Ignored when `output` is given, more than one file * was processed, or `stdout` is false. * * @example * var cli = {'stdout': process.stdout.write}; * var fileSet = new FileSet(cli); * var file = new File({ * 'directory': '~', * 'filename': 'example', * 'extension': 'md', * 'contents': '# Hello' * }); * fileSet.add(file); * * stdout({ * 'output': false, * 'file': file, * 'fileSet': fileSet * }); * * @param {Object} context */ function stdout(context) { var fileSet = context.fileSet; var file = context.file; if ( !fileSet.cli.watch && fileSet.cli.out && fileSet.length === 1 && (!context.output || !file.filePath()) ) { if (!file.namespace('mdast:cli').given) { debug('Ignoring programmatically added file'); return; } debug('Writing document to standard out'); fileSet.cli.stdout(context.file.toString()); } else { debug('Ignoring writing to standard out'); } } /* * Expose. */ module.exports = stdout;