Builders
Builders are Go templates in YAML format that contain the structure of folders and files to be created.
Structure
A builder is defined as follows:
global: Global variables that can be used in all templates.
structure: The structure of folders and files that will be created.
Directories:
The structure is defined in a tree format, where each nested item in the tree represents a directory.
Files:
For Mr. Smith to identify an item as a file, an extension must be defined. In a file, there are the properties:
- template: path to the file that contains the base template of the file to be created.
- data: a map of data that will be transformed into variables to be used in the template.
- includes: a list of templates that can be used within the base template.
Example:
Result:
Directorysrc
Directoryservices
- UserService.ts
- index.ts
Variables
Since Builders are nothing more than Go templates, it is possible to build them dynamically using variables.
Variables within Go templates are defined between {{}}
. In Mr. Smith, they need to be prefixed with .data
to take effect, see the example:
Variables:
- packageName:
github.com/mr-smith-org/simple-project
- serviceName:
User
Result:
Directorysrc
Directoryservices
- UserService.ts
- index.ts
Advanced Usage
It is possible to create really complex structures using builders. In the example below, the builder is generated from a Swagger.json file and creates the folder structure dynamically according to the definitions and tags found in the file:
To learn more about text templates and how to use them with Mr. Smith, visit the link: Text Templates in Go