microgen
micro-generator for individual files, easy like sunday morning
Yet another generator; how's it different?
- any file, anywhere on disk can be a template
- no need to install templates (like heavy weight project generators)
- easiest way to fill in templates, using simple handlebars placeholders
- no data files required (like other handlebars cli's)
- you'll be prompted to fill in the data at runtime
Installation
$ npm install microgen # --global
Usage
$ microgen --help Usage: microgen <template-file> [output-file] Options: -h, --help show usage help -p, --pipe pipe output to stdout, instead of writing to file output-file
How does it work?
A microgen template is any file that can have handlebars placeholders. Microgen will scan the template for placeholders and prompt you to fill in a value for each one.
Supported placeholders:
- Variable
{{some-value}}
- Block
{{#some-boolean}}something{{else}}something else{{/some-boolean}}
{{^}}
is the same as{{else}}
- You can use string literals, e.g.
{{#"Are you happy"}}great{{/"Are you happy"}}
- Comment
{{!some string to display when prompting}}
{{!--x--}}
is the same as{{!x}}
{{!}}
just adds a newline to the display
For example, say you have a package.json
template file:
!== Let the Good Times Roll == "name": "{{name}}" "repository": "{{owner}}/{{name}}" "description": "{{description}}"!#"Include Dependencies" "dependencies": #assert-dotenv "assert-dotenv": "3.0.0"/assert-dotenv!#"Use a CLI Helper [meow, inquirer, commander]"#meow "meow": "^3.0.0"else#inquirer "inquirer": "^1.0.2"^#commander "commander": "^2.9.0"/commander/inquirer/meow/"Use a CLI Helper [meow, inquirer, commander]" /"Include Dependencies"
Microgen will prompt you like so:
== Let the Good Times Roll == name: smileowner: bustercdescription: writes :) to stdout Include Dependencies : y assert-dotenv : y Use a CLI Helper [meow, inquirer, commander] : y meow : n inquirer : n commander : y
...and the resulting output file will contain:
Respect
microgen was inspired by khaos
If you need heavy weight project scaffolding generators, then look into plop
and yo
License
ISC © Buster Collings