generateBloc function

void generateBloc(
  1. ArgResults argResults, {
  2. bool dryRun = false,
})

The generateItems function generates the folder structure according feature by folder pattern.

dryRun is a dev-only boolean to generate example folders

Implementation

void generateBloc(
  ArgResults argResults, {
  bool dryRun = false,
}) async {
  final customPath = argResults['path'] != null ? true : false;
  var dir = argResults['path'] ?? 'feature';
  if (dryRun) {
    dir = 'example';
  }
  try {
    final brick = Brick.git(
      GitPath(
        'https://github.com/bazl-E/feature_folder_structure',
        path: 'bricks/bloc',
      ),
    );
    final generator = await MasonGenerator.fromBrick(brick);
    final target = DirectoryGeneratorTarget(
      Directory(customPath
          ? DirectoryService.replaceAsExpected(path: 'lib/$dir')
          : DirectoryService.paths[dir]!),
    );
    await generator.generate(
      target,
      vars: <String, dynamic>{'name': argResults['name'].toString()},
    );
  } on Exception catch (e) {
    LogService.error(e.toString());
  }
}