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 #660 from Parabeac/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ivan-015 authored May 8, 2022
2 parents 96f2739 + 50c40e4 commit 6b09e9c
Show file tree
Hide file tree
Showing 33 changed files with 269 additions and 151 deletions.
3 changes: 2 additions & 1 deletion lib/configurations/configurations.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"tablet": 600,
"desktop": 1280
},
"componentIsolation": "widgetbook"
"componentIsolation": "widgetbook",
"folderArchitecture": "domain"
}
77 changes: 76 additions & 1 deletion lib/controllers/main_info.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'dart:convert';
import 'dart:io';

import 'package:args/args.dart';
import 'package:parabeac_core/interpret_and_optimize/helpers/pb_configuration.dart';
import 'package:path/path.dart' as p;
import 'package:sentry/sentry.dart';

class MainInfo {
static final MainInfo _singleton = MainInfo._internal();
Expand Down Expand Up @@ -96,6 +98,79 @@ class MainInfo {
return p.normalize(p.absolute(path));
}

/// Populates the corresponding fields of the [MainInfo] object with the
/// corresponding [arguments].
///
/// Remember that [MainInfo] is a Singleton, therefore, nothing its going to
/// be return from the function. When you use [MainInfo] again, its going to
/// contain the proper values from [arguments]
void collectArguments(ArgResults arguments) {
var info = MainInfo();

info.configuration =
generateConfiguration(p.normalize(arguments['config-path']));

/// Detect platform
info.platform = Platform.operatingSystem;

info.figmaOauthToken = arguments['oauth'];
info.figmaKey = arguments['figKey'];
info.figmaProjectID = arguments['fig'];

info.designFilePath = arguments['path'];
if (arguments['pbdl-in'] != null) {
info.pbdlPath = arguments['pbdl-in'];
}

info.designType = determineDesignTypeFromArgs(arguments);
info.exportStyles = !arguments['exclude-styles'];
info.projectName ??= arguments['project-name'];

/// If outputPath is empty, assume we are outputting to design file path
info.outputPath = arguments['out'] ??
p.dirname(info.designFilePath ?? Directory.current.path);

info.exportPBDL = arguments['export-pbdl'] ?? false;

/// In the future when we are generating certain dart files only.
/// At the moment we are only generating in the flutter project.
info.pngPath = p.join(info.genProjectPath, 'lib/assets/images');
}

/// Generating the [PBConfiguration] based in the configuration file in [path]
PBConfiguration generateConfiguration(String path) {
var configuration;
try {
///SET CONFIGURATION
// Setting configurations globally
configuration =
PBConfiguration.fromJson(json.decode(File(path).readAsStringSync()));
} catch (e, stackTrace) {
Sentry.captureException(e, stackTrace: stackTrace);
}
configuration ??= PBConfiguration.genericConfiguration();
return configuration;
}

/// Determine the [MainInfo.designType] from the [arguments]
///
/// If [arguments] include `figKey` or `fig`, that implies that [MainInfo.designType]
/// should be [DesignType.FIGMA]. If there is a `path`, then the [MainInfo.designType]
/// should be [DesignType.SKETCH]. Otherwise, if it includes the flag `pndl-in`, the type
/// is [DesignType.PBDL].Finally, if none of the [DesignType] applies, its going to default
/// to [DesignType.UNKNOWN].
DesignType determineDesignTypeFromArgs(ArgResults arguments) {
if ((arguments['figKey'] != null || arguments['oauth'] != null) &&
arguments['fig'] != null) {
return DesignType.FIGMA;
} else if (arguments['path'] != null) {
return DesignType.SKETCH;
} else if (arguments['pbdl-in'] != null) {
return DesignType.PBDL;
}
return DesignType.UNKNOWN;
}

factory MainInfo() {
return _singleton;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:parabeac_core/interpret_and_optimize/helpers/pb_state_management
import 'package:parabeac_core/interpret_and_optimize/services/pb_platform_orientation_linker_service.dart';
import 'package:parabeac_core/interpret_and_optimize/state_management/directed_state_graph.dart';
import 'package:recase/recase.dart';
import 'package:path/path.dart' as p;

class CommandGenMiddleware extends Middleware
with PBPlatformOrientationGeneration {
Expand Down Expand Up @@ -68,14 +69,16 @@ class CommandGenMiddleware extends Middleware
var componentSetName =
(tree.rootNode as PBSharedMasterNode).componentSetName;
relativePath = componentSetName != null
? relativePath + '/' + componentSetName.snakeCase
? p.join(relativePath, componentSetName.snakeCase)
: relativePath;
}

command = WriteSymbolCommand(
tree.UUID,
tree.identifier,
generationManager.generate(tree.rootNode, context),
relativePath: relativePath,
symbolPath:
p.join(WriteSymbolCommand.DEFAULT_SYMBOL_PATH, relativePath),
);
}
if (command != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class BLoCMiddleware extends StateManagementMiddleware {
PBSymbolStorage().getSharedMasterNodeBySymbolID(node.SYMBOL_ID);
return p.join(
fileStrategy.GENERATED_PROJECT_PATH,
FileStructureStrategy.RELATIVE_VIEW_PATH,
FileStructureStrategy.RELATIVE_WIDGET_PATH,
'${generalStateName.snakeCase}_bloc',
'${ImportHelper.getName(symbolMaster.name).snakeCase}_bloc',
);
Expand Down Expand Up @@ -193,14 +193,14 @@ class BLoCMiddleware extends StateManagementMiddleware {
tree.UUID,
state.name.snakeCase,
tree.context.generationManager.generate(state, tree.context),
relativePath: generalName,
symbolPath: WriteSymbolCommand.DEFAULT_SYMBOL_PATH + generalName,
));
});

// Generate default node's view page
fileStrategy.commandCreated(WriteSymbolCommand('${context.tree.UUID}',
node.name.snakeCase, generationManager.generate(node, context),
relativePath: generalName));
symbolPath: WriteSymbolCommand.DEFAULT_SYMBOL_PATH + generalName));

/// Creates cubit page
context.managerData.addImport(FlutterImport('meta.dart', 'meta'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ProviderMiddleware extends StateManagementMiddleware {
? p.join(fileStrategy.RELATIVE_MODEL_PATH,
ImportHelper.getName(symbolMaster.name).snakeCase)
: p.join(
FileStructureStrategy.RELATIVE_VIEW_PATH,
FileStructureStrategy.RELATIVE_WIDGET_PATH,
ImportHelper.getName(symbolMaster.name).snakeCase,
node.functionCallName.snakeCase);
return p.join(fileStrategy.GENERATED_PROJECT_PATH, import);
Expand Down Expand Up @@ -105,7 +105,8 @@ class ProviderMiddleware extends StateManagementMiddleware {
}
watcherName = getNameOfNode(node);

var parentDirectory = ImportHelper.getName(node.name).snakeCase;
var parentDirectory = WriteSymbolCommand.DEFAULT_SYMBOL_PATH +
ImportHelper.getName(node.name).snakeCase;

// Generate model's imports
var modelGenerator = PBFlutterGenerator(ImportHelper(),
Expand All @@ -125,9 +126,12 @@ class ProviderMiddleware extends StateManagementMiddleware {
ownership: FileOwnership.DEV,
),
// Generate default node's view page
WriteSymbolCommand(context.tree.UUID, node.name.snakeCase,
generationManager.generate(node, context),
relativePath: parentDirectory),
WriteSymbolCommand(
context.tree.UUID,
node.name.snakeCase,
generationManager.generate(node, context),
symbolPath: parentDirectory,
),
].forEach(fileStrategy.commandCreated);

(configuration as ProviderGenerationConfiguration)
Expand All @@ -150,7 +154,7 @@ class ProviderMiddleware extends StateManagementMiddleware {
tree.UUID,
state.name.snakeCase,
tree.context.generationManager.generate(state, tree.context),
relativePath: parentDirectory,
symbolPath: parentDirectory,
));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class RiverpodMiddleware extends StateManagementMiddleware {
}
watcherName = getNameOfNode(node);

var parentDirectory = ImportHelper.getName(node.name).snakeCase;
var parentDirectory = WriteSymbolCommand.DEFAULT_SYMBOL_PATH +
ImportHelper.getName(node.name).snakeCase;

// Generate model's imports
var modelGenerator = PBFlutterGenerator(ImportHelper(),
Expand All @@ -109,9 +110,12 @@ class RiverpodMiddleware extends StateManagementMiddleware {
ownership: FileOwnership.DEV,
),
// Generate default node's view page
WriteSymbolCommand(context.tree.UUID, node.name.snakeCase,
generationManager.generate(node, context),
relativePath: parentDirectory),
WriteSymbolCommand(
context.tree.UUID,
node.name.snakeCase,
generationManager.generate(node, context),
symbolPath: parentDirectory,
),
].forEach(fileStrategy.commandCreated);

var nodeStateGraph = stmgHelper.getStateGraphOfNode(node);
Expand All @@ -129,7 +133,7 @@ class RiverpodMiddleware extends StateManagementMiddleware {
tree.UUID,
state.name.snakeCase,
tree.context.generationManager.generate(state, tree.context),
relativePath: parentDirectory,
symbolPath: parentDirectory,
));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class StatefulMiddleware extends StateManagementMiddleware {
PBSymbolStorage().getSharedMasterNodeBySymbolID(node.SYMBOL_ID);
var path = p.join(
fileStrategy.GENERATED_PROJECT_PATH,
FileStructureStrategy.RELATIVE_VIEW_PATH,
FileStructureStrategy.RELATIVE_WIDGET_PATH,
ImportHelper.getName(symbolMaster.name).snakeCase,
node.functionCallName.snakeCase);
return path;
Expand Down Expand Up @@ -71,7 +71,8 @@ class StatefulMiddleware extends StateManagementMiddleware {
tree.UUID,
state.name.snakeCase,
tree.context.generationManager.generate(state, tree.context),
relativePath: ImportHelper.getName(node.name).snakeCase,
symbolPath: WriteSymbolCommand.DEFAULT_SYMBOL_PATH +
ImportHelper.getName(node.name).snakeCase,
));
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +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:path/path.dart' as p;

import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/commands/file_structure_command.dart';
Expand All @@ -9,7 +11,8 @@ class AddConstantCommand extends FileStructureCommand {
String name;
String type;
String value;
final String CONST_DIR_PATH = 'lib/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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +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: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 All @@ -9,7 +11,8 @@ class ExportPlatformCommand extends NodeFileStructureCommand {
PLATFORM platform;
String fileName;
String folderName;
static final String WIDGET_PATH = 'lib/screens';
static final String WIDGET_PATH =
GetIt.I.get<PathService>().viewsRelativePath;

ExportPlatformCommand(
String UUID, this.platform, this.folderName, this.fileName, String code,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import 'package:get_it/get_it.dart';
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/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 '../file_ownership_policy.dart';

class OrientationBuilderCommand extends FileStructureCommand {
static final DIR_TO_ORIENTATION_BUILDER = 'lib/widgets/';
static final DIR_TO_ORIENTATION_BUILDER =
GetIt.I.get<PathService>().widgetsRelativePath;
static final NAME_TO_ORIENTAION_BUILDER =
'responsive_orientation_builder.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
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: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';
import 'package:parabeac_core/generation/generators/value_objects/file_structure_strategy/pb_file_structure_strategy.dart';
import 'package:parabeac_core/interpret_and_optimize/services/pb_platform_orientation_linker_service.dart';

class ResponsiveLayoutBuilderCommand extends FileStructureCommand {
static final DIR_TO_RESPONSIVE_LAYOUT = 'lib/widgets/';
static final DIR_TO_RESPONSIVE_LAYOUT =
GetIt.I.get<PathService>().widgetsRelativePath;
static final NAME_TO_RESPONSIVE_LAYOUT = 'responsive_layout_builder.dart';

ResponsiveLayoutBuilderCommand(String UUID) : super(UUID);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +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: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 All @@ -9,7 +11,7 @@ class WriteScreenCommand extends NodeFileStructureCommand {
String relativePath;
String fileExtension;

static final SCREEN_PATH = 'lib/screens';
static final SCREEN_PATH = GetIt.I.get<PathService>().viewsRelativePath;

WriteScreenCommand(String UUID, this.name, this.relativePath, String code,
{FileOwnership ownership = FileOwnership.PBC,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
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: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';

/// Command that writes a `symbol` to the project.
class WriteSymbolCommand extends NodeFileStructureCommand {
static const String DEFAULT_SYMBOL_PATH = 'lib/widgets';
static String DEFAULT_SYMBOL_PATH =
GetIt.I.get<PathService>().widgetsRelativePath;

final String symbolPath;
String symbolPath;
String fileName;

/// The [relativePath] within the [symbolPath]
/// The [symbolPath] has the relative path within
///
/// For example, you are looking for `lib/widgets/some_element/element.dart`,
/// then the [relativePath] would be `some_element/` and the [fileName] would be `element.dart`.
String relativePath;
/// then the [symbolPath] would be `lib/widgets/some_element/`
WriteSymbolCommand(String UUID, this.fileName, String code,
{this.relativePath = '',
this.symbolPath = DEFAULT_SYMBOL_PATH,
FileOwnership ownership = FileOwnership.PBC})
: super(UUID, code, ownership);
WriteSymbolCommand(
String UUID,
this.fileName,
String code, {
this.symbolPath = '',
FileOwnership ownership = FileOwnership.PBC,
}) : super(UUID, code, ownership);

/// Writes a symbol file containing [generationViewData] with [fileName] as its filename.
///
/// Returns path to the file that was created.
@override
Future<String> write(FileStructureStrategy strategy) {
var absPath = relativePath.isEmpty
? p.join(strategy.GENERATED_PROJECT_PATH, symbolPath)
: p.join(strategy.GENERATED_PROJECT_PATH, symbolPath, relativePath);
symbolPath = symbolPath.isEmpty ? DEFAULT_SYMBOL_PATH : symbolPath;
var absPath = p.join(strategy.GENERATED_PROJECT_PATH, symbolPath);

strategy.writeDataToFile(code, absPath, fileName,
UUID: UUID, ownership: ownership);
Expand Down
Loading

0 comments on commit 6b09e9c

Please sign in to comment.