felangel / felangel/mason

feat: In-file code generation + diff summary proposal

Open
#394 2 comments 2 reactions 0 assignees View on GitHub
enhancement candidate
Dominant language
Dart
Stars
1.1k
Forks
113
PR merge metrics
No merged PRs in 30d

Description

**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

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.