This repository has been archived by the owner on Jan 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #670 from Parabeac/dev
Dev
- Loading branch information
Showing
27 changed files
with
563 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...eneration/flutter_project_builder/post_gen_tasks/global_styling/colors_post_gen_task.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:parabeac_core/controllers/main_info.dart'; | ||
import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/post_gen_task.dart'; | ||
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/commands/add_constant_command.dart'; | ||
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/file_ownership_policy.dart'; | ||
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/path_services/path_service.dart'; | ||
import 'package:parabeac_core/generation/generators/value_objects/generation_configuration/pb_generation_configuration.dart'; | ||
import 'package:pbdl/pbdl.dart'; | ||
import 'package:recase/recase.dart'; | ||
import 'package:uuid/uuid.dart'; | ||
|
||
class ColorsPostGenTask extends PostGenTask { | ||
GenerationConfiguration generationConfiguration; | ||
|
||
List<PBDLGlobalColor> colors; | ||
|
||
ColorsPostGenTask( | ||
this.generationConfiguration, | ||
this.colors, | ||
); | ||
@override | ||
void execute() { | ||
var constColors = <ConstantHolder>[]; | ||
var mainInfo = MainInfo(); | ||
|
||
/// Format colors to be added to constants file | ||
colors.forEach((color) { | ||
constColors.add(ConstantHolder( | ||
'Color', | ||
color.name.camelCase, | ||
'Color(${color.color.toHex()})', | ||
description: color.description, | ||
)); | ||
}); | ||
|
||
/// Write colors to constants file in `colors.g.dart` | ||
generationConfiguration.fileStructureStrategy.commandCreated( | ||
WriteConstantsCommand( | ||
Uuid().v4(), | ||
constColors, | ||
filename: '${mainInfo.projectName.snakeCase}_colors', | ||
ownershipPolicy: FileOwnership.PBC, | ||
imports: 'import \'package:flutter/material.dart\';', | ||
relativePath: GetIt.I.get<PathService>().themingRelativePath, | ||
), | ||
); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...tion/flutter_project_builder/post_gen_tasks/global_styling/global_styling_aggregator.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import 'package:parabeac_core/generation/flutter_project_builder/flutter_project_builder.dart'; | ||
import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/global_styling/colors_post_gen_task.dart'; | ||
import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/global_styling/text_styles_post_gen_task.dart'; | ||
import 'package:pbdl/pbdl.dart'; | ||
|
||
class GlobalStylingAggregator { | ||
/// Examines [globalStyles] and adds PostGenTasks to [builder] | ||
static void addPostGenTasks( | ||
FlutterProjectBuilder builder, PBDLGlobalStyles globalStyles) { | ||
if (globalStyles.colors != null && globalStyles.colors.isNotEmpty) { | ||
builder.postGenTasks.add( | ||
ColorsPostGenTask( | ||
builder.generationConfiguration, | ||
globalStyles.colors, | ||
), | ||
); | ||
} | ||
|
||
if (globalStyles.textStyles != null && globalStyles.textStyles.isNotEmpty) { | ||
builder.postGenTasks.add( | ||
TextStylesPostGenTask( | ||
builder.generationConfiguration, | ||
globalStyles.textStyles, | ||
), | ||
); | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...tion/flutter_project_builder/post_gen_tasks/global_styling/text_styles_post_gen_task.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:parabeac_core/controllers/main_info.dart'; | ||
import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/post_gen_task.dart'; | ||
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/commands/add_constant_command.dart'; | ||
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/file_ownership_policy.dart'; | ||
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/path_services/path_service.dart'; | ||
import 'package:parabeac_core/generation/generators/value_objects/generation_configuration/pb_generation_configuration.dart'; | ||
import 'package:parabeac_core/generation/generators/visual-widgets/pb_text_gen.dart'; | ||
import 'package:pbdl/pbdl.dart'; | ||
import 'package:recase/recase.dart'; | ||
import 'package:uuid/uuid.dart'; | ||
|
||
/// Class that generates all global [TextStyles] and exports them to a file | ||
class TextStylesPostGenTask extends PostGenTask { | ||
GenerationConfiguration generationConfiguration; | ||
List<PBDLGlobalTextStyle> textStyles; | ||
|
||
TextStylesPostGenTask(this.generationConfiguration, this.textStyles); | ||
|
||
@override | ||
void execute() { | ||
var constTextStyles = <ConstantHolder>[]; | ||
var mainInfo = MainInfo(); | ||
|
||
/// Format text styles to be added to constants file | ||
textStyles.forEach((globalTextStyle) { | ||
constTextStyles.add(ConstantHolder( | ||
'TextStyle', | ||
globalTextStyle.name.camelCase, | ||
_textStyleStr(globalTextStyle.textStyle), | ||
description: globalTextStyle.description, | ||
)); | ||
}); | ||
|
||
generationConfiguration.fileStructureStrategy.commandCreated( | ||
WriteConstantsCommand( | ||
Uuid().v4(), | ||
constTextStyles, | ||
filename: '${mainInfo.projectName.snakeCase}_text_styles', | ||
ownershipPolicy: FileOwnership.PBC, | ||
imports: 'import \'package:flutter/material.dart\';', | ||
relativePath: GetIt.I.get<PathService>().themingRelativePath, | ||
), | ||
); | ||
} | ||
|
||
// TODO: Abstract so that Text and this use the same TextStyle generator. | ||
String _textStyleStr(PBDLTextStyle textStyle) { | ||
return ''' | ||
TextStyle( | ||
fontSize: ${textStyle.fontSize}, | ||
fontWeight: FontWeight.w${textStyle.fontWeight}, | ||
letterSpacing: ${textStyle.letterSpacing}, | ||
fontFamily: \'${textStyle.fontFamily}\', | ||
decoration: ${PBTextGen.getDecoration(textStyle.textDecoration)}, | ||
fontStyle: ${(textStyle.italics ?? false) ? 'FontStyle.italic' : 'FontStyle.normal'}, | ||
) | ||
'''; | ||
} | ||
} |
100 changes: 78 additions & 22 deletions
100
...ation/generators/value_objects/file_structure_strategy/commands/add_constant_command.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,96 @@ | ||
import 'package:get_it/get_it.dart'; | ||
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/file_ownership_policy.dart'; | ||
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/path_service.dart'; | ||
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/path_services/path_service.dart'; | ||
import 'package:path/path.dart' as p; | ||
|
||
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/commands/file_structure_command.dart'; | ||
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/pb_file_structure_strategy.dart'; | ||
import 'package:recase/recase.dart'; | ||
|
||
/// Command used to add a constant to the project's constants file | ||
class AddConstantCommand extends FileStructureCommand { | ||
String name; | ||
String type; | ||
String value; | ||
/// Command used to write constants to the project's constants file | ||
class WriteConstantsCommand extends FileStructureCommand { | ||
/// Optional filename to export the constant to | ||
String filename; | ||
|
||
/// Optional imports to be appended to the file | ||
String imports; | ||
|
||
/// Optional [FileOwnership] of the file to be written. | ||
/// | ||
/// Will be [FileOwnership.DEV] by default. | ||
FileOwnership ownershipPolicy; | ||
|
||
/// Optional path to export the constants. | ||
String relativePath; | ||
|
||
List<ConstantHolder> constants; | ||
final String CONST_DIR_PATH = | ||
GetIt.I.get<PathService>().constantsRelativePath; | ||
final String CONST_FILE_NAME = 'constants.dart'; | ||
|
||
AddConstantCommand(String UUID, this.name, this.type, this.value) | ||
: super(UUID); | ||
WriteConstantsCommand( | ||
String UUID, | ||
this.constants, { | ||
this.filename, | ||
this.imports = '', | ||
this.ownershipPolicy, | ||
this.relativePath, | ||
}) : super(UUID) { | ||
relativePath ??= CONST_DIR_PATH; | ||
} | ||
|
||
/// Adds a constant containing `type`, `name` and `value` to `constants.dart` file | ||
/// Writes constants containing `type`, `name` and `value` to `constants.dart` file | ||
@override | ||
Future<void> write(FileStructureStrategy strategy) async { | ||
strategy.appendDataToFile( | ||
_addConstant, | ||
p.join(strategy.GENERATED_PROJECT_PATH, CONST_DIR_PATH), | ||
CONST_FILE_NAME, | ||
ownership: FileOwnership.DEV, | ||
var constBuffer = StringBuffer()..writeln(imports); | ||
|
||
var className = filename.pascalCase; | ||
|
||
/// Write class declaration | ||
constBuffer.writeln('class $className {'); | ||
|
||
/// Write constants | ||
constants.forEach((constant) { | ||
var description = | ||
constant.description.isNotEmpty ? '/// ${constant.description}' : ''; | ||
var constStr = | ||
'static const ${constant.type} ${constant.name} = ${constant.value};'; | ||
|
||
constBuffer.writeln('$description\n$constStr'); | ||
}); | ||
|
||
constBuffer.writeln('}'); | ||
|
||
/// Write file | ||
strategy.writeDataToFile( | ||
constBuffer.toString(), | ||
p.join( | ||
strategy.GENERATED_PROJECT_PATH, | ||
relativePath, | ||
), | ||
filename ?? CONST_FILE_NAME, | ||
ownership: ownershipPolicy ?? FileOwnership.PBC, | ||
); | ||
} | ||
} | ||
|
||
List<String> _addConstant(List<String> lines) { | ||
var constStr = 'const $type $name = $value;'; | ||
var result = List<String>.from(lines); | ||
if (!result.contains(constStr)) { | ||
result.add(constStr); | ||
} | ||
return result; | ||
} | ||
class ConstantHolder { | ||
/// Name of the constant to be added | ||
String name; | ||
|
||
/// Type of the constant to be added | ||
String type; | ||
|
||
/// What the constant's value is | ||
String value; | ||
|
||
/// Optional description to put as comment above the constant | ||
String description; | ||
|
||
ConstantHolder( | ||
this.type, | ||
this.name, | ||
this.value, { | ||
this.description = '', | ||
}); | ||
} |
2 changes: 1 addition & 1 deletion
2
...on/generators/value_objects/file_structure_strategy/commands/export_platform_command.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...enerators/value_objects/file_structure_strategy/commands/orientation_builder_command.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ors/value_objects/file_structure_strategy/commands/responsive_layout_builder_command.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ation/generators/value_objects/file_structure_strategy/commands/write_screen_command.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.