felangel / felangel/mason

Generating multiple files from a `list` type

Open
#1,153 0 comments 4 reactions 0 assignees View on GitHub
bug
Dominant language
Dart
Stars
1.1k
Forks
113
PR merge metrics
No merged PRs in 30d

Description

Hi!

I have this question about generating a list of files, but after search on docs and other issues, I think this is not implemented. Or maybe I do it in the wrong way... πŸ€”
I create this bug as a bug, but feel free to label it correctly if I miss something.

**Description**
I want to generate a list of files, from a `list` param in the `brick.yaml` file. This will allow the user of the brick to generate multiple files with the same logic inside.

For example, we want to generate multiple models from a brick called `generate_data_models`, with the following `brick.yaml` file:
```yaml
name: generate_data_models
description: Creates a new data models
version: 0.1.0+1

environment:
mason: ">=0.1.0-dev.51 <0.1.0"

vars:
data_folder_name:
type: string
description: Name of the data folder to put the model files inside.
prompt: What is the data folder name?
models:
type: list
description: List of models, used to create basic model class files.
prompt: What are the models names to create (separated by comma)?
separator: ","
```

And the following brick tree:
```sh
.
β”œβ”€β”€ CHANGELOG.md
β”œβ”€β”€ LICENSE
β”œβ”€β”€ README.md
β”œβ”€β”€ __brick__
β”‚   └── lib
β”‚      └── data
β”‚      └── {{data_folder_name.snakeCase()}}
β”‚      β”œβ”€β”€ data
β”‚      β”‚   └── data.dart
β”‚      β”œβ”€β”€ models
β”‚      β”‚   β”œβ”€β”€ models.dart
β”‚      β”‚   └── {{#models}}{{..snakeCase()}}.dart{{
β”‚      β”‚   └── models}}
β”‚      └── {{data_folder_name.snakeCase()}}.dart
└── brick.yaml
```

When I generate the code from this brick, this will create the following tree (inspired by the [Weather tuturial](https://bloclibrary.dev/#/flutterweathertutorial)):
```sh
lib/data
└── open_meteo_api
β”œβ”€β”€ data
β”‚   └── data.dart
β”œβ”€β”€ models
β”‚   β”œβ”€β”€ location.dartweather.dart
β”‚   └── models.dart
└── open_meteo_api.dart
```

The expected output will be two separated files generated for `location` & `weather`:
```sh
lib/data
└── open_meteo_api
β”œβ”€β”€ data
β”‚   └── data.dart
β”œβ”€β”€ models
β”‚   β”œβ”€β”€ location.dart
β”‚   β”œβ”€β”€ models.dart
β”‚   └── weather.dart
└── open_meteo_api.dart
```
Plus, inside each file we want to access to the current `model` to generate the relevant code class code for this model.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.