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

Commit

Permalink
Merge pull request #619 from Parabeac/hotfix/flutter-writer
Browse files Browse the repository at this point in the history
Hotfix/flutter writer
  • Loading branch information
ivan-015 committed Mar 21, 2022
2 parents d42fc1a + 9a20876 commit d39c4e9
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 26 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ parabeac_core converts design files into isolated & responsive Flutter code for
[![Discord Chat](https://img.shields.io/discord/308323056592486420.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/qUrghes) [![https://twitter.com/parabeac?lang=en](https://img.shields.io/twitter/url/http/shields.io.svg?style=social&style=plastic)](https://twitter.com/parabeac?lang=en) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg)](https://github.com/Parabeac/parabeac_core/blob/stable/CODE_OF_CONDUCT.md) <a href="https://dev.to/parabeac"><img src="https://d2fltix0v2e0sb.cloudfront.net/dev-badge.svg" alt="bravemaster619's DEV Profile" height="22" width="22"></a>

<h3>
<a href="https://docs.parabeac.com/docs/hello-world-guide">Hello World</a>
<a href="https://docs.parabeac.com/docs/hello-world">Hello World</a>
<span> · </span>
<a href="https://docs.parabeac.com/docs/creating-a-production-app/fundamental-laws-of-parabeac">Fundamental Laws of Parabeac</a>
<span> · </span>
Expand Down Expand Up @@ -89,7 +89,7 @@ Due to the lack of requested support for Sketch and the major updates to this pr

# Running the generated code

We recommend following our [Hello World guide](https://docs.parabeac.com/docs/hello-world-guide) but if you feel experienced enough with Flutter, feel free to jump right in here:
We recommend following our [Hello World guide](https://docs.parabeac.com/docs/hello-world) but if you feel experienced enough with Flutter, feel free to jump right in here:

### Running a Figma Frame/Screen
![Figma Frame Example](https://github.com/Parabeac/parabeac_core/blob/stable/repo_assets/figma_frame_example.png?raw=true)
Expand Down Expand Up @@ -140,8 +140,10 @@ The best way to run and test a component package is to use tools like Storybook.

_Be sure to use Figma Components_

To run the widgetbook, instead of running the normal `flutter run`, you want to run `flutter run lib/main_widgetbook.g.dart`.

# What's Next?
Be sure to complete our [Hello World Guide](https://docs.parabeac.com/docs/hello-world-guide) or read the [docs](https://docs.parabeac.com/) so you know how to handle the code generated.
Be sure to complete our [Hello World Guide](https://docs.parabeac.com/docs/hello-world) or read the [docs](https://docs.parabeac.com/) so you know how to handle the code generated.

## Enabling the design team to create pull requests
If you find the viability in the code generation to support continuous design changes, create a free account on [Parabeac Nest](https://app.parabeac.com) where you can create an integration between Figma & the project Github repo.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class EntryFileCommand extends NodeFileStructureCommand {
this.projectName = 'Parabeac-Core Generated Project',
this.mainCode = 'runApp(MyApp());',
FileOwnership ownership = FileOwnership.DEV})
: super('ENTRY_FILE', '''
: super(
'ENTRY_FILE',
'''
import 'package:flutter/material.dart';
$entryScreenImport
Expand All @@ -55,7 +57,8 @@ class MyApp extends StatelessWidget {
}
}
''', ownership) {
''',
ownership) {
if ((entryScreenImport == null && entryScreenName != null) ||
(entryScreenName == null && entryScreenName != null)) {
throw NullThrownError();
Expand All @@ -66,7 +69,6 @@ class MyApp extends StatelessWidget {
Future write(FileStructureStrategy strategy) {
strategy.writeDataToFile(
code, strategy.GENERATED_PROJECT_PATH, p.join('lib', mainFileName),
UUID: UUID,
ownership: ownership);
UUID: UUID, ownership: ownership);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ class ExportPlatformCommand extends NodeFileStructureCommand {
static final String WIDGET_PATH = 'lib/screens';

ExportPlatformCommand(
String UUID,
this.platform,
this.folderName,
this.fileName,
String code,
{FileOwnership ownership = FileOwnership.PBC}
) : super(UUID, code, ownership);
String UUID, this.platform, this.folderName, this.fileName, String code,
{FileOwnership ownership = FileOwnership.PBC})
: super(UUID, code, ownership);

@override
Future write(FileStructureStrategy strategy) async {
Expand All @@ -28,6 +24,7 @@ class ExportPlatformCommand extends NodeFileStructureCommand {
folderName,
platform.toString().toLowerCase().replaceAll('platform.', ''),
);
strategy.writeDataToFile(code, path, fileName, UUID: UUID, ownership: ownership);
strategy.writeDataToFile(code, path, fileName,
UUID: UUID, ownership: ownership);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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/file_ownership_policy.dart';
import 'package:path/path.dart';

/// Class that relies on `code` to implement its `write` method.
abstract class NodeFileStructureCommand extends FileStructureCommand {
Expand All @@ -9,7 +10,6 @@ abstract class NodeFileStructureCommand extends FileStructureCommand {
/// through [write]
FileOwnership ownership;

NodeFileStructureCommand(String UUID, this.code,
this.ownership)
NodeFileStructureCommand(String UUID, this.code, this.ownership)
: super(UUID);
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ abstract class FileStructureStrategy implements CommandInvoker {
p.setExtension(
name, fileOwnershipPolicy.getFileExtension(ownership, ext)));

if (FileOwnership.PBC == ownership) {
data = _setHeader(data);
}

if (_fileSystemAnalyzer.containsFile(file.path) &&
ownership == FileOwnership.DEV) {
/// file is going to be ignored
Expand Down Expand Up @@ -248,6 +252,18 @@ abstract class FileStructureStrategy implements CommandInvoker {
}
}

String _setHeader(String code) {
return '''
// *********************************************************************************
// PARABEAC-GENERATED CODE. DO NOT MODIFY.
//
// FOR MORE INFORMATION ON HOW TO USE PARABEAC, PLEASE VISIT docs.parabeac.com
// *********************************************************************************
''' +
'\n\n' +
code;
}

File getFile(String directory, String name) => File(p.join(directory, name));
}

Expand Down
10 changes: 2 additions & 8 deletions lib/generation/generators/writers/pb_flutter_writer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,8 @@ class MyApp extends StatelessWidget {
}

/// Add assets
if (modifiableyaml.containsKey('flutter')) {
var assets = _getAssetFileNames();

/// If there are no assets to add, simply return.
if (assets.isEmpty) {
return;
}

var assets = _getAssetFileNames();
if (modifiableyaml.containsKey('flutter') && assets.isNotEmpty) {
/// Add only elements that are not already in the yaml
if (modifiableyaml['flutter'].containsKey('assets') &&
modifiableyaml['flutter']['assets'] != null) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: parabeac_core
description: Continuous Design / Continuous Integration for Figma-to-Flutter

version: 2.6.0
version: 2.6.1
# homepage: https://www.example.com

environment:
Expand Down

0 comments on commit d39c4e9

Please sign in to comment.