Mason allows developers to create and consume reusable templates called bricks.
# Activate from pub.dev
$ pub global activate mason
# Or install using Homebrew
$ brew tap felangel/mason
$ brew install mason
$ mason init
mason init
initializes the Mason CLI in the current directory.
Running mason init
generates a mason.yaml
and an example brick
so that you can get started immediately.
bricks:
hello:
path: bricks/hello
To get all bricks registered in mason.yaml
run:
$ mason get
Then you can use mason make
to generate your first file:
$ mason make hello
Any variables can be passed as command line args.
$ mason make hello --name Felix
Any variables which aren't specified as command line args will be prompted.
$ mason make hello
name: Felix
Any variables can be passed via json file:
$ mason make hello --json hello.json
where hello.json
is:
{
"name": "Felix"
}
The above commands will all generate HELLO.md
in the current directory with the following content:
Hello Felix!
Create a new brick using the mason new
command.
$ mason new <BRICK_NAME>
The above command will generate a new brick in the bricks
directory with a brick.yaml
and __brick__
template directory.
The brick.yaml
contains metadata for a brick
template.
name: example
description: An example brick
vars:
- name
Write your brick template in the __brick__
directory using mustache templates. See the mustache manual for detailed usage information.
__brick__/example.md
# Hello {{name}}!
❗ Note: __brick__
can contain multiple files and subdirectories
❗ Note: use {{{variable}}}
instead of {{variable}}
when you want the value of variable
to be unescaped
It is possible to resolve files based on path input variables using the {{% %}}
tag.
For example, given the following brick.yaml
:
name: app_icon
description: Create an app_icon file from a URL
vars:
- url
And the following brick template:
__brick__/{{% url %}}
Running mason make 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. Check out the app icon example brick to try it out.
You can use mason to generate a bundle for an existing template. Bundles are convenient for cases where you want to include your template as part of a standalone CLI. Very Good CLI is a great example.
There are currently two types of bundles:
- Universal - a platform-agnostic bundle
- Dart - a Dart specific bundle
To generate a bundle:
# Universal Bundle
mason bundle ./path/to/brick -d ./path/to/destination
# Dart Bundle
mason bundle ./path/to/brick -t dart -d ./path/to/destination
$ 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:
bundle Generates a bundle from a brick template
cache Interact with mason cache
get Gets all bricks.
init Initialize mason in the current directory.
make Generate code using an existing brick template.
new Creates a new brick template.