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 #670 from Parabeac/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mergify[bot] authored Jun 22, 2022
2 parents ad79d4a + eb52aa2 commit 492abd8
Show file tree
Hide file tree
Showing 27 changed files with 563 additions and 151 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Flutter action
uses: subosito/flutter-action@v1.4.0
uses: subosito/flutter-action@v2

- name: Install dependencies
run: flutter pub get
run: dart pub get
- name: Run tests
run: flutter pub run test
run: dart run test
env:
FIG_API_KEY: ${{ secrets.FIG_API_KEY }}
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ The handoff between designers & developers is one of the most costly and frustra
* [Running a Figma Component](#running-a-figma-component)
* [Running a Component Package with Widgetbook](#running-a-component-package)
* [Other](#other)
* [Global Theming](#global-theming)
* [TextStyles](#textstyles)
* [Colors](#colors)
* [Internal Use](#internal-use)
* [External Use With Another Flutter Package](#external-use-with-another-flutter-package)

* [All parabeac_core configurations](#all-parabeac_core-configurations)
* [Metrics](#metrics)

Expand Down Expand Up @@ -150,6 +156,79 @@ If you find the viability in the code generation to support continuous design ch
## Stay up to date
Follow or subscribe to our [Twitter](https://twitter.com/parabeac), [Youtube](https://www.youtube.com/channel/UCgfDd4tQYZ5a_A5qxknmh8w), [Dev.to](https://dev.to/parabeac) &/or [Newsletter](https://share.hsforms.com/1uu1ZTrhPSwK69T2md__lCw5i54a) to stay up to date on product releases. And if you want to influence the direction of this project, create an [issue](https://github.com/Parabeac/parabeac_core/issues/new/choose) or join our [Discord](https://discord.gg/qUrghes), we'd love to hear your feedback.
# Other
## Global Theming
* parabeac_core has support for global theming for **TextStyles** and **Colors**. If detected, parabeac_core will export two files containing the styles ready for internal and external use.
* For more information on how to set up Global Styles in your design file, read the following [Global Styling Docs](https://docs.parabeac.com/docs/learn-the-parabeac-way/global-styling).

### TextStyles
* If parabeac_core detects global TextStyles in the design file, it will export a file under `lib/theme/<your_package_name>_text_styles.g.dart`. This file will contain all global TextStyles of the design file in the following format:

```dart
class <YourPackageName>TextStyles {
/// Parabeac Style Description
static const TextStyle parabeacTextStyle = TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w700,
letterSpacing: 6.0,
fontFamily: 'Inter',
decoration: TextDecoration.none,
fontStyle: FontStyle.italic,
);
static const TextStyle newStyle = TextStyle(
fontSize: 12.0,
fontWeight: FontWeight.w400,
letterSpacing: 0.0,
fontFamily: 'Inter',
decoration: TextDecoration.none,
fontStyle: FontStyle.normal,
);
}
```
### Colors
* If parabeac_core detects global Colors in the design file, it will export a file under `lib/theme/<your_package_name>_colors.g.dart`. This file will contain all global TextStyles of the design in the following format:
```dart
class <YourPackageName>Colors {
/// Parabeac Red Description
static const Color parabeacRed = Color(0xffff0d0d);
static const Color parabeacBlue = Color(0xff28e5ff);
static const Color parabeacGreen = Color(0xff49ff0a);
}
```

<!-- TODO: Add Global theming documentation when it is ready. -->

### Internal Use

Styling classes can be used easily within the parabeac-generated package by simply importing the file as follows:

```dart
/// Text Styles import
import 'package:<your_package_name>/theme/<your_package_name>_text_styles.g.dart';
/// Colors import
import 'package:<your_package_name>/theme/<your_package_name>_colors.g.dart';
```
and using them like so:
```dart
/// To use a TextStyle
<YourPackageName>TextStyles.parabeacTextStyles;
/// To use a Color
<YourPackageName>Colors.parabeacRed;
```

### External Use With Another Flutter Package
In order to use global styling with another Flutter package, you must add the parabeac-generate package to your own Flutter package as follows:
```yaml
dependencies:
<your_package_name>:
path: path/to/<your_package_name>
```
For more options on how to import this package, see the following [Dart package dependency docs](https://dart.dev/tools/pub/dependencies).
## All parabeac_core Configurations
* `"componentIsolation"` - _Valid Values Below_
* `"none"`
Expand Down
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,
),
);
}
}
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,
),
);
}
}
}
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'},
)
''';
}
}
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 = '',
});
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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/node_file_structure_command.dart';
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/pb_file_structure_strategy.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:get_it/get_it.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';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:collection';
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/controllers/main_info.dart';
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/commands/file_structure_command.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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/node_file_structure_command.dart';
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/pb_file_structure_strategy.dart';
Expand Down
Loading

0 comments on commit 492abd8

Please sign in to comment.