From 1abf6ccb3669a02433ee8d6e9a6729a5feee09eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20L=C3=A9on?= Date: Mon, 8 Aug 2022 14:35:40 +0100 Subject: [PATCH] simplify syntax model and conversion algorithm --- apps/wyatt_feature_brick/brick_config.yaml | 38 -------- .../feature_brick_file.dart | 7 -- tools/brick_generator/README.md | 49 +++++++--- .../brick_generator/bin/brick_generator.dart | 19 ++-- .../lib/models/brick_variable.dart | 8 +- .../lib/models/variable_syntax.dart | 95 ------------------- 6 files changed, 50 insertions(+), 166 deletions(-) delete mode 100644 apps/wyatt_feature_brick/brick_config.yaml delete mode 100644 apps/wyatt_feature_brick/lib/feature_brick_folder/feature_brick_file.dart delete mode 100644 tools/brick_generator/lib/models/variable_syntax.dart diff --git a/apps/wyatt_feature_brick/brick_config.yaml b/apps/wyatt_feature_brick/brick_config.yaml deleted file mode 100644 index 6e95484..0000000 --- a/apps/wyatt_feature_brick/brick_config.yaml +++ /dev/null @@ -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 diff --git a/apps/wyatt_feature_brick/lib/feature_brick_folder/feature_brick_file.dart b/apps/wyatt_feature_brick/lib/feature_brick_folder/feature_brick_file.dart deleted file mode 100644 index 2a067bc..0000000 --- a/apps/wyatt_feature_brick/lib/feature_brick_folder/feature_brick_file.dart +++ /dev/null @@ -1,7 +0,0 @@ -class FeatureBrick { - var featureBrick = 0; -} - -class DescriptionClass { - var descriptionClass = 0; -} diff --git a/tools/brick_generator/README.md b/tools/brick_generator/README.md index 84ed49f..885baa8 100644 --- a/tools/brick_generator/README.md +++ b/tools/brick_generator/README.md @@ -8,22 +8,43 @@ 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: - 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 +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 ``` then run command with project path diff --git a/tools/brick_generator/bin/brick_generator.dart b/tools/brick_generator/bin/brick_generator.dart index 068d9d6..f3447e9 100644 --- a/tools/brick_generator/bin/brick_generator.dart +++ b/tools/brick_generator/bin/brick_generator.dart @@ -68,11 +68,11 @@ Future main(List 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 main(List 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()}}', ), ) diff --git a/tools/brick_generator/lib/models/brick_variable.dart b/tools/brick_generator/lib/models/brick_variable.dart index 60f4fcc..a34e704 100644 --- a/tools/brick_generator/lib/models/brick_variable.dart +++ b/tools/brick_generator/lib/models/brick_variable.dart @@ -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(); - } } } diff --git a/tools/brick_generator/lib/models/variable_syntax.dart b/tools/brick_generator/lib/models/variable_syntax.dart deleted file mode 100644 index 0b38352..0000000 --- a/tools/brick_generator/lib/models/variable_syntax.dart +++ /dev/null @@ -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', - ); - } - } -}