runAllBuildRunners method
Run build_runner for all projects that need it with progress
Implementation
Future<bool> runAllBuildRunners() async {
// Build list of projects needing build_runner. Only include a project if
// its pubspec.yaml actually depends on build_runner — otherwise
// `dart run build_runner build` blows up with
// "Could not find package `build_runner` or file `build_runner`"
// and (in interactive mode) prompts the user for retry/skip/abort.
final List<(String, String)> projects = <(String, String)>[];
// Models package needs build_runner for serialization
if (config.createModels) {
final String path = p.join(config.outputDir, config.modelsPackageName);
if (_pubspecDependsOnBuildRunner(path)) {
projects.add(('Models', path));
}
}
// CLI apps may need build_runner for cli_gen; check the pubspec first
// so templates that ship without build_runner (the current
// arcane_cli_app does) do not trigger an unconditional failure.
if (config.template == TemplateType.arcaneCli) {
final String path = p.join(config.outputDir, config.appName);
if (_pubspecDependsOnBuildRunner(path)) {
projects.add(('CLI app', path));
}
}
if (projects.isEmpty) {
return true;
}
// Run build_runner for each project with progress
for (int i = 0; i < projects.length; i++) {
final (name, path) = projects[i];
UserPrompt.showProgress(i, projects.length, 'Running build_runner for $name...');
if (!await runBuildRunner(path)) {
warn('Failed to run build_runner for $name');
}
}
UserPrompt.showProgress(projects.length, projects.length, 'Code generation complete');
return true;
}