mason 0.0.1-dev.10 mason: ^0.0.1-dev.10 copied to clipboard
A Dart template generator which helps teams generate files quickly and consistently.
⛏️ mason #
A Dart template generator which helps teams generate files quickly and consistently.
pub global activate mason
Creating Custom Templates #
Define Template YAML #
greetings.yaml
name: greetings
description: A Simple Greetings Template
vars:
- name
Define Template #
Write your template in __template__
using mustache templates. See the mustache manual for detailed usage information.
__template__/greetings.md
# Greetings {{name}}!
❗ Note: templates can consist of multiple files and subdirectories
File Resolution
It is possible to resolve files based on path input variables using the <% %>
tag.
For example, given the following template.yaml
:
name: app_icon
description: Create an app_icon file from a URL
vars:
- url
And the following template:
__template__/<% url %>
Running mason build app_icon -- --url path/to/icon.png
will generate icon.png
with the contents of path/to/icon.png
where the path/to/icon.png
can be either a local or remote path.
Consuming Templates #
Create a Mason YAML #
Define a mason.yaml
at the root directory of your project.
templates:
greetings:
path: ./greetings.yaml
widget:
git:
url: git@github.com:felangel/mason.git
path: templates/widget/template.yaml
Then you can use mason build <greetings|widget>
:
mason build greetings -- --name Felix
mason build widget -- --name my_widget
Command Line Variables #
Any variables can be passed as command line args.
$ mason build greetings -- --name Felix
Variable Prompts #
Any variables which aren't specified as command line args will be prompted.
$ mason build greetings
name: Felix
JSON Input Variables #
Any variables can be passed via json file:
$ mason build greetings --json greetings.json
where greetings.json
is:
{
"name": "Felix"
}
The above commands should all generate GREETINGS.md
in the current directory with the following content:
# Greetings Felix!
Usage #
$ mason --help
⛏️ mason • lay the foundation!
Usage: mason <command> [arguments]
Global options:
-h, --help Print this usage information.
--version Print the current version.
Available commands:
build Generate code using an existing template.