generate method

  1. @override
Future<void> generate(
  1. List<IModuleCodeContributor> modules,
  2. Logger logger,
  3. Map<String, dynamic> coreVars,
  4. String generateTo,
)
override

Generates files based on provided modules and context.

Implementation

@override
Future<void> generate(
  List<IModuleCodeContributor> modules,
  Logger logger,
  Map<String, dynamic> coreVars,
  String generateTo,
) async {
  final dslGenerators = modules.whereType<DslAwareCodeGenerator>().toList();
  final diGroups = modules.map((m) => m.di).expand((e) => e).toList();
  final routeGroups = modules.map((m) => m.routes).toList();
  final shellDeclarations = _toShellDeclarations(routeGroups);
  final initialRoute = cliContext.initialRoute ?? '/noModules';

  final context = DslContext(
    projectRootPath: generateTo,
    mustacheVariables: coreVars,
    logger: logger,
    diGroups: diGroups,
    routeGroups: routeGroups,
    shellDeclarations: shellDeclarations,
    initialRoute: initialRoute,
  );

  for (final dslGenerator in dslGenerators) {
    final files = await dslGenerator.generateFromDsl(context);
    for (final file in files) {
      await strategy.write(file);
    }
  }
}