run method

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

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future<int> run() async {
  logger.logInfo(
    ColorizeLogger.dim("distribute $packageVersion  environment check"),
  );
  logger.logEmpty();

  final checks = <_Check>[
    await _checkTool(
      'Flutter',
      'flutter',
      ['--version'],
      hint: 'Install from https://flutter.dev/docs/get-started/install',
    ),
    await _checkTool(
      'Git',
      'git',
      ['--version'],
      hint: 'Required for the GIT_* built-in variables.',
      optional: true,
    ),
    await _checkTool(
      'Fastlane',
      'fastlane',
      ['--version'],
      hint: 'Only needed for the fastlane publisher: gem install fastlane',
      optional: true,
    ),
    await _checkTool(
      'Firebase CLI',
      'firebase',
      ['--version'],
      hint: 'Only needed for the firebase publisher: '
          'npm i -g firebase-tools',
      optional: true,
    ),
    if (Platform.isMacOS)
      await _checkTool(
        'Xcode (xcrun altool)',
        'xcrun',
        ['altool', '--help'],
        hint: 'Only needed for the xcrun publisher.',
        optional: true,
      ),
    await _checkCompression(),
    _checkProject(),
    _checkFile(
      'Google Play service account',
      Files.fastlaneJson.path,
      hint: 'Only needed for the fastlane publisher. '
          'Pass it with `distribute init -g <path>`.',
      optional: true,
    ),
    await _checkConfig(),
  ];

  // Pad the labels so the details line up into a readable second column.
  final width = checks
      .map((check) => check.label.length)
      .reduce((a, b) => a > b ? a : b);

  for (final check in checks) {
    final line =
        '${check.label.padRight(width)}  ${ColorizeLogger.dim(check.detail)}';
    if (check.ok) {
      logger.logSuccess(line);
    } else if (check.optional) {
      logger.logWarning(line);
    } else {
      logger.logError(line);
    }
    if (!check.ok && check.hint != null) logger.logDetail(check.hint!);
  }

  await _printBuiltins();

  final failures = checks.where((c) => !c.ok && !c.optional).length;
  final warnings = checks.where((c) => !c.ok && c.optional).length;

  logger.logEmpty();
  if (failures > 0) {
    logger.logError(
      "$failures required check(s) failed  "
      "${ColorizeLogger.dim("$warnings optional skipped")}",
    );
    return 1;
  }
  logger.logSuccess(
    "all required checks passed"
    "${warnings > 0 ? "  ${ColorizeLogger.dim("$warnings optional tool(s) missing")}" : ""}",
  );
  return 0;
}