run method

Future<void> run(
  1. HookPoint point,
  2. HookContext context
)

Runs every command registered for point, in order.

Implementation

Future<void> run(HookPoint point, HookContext context) async {
  final commands = load()[point] ?? const [];
  if (commands.isEmpty) return;

  final environment = context.toEnvironment(point);
  for (final command in commands) {
    Logger.info('Running ${point.key} hook: `$command`');
    final int exitCode;
    try {
      final process = await Process.start(
        _shell,
        [_shellFlag, command],
        workingDirectory: projectDir,
        environment: environment,
        mode: ProcessStartMode.inheritStdio,
      );
      exitCode = await process.exitCode;
    } catch (e, s) {
      throw BuildException(
        'Could not start ${point.key} hook `$command`: $e',
        fix: 'Check the command in $configFileName.',
        originalStackTrace: s,
      );
    }
    if (exitCode != 0) {
      throw BuildException(
        '${point.key} hook failed with exit code $exitCode: `$command`',
        fix: 'Fix the hook (see its output above) or remove it from '
            '$configFileName. Hooks receive UDARA_CLIENT, UDARA_CLIENT_DIR, '
            'UDARA_BUNDLE_ID and other UDARA_* variables.',
      );
    }
  }
}