felangel / mason

Tools which allow developers to create and consume reusable templates called bricks.
https://docs.brickhub.dev
969 stars 97 forks source link

fix: mason make - does not replace {{vars}} in only one of the files - why? #304

Closed aaongr closed 2 years ago

aaongr commented 2 years ago

Hello, A wonderful and amazing day for all of Us :)

First of all I would like to express my gratitude for this amazing tool and for all the other great stuff that you have made I started to use the mason and I have a strange behaviour

Description In my mason project (https://github.com/itgaia/itg_mason) I am using the {{#snakeCase}}{{name_plural}}{{/snakeCase}} in all of the files under __brick__ After I run mason make feature --on-conflict overwrite -o ~/dev/flutter/_itg_tutorials/dev_framework_tutorial --name_singular link --name_plural links I get the message Generated 25 file(s) and inside of them there is the ~/dev/flutter/_itg_tutorials/dev_framework_tutorial/lib/src/features/links/data/links_repository_impl.dart (new) file But when I open the generated file, inside of it the {{vars}} still exist.... Please note that the file name was bricks/feature/__brick__/lib/src/features/{{#snakeCase}}{{name_plural}}{{/snakeCase}}/data/{{#snakeCase}}{{name_plural}}{{/snakeCase}}_repository_impl.dart so it worked as expected in the file name...

Steps To Reproduce

  1. git clone the repository git@github.com:itgaia/itg_mason.git
  2. run mason make feature --on-conflict overwrite -o ./test_run --name_singular link --name_plural links
  3. open the file ./test_run/lib/src/features/links/data/links_repository_impl.dart
  4. See:
    
    import 'package:dartz/dartz.dart';

import '{{#snakeCase}}{{name_plural}}{{/snakeCase}}_local_datasource.dart'; import '{{#snakeCase}}{{name_plural}}{{/snakeCase}}_model.dart'; import '{{#snakeCase}}{{name_plural}}{{/snakeCase}}_remote_datasource.dart'; import '../../../app/constants.dart'; import '../../../common/helper.dart'; import '../../../core/error/exception.dart'; import '../../../core/error/failures.dart'; import '../domain/{{#snakeCase}}{{name_plural}}{{/snakeCase}}_repository.dart';

const msgBaseSourceClass = '{{#pascalCase}}{{name_plural}}{{/pascalCase}}RepositoryImpl'; String msgBaseSourceMethod = ''; void msgLogInfo(String msg) => itgLogVerbose('[$msgBaseSourceClass/$msgBaseSourceMethod] $msg'); void msgLogError(String msg) => itgLogError('[$msgBaseSourceClass/$msgBaseSourceMethod] $msg');

class {{#pascalCase}}{{name_plural}}{{/pascalCase}}RepositoryImpl implements {{#pascalCase}}{{name_plural}}{{/pascalCase}}Repository { ..........



**Expected Behavior**
The `{{#pascalCase}}{{name_plural}}{{/pascalCase}}` should have been replaced with 'Links'

The version of mason is: 0.1.0-dev.17

Any ideas why is this happening?

How can I debug situations like this where the make process is not completes as expected?

Thank you again for this wonderful tool

I wish to all of Us all the best and a wonderful, peaceful and magical continuation in our lives
With my warmest regards for all the World

aAon
mokamhawy commented 2 years ago

Same issue here.

aaongr commented 2 years ago

Dear felangel, An amazing and wonderful new day for all of us

I would like to assist you in the development of this amazing package (and others)...

Can you please tell me how can I do this? Is there a working space for collaborating, discussing things to be done, and assigned tasks, and monitor progress? It could be my honour if you accept my offer.

Thank you again for all those amazing things that you have done and continue to do for all of us I am grateful

With my warmest regards for an extraordinary continuation in our day

aaongr commented 2 years ago

The problem exists in those 2 lines of code:

              {{#snakeCase}}{{name_plural}}{{/snakeCase}}.add({{#snakeCase}}{{name_plural}}{{/snakeCase}}Item.copyWith(id: '${{{#snakeCase}}{{name_plural}}{{/snakeCase}}.length+1}'));

and

            //   {{#snakeCase}}{{name_plural}}{{/snakeCase}}.add({{#snakeCase}}{{name_plural}}{{/snakeCase}}Item.copyWith(id: '${{{#snakeCase}}{{name_plural}}{{/snakeCase}}.length+1}'));

The actual problem is the {{{, one from the content and the other 2 from the {{#snakeCase}}{{name_plural}}{{/snakeCase}}

Can I instruct, somehow, mason to treat the first one ({) as a text and not as a special character? Like escaping in regex....

aymswick commented 2 years ago

I've also just come across this - for some reason a specific template under my app/test folder fails to interpolate even a single instance of {{name}}. I suspect I am writing invalid syntax somewhere, but I searched and don't have the same {{{ (3 curly brackets) problem @aaongr described above. Will continue to investigate.

GuillaumeJulien commented 2 years ago

I think I have the same issue, I tried to create a file config like that =>

class {{client.pascalCase()}} extends AppConfig {
  String? foo = '{{foo}}';
  final String bar = '{{bar}}';

  {{client.pascalCase()}}(String envString) : super(envString);
}

foo = test bar = test client = test as a result, I have :

class Test extends AppConfig {
  String? foo = 'foo'; <--
  final String bar = 'bar'; <--

 Test(String envString) : super(envString);
}
felangel commented 2 years ago

Is this still an issue on the latest version of mason/mason_cli?

felangel commented 2 years ago

Closing for now but feel free to comment if you're still encountering this issue and provide a link to a reproduction sample, thanks!