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 #595 from Parabeac/release/2.4.0
Release/2.4.0
- Loading branch information
Showing
32 changed files
with
538 additions
and
416 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
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
17 changes: 17 additions & 0 deletions
17
.../flutter_project_builder/post_gen_tasks/comp_isolation/component_isolation_generator.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,17 @@ | ||
import 'package:parabeac_core/generation/flutter_project_builder/import_helper.dart'; | ||
import 'package:parabeac_core/generation/generators/util/pb_generation_project_data.dart'; | ||
|
||
/// Class that represents a Component Isolation Generator. | ||
/// | ||
/// This class sets up the Component Isolation Package (i.e. Widgetbook, Dashbook, etc.) | ||
/// to create the necessary classes and generate the code at the end. | ||
abstract class ComponentIsolationGenerator { | ||
/// Method that generates the code for this generator. | ||
String generateCode(ImportHelper importHelper); | ||
|
||
/// Path to the file to be written, relative to the `lib` directory. | ||
String fileName; | ||
|
||
/// projectData used to add dependencies to the project. | ||
PBGenerationProjectData projectData; | ||
} |
35 changes: 35 additions & 0 deletions
35
lib/generation/flutter_project_builder/post_gen_tasks/comp_isolation/isolation_node.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,35 @@ | ||
/// Class that represents a generic Component Isolation Node. | ||
/// | ||
/// For instance, Widgetbook may have Categories, Folders, etc., | ||
/// while Dashbook has Stories and Chapters. This node can represent | ||
/// these in a generic way. | ||
abstract class IsolationNode { | ||
String name; | ||
|
||
List<IsolationNode> children; | ||
|
||
/// Generates a string representation of how the | ||
/// [IsolationNode] should be printed. | ||
String generate(); | ||
|
||
IsolationNode({this.children, this.name}) { | ||
children ??= <IsolationNode>[]; | ||
} | ||
|
||
/// Adds a child to the [IsolationNode]. | ||
void addChild(IsolationNode child) { | ||
children.add(child); | ||
} | ||
|
||
List<IsolationNode> getType<T extends IsolationNode>() => | ||
children.whereType<T>().toList(); | ||
|
||
/// Returns [IsolationNode] with type [T] and name [name]. | ||
/// | ||
/// Returns null if no such node exists. | ||
IsolationNode getNamed<T extends IsolationNode>(String name) => | ||
children.whereType<T>().firstWhere( | ||
(element) => element.name == name, | ||
orElse: () => null, | ||
); | ||
} |
25 changes: 25 additions & 0 deletions
25
...ration/flutter_project_builder/post_gen_tasks/comp_isolation/isolation_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,25 @@ | ||
import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/comp_isolation/component_isolation_generator.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/write_symbol_command.dart'; | ||
import 'package:parabeac_core/generation/generators/value_objects/generation_configuration/pb_generation_configuration.dart'; | ||
|
||
/// This class is responsible for coordinating the generation of the | ||
/// component isolation code based on the given configuration. | ||
class IsolationPostGenTask implements PostGenTask { | ||
/// Specific instance of the configuration to execute | ||
ComponentIsolationGenerator compIsoConfiguration; | ||
|
||
/// GenerationConfiguration to get strategy and imports | ||
GenerationConfiguration generationConfiguration; | ||
IsolationPostGenTask(this.compIsoConfiguration, this.generationConfiguration); | ||
@override | ||
void execute() { | ||
var isolationCode = compIsoConfiguration.generateCode( | ||
generationConfiguration.generationManager.importProcessor); | ||
var fileName = compIsoConfiguration.fileName; | ||
|
||
/// TODO: WriteSymbolCommand was used as a workaround. We should generate a command that generically writes any file | ||
generationConfiguration.fileStructureStrategy.commandCreated( | ||
WriteSymbolCommand(null, fileName, isolationCode, symbolPath: 'lib/')); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...roject_builder/post_gen_tasks/comp_isolation/widgetbook/entities/widgetbook_category.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,33 @@ | ||
import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/comp_isolation/isolation_node.dart'; | ||
import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/comp_isolation/widgetbook/entities/widgetbook_folder.dart'; | ||
import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/comp_isolation/widgetbook/entities/widgetbook_widget.dart'; | ||
|
||
/// Class that represents a WidgetBook Category. | ||
class WidgetBookCategory extends IsolationNode { | ||
WidgetBookCategory({ | ||
String name = 'Parabeac-Generated', | ||
}) : super(name: name); | ||
|
||
@override | ||
String generate() { | ||
var folders = getType<WidgetBookFolder>(); | ||
var widgets = getType<WidgetBookWidget>(); | ||
|
||
var folderGen = ''; | ||
var widgetsGen = ''; | ||
|
||
if (folders != null && folders.isNotEmpty) { | ||
folderGen = folders.map((f) => f.generate()).join('\n'); | ||
} | ||
if (widgets != null && widgets.isNotEmpty) { | ||
widgetsGen = widgets.map((w) => w.generate()).join('\n'); | ||
} | ||
return ''' | ||
WidgetbookCategory( | ||
name: 'Parabeac-Generated', | ||
${folderGen.isNotEmpty ? 'folders: [\n$folderGen\n],\n' : ''} | ||
${widgetsGen.isNotEmpty ? 'widgets: [\n$widgetsGen\n],\n' : ''} | ||
) | ||
'''; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
..._project_builder/post_gen_tasks/comp_isolation/widgetbook/entities/widgetbook_folder.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,21 @@ | ||
import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/comp_isolation/isolation_node.dart'; | ||
import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/comp_isolation/widgetbook/entities/widgetbook_widget.dart'; | ||
|
||
class WidgetBookFolder extends IsolationNode { | ||
WidgetBookFolder(String name) : super(name: name); | ||
|
||
@override | ||
String generate() { | ||
var widgets = getType<WidgetBookWidget>(); | ||
var genWidgets = ''; | ||
if (widgets != null && widgets.isNotEmpty) { | ||
genWidgets = widgets.map((node) => node.generate()).join(',\n'); | ||
} | ||
return ''' | ||
WidgetbookFolder( | ||
name: '$name', | ||
${genWidgets.isNotEmpty ? 'widgets: [\n$genWidgets\n],\n' : ''} | ||
) | ||
'''; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...roject_builder/post_gen_tasks/comp_isolation/widgetbook/entities/widgetbook_use_case.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,16 @@ | ||
import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/comp_isolation/isolation_node.dart'; | ||
|
||
class WidgetBookUseCase extends IsolationNode { | ||
String builderCode; | ||
WidgetBookUseCase(String name, this.builderCode) : super(name: name); | ||
|
||
@override | ||
String generate() { | ||
return ''' | ||
WidgetbookUseCase( | ||
name: '$name', | ||
builder: (context) => Center(child: $builderCode), | ||
), | ||
'''; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
..._project_builder/post_gen_tasks/comp_isolation/widgetbook/entities/widgetbook_widget.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,22 @@ | ||
import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/comp_isolation/isolation_node.dart'; | ||
import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/comp_isolation/widgetbook/entities/widgetbook_use_case.dart'; | ||
|
||
/// Node that represents a Widgetbook component. | ||
class WidgetBookWidget extends IsolationNode { | ||
WidgetBookWidget(String name) : super(name: name); | ||
|
||
@override | ||
String generate() { | ||
var useCases = getType<WidgetBookUseCase>(); | ||
var useCasesGen = ''; | ||
if (useCases != null && useCases.isNotEmpty) { | ||
useCasesGen = useCases.map((useCase) => useCase.generate()).join('\n'); | ||
} | ||
return ''' | ||
WidgetbookWidget( | ||
name: '$name', | ||
${useCasesGen.isNotEmpty ? 'useCases: [\n$useCasesGen\n],\n' : ''} | ||
) | ||
'''; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...lutter_project_builder/post_gen_tasks/comp_isolation/widgetbook/widgetbook_generator.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,69 @@ | ||
import 'package:parabeac_core/controllers/main_info.dart'; | ||
import 'package:parabeac_core/generation/flutter_project_builder/import_helper.dart'; | ||
import 'package:parabeac_core/generation/flutter_project_builder/post_gen_tasks/comp_isolation/component_isolation_generator.dart'; | ||
import 'package:parabeac_core/generation/generators/import_generator.dart'; | ||
import 'package:parabeac_core/generation/generators/util/pb_generation_project_data.dart'; | ||
import 'package:parabeac_core/interpret_and_optimize/services/component_isolation/widgetbook_service.dart'; | ||
|
||
class WidgetbookGenerator implements ComponentIsolationGenerator { | ||
@override | ||
String fileName = 'main_widgetbook.dart'; | ||
|
||
WidgetbookGenerator(this.projectData) { | ||
projectData.addDependencies('widgetbook', '2.0.5-beta'); | ||
} | ||
|
||
@override | ||
PBGenerationProjectData projectData; | ||
|
||
@override | ||
String generateCode(ImportHelper helper) { | ||
var category = WidgetBookService.category; | ||
var treeIds = WidgetBookService.treeIds; | ||
var generatedCode = category.generate(); | ||
|
||
var imports = treeIds | ||
.map( | ||
(id) => helper | ||
.getFormattedImports( | ||
id, | ||
importMapper: (import) => FlutterImport( | ||
import, | ||
MainInfo().projectName, | ||
), | ||
) | ||
.join('\n'), | ||
) | ||
.join(''); | ||
return ''' | ||
import 'package:widgetbook/widgetbook.dart'; | ||
import 'package:flutter/material.dart'; | ||
$imports | ||
void main() { | ||
runApp(const MyApp()); | ||
} | ||
class MyApp extends StatelessWidget { | ||
const MyApp({Key? key}) : super(key: key); | ||
@override | ||
Widget build(BuildContext context){ | ||
return Widgetbook( | ||
themes: [ | ||
WidgetbookTheme(name: 'Light', data: ThemeData.light()), | ||
], | ||
devices: const [ | ||
Apple.iPhone11ProMax, | ||
Samsung.s10, | ||
], | ||
categories: [ | ||
$generatedCode, | ||
], | ||
appInfo: AppInfo(name: 'MyApp'), | ||
); | ||
} | ||
} | ||
'''; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
lib/generation/flutter_project_builder/post_gen_tasks/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,5 @@ | ||
/// Abstract class for Tasks that will run post-generation. | ||
abstract class PostGenTask { | ||
/// Executes the [PostGenTask]. | ||
void execute(); | ||
} |
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
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.