# Dart - Brick Generator

A simple command-line application which allows to generate the template of a brick from a project which compiles. 

With an entrypoint in `bin/` , library code in `lib/` .

## How to use

* Add your app in `apps/`.
* Add `brickgen.yaml` in you app folder and add this fields:

```yaml
name: brick_name
description: An awesome brick

version: 0.1.0

vars:
  bundle_id:
    compilable: io.wyattapp.new
    type: string
    description: The bundle id used in Android and iOS
    default: io.wyattapp.new
    prompt: "What is the bundle id?"

  flutter:
    type: boolean
    description: If this app is a Flutter or Dart project.
    default: false
    prompt: "Is it Flutter app ?"

brickgen:
  path_to_brickify: brick_folder
  ignore:
    - .env
    - node_modules/
  hooks: true
  boolean_file_system:
    flutter:
      folders:
        on_true:
          - android
          - ios
        on_false:
          - bin
      files:
        on_true:
          - l10n.yaml
          - trapeze.yaml

```

Project structure must be like:

```
apps
├── brick_name
│   ├── brickgen.yaml
│   ├── hooks
│   │   └── pre_gen.dart
│   ├── brick_folder
│   │   └── ... compilable project
```

Then run command with project path

```sh
dart ./tools/brick_generator/bin/brickgen.dart ./apps/brick_name ./bricks/
```

Available options:

```text
-h, --help            Show this help dialog
-v, --verbose         Show additional diagnostic info
-r, --remove-empty    Remove empty folders (if not it creates .gitkeep in each empty folders)
```

## TODO

* [ ] hooks
  - [x] post hooks
  - [x] pre hooks
  - [ ] add partial hooks
* [ ] bool variables
  - [x] boolean file system
  - [ ] boolean mapping
* [ ] enum variables
* [ ] array variables

## Current specification

### File Structure

```
apps
├── <brick_name>
│   ├── brickgen.yaml
│   ├── hooks
│   │   └── pre_gen.dart
│   ├── <brick_folder>
│   │   └── ... compilable project
```

### Brick (Mason)

```yaml
name: <brick_name>
description: <brick_description>

version: 0.1.0

vars:
  ...
```

- name: the brick name (will be in `brick.yaml`)
- description: the brick description (will be in `brick.yaml`)
- version: the brick version (will be in `brick.yaml`)
- vars: the brick variables (will be in `brick.yaml`)

#### String variable

```yaml
name:
  compilable: <compilable>
  type: string
  description: <description>
  default: <default>
  prompt: <prompt>
  formats:
      - ...
```

- name: the variable name (will be in `brick.yaml`)
  - compilable: the variable compilable name used in brickgen project
  - type: variable type, here string, (will be in `brick.yaml`)
  - default: default value (will be in `brick.yaml`)
  - prompt: the displayed prompt at the brick generation (will be in `brick.yaml`)
  - formats: optional list of formats that are detected.
    - if no formats provided, all possible syntaxes are detected.

#### Boolean variable

```yaml
name:
  type: boolean
  description: <description>
  default: <default>
  prompt: <prompt>
```

- name: the variable name (will be in `brick.yaml`)
  - type: variable type, here string, (will be in `brick.yaml`)
  - default: default value (will be in `brick.yaml`)
  - prompt: the displayed prompt at the brick generation (will be in `brick.yaml`)

> Identical to Mason

### Brickgen

```yaml
brickgen:
  path_to_brickify: <brick_folder>
  ignore:
    - ...
  hooks: true
  boolean_file_system:
    ...
```

- path_to_brickify: the path of the compilable project that will be brickified
- ignore: list of the ignored files and folders. 
  - be sure to add an `/` at the end of the folders name.
- hooks: copy or not `hooks` folder
- boolean_file_system: list of the boolean file system variables

#### Boolean File System

```yaml
boolean_file_system:
  boolean:
    folders:
      on_true:
        - ...
      on_false:
        - ...
    files:
      on_true:
        - ...
      on_false:
        - ...
```

- boolean: name of the `boolean` variable used.
- folders
  - on_true: list of the folders includes if the variable is `true`
  - on_true: list of the folders includes if the variable is `false`
- files
  - on_true: list of the files includes if the variable is `true`
  - on_true: list of the files includes if the variable is `false`

> `on_true` and `on_false` are optionnal. (You are allowed to set one or two of them).

## Specifications (WIP)

File structure:

```
apps
├── <brick_name>
│   ├── brickgen.yaml
│   ├── hooks
│   │   └── pre_gen.dart
│   ├── <brick_folder>
│   │   └── ... compilable project
```

Configuration: `brickgen.yaml`

```yaml
name: <brick_name>
description: <brick_description>

version: 0.1.0

vars:
  display_name:
    compilable: Display Name
    type: string
    description: The display name
    default: Display Name
    prompt: "What is the display name?"
    formats:
      - title_case

  project_name:
    compilable: wyatt_app_template
    type: string
    description: The project name
    default: wyatt_app
    prompt: "What is the project name?"
    formats:
      - snake_case

  bundle_id:
    compilable: io.wyattapp.new
    type: string
    description: The bundle id used in Android and iOS
    default: io.wyattapp.new
    prompt: "What is the bundle id?"
    formats:
      - dot_case

  flutter:
    type: boolean
    description: If this app is a Flutter or Dart project.
    default: false
    prompt: "Is it Flutter app ?"

brickgen:
  path_to_brickify: <brick_folder>
  ignore:
    - .env
    - node_modules/
  hooks: true
  boolean_mapping:
    flutter:
      folders:
        - "test":
            on_true: "test"
            on_false: "test_dart"
      files:
        - "pubspec.yaml":
            on_true: pubspec.yaml
            on_false: pubspec.dart.yaml
  boolean_file_system:
    flutter:
      folders:
        on_true:
          - android
          - ios
        on_false:
          - bin
      files:
        on_true:
          - l10n.yaml
          - trapeze.yaml
```

Will generate:

```
bricks
├── <brick_name>
│   ├── brick.yaml
│   ├── hooks
│   │   └── pre_gen.dart
│   ├── __brick__
│   │   └── <brick_folder>
```

> It creates a sub folder in __brick__


### How copy works

- Case 1

```
apps
├── brick_1
│   ├── brickgen.yaml
│   ├── hooks
│   │   └── pre_gen.dart
│   ├── brick_1
│   │   ├── lib/
│   │   └── pubspec.yaml
```

```yaml
...
name: awesome_brick_1
brickgen:
  path_to_brickify: brick_1
  hooks: true
...
```

```sh
dart ./tools/brick_generator/bin/brickgen.dart ./apps/brick_1 ./bricks/
```

Will generate:

```
bricks
├── awesome_brick_1
│   ├── brick.yaml
│   ├── hooks
│   │   └── pre_gen.dart
│   ├── __brick__
│   │   ├── lib/
│   │   └── pubspec.yaml
```

***

- Case 2

```
apps
├── brick_2
│   ├── brickgen.yaml
│   ├── hooks
│   │   └── pre_gen.dart
│   ├── brick_2
│   │   ├── lib
│   │   │   └── widget.dart
│   │   └── pubspec.yaml
```

```yaml
...
name: awesome_brick_2
brickgen:
  path_to_brickify: brick_2/lib
  hooks: false
...
```

```sh
dart ./tools/brick_generator/bin/brickgen.dart ./apps/brick_2 ./bricks/
```

Will generate:

```
bricks
├── awesome_brick_2
│   ├── brick.yaml
│   ├── __brick__
│   │   └── widget.dart
```