work on brick generator dart script #3
| @ -1,38 +0,0 @@ | ||||
| brick_name: wyatt_feature_brick | ||||
| 
 | ||||
| path_to_brickify: lib/feature_brick_folder | ||||
| 
 | ||||
| variables: | ||||
|   feature_brick: | ||||
|     variable_name: feature_brick | ||||
|     type: string | ||||
|     syntax: | ||||
|       camel_case: featureBrick | ||||
|       constant_case: FEATURE_BRICK | ||||
|       dot_case: feature.brick | ||||
|       header_case: Feature-Brick | ||||
|       lower_case: feature brick | ||||
|       pascal_case: FeatureBrick | ||||
|       param_case: feature-brick | ||||
|       sentence_case: Feature brick | ||||
|       snake_case: feature_brick | ||||
|       title_case: Feature Brick | ||||
|       upper_case: FEATURE BRICK | ||||
|   description: | ||||
|     variable_name: description | ||||
|     type: string | ||||
|     syntax: | ||||
|       camel_case: description | ||||
|       constant_case: DESCRIPTION | ||||
|       dot_case: description | ||||
|       header_case: Description | ||||
|       lower_case: description | ||||
|       pascal_case: Description | ||||
|       param_case: description | ||||
|       sentence_case: Description | ||||
|       snake_case: description | ||||
|       title_case: Description | ||||
|       upper_case: DESCRIPTION | ||||
|   isBloc: | ||||
|     variable_name: bloc | ||||
|     type: bool | ||||
| @ -1,7 +0,0 @@ | ||||
| class FeatureBrick { | ||||
|   var featureBrick = 0; | ||||
| } | ||||
| 
 | ||||
| class DescriptionClass { | ||||
|   var descriptionClass = 0; | ||||
| } | ||||
| @ -8,11 +8,14 @@ in `lib/`. | ||||
| 
 | ||||
| ```yaml | ||||
| brick_name: wyatt_feature_brick | ||||
| project_name: projet_name | ||||
| 
 | ||||
| path_to_brickify: lib/feature_brick_test_folder | ||||
| path_to_brickify: lib/feature_brick_folder | ||||
| 
 | ||||
| syntax: | ||||
| variables: | ||||
|   feature_brick: | ||||
|     variable_name: feature_brick | ||||
|     type: string | ||||
|     syntax: | ||||
|       camel_case: featureBrick | ||||
|       constant_case: FEATURE_BRICK | ||||
|       dot_case: feature.brick | ||||
| @ -24,6 +27,24 @@ syntax: | ||||
|       snake_case: feature_brick | ||||
|       title_case: Feature Brick | ||||
|       upper_case: FEATURE BRICK | ||||
|   description: | ||||
|     variable_name: description | ||||
|     type: string | ||||
|     syntax: | ||||
|       camel_case: description | ||||
|       constant_case: DESCRIPTION | ||||
|       dot_case: description | ||||
|       header_case: Description | ||||
|       lower_case: description | ||||
|       pascal_case: Description | ||||
|       param_case: description | ||||
|       sentence_case: Description | ||||
|       snake_case: description | ||||
|       title_case: Description | ||||
|       upper_case: DESCRIPTION | ||||
|   isBloc: | ||||
|     variable_name: bloc | ||||
|     type: bool | ||||
| ``` | ||||
| 
 | ||||
| then run command with project path | ||||
|  | ||||
| @ -68,11 +68,11 @@ Future<void> main(List<String> arguments) async { | ||||
|           for (final variable in brickConfig.variables!) { | ||||
|             if (variable?.type == VariabelType.string) { | ||||
|               for (final syntax in VariableStringSyntax.values) { | ||||
|                 final toReplace = variable?.syntax?.getValue(syntax); | ||||
|                 final toReplace = variable?.syntax?[syntax.mapKey] as String?; | ||||
|                 if (toReplace != null) { | ||||
|                   contents = contents.replaceAll( | ||||
|                     variable!.syntax!.getValue(syntax)!, | ||||
|                     '{{#${syntax.id}}}{{${variable.name}}}{{/${syntax.id}}}', | ||||
|                     toReplace, | ||||
|                     '{{#${syntax.id}}}{{${variable?.name}}}{{/${syntax.id}}}', | ||||
|                   ); | ||||
|                 } | ||||
|               } | ||||
| @ -89,14 +89,21 @@ Future<void> main(List<String> arguments) async { | ||||
| 
 | ||||
|         if (brickConfig.variables != null) { | ||||
|           for (final variable in brickConfig.variables!) { | ||||
|             if (variable?.type == VariabelType.string) { | ||||
|               if (filePath.contains(variable!.syntax!.snakeCase!)) { | ||||
|             if (variable?.type == VariabelType.string && | ||||
|                 variable?.syntax?[VariableStringSyntax.snakeCase.mapKey] != | ||||
|                     null) { | ||||
|               print(variable?.syntax?[VariableStringSyntax.snakeCase.mapKey]); | ||||
|               if (filePath.contains( | ||||
|                 variable!.syntax![VariableStringSyntax.snakeCase.mapKey] | ||||
|                     as String, | ||||
|               )) { | ||||
|                 var pathList = | ||||
|                     filePath.split(Platform.pathSeparator).sublist(3); | ||||
|                 pathList = pathList | ||||
|                     .map( | ||||
|                       (segment) => segment.replaceAll( | ||||
|                         variable.syntax!.snakeCase!, | ||||
|                         variable.syntax![VariableStringSyntax.snakeCase.mapKey] | ||||
|                             as String, | ||||
|                         '{{${variable.name}.snakeCase()}}', | ||||
|                       ), | ||||
|                     ) | ||||
|  | ||||
| @ -1,4 +1,3 @@ | ||||
| import 'package:brick_generator/models/variable_syntax.dart'; | ||||
| import 'package:brick_generator/models/variable_type.dart'; | ||||
| import 'package:yaml/yaml.dart'; | ||||
| 
 | ||||
| @ -9,7 +8,7 @@ const _syntaxKey = 'syntax'; | ||||
| class BrickVariable { | ||||
|   String? name; | ||||
|   VariabelType? type; | ||||
|   VariableSyntax? syntax; | ||||
|   YamlMap? syntax; | ||||
| 
 | ||||
|   BrickVariable({ | ||||
|     required this.name, | ||||
| @ -25,7 +24,7 @@ class BrickVariable { | ||||
|       ? BrickVariable( | ||||
|           name: data[_variableNameKey] as String?, | ||||
|           type: VariabelType.stringToEnum(data[_typeKey] as String?), | ||||
|           syntax: VariableSyntax.from(data[_syntaxKey] as YamlMap?), | ||||
|           syntax: data[_syntaxKey] as YamlMap?, | ||||
|         ) | ||||
|       : null; | ||||
| 
 | ||||
| @ -35,8 +34,5 @@ class BrickVariable { | ||||
|         'Yaml file is not conform', | ||||
|       ); | ||||
|     } | ||||
|     if (type == VariabelType.string) { | ||||
|       syntax?.checkFormat(); | ||||
|     } | ||||
|   } | ||||
| } | ||||
|  | ||||
| @ -1,95 +0,0 @@ | ||||
| import 'package:brick_generator/models/variable_string_syntax.dart'; | ||||
| import 'package:yaml/yaml.dart'; | ||||
| 
 | ||||
| class VariableSyntax { | ||||
|   String? camelCase; | ||||
|   String? constantCase; | ||||
|   String? dotCase; | ||||
|   String? headerCase; | ||||
|   String? lowerCase; | ||||
|   String? pascalCase; | ||||
|   String? paramCase; | ||||
|   String? sentenceCase; | ||||
|   String? snakeCase; | ||||
|   String? titleCase; | ||||
|   String? upperCase; | ||||
| 
 | ||||
|   VariableSyntax({ | ||||
|     required this.camelCase, | ||||
|     required this.constantCase, | ||||
|     required this.dotCase, | ||||
|     required this.headerCase, | ||||
|     required this.lowerCase, | ||||
|     required this.pascalCase, | ||||
|     required this.paramCase, | ||||
|     required this.sentenceCase, | ||||
|     required this.snakeCase, | ||||
|     required this.titleCase, | ||||
|     required this.upperCase, | ||||
|   }); | ||||
| 
 | ||||
|   VariableSyntax._(); | ||||
|   factory VariableSyntax.parser() => VariableSyntax._(); | ||||
| 
 | ||||
|   static VariableSyntax? from(YamlMap? data) => data != null | ||||
|       ? VariableSyntax( | ||||
|           camelCase: data[VariableStringSyntax.camelCase.mapKey] as String?, | ||||
|           constantCase: | ||||
|               data[VariableStringSyntax.constantCase.mapKey] as String?, | ||||
|           dotCase: data[VariableStringSyntax.dotCase.mapKey] as String?, | ||||
|           headerCase: data[VariableStringSyntax.headerCase.mapKey] as String?, | ||||
|           lowerCase: data[VariableStringSyntax.lowerCase.mapKey] as String?, | ||||
|           pascalCase: data[VariableStringSyntax.pascalCase.mapKey] as String?, | ||||
|           paramCase: data[VariableStringSyntax.paramCase.mapKey] as String?, | ||||
|           sentenceCase: | ||||
|               data[VariableStringSyntax.sentenceCase.mapKey] as String?, | ||||
|           snakeCase: data[VariableStringSyntax.snakeCase.mapKey] as String?, | ||||
|           titleCase: data[VariableStringSyntax.titleCase.mapKey] as String?, | ||||
|           upperCase: data[VariableStringSyntax.upperCase.mapKey] as String?, | ||||
|         ) | ||||
|       : null; | ||||
|   String? getValue(VariableStringSyntax key) { | ||||
|     switch (key) { | ||||
|       case VariableStringSyntax.camelCase: | ||||
|         return camelCase; | ||||
|       case VariableStringSyntax.constantCase: | ||||
|         return constantCase; | ||||
|       case VariableStringSyntax.dotCase: | ||||
|         return dotCase; | ||||
|       case VariableStringSyntax.headerCase: | ||||
|         return headerCase; | ||||
|       case VariableStringSyntax.lowerCase: | ||||
|         return lowerCase; | ||||
|       case VariableStringSyntax.pascalCase: | ||||
|         return pascalCase; | ||||
|       case VariableStringSyntax.paramCase: | ||||
|         return paramCase; | ||||
|       case VariableStringSyntax.sentenceCase: | ||||
|         return sentenceCase; | ||||
|       case VariableStringSyntax.snakeCase: | ||||
|         return snakeCase; | ||||
|       case VariableStringSyntax.titleCase: | ||||
|         return titleCase; | ||||
|       case VariableStringSyntax.upperCase: | ||||
|         return upperCase; | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   void checkFormat() { | ||||
|     if (camelCase == null || | ||||
|         constantCase == null || | ||||
|         dotCase == null || | ||||
|         headerCase == null || | ||||
|         lowerCase == null || | ||||
|         pascalCase == null || | ||||
|         paramCase == null || | ||||
|         sentenceCase == null || | ||||
|         snakeCase == null || | ||||
|         titleCase == null || | ||||
|         upperCase == null) { | ||||
|       throw ArgumentError( | ||||
|         'Yaml file is not conform', | ||||
|       ); | ||||
|     } | ||||
|   } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user