replaceInFile method

void replaceInFile(
  1. String path,
  2. Map<String, String> replacements
)

Replaces strings in a file's content.

Implementation

void replaceInFile(String path, Map<String, String> replacements) {
  try {
    String content = readFile(path);
    replacements.forEach((target, replacement) {
      content = content.replaceAll(target, replacement);
    });
    writeFile(path, content);
  } catch (e) {
    throw CliException('Failed to perform replacements in file $path', e);
  }
}