Mason: The Swiss Army Knife for Code Generation
What is Mason?
Mason: The Swiss Army Knife for Code Generation

What is Mason?
Mason is a free tool made by Felix Angelov from Very Good Ventures. It’s used to create files and folders from predefined templates, which are like building blocks. You make these templates, and then with the Mason tool, you can easily create and organize new files based on those templates. This is helpful for keeping your code neat and consistent in larger projects.
Installation
# 🎯 Activate from https://pub.dev
dart pub global activate mason_cli
# 🍺 Or install from https://brew.sh
brew tap felangel/mason
brew install mason
Initializing
mason init
mason init initializes the Mason CLI in the current directory.
Running mason init generates a mason.yaml so that you can get started immediately.
# Register bricks which can be consumed via the Mason CLI.
# Run "mason get" to install all registered bricks.
# To learn more, visit https://docs.brickhub.dev.
bricks:
# Bricks can be imported via version constraint from a registry.
# Uncomment the following line to import the "hello" brick from BrickHub.
# hello: 0.1.0+1
# Bricks can also be imported via remote git url.
# Uncomment the following lines to import the "widget" brick from git.
# widget:
# git:
# url: https://github.com/felangel/mason.git
# path: bricks/widget
For example, we can uncomment the “hello” brick (hello: 0.1.0+1):
bricks:
hello: 0.1.0+1
Next, get all bricks registered in mason.yaml via:
mason get
Then you can use mason make to generate your first file:
mason make hello
As you run these commands, it will ask you about a name like this:

Also, create a HELLO.md file

Bricks
Bricks are just reusable templates that you can change and use to make code with dynamic variables.
Mason uses mustache, a logic-less template syntax. To learn more about mustaches, check out this documentation.
We can add bricks in the following ways:
- brickhub.dev
- Github
- Local Path

Create a new brick using the mason new command.
# Generate a new brick in the current directory.
mason new <BRICK_NAME>
# Generate a new brick with a custom description.
mason new <BRICK_NAME> --desc "My awesome, new brick!"
# Generate a new brick with hooks.
mason new <BRICK_NAME> --hooks
# Generate a new brick in custom path.
mason new <BRICK_NAME> --output-dir ./path/to/brick
# Generate a new brick in custom path shorthand syntax.
mason new <BRICK_NAME> -o ./path/to/brick
The brick.yaml contains metadata for a brick template.
name: example
description: An example brick
version: 0.1.0+1
environment:
mason: ">=0.1.0-dev <0.1.0"
vars:
name:
type: string
description: Your name.
default: Dash
prompt: What is your name?
name: example will be replaced by your brick name.
Example 1:
I have created a brick by name weather:

It has created a weather brick.

Come to mason.yaml file and set path

Now, I have created a weather.md file inside __brick__

Inside this weather.md file, I have added text with “mustache templating syntax”.

Now, If you go to brick.yaml file

Now it isname: weather, and I have passed parameters as vars in brick.yaml file.
Now run
mason get
and after that, run the following command and pass values to parameters
mason make weather

It will generate a weather.md file

and the weather.md file looks like this

Example 2:
I have created a brick by name bloc_pattern and set its path inside maosn.yaml

and brick.yaml looks like this

In the __brick__we will create a state class and a cubit class.
{{#snakeCase}}{{name}}_state{{/snakeCase}}.dart
part of '{{#snakeCase}}{{name}}_cubit{{/snakeCase}}.dart';class {{#pascalCase}}{{name}}State{{/pascalCase}} extends Equatable {
const {{#pascalCase}}{{name}}State{{/pascalCase}}();@override
List<Object?> get props => [];
}
{{#snakeCase}}{{name}}_cubit{{/snakeCase}}.dart
import 'package:equatable/equatable.dart';
import 'package:flutter_bloc/flutter_bloc.dart';part '{{#snakeCase}}{{name}}_state{{/snakeCase}}.dart';class {{#pascalCase}}{{name}}Cubit{{/pascalCase}} extends Cubit<{{#pascalCase}}{{name}}State{{/pascalCase}}> {
{{#pascalCase}}{{name}}Cubit{{/pascalCase}}() : super(const {{#pascalCase}}{{name}}State{{/pascalCase}}());}
As you run the following command, it create state and cubit class


Forget about the red lines because I have not added packages.
Use in other projects:
Now, if you want to use bricks in your projects, then first of all you need to add them.
The add command allows developers to add brick templates locally or globally on their machines from either a local path or git url. By default mason add will add the template locally but bricks can be added globally by providing the --global (-g) flag.
Add Usage
# add latest version from registry
mason add my_brick
# add latest version from registry (global)
mason add --global my_brick
# add version 0.1.0 from registry
mason add my_brick 0.1.0
# add version 0.1.0 from registry (global)
mason add --global my_brick 0.1.0
# add from registry shorthand syntax (global)
mason add -g my_brick
# add from path
mason add my_brick --path ./path/to/my_brick
# add from path (global)
mason add --global my_brick --path ./path/to/my_brick
# add from path shorthand syntax (global)
mason add -g my_brick --path ./path/to/my_brick
# add from git url
mason add my_brick --git-url https://github.com/org/repo
# add from git url (global)
mason add -g my_brick --git-url https://github.com/org/repo
# add from git url with path
mason add my_brick --git-url https://github.com/org/repo --git-path path/to/my_brick
# add from git url with path and ref
mason add my_brick --git-url https://github.com/org/repo --git-path path/to/my_brick --git-ref tag-name
Once a brick is added it can be used via the mason make command:
mason make <BRICK_NAME>
Thank you for reading 👋
I hope you enjoyed this article. If you have any queries or suggestions please let me know in the comments down below.
You can connect with me on LinkedIn.
메타데이터
- post_id
- ce98db445a3f
- slug
- mason-the-swiss-army-knife-for-code-generation-ce98db445a3f
- url
- https://medium.com/@shehzad_raheem/mason-the-swiss-army-knife-for-code-generation-ce98db445a3f
- canonical_url
- https://medium.com/@shehzad_raheem/mason-the-swiss-army-knife-for-code-generation-ce98db445a3f
- author_url
- https://medium.com/@shehzad_raheem
- status
- ok
- fetched_at
- 2026-08-24 10:15:10