editFileContent static method

void editFileContent(
  1. String path,
  2. String newContent, {
  3. bool canFormated = true,
  4. bool showLog = true,
})

Implementation

static void editFileContent(String path, String newContent,
    {bool canFormated = true, bool showLog = true}) {
  final file = File(path);
  if (file.existsSync()) {
    file.writeAsStringSync(canFormated
        ? DartFormatter(languageVersion: DartFormatter.latestLanguageVersion)
            .format(newContent)
        : newContent);
    if (showLog) {
      stdout.write(
          '${ColorsText.green}  ✓${ColorsText.reset} Updated file: ${ColorsText.cyan}$path${ColorsText.reset}\n');
    }
  } else {
    createFileWithContent(path, newContent);
  }
}