writeOutputs method

OutputWriter writeOutputs(
  1. List<OutputTask> tasks
)

Converts the given tasks into files and writes them.

Implementation

OutputWriter writeOutputs(List<OutputTask> tasks) {
  for (var task in tasks) {
    final outputDir = task.outputPath.getDir();
    if (outputDir.isNotEmpty && !exists(outputDir)) {
      createDir(outputDir, recursive: true);
    }

    final writeMethod = task.writeMethod;

    // Keep existing file
    if (writeMethod is KeepExistingFile) {
      if (!exists(task.outputPath)) task.outputPath.write(task.fileContent);
    }

    // Replace existing file
    else if (writeMethod is ReplaceExistingFile) {
      task.outputPath.write(task.fileContent);
    }

    // Replace file
    else if (writeMethod is ExtendFile) {
      if (exists(task.outputPath)) {
        _extendFile(task, writeMethod.extendAt);
      } else {
        task.outputPath.write(task.fileContent);
      }
    }
  }

  return this;
}