unified-engine can be configured extensively by engine authors.
- options.processor
- options.cwd
- options.files
- options.extensions
- options.streamIn
- options.filePath
- options.streamOut
- options.streamError
- options.out
- options.output
- options.alwaysStringify
- options.tree
- options.treeIn
- options.treeOut
- options.inspect
- options.rcName
- options.packageField
- options.detectConfig
- options.rcPath
- options.settings
- options.ignoreName
- options.detectIgnore
- options.ignorePath
- options.silentlyIgnore
- options.plugins
- options.pluginPrefix
- options.defaultConfig
- options.configTransform
- options.reporter
- options.reporterOptions
- options.color
- options.silent
- options.quiet
- options.frail
Unified processor to transform files.
- Type:
Processor
The following example reformats stdin(4) using remark, writes the report to stderr(4), and formatted document to stdout(4).
var engine = require('unified-engine')
var remark = require('remark')
engine({processor: remark}, done)
function done(err) {
if (err) throw err
}Directory to search files in, load plug-ins from, and more.
- Type:
string - Default:
process.cwd()
The following example reformats readme.md. The doc directory is used to
process from.
var path = require('path')
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
cwd: path.join(process.cwd(), 'doc'),
files: ['readme.md'],
output: true
},
done
)
function done(err) {
if (err) throw err
}Paths or globs, or vfiles to files and directories to process.
Fileglobs (for example, *.md) can be given to add all matching files.
Directories and globs to directories can be given alongside
extensions to search directories for files matching an
extension (for example, dir to add dir/readme.txt and dir/sub/history.text
if extensions is ['txt', 'text']). This searching will not include
node_modules or hidden directories (those starting with a dot, ., like
.git).
- Type:
Array.<string> - Default:
[]
The following example processes README and all files with an md extension
in doc.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark,
files: ['README', 'doc'],
extensions: ['md']
},
done
)
function done(err) {
if (err) throw err
}If files matches directories, those directories are searched for
files whose extension matches the given extensions.
In addition, if treeIn is turned on and output is
true or points to a directory, generated files are given the first extension.
- Type:
Array.<string> - Default:
[]
The following example reformats all files with md, markdown, and mkd
extensions in the current directory.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark,
files: ['.'],
extensions: ['md', 'mkd', 'markdown'],
output: true
},
done
)
function done(err) {
if (err) throw err
}Stream to read from if no files are found or given. If streamIn is the only
possible source of input but it’s a TTY, an error is thrown.
- Type:
ReadableStream - Default:
process.stdin
The following example uses remark-lint to lint an incoming
stream.
var PassThrough = require('stream').PassThrough
var engine = require('unified-engine')
var remark = require('remark')
var recommended = require('remark-preset-lint-recommended')
var streamIn = new PassThrough()
engine(
{
processor: remark(),
plugins: [recommended],
streamIn: streamIn,
out: false
},
done
)
streamIn.write('doc')
setTimeout(delayed, 100)
function delayed() {
streamIn.end('ument')
}
function done(err) {
if (err) throw err
}Yields:
<stdin>
1:1 warning Missing newline character at end of file final-newline remark-lint
⚠ 1 warningFile path to process the given file on streamIn as, if any.
- Type:
string(optional)
The following example shows the same as before, with a filePath added, which
is shown in the report:
var PassThrough = require('stream').PassThrough
var engine = require('unified-engine')
var remark = require('remark')
var recommended = require('remark-preset-lint-recommended')
var streamIn = new PassThrough()
engine(
{
processor: remark(),
plugins: [recommended],
filePath: '~/alpha/bravo/charlie.md',
streamIn: streamIn,
out: false
},
done
)
streamIn.write('doc')
setTimeout(function() {
streamIn.end('ument')
}, 100)
function done(err) {
if (err) throw err
}Yields:
~/alpha/bravo/charlie.md
1:1 warning Missing newline character at end of file final-newline remark-lint
⚠ 1 warningStream to write processed files to. This behaviour is suppressed if:
outisfalseoutputis notfalse- multiple files are processed
- a fatal error occurred while processing a file
- Type:
WritableStream - Default:
process.stdout
The following example reads readme.md and writes the compiled document to
readme-two.md. Note that this can also be achieved by passing
output: 'readme-two.md' instead of streamOut.
var fs = require('fs')
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
files: ['readme.md'],
streamOut: fs.createWriteStream('readme-two.md')
},
done
)
function done(err) {
if (err) throw err
}Stream to write the report (if any) to.
- Type:
WritableStream - Default:
process.stderr
The following example uses remark-lint to lint readme.md and
writes the report to report.txt.
var fs = require('fs')
var engine = require('unified-engine')
var remark = require('remark')
var recommended = require('remark-preset-lint-recommended')
engine(
{
processor: remark(),
files: ['readme.md'],
plugins: [recommended],
out: false,
streamErr: fs.createWriteStream('report.txt')
},
done
)
function done(err) {
if (err) throw err
}Whether to write the processed file to streamOut. The default
behaviour is to only write under some conditions, as specified in the section
on streamOut, but if out is false nothing will be written
to streamOut.
- Type:
boolean - Default: depends (see above)
The following example uses remark-lint to lint readme.md,
writes the report, and ignores the compiled document.
var engine = require('unified-engine')
var remark = require('remark')
var recommended = require('remark-preset-lint-recommended')
engine(
{
processor: remark(),
files: ['readme.md'],
plugins: [recommended],
out: false
},
done
)
function done(err) {
if (err) throw err
}Whether to write successfully processed files and where to.
- When
true, overwrites the given files - When
false, does not write to the file-system - When pointing to an existing directory, files are written to that directory and keep their original basenames
- When the parent directory of the given path exists and one file is processed, the file is written to the given path
- Otherwise, a fatal error is thrown
Note that if treeIn is turned on, generated files get the first
defined extensions. If treeOut is turned on,
generated files receive the 'json' extension. If inspect is
turned on, generated files receive the 'txt' extension.
- Type:
stringorboolean - Default:
false
The following example writes all files in src/ with an md extension,
compiled, to dest/.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
files: ['src/'],
extensions: ['md'],
output: 'dest/'
},
done
)
function done(err) {
if (err) throw err
}Whether to always stringify successful documents. By default, documents are
stringified when it’s detected that a file is to be written to stdout(4)
or the file system. If files are handled and possibly written somewhere later,
set this option to true.
- Type:
boolean - Default:
false
Whether to treat both input and output as a syntax tree. If given, specifies
the default value for both treeIn and treeOut.
- Type:
boolean, optional - Default:
false
The following example reads tree.json, then remark-unlink
transforms the syntax tree, and the transformed tree is written to
stdout(4).
var engine = require('unified-engine')
var remark = require('remark')
var unlink = require('remark-unlink')
engine(
{
processor: remark(),
plugins: [unlink],
files: ['tree.json'],
tree: true
},
done
)
function done(err) {
if (err) throw err
}Where tree.json looks as follows:
{
"type": "paragraph",
"children": [{
"type": "link",
"url": "https://example.com",
"children": [{
"type": "text",
"value": "foo"
}]
}]
}Yields:
{
"type": "paragraph",
"children": [{
"type": "text",
"value": "foo"
}]
}Treat input as a JSON.stringifyd syntax tree, thus skipping
the parsing phase and passing the syntax tree right
through to transformers.
If extensions are given, sets the extension of processed files
to the first one.
- Type:
boolean, optional - Default:
options.tree
The following example reads tree.json, then remark-unlink
transforms the syntax tree, the tree is compiled, and the resulting document is
written to stdout(4).
var engine = require('unified-engine')
var remark = require('remark')
var unlink = require('remark-unlink')
engine(
{
processor: remark(),
plugins: [unlink],
files: ['tree.json'],
treeIn: true
},
done
)
function done(err) {
if (err) throw err
}Where tree.json looks as follows:
{
"type": "paragraph",
"children": [{
"type": "link",
"url": "https://example.com",
"children": [{
"type": "text",
"value": "foo"
}]
}]
}Yields:
fooSkip the compilation phase and compile the transformed syntax tree to JSON.
Sets the extension of processed files to json, if possible.
- Type:
boolean, optional - Default:
options.tree
The following example shows a script which reads and parses doc.md, then
remark-unlink transforms the syntax tree, and the tree is
written to stdout(4).
var engine = require('unified-engine')
var remark = require('remark')
var unlink = require('remark-unlink')
engine(
{
processor: remark(),
plugins: [unlink],
files: ['doc.md'],
treeOut: true
},
done
)
function done(err) {
if (err) throw err
}Where doc.md looks as follows:
[foo](https://example.com)Yields:
{
"type": "paragraph",
"children": [{
"type": "text",
"value": "foo"
}]
}Skip the compilation phase and output a syntax tree
formatted with unist-util-inspect.
Sets the extension of processed files to txt if possible.
Uses ANSI colour sequences in the formatted syntax tree if color is turned on.
- Type:
boolean, optional - Default:
false
The following example shows a script which reads and parses doc.md, then
remark-unlink transforms the syntax tree, the tree is
formatted with unist-util-inspect, and finally written
to stdout(4).
var engine = require('unified-engine')
var remark = require('remark')
var unlink = require('remark-unlink')
engine(
{
processor: remark(),
plugins: [unlink],
files: ['doc.md'],
inspect: true
},
done
)
function done(err) {
if (err) throw err
}Where doc.md looks as follows:
[foo](https://example.com)Yields:
root[1] (1:1-2:1, 0-27)
└─ paragraph[1] (1:1-1:27, 0-26)
└─ text: "foo" (1:2-1:5, 1-4)Name of configuration file to load. If given and
detectConfig is not false, $rcName files are loaded and
parsed as JSON, $rcName.js are required, and $rcName.yml and
$rcName.yaml are loaded with js-yaml (safeLoad).
- Type:
string, optional
The following example processes readme.md, and allows configuration from
.remarkrc, .remarkrc.js, and .remarkrc.yaml files.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
rcName: '.remarkrc',
files: ['readme.md']
},
done
)
function done(err) {
if (err) throw err
}Property at which configuration can live in package.json files.
If given and detectConfig is not false, package.json
files are loaded and parsed as JSON and their $packageField property is used
for configuration.
- Type:
string, optional
The following example processes readme.md, and allows configuration from
remarkConfig fields in package.json files.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
packageField: 'remarkConfig',
files: ['readme.md']
},
done
)
function done(err) {
if (err) throw err
}Whether to search for configuration files ($rcName,
$rcName.js, $rcName.yaml, and package.json with
$packageField).
- Type:
boolean, optional - Default:
trueifrcNameorpackageFieldare given
The following example processes readme.md but does not allow configuration
from .remarkrc or package.json files, as detectConfig is false.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
detectConfig: false,
rcName: '.remarkrc',
packageField: 'remarkConfig',
files: ['readme.md']
},
done
)
function done(err) {
if (err) throw err
}File-path to a config file to load, regardless of
detectConfig or rcName.
If the file’s extension is yml or yaml, it’s loaded as YAML. If the file’s
extension is js, it’s required. If the file’s basename is package.json,
the property at packageField is used. Otherwise, the file
is parsed as JSON.
- Type:
string, optional
The following example processes readme.md and loads configuration from
config.json.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
rcPath: 'config.json',
files: ['readme.md']
},
done
)
function done(err) {
if (err) throw err
}Configuration for the parser and compiler of the processor.
- Type:
Object, optional
The following example processes readme.md and configures the parser and
compiler with position: false.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
files: ['readme.md'],
settings: {position: false}
},
done
)
function done(err) {
if (err) throw err
}Name of ignore file to load. If given and
detectIgnore is not false, $ignoreName files are loaded.
- Type:
string, optional
The following example processes files in the current working directory with an
md extension, and is configured to ignore file paths from the closest
.remarkignore file.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
files: ['.'],
extensions: ['md'],
ignoreName: '.remarkignore'
},
done
)
function done(err) {
if (err) throw err
}Whether to search for ignore files ($ignoreName).
- Type:
boolean, optional - Default:
trueifignoreNameis given
The following example processes files in the current working directory with an
md extension but does not ignore file paths from the closest
.remarkignore file, because detectIgnore is false.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
files: ['.'],
extensions: ['md'],
ignoreName: '.remarkignore',
detectIgnore: false
},
done
)
function done(err) {
if (err) throw err
}File-path to ignore file to load, regardless of
detectIgnore or ignoreName.
- Type:
string, optional
The following example processes files in the current working directory with an
md extension and ignores file paths specified in .gitignore.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
files: ['.'],
extensions: ['md'],
ignorePath: '.gitignore'
},
done
)
function done(err) {
if (err) throw err
}Skip given files which are ignored by ignore files,
instead of warning about them.
- Type:
boolean, default:false
Plug-ins to load and attach with options to the processor for every processed file.
- Type:
Object,Array, optional. Same format aspluginsin config files
The following example processes readme.md and loads the
remark-preset-lint-recommended plug-in.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
files: ['readme.md'],
plugins: ['remark-preset-lint-recommended']
},
done
)
function done(err) {
if (err) throw err
}Allow plug-ins to be specified without a prefix. For example, if a plug-in is
specified with a name of foo, and pluginPrefix is bar, both bar-foo and
foo are checked in node_modules/ directories.
Note: If a prefix is specified, plug-ins with that prefix are preferred over plug-ins without that prefix.
- Type:
string, optional
The following example processes readme.md and loads the
preset-lint-recommended plug-in. Because pluginPrefix is given, this
resolves to remark-preset-lint-recommended from node_modules/ if
available.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
files: ['readme.md'],
pluginPrefix: 'remark',
plugins: ['preset-lint-recommended']
},
done
)
function done(err) {
if (err) throw err
}Optional object with plugins and/or settings to use if no config file is
supplied by the user.
- Type:
Object, optional
The following example processes readme.md. If package.json exists, that
config is used, otherwise the configuration at defaultConfig is used.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
files: ['readme.md'],
packageField: 'remarkConfig',
defaultConfig: {settings: {commonmark: true}}
},
done
)
function done(err) {
if (err) throw err
}Where package.json contains:
{
"name": "foo",
"private": true,
"remarkConfig": {
"settings": {
"footnotes": true
}
}
}Want configuration files in a different format? Pass a configTransform
function. It will be invoked with the parsed value from configuration files
and the file-path to the found file, and should return a config object (with
plugins and/or settings).
- Type:
Function, optional
The following example processes readme.md and loads options from custom
(from a package.json). configTransform is invoked with those options and
transforms it to configuration unified-engine understands.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
files: ['readme.md'],
packageField: 'custom',
configTransform: configTransform
},
done
)
function done(err) {
if (err) throw err
}
function configTransform(config) {
return {settings: (config || {}).options}
}Where package.json contains:
{
"name": "foo",
"private": true,
"custom": {
"options": {
"position": false
}
}
}Reporter to use. Reporters must be loadable from the cwd (such as by
installing them from that directory with npm). Reporters must be VFile
reporters.
- Type:
stringorfunction, optional, default:require('vfile-reporter'). Ifstring, the reporter’s prefix (vfile-reporter-) can be omitted, so ifjsonis given,vfile-reporter-jsonis loaded if it exists, and otherwise thejsonmodule itself is loaded (which in this example won’t work as it’s not a reporter)
The quiet, silent, and color options may not
work with the used reporter.
The following example processes all HTML files in the current directory with
rehype, configures the processor with .rehyperc files, and prints a report
in json, with reporter options.
var engine = require('unified-engine')
var rehype = require('rehype')
engine(
{
processor: rehype(),
files: ['.'],
extensions: ['html'],
rcName: '.rehyperc',
reporter: 'json',
reporterOptions: {pretty: true}
},
done
)
function done(err) {
if (err) throw err
}Options to pass to the reporter.
- Type:
Object, optional
The quiet, silent, and color options are
preferred over reporterOptions (and passed too).
See options.reporter for an example.
Whether to report or inspect with ANSI colour sequences.
- Type:
boolean, default:false
This option may not work with the used reporter.
The following example processes readme.md and uses colour in the
report.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
files: ['readme.md'],
color: true,
out: false
},
done
)
function done(err) {
if (err) throw err
}Yields:
�[4m�[32mreadme.md�[39m�[24m: no issues foundShow only fatal errors in the report.
- Type:
boolean, default:false
This option may not work with the used reporter.
The following example uses remark-lint to lint readme.md but
does not report any warnings or success messages, only fatal errors, if they
occur.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
files: ['readme.md'],
plugins: ['remark-preset-lint-recommended'],
silent: true
},
done
)
function done(err) {
if (err) throw err
}Whether to ignore processed files without any messages in the report. The default behaviour is to show a success message.
- Type:
boolean, default:options.silent
This option may not work with the used reporter.
The following example uses remark-lint to lint readme.md.
Nothing is reported if the file processed successfully.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
files: ['readme.md'],
plugins: ['remark-preset-lint-recommended'],
quiet: true
},
done
)
function done(err) {
if (err) throw err
}Count warnings as errors when calculating if the process succeeded.
- Type:
boolean, default:false
The following example uses remark-lint to lint readme.md and
logs the exit code. Normally, only errors turn the code to 1, but in
frail mode lint warnings result in the same.
var engine = require('unified-engine')
var remark = require('remark')
engine(
{
processor: remark(),
files: ['readme.md'],
plugins: ['remark-preset-lint-recommended'],
frail: true
},
done
)
function done(err, code) {
process.exit(err ? 1 : code)
}