runCli function

Future<void> runCli(
  1. CliContext context
)

Entrypoint that orchestrates project generation using selected modules.

Implementation

Future<void> runCli(CliContext context) async {
  final cliGenerator = await MasonGenerator.fromBundle(smfCliBrickBundle);
  final coreVars = <String, dynamic>{
    kWorkingDirectory: context.outputDirectory,
    'modules': '[${context.selectedModules.map(
          (e) => "'${e.moduleDescriptor.name}'",
        ).join(',')}]',
    'app_name': context.name,
    'org_name': context.packageName,
    'strict_mode': context.strictMode == StrictMode.strict,
  };
  await cliGenerator.hooks.preGen(
    vars: coreVars,
    onVarsChanged: coreVars.addAll,
    logger: context.logger,
  );

  final writeStrategy = CompositeWriteStrategy([DefaultWriteStrategy()]);

  // Generate individual brick contributions
  context.logger.info('πŸ“¦ Generating brick contributions...');
  await BrickGenerator(context.moduleResolver).generate(
    context.selectedModules,
    context.logger,
    coreVars,
    context.outputDirectory,
  );

  // Generate shared file contributions
  context.logger.info('πŸ”§ Applying shared file contributions...');
  await const SharableGenerator().generate(
    context.selectedModules,
    context.logger,
    coreVars,
    coreVars[kWorkingDirectory] as String,
  );

  context.logger.info('πŸ›£οΈ Generating from dsls...');
  await DslGenerator(writeStrategy, cliContext: context).generate(
    context.selectedModules,
    context.logger,
    coreVars,
    coreVars[kWorkingDirectory] as String,
  );

  // Generate dependencies to pubspec
  context.logger.info('πŸ“‹ Updating pubspec.yaml...');
  await const PubspecGenerator().generate(
    context.selectedModules,
    context.logger,
    coreVars,
    coreVars[kWorkingDirectory] as String,
  );

  context.logger.info('🏁 Running post gen cli hook...');
  await cliGenerator.hooks.postGen(
    vars: coreVars,
    logger: context.logger,
  );
}