felangel / felangel/mason

feat: In-file code generation + diff summary proposal

Abierto
#394 2 comentarios 2 reacciones 0 asignados Ver en GitHub
enhancement candidate
Lenguaje dominante
Dart
Estrellas
1.1k
Forks
113
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

**Description**

It's a common use case the inclusion of your generated code to well known existing files. This is a proposal for that:

Suppose this tree:
```
├── classes
│ ├── index.dart
│ ├── classes
│ │ ├── class1.dart
│ │ └── class2.dart
```

`index.dart` contents:
```dart
//classes/index.dart

@masonAppend('generatedClassesVar', '{{name.pascalCase()}}()')
var classesGenerated = {Class1(), Class2()};

//List of generated classes:
// - Class1
// - Class2
// @masonBefore('generatedClassesList', '// - {{name.pascalCase()}})

@masonAfter('anythingElse', 'var {{name}}{{/hasAssign}}{{assign}}{{#hasAssign}};')
var aThing;
var anythingElse = {};
var anotherThing = false;
```

and the brick that generated those files:
```dart
//bricks/classes/__brick__/classes/classes/{{name.camelCase()}}.dart
class {{name.pascalCase()}}() {
//...
}
```
```yaml
#bricks/classes/brick.yaml
name: classes
description: Create classes
version: 0.1.0+1
vars:
name:
type: string
description: The class name.
prompt: Enter your class name.
files:
classes/index.dart: generatedClassesVar
classes/index.dart: generatedClassesList
```

The CLI usage should be something like this:

image

#### observations
- The annotations could be replaced with markers, i.e. some recognizable string that could be included in a comment like `@masonBefore` in this example. It could be replaced to `// #masonBefore` or anything better.
- The `files:`on the YAML is intended to be discussed, together with its syntax.
- A cheap way of having the in-file generation feature done would be adding hooks, but I'm way sure this feature is a must-have for a code-generation solution like mason that should work out of the box with that few configuration lines of the YAML.
- A cheap way of showing the summary would be using `git diff`, it could start as a by default showable if the package has one and the working dir is clean (creating the whole commit, wether by default or as a configuration or flag)

**Requirements**

- [ ] Discuss proposal
- [ ] Approve working draft
- [ ] Make annotations
- [ ] Make editing logic
- [ ] Add diff summary to command outputs

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.