What is unified-engine?
The unified-engine is a powerful tool for processing text using plugins. It is part of the unified collective, which is a project that provides a suite of tools for working with content as structured data. The engine allows you to read, process, and write files using a pipeline of plugins, making it highly extensible and customizable.
What are unified-engine's main functionalities?
Reading Files
This feature allows you to read files from the filesystem. In this example, the engine reads a Markdown file using the 'remark-parse' plugin.
const engine = require('unified-engine');
const vfile = require('to-vfile');
engine({
files: ['example.md'],
processor: unified().use(require('remark-parse')),
cwd: process.cwd(),
extensions: ['md'],
output: false
}, (err, status) => {
if (err) throw err;
console.log('Files read successfully');
});
Processing Files
This feature allows you to process files using a pipeline of plugins. In this example, the engine processes a Markdown file and converts it to HTML using 'remark-parse' and 'remark-html' plugins.
const engine = require('unified-engine');
const unified = require('unified');
const markdown = require('remark-parse');
const html = require('remark-html');
engine({
files: ['example.md'],
processor: unified().use(markdown).use(html),
cwd: process.cwd(),
extensions: ['md'],
output: 'example.html'
}, (err, status) => {
if (err) throw err;
console.log('Files processed successfully');
});
Writing Files
This feature allows you to write processed files back to the filesystem. In this example, the engine writes the processed HTML output to 'example.html'.
const engine = require('unified-engine');
const vfile = require('to-vfile');
const unified = require('unified');
const markdown = require('remark-parse');
const html = require('remark-html');
engine({
files: ['example.md'],
processor: unified().use(markdown).use(html),
cwd: process.cwd(),
extensions: ['md'],
output: 'example.html'
}, (err, status) => {
if (err) throw err;
console.log('Files written successfully');
});
Other packages similar to unified-engine
gulp
Gulp is a toolkit for automating painful or time-consuming tasks in your development workflow. It uses a code-over-configuration approach and is highly extensible with plugins. Compared to unified-engine, Gulp is more general-purpose and can handle a wider range of tasks beyond text processing.
webpack
Webpack is a module bundler primarily for JavaScript, but it can transform front-end assets like HTML, CSS, and images if the corresponding loaders are used. While unified-engine focuses on processing text files using plugins, Webpack is more about bundling and optimizing assets for web applications.
broccoli
Broccoli is a fast, reliable asset pipeline, supporting constant-time rebuilds and compact build definitions. It is similar to Gulp but focuses more on the build pipeline for front-end assets. Compared to unified-engine, Broccoli is more specialized in asset management and build processes.
unified-engine
unified engine to process multiple files, lettings users configure
from the file system.
Contents
What is this?
This package is the engine.
It’s what you use underneath when you use remark-cli
or a
language server.
Compared to unified, this deals with multiple files, often from the file
system, and with configuration files and ignore files.
When should I use this?
You typically use something that wraps this, such as:
You can use this to make such things.
Install
This package is ESM only.
In Node.js (version 14.14+ or 16.0+), install with 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
}
API
This package exports the identifier engine
.
There is no default export.
engine(options, callback)
Process files according to options
and call callback
when
done.
processor
(Processor
)
— unified processor to transform filescwd
(string
or URL
, default: process.cwd()
)
— directory to search files in, load plugins from, and morefiles
(Array<string|URL|VFile>
, optional)
— paths or globs to files and directories, virtual files, or URLs, to
processextensions
(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 givenfilePath
(string
, optional)
— file path to process the given file on streamIn
asstreamOut
(WritableStream
, default: process.stdout
)
— stream to write processed files tostreamError
(WritableStream
, default: process.stderr
)
— stream to write the report (if any) toout
(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 toalwaysStringify
(boolean
, default: false
)
— whether to always serialize successfully processed filestree
(boolean
, default: false
)
— whether to treat both input and output as a syntax treetreeIn
(boolean
, default: tree
)
— whether to treat input as a syntax treetreeOut
(boolean
, default: tree
)
— whether to treat output as a syntax treeinspect
(boolean
, default: false
)
— whether to output a formatted syntax treercName
(string
, optional)
— name of configuration files to loadpackageField
(string
, optional)
— property at which configuration can be found in package.json
filesdetectConfig
(boolean
, default: whether rcName
or
packageField
is given)
— whether to search for configuration filesrcPath
(string
, optional)
— filepath to a configuration file to loadsettings
(Object
, optional)
— configuration for the parser and compiler of the processorignoreName
(string
, optional)
— name of ignore files to loaddetectIgnore
(boolean
, default: whether ignoreName
is given)
— whether to search for ignore filesignorePath
(string
, optional)
— filepath to an ignore file to loadignorePathResolveFrom
('dir'
or 'cwd'
,
default: 'dir'
)
— resolve patterns in ignorePath
from the current working directory or the
file’s directoryignorePatterns
(Array<string>
, optional)
— patterns to ignore in addition to ignore files, if anyignoreUnconfigured
(boolean
, default: false
)
— ignore files that do not have an associated detected configuration filesilentlyIgnore
(boolean
, default: false
)
— skip given files if they are ignoredplugins
(Array|Object
, optional)
— plugins to usepluginPrefix
(string
, optional)
— optional prefix to use when searching for pluginsconfigTransform
(Function
, optional)
— transform config files from a different schemareporter
(string
or function
, default:
import {reporter} from 'vfile-reporter'
)
— reporter to usereporterOptions
(Object?
, optional)
— config to pass to the used reportercolor
(boolean
, default: false
)
— whether to report with ANSI color sequencessilent
(boolean
, default: false
)
— report only fatal errorsquiet
(boolean
, default: silent
)
— do not report successful filesfrail
(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 on your part as a
developer), or a status code and the processing context.
Parameters
error
(Error
) — fatal errorcode
(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 occurcontext
(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.
Types
This package is fully typed with TypeScript.
It additionally exports the following types:
VFileReporterOptions
— models options passed to vfile reportersVFileReporter
— models the signature accepted as a vfile reporterFileSet
— models what is passed to plugins as a second parameterCompleter
— models file set pluginsResolveFrom
— models the enum allowed for options.ignorePathResolveFrom
ConfigTransform
— models the signature of options.configTransform
Preset
— models a preset, like Preset
from unified
but accepts
stringsOptions
— models configurationContext
— models the third parameter to callback
Callback
— models the signature of callback
Compatibility
Projects maintained by the unified collective are compatible with all maintained
versions of Node.js.
As of now, that is Node.js 14.14+ or 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
Security
unified-engine
loads and evaluates configuration files, plugins, and presets
from the file system (often from node_modules/
).
That means code that is on your file system runs.
Make sure you trust the workspace where you run unified-engine
and be careful
with packages from npm and changes made by contributors.
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