run method

dynamic run()

Executes the configured command and prints stdout and stderr with colored formatting.

  • Green for success output
  • Blue for warnings
  • Red for errors

The method returns a Future that completes after the command runs.

Implementation

dynamic run() async {
  if (executable == "dart") {
    _addStoredEnvironmentVarsToArguments();
  }
  final stopwatch = Stopwatch()..start();
  final taskSpinner = Spinner(AnsiStyles.cyan(
      "✔ [task ${AnsiStyles.cyanBright.bold(name)}${AnsiStyles.cyan("] started...")}"));
  taskSpinner.start();
  var result = await Process.run(
    executable,
    arguments,
    workingDirectory: workingDirectory,
  );
  taskSpinner.stop();
  stopwatch.stop();

  final taskStdOut = result.stdout.toString();
  final isDartCompileTask = executable == "dart" && arguments.contains("compile");
  final isDartCompileError = isDartCompileTask && taskStdOut.contains("Error");
  // final isDartCompileWarning = isDartCompileTask && taskStdOut.contains("Warning");

  // Print non dart compile errors - e.g `dart sass ...`
  if (result.stderr.toString().trim().isNotEmpty && !isDartCompileTask) {
    _printNoneDartCompileTaskErrors(result);
  }

  // Print non dart compile warnings
  _printNonDartCompileTaskWarnings(result);

  // Print Dart compile errors
  if (isDartCompileError) {
    _printDartCompileTaskErrors(taskStdOut);
  } else {
    // All dart tasks get printed here
    _printDartTaskSuccess(stopwatch);
  }
}