DEV Community

Cover image for 🧱 Make templates with Mason CLI
Aymeric Le Feyer
Aymeric Le Feyer

Posted on • Updated on

🧱 Make templates with Mason CLI

🇫🇷 French version

Template and rule

🧑‍💻 The job of a developer is also copy/paste of already existing snippets. Why reinvent the wheel with each new project?

A template, or boilerplate, allows you to start a project or a new feature with a solid code base.

To facilitate the usage of template, BrickHub offers a new tool : Mason CLI.

Mason's logo

➡️  The promise is simple, that of being able to create reusable bricks in your projects, all via a CLI. (Command Line Interface)

🧱  A brick being a set of files that can be generated according to different parameters.

Usage of the brick **hello**

Usage of the hello brick

The brick flutter_getx available on brickhub allows to create a Flutter project with the GetX architecture. It is enough to give some parameters to create the project.

Addition of the brick **flutter_getx** and usage

Addition of the brick flutter_getx and usage

👉  With templates, it is possible to simplify project creation.

Bring your brick to the building

➕ To create a custom brick, just place all the files to be generated in the __brick__ directory after entering the following command :

mason new <BRICK_NAME>
Enter fullscreen mode Exit fullscreen mode

Example of using the command  raw `mason new` endraw

Example of using the command mason new

Architecture of a new brick

Architecture of a new brick

ℹ️  The brick.yaml file lists all the bricks of the project.

🥸  The mustache notation is used to inject variables in files.

Hello {{name}}!
Enter fullscreen mode Exit fullscreen mode

🖥 Once your brick has been created, it is possible to publish it on brickhub so that other users can use it. In a professional setting, it is possible to host your bricks elsewhere and then add them to the project manually, by changing the reference of the bricks registered in the .mason folder of your project.

📑  For more information on creating custom bricks, the official documentation is well provided → https://pub.dev/packages/mason_cli

And now ? All that remains is to test the power of the tool on your side, and perhaps you will use it in your next projects?

Top comments (0)