md-template
Build markdown from es6-templates and js
All js files will be executed and exported object will be deeply merged together in order. This data will be made available to the template.
Example
md-template ./template.md ./data.js > README.md
CLI
module { const execSync = ; const fs = ; const path = ; const os = ; const uuid = ; const expected = ` # one 1 ## two 2 ## RGB red green blue `; const template = ` # one \${one} ## two \${two} ## RGB \${color_channels.slice(0,3).join(" ")} `; // NOTE: backslashes not neccissary in actual file const data = ` module.exports = { one: 1, two: 2, color_channels: ["red", "green", "blue", "alpha"] }; `; const demoDir = path; fs; const templatePath = path; const dataPath = path; fs; fs; const result = ; return result === expected;};
Usage
md-template: type: object example: md-template <TEMPLATE> <...DATA> [options] description: > Generates document from templated object and exported data. Prints new document to stdout properties: TEMPLATE: type: string example: template.md description: > Path to document whose text content will be used as a template string DATA: type: array description: > Paths to json files which will be required, properties exported by these scripts will be deeply merged in the order in the command and made available to template items: type: string example: data.js options: type: object properties: "-h": type: boolean description: > When present, prints help file to stderr and returns non-0 exit code
API
moduleexports = async { const execSync = ; const fs = ; const path = ; const os = ; const uuid = ; const expected = ` # one 1 ## two 2 ## RGB red green blue `; const template = ` # one \${one} ## two \${two} ## RGB \${color_channels.slice(0,3).join(" ")} `; // NOTE: backslashes not neccissary in actual file const data = ` module.exports = { one: 1, two: 2, color_channels: ["red", "green", "blue", "alpha"] }; `; const demoDir = path; fs; const templatePath = path; const dataPath = path; fs; fs; const results = await templatePath: templatePath scriptPaths: dataPath ; return results === expected;};
arguments
templatePath
type: string
path to template file
scriptPaths
type: string | array
paths of scripts which will be executed and their results deeply merged together in order, and this data will be available to the template