planPreBuild function

List<PreBuildCommand> planPreBuild(
  1. AppConfig config,
  2. Iterable<PreBuildStep> steps
)

Commands for steps, in the order that works: flutter clean wipes .dart_tool, so it is always followed by pub get before code generation.

Implementation

List<PreBuildCommand> planPreBuild(
    AppConfig config, Iterable<PreBuildStep> steps) {
  final chosen = steps.toSet();
  final flutter = config.flutter;
  return [
    if (chosen.contains(PreBuildStep.clean)) ...[
      PreBuildCommand('flutter clean', [...flutter, 'clean']),
      PreBuildCommand('flutter pub get', [...flutter, 'pub', 'get']),
    ],
    if (chosen.contains(PreBuildStep.buildRunner))
      PreBuildCommand('build_runner build', [
        ..._dartCommand(flutter),
        'run',
        'build_runner',
        'build',
        ...config.preBuild.buildRunnerArgs,
      ]),
    if (chosen.contains(PreBuildStep.genL10n))
      PreBuildCommand('flutter gen-l10n', [...flutter, 'gen-l10n']),
  ];
}