unified-engine

Engine to process multiple files with unified

Usage no npm install needed!

<script type="module">
  import unifiedEngine from 'https://cdn.skypack.dev/unified-engine';
</script>

README

unified-engine

Build Coverage Downloads Sponsors Backers Chat

Engine to process multiple files with unified, allowing users to configure from the file system.

Projects

The following projects wrap the engine:

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

npm:

npm install unified-engine

Use

The following example processes all files in the current directory with a Markdown extension with remark, allows configuration from .remarkrc and package.json files, ignoring files from .remarkignore files, and more.

import {engine} from 'unified-engine'
import {remark} from 'remark'

engine(
  {
    processor: remark,
    files: ['.'],
    extensions: ['md', 'markdown', 'mkd', 'mkdn', 'mkdown'],
    pluginPrefix: 'remark',
    rcName: '.remarkrc',
    packageField: 'remarkConfig',
    ignoreName: '.remarkignore',
    color: true
  },
  done
)

function done(error) {
  if (error) throw error
}

Contents

API

This package exports the following identifiers: engine. There is no default export.

engine(options, callback)

Process files according to options and call callback when done.

options
  • processor (Processor) — unified processor to transform files
  • cwd (string, default: process.cwd()) — Directory to search files in, load plugins from, and more
  • files (Array<string|VFile>, optional) — Paths or globs to files and directories, or virtual files, to process
  • extensions (Array<string>, optional) — If files matches directories, include files with extensions
  • streamIn (ReadableStream, default: process.stdin) — Stream to read from if no files are found or given
  • filePath (string, optional) — File path to process the given file on streamIn as
  • streamOut (WritableStream, default: process.stdout) — Stream to write processed files to
  • streamError (WritableStream, default: process.stderr) — Stream to write the report (if any) to
  • out (boolean, default: depends) — Whether to write the processed file to streamOut
  • output (boolean or string, default: false) — Whether to write successfully processed files, and where to
  • alwaysStringify (boolean, default: false) — Whether to always serialize successfully processed files
  • tree (boolean, default: false) — Whether to treat both input and output as a syntax tree
  • treeIn (boolean, default: tree) — Whether to treat input as a syntax tree
  • treeOut (boolean, default: tree) — Whether to treat output as a syntax tree
  • inspect (boolean, default: false) — Whether to output a formatted syntax tree
  • rcName (string, optional) — Name of configuration files to load
  • packageField (string, optional) — Property at which configuration can be found in package.json files
  • detectConfig (boolean, default: whether rcName or packageField is given) — Whether to search for configuration files
  • rcPath (string, optional) — Filepath to a configuration file to load
  • settings (Object, optional) — Configuration for the parser and compiler of the processor
  • ignoreName (string, optional) — Name of ignore files to load
  • detectIgnore (boolean, default: whether ignoreName is given) — Whether to search for ignore files
  • ignorePath (string, optional) — Filepath to an ignore file to load
  • ignorePathResolveFrom ('dir' or 'cwd', default: 'dir') — Resolve patterns in ignorePath from the current working directory or the file’s directory
  • ignorePatterns (Array<string>, optional) — Patterns to ignore in addition to ignore files, if any
  • silentlyIgnore (boolean, default: false) — Skip given files if they are ignored
  • plugins (Array|Object, optional) — Plugins to use
  • pluginPrefix (string, optional) — Optional prefix to use when searching for plugins
  • configTransform (Function, optional) — Transform config files from a different schema
  • reporter (string or function, default: import {reporter} from 'vfile-reporter') — Reporter to use
  • reporterOptions (Object?, optional) — Config to pass to the used reporter
  • color (boolean, default: false) — Whether to report with ANSI color sequences
  • silent (boolean, default: false) — Report only fatal errors
  • quiet (boolean, default: silent) — Do not report successful files
  • frail (boolean, default: false) — Call back with an unsuccessful (1) code on warnings as well as errors

function callback(error[, code, context])

Called when processing is complete, either with a fatal error if processing went horribly wrong (probably due to incorrect configuration), or a status code and the processing context.

Parameters
  • error (Error) — Fatal error
  • code (number) — Either 0 if successful, or 1 if unsuccessful. The latter occurs if fatal errors happen when processing individual files, or if frail is set and warnings occur
  • context (Object) — Processing context, containing internally used information and a files array with the processed files

Plugins

doc/plugins.md describes in detail how plugins can add more files to be processed and handle all transformed files.

Configuration

doc/configure.md describes in detail how configuration files work.

Ignoring

doc/ignore.md describes in detail how ignore files work.

Contribute

See contributing.md in unifiedjs/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer