runCli function
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,
);
}