Advanced
Parsers
Eventvisor ships with built in YAML and JSON parsers. You can also provide a custom parser when project definitions use another format.
The built in implementations are published in @eventvisor/parsers and used by the CLI through @eventvisor/core. YAML writes preserve existing comments where possible, including changes made by promotion and other editorial operations.
Built-in parsers#
YAML#
By default, Eventvisor assumes all your definitions are written in YAML and no extra configuration is needed in that case:
module.exports = { tags: ['web'], // optional if value is "yml" parser: 'yml',}You can find an example project using YAML here.
JSON#
If we wish to use JSON files instead of YAMLs, we can do so by specifying the parser option:
module.exports = { tags: ['web'], // define the parser to use parser: 'json',}You can find an example project using JSON here.
Custom#
If you wish to define your events and attributes in some other language besides YAML and JSON, you can provide your own custom parser.
A parser declares its file extension and provides both parse and stringify functions. Eventvisor passes the current file path as an optional second argument. This allows a parser to preserve comments or formatting when it rewrites an existing definition.
Let's say we wish to use TOML files for our definitions.
We start by installing the @iarna/toml package:
$ npm install --save-dev @iarna/tomlNow we define a custom parser in our configuration:
const TOML = require('@iarna/toml')module.exports = { tags: ['web'], parser: { extension: 'toml', parse: (content) => TOML.parse(content), stringify: (content) => TOML.stringify(content), },}
