Bebar
What is it?
Bebar combines multiple powerfull tools so you can grab data somwhere, and merge it with a template to produce documents.
In a .bebar file, you indicate a few things:
- Where your data is (a path, a webserver). it can be json, yaml, csv, xml, ...
- A template file in a mustache format
- Where to put the result for the merge between you data and your template
And with this you will be able to generate a new readable file thw way you want.
Additionnaly, you can also indicate:
- Where to find partial mustache templates (so you can split and reuse your template parts)
- Where to find helpers which are javascript functions to help you transform your data (to display human-readable dates, currency amounts, various conversions, ...)
- Prettify options so your final output looks beter!
How to use Bebar
Install
npm install -g bebar
Run
bebar
Command line arguments
-
-f, --filename
[optional] The filename of you bebar file(s). The path can include a wildcard. If ommited, will default to *.bebar. -
-v, --verbosity
[optional] Indicates the verbosity level to use. If ommited, will default to INFO. Possible values are INFO, WARN, ERROR and NONE.
A basic example
The data (schools.json)
[
{
"id": 1,
"name": "Harvard University"
},
{
"id": 2,
"name": "Massachusetts Institute of Technology"
},
{
"id": 3,
"name": "Stanford University"
},
]
The template (list_of_schools.mustache)
The bebar file (schools.bebar)
data:
-
file: ./schools.json
templates:
-
file: list_of_schools.mustache
output: schools.md
The result (schools.md)
# List of schools
1. Harvard University
2. Massachusetts Institute of Technology
3. Stanford University
Installation
npm install bebar -g
Usage
Command
Options
How to create a bebar file
Your bebar file should is in yaml format. It is used to tell bebar where to find your data, your templates, where to generate files...
Loading data
You can get your data from anywhere with bebar (a csv, xml, json, yaml, ...).
Full explanations & examples here
Setup your template(s)
Your data will be 'merged' with a mustache template to produce an output result.
Full explanations & examples here
Setup helper functions
You can load javascript functions to help you format your data.
Full explanations & examples here
Setup partial functions
If your template file is too big, or you want to be able to resuse parts of templates, you can split your files using partials and call them from your template.
Full explanations & examples here
Credits
Dependencies
- handlebar to process templates
- axios to fetch http requests.
- eemeli/yaml to parse yaml contents.
- mafintosh/csv-parser to parse csv contents.
- naturalIntelligence/fast-xml-parser to parse xml contents.
- node-eval to parse and run javascript files.
- prettier to format your resulting files.
- glob to get all the files when using wildcards in paths.
- commander to parse command line arguments.
- chalk To colorize the console outputs.
- clear To clear the console.
- figlet Just for fun, to have a nicer console.
Dev dependencies
- typescript
- axios-mock-adapter to mock axios http calls.
- copyfiles to copy some files at build time.
- eslint for code styling.
- eslint-config-google for code styling.
- jest for testing
- ts-jest to configure jest for typescript.
- typedoc to produce the api documentation.