Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Release 1.3.1 - Bug Fixes and ability to export and import PBDL files
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Herrera authored and Eduardo Herrera committed Feb 2, 2021
2 parents 7f99776 + 0eb15f1 commit 96e518d
Show file tree
Hide file tree
Showing 120 changed files with 4,171 additions and 597 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ Since Figma operates from a cloud native approach we use the Figma File ID and a
3. Scroll Down to the "Create a new Personal Access Token"
4. Create a new Personal Access Token with the name Parabeac, you should then be prompted with your new API Key. Make sure to copy this as you wont be able to access it again after you click confirm. (It should look something like this: ```64522-a0e5509a-d5ce-47a8-880b-c295f9cb27ed```

<<<<<<< HEAD
=======
## Metrics
Parabeac-core keeps track of how many times it is run. Although we do not collect any personal information, you can turn off metrics at any time by creating the environment variable `PB_METRICS = "false"`.
>>>>>>> dev
## Using State Management Configuration
![State Management](https://kindling-sketch.s3.amazonaws.com/PB_to_Flutter_with_State_management.png)

Expand All @@ -118,9 +123,13 @@ To set the state management configuration, head over to edit `/Parabeac-Core/lib
```

Here you can replace the `state-management` property to `bloc` or `provider`. Soon you can also set `riverpod`.
<<<<<<< HEAD

You can learn how to easily create your own state management configuration in the [wiki](https://github.com/Parabeac/Parabeac-Core/wiki/How-to-Create-a-State-Management-Configuration), let us know if you're thinking about doing this and if you need any help!
=======
>>>>>>> dev
You can learn how to easily create your own state management configuration in the [wiki](https://github.com/Parabeac/Parabeac-Core/wiki/How-to-Create-a-State-Management-Configuration), let us know if you're thinking about doing this and if you need any help!
# Running the exported code
### Requirements
- Flutter
Expand Down
22 changes: 11 additions & 11 deletions lib/configurations/configurations.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"default": {
"widgetStyle": "Material",
"widgetType": "Stateless",
"widgetSpacing": "Expanded",
"layoutPrecedence": [
"column",
"row",
"stack"
]
},
"state-management": "provider"
"default": {
"widgetStyle": "Material",
"widgetType": "Stateless",
"widgetSpacing": "Expanded",
"layoutPrecedence": [
"column",
"row",
"stack"
]
},
"state-management": "none"
}
98 changes: 97 additions & 1 deletion lib/controllers/controller.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import 'package:parabeac_core/controllers/interpret.dart';
import 'package:parabeac_core/generation/flutter_project_builder/flutter_project_builder.dart';
import 'package:parabeac_core/generation/generators/util/pb_generation_view_data.dart';
import 'package:parabeac_core/generation/generators/writers/pb_flutter_writer.dart';
import 'package:parabeac_core/generation/generators/writers/pb_traversal_adapter_writer.dart';
import 'package:parabeac_core/generation/pre-generation/pre_generation_service.dart';
import 'package:parabeac_core/input/helper/asset_processing_service.dart';
import 'package:parabeac_core/input/helper/azure_asset_service.dart';
import 'package:parabeac_core/input/helper/design_project.dart';
import 'package:quick_log/quick_log.dart';
import 'dart:convert';
import 'dart:io';
Expand All @@ -10,7 +19,41 @@ abstract class Controller {
Controller();

void convertFile(
var fileAbsPath, var projectPath, var configurationPath, var configType);
var fileAbsPath,
var projectPath,
var configurationPath,
var configType, {
bool jsonOnly = false,
DesignProject designProject,
AssetProcessingService apService,
}) async {
/// IN CASE OF JSON ONLY
if (jsonOnly) {
return stopAndToJson(designProject, apService);
}

Interpret().init(projectPath);

var pbProject = await Interpret().interpretAndOptimize(designProject);

pbProject.forest.forEach((tree) => tree.data = PBGenerationViewData());

await PreGenerationService(
projectName: projectPath,
mainTree: pbProject,
pageWriter: PBTraversalAdapterWriter(),
).convertToFlutterProject();

//Making the data immutable for writing into the file
pbProject.forest.forEach((tree) => tree.data.lockData());

var fpb = FlutterProjectBuilder(
projectName: projectPath,
mainTree: pbProject,
pageWriter: PBFlutterWriter());

await fpb.convertToFlutterProject();
}

void configure(var configurationPath, var configType) async {
Map configurations;
Expand All @@ -34,4 +77,57 @@ abstract class Controller {
MainInfo().configurations = configurations;
MainInfo().configurationType = configType;
}

/// Method that returns the given path and ensures
/// it ends with a /
String verifyPath(String path) {
if (path.endsWith('/')) {
return path;
} else {
return '${path}/';
}
}

Future<void> stopAndToJson(
DesignProject project, AssetProcessingService apService) async {
var uuids = processRootNodeUUIDs(project, apService);
// Process rootnode UUIDs
await apService.processRootElements(uuids);
project.projectName = MainInfo().projectName;
var projectJson = project.toPBDF();
projectJson['azure_container_uri'] = AzureAssetService().getContainerUri();
var encodedJson = json.encode(projectJson);
File('${verifyPath(MainInfo().outputPath)}${project.projectName}.json')
.writeAsStringSync(encodedJson);
log.info(
'Created PBDL JSON file at ${verifyPath(MainInfo().outputPath)}${project.projectName}.json');
}

/// Iterates through the [project] and returns a list of the UUIDs of the
/// rootNodes
Map<String, Map> processRootNodeUUIDs(
DesignProject project, AssetProcessingService apService) {
var result = <String, Map>{};

for (var page in project.pages) {
for (var screen in page.screens) {
screen.imageURI = AzureAssetService().getImageURI('${screen.id}.png');
result[screen.id] = {
'width': screen.designNode.boundaryRectangle.width,
'height': screen.designNode.boundaryRectangle.height
};
}
}

for (var page in project.miscPages) {
for (var screen in page.screens) {
result[screen.id] = {
'width': screen.designNode.boundaryRectangle.width,
'height': screen.designNode.boundaryRectangle.height
};
}
}

return result;
}
}
42 changes: 42 additions & 0 deletions lib/controllers/design_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:parabeac_core/input/helper/asset_processing_service.dart';
import 'package:parabeac_core/input/helper/azure_asset_service.dart';
import 'package:parabeac_core/input/helper/design_project.dart';
import 'package:quick_log/quick_log.dart';

import 'controller.dart';

class DesignController extends Controller {
@override
var log = Logger('FigmaController');

DesignController();

@override
void convertFile(
var pbdf,
var outputPath,
var configurationPath,
var configType, {
bool jsonOnly = false,
DesignProject designProject,
AssetProcessingService apService,
}) async {
configure(configurationPath, configType);

var designProject = await generateDesignProject(pbdf, outputPath);
AzureAssetService().projectUUID = pbdf['id'];

await super.convertFile(
pbdf,
outputPath,
configurationPath,
configType,
designProject: designProject,
jsonOnly: jsonOnly,
);
}

DesignProject generateDesignProject(var pbdf, var proejctName) {
return DesignProject.fromPBDF(pbdf);
}
}
65 changes: 29 additions & 36 deletions lib/controllers/figma_controller.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import 'package:parabeac_core/controllers/controller.dart';
import 'package:parabeac_core/generation/flutter_project_builder/flutter_project_builder.dart';
import 'package:parabeac_core/generation/generators/util/pb_generation_view_data.dart';
import 'package:parabeac_core/generation/generators/writers/pb_flutter_writer.dart';
import 'package:parabeac_core/generation/generators/writers/pb_traversal_adapter_writer.dart';
import 'package:parabeac_core/generation/pre-generation/pre_generation_service.dart';
import 'package:parabeac_core/input/figma/entities/layers/frame.dart';
import 'package:parabeac_core/input/figma/helper/figma_node_tree.dart';
import 'package:parabeac_core/input/figma/helper/figma_asset_processor.dart';
import 'package:parabeac_core/input/figma/helper/figma_project.dart';
import 'package:parabeac_core/input/helper/asset_processing_service.dart';
import 'package:parabeac_core/input/helper/design_project.dart';
import 'package:quick_log/quick_log.dart';

import 'interpret.dart';
Expand All @@ -18,40 +16,35 @@ class FigmaController extends Controller {
FigmaController();

@override
void convertFile(var jsonFigma, var outputPath, var configurationPath,
var configType) async {
void convertFile(
var jsonFigma,
var outputPath,
var configurationPath,
var configType, {
bool jsonOnly = false,
DesignProject designProject,
AssetProcessingService apService,
}) async {
configure(configurationPath, configType);

var figmaNodeTree = await generateFigmaTree(jsonFigma, outputPath);
var figmaProject = await generateFigmaTree(jsonFigma, outputPath);

figmaNodeTree = declareScaffolds(figmaNodeTree);
figmaProject = declareScaffolds(figmaProject);

Interpret().init(outputPath);

var pbProject = await Interpret().interpretAndOptimize(figmaNodeTree);

pbProject.forest.forEach((tree) => tree.data = PBGenerationViewData());

await PreGenerationService(
projectName: outputPath,
mainTree: pbProject,
pageWriter: PBTraversalAdapterWriter(),
).convertToFlutterProject();

//Making the data immutable for writing into the file
pbProject.forest.forEach((tree) => tree.data.lockData());

var fpb = FlutterProjectBuilder(
projectName: outputPath,
mainTree: pbProject,
pageWriter: PBFlutterWriter());

await fpb.convertToFlutterProject();
await super.convertFile(
jsonFigma,
outputPath,
configurationPath,
configType,
designProject: figmaProject,
jsonOnly: jsonOnly,
apService: apService,
);
}

FigmaNodeTree generateFigmaTree(var jsonFigma, var projectname) {
FigmaProject generateFigmaTree(var jsonFigma, var projectname) {
try {
return FigmaNodeTree(projectname, jsonFigma);
return FigmaProject(projectname, jsonFigma);
} catch (e, stackTrace) {
print(e);
return null;
Expand All @@ -60,11 +53,11 @@ class FigmaController extends Controller {

/// This method was required for Figma, so we could
/// detect which `FigmaFrame` were Scaffolds or Containers
FigmaNodeTree declareScaffolds(FigmaNodeTree tree) {
FigmaProject declareScaffolds(FigmaProject tree) {
for (var page in tree.pages) {
for (var item in page.getPageItems()) {
if (item.root is FigmaFrame) {
(item.root as FigmaFrame).isScaffold = true;
if (item.designNode is FigmaFrame) {
(item.designNode as FigmaFrame).isScaffold = true;
}
}
}
Expand Down
20 changes: 12 additions & 8 deletions lib/controllers/interpret.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'package:parabeac_core/controllers/main_info.dart';
import 'package:parabeac_core/design_logic/design_node.dart';
import 'package:parabeac_core/generation/generators/pb_generation_manager.dart';
import 'package:parabeac_core/generation/prototyping/pb_prototype_linker_service.dart';
import 'package:parabeac_core/input/helper/node_tree.dart';
import 'package:parabeac_core/input/helper/page.dart';
import 'package:parabeac_core/input/helper/page_item.dart';
import 'package:parabeac_core/input/helper/design_project.dart';
import 'package:parabeac_core/input/helper/design_page.dart';
import 'package:parabeac_core/input/helper/design_screen.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/inherited_scaffold.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/layouts/temp_group_layout_node.dart';
import 'package:parabeac_core/interpret_and_optimize/entities/pb_shared_master_node.dart';
Expand Down Expand Up @@ -47,7 +47,7 @@ class Interpret {
_interpret._pbPrototypeLinkerService = PBPrototypeLinkerService();
}

Future<PBProject> interpretAndOptimize(NodeTree tree) async {
Future<PBProject> interpretAndOptimize(DesignProject tree) async {
_pb_project = PBProject(projectName, tree.sharedStyles);

///3rd Party Symbols
Expand All @@ -67,7 +67,7 @@ class Interpret {
return _pb_project;
}

Future<Iterable<PBIntermediateTree>> _generateGroup(Page group) async {
Future<Iterable<PBIntermediateTree>> _generateGroup(DesignPage group) async {
var tempForest = <PBIntermediateTree>[];
var pageItems = group.getPageItems();
for (var i = 0; i < pageItems.length; i++) {
Expand Down Expand Up @@ -96,22 +96,26 @@ class Interpret {
return tempForest;
}

Future<PBIntermediateTree> _generateScreen(PageItem item) async {
Future<PBIntermediateTree> _generateScreen(DesignScreen item) async {
var currentContext = PBContext(
jsonConfigurations:
MainInfo().configurations ?? MainInfo().defaultConfigs);

var parentComponent = item.root;
var parentComponent = item.designNode;

var stopwatch = Stopwatch()..start();

/// VisualGenerationService
var intermediateTree = PBIntermediateTree(item.root.name);
var intermediateTree = PBIntermediateTree(item.designNode.name);
currentContext.treeRoot = intermediateTree;
currentContext.project = _pb_project;
intermediateTree.rootNode = await visualGenerationService(
parentComponent, currentContext, stopwatch);

if (intermediateTree.rootNode == null) {
return intermediateTree;
}

///
/// pre-layout generation service for plugin nodes.
/// NOTE Disabled Plugin Control Service for right now
Expand Down
Loading

0 comments on commit 96e518d

Please sign in to comment.