runScripts static method

Future<void> runScripts(
  1. List<String> commands,
  2. String workingDirectory,
  3. CommandLogger logger, {
  4. required String scriptType,
  5. int padHeadingRight = 0,
  6. IOSink? stdout,
  7. IOSink? stderr,
})

Implementation

static Future<void> runScripts(
  final List<String> commands,
  final String workingDirectory,
  final CommandLogger logger, {
  required final String scriptType,
  final int padHeadingRight = 0,
  final IOSink? stdout,
  final IOSink? stderr,
}) async {
  if (commands.isEmpty) {
    return;
  }

  logger.info('Running $scriptType scripts:', newParagraph: true);
  for (var i = 0; i < commands.length; i++) {
    final command = commands[i];

    int exitCode;
    try {
      exitCode = await _runScript(
        command,
        heading: '(${i + 1}/${commands.length}) $command'.padRight(
          padHeadingRight,
        ),
        workingDirectory: workingDirectory,
        logger: logger,
        stdout: stdout,
        stderr: stderr,
      );
    } on Exception catch (e, stackTrace) {
      throw ErrorExitException(
        '$scriptType script failed: "$command"',
        e,
        stackTrace,
      );
    }
    if (exitCode != 0) {
      throw ErrorExitException(
        '$scriptType script failed with exit code $exitCode: "$command"',
      );
    }
  }
}