doRun method

  1. @override
Future<int> doRun()
override

Implementation

@override
Future<int> doRun() async {
  printInfo('Start code generation...');

  final rootDirPath = p.current;
  printVerbose('Current directory: $rootDirPath');
  printVerbose('Search for pubspec with $_buildRunner dependency');

  final targets = await _findTargets();
  printVerbose('Found ${targets.length} target(s)');

  if (targets.isEmpty) {
    return success(
      message: '🔍 No pubspec.yaml with $_buildRunner dependency found.',
    );
  }

  for (final target in targets) {
    final relativePath = p.relative(target.pubspec.path, from: rootDirPath);
    printInfo('Generating code for $relativePath'
        '${target.useWorkspace ? ' (workspace)' : ''}');

    setCurrentDir(target.pubspec.parent.path);
    printVerbose('Current directory: ${Directory.current.path}');

    await flutter.runPubOrFail(
      'build_runner',
      [
        'build',
        '--delete-conflicting-outputs',
        if (target.useWorkspace) '--workspace',
      ],
      // Deps are already resolved while gating workspace generation, so avoid
      // a redundant pub get here.
      prependWithPubGet: !target.depsResolved,
      title: 'Running code generation',
    );

    printInfo('Generation for $relativePath - DONE');
  }

  return success(message: '🛠️ Code generation complete!');
}