fileUpdate function

Future<void> fileUpdate(
  1. String destinationPath,
  2. List<String> apiResponseImport,
  3. List<String> dataSourceAppendLines,
  4. [bool isAppendEOF = false]
)

Implementation

Future<void> fileUpdate(String destinationPath, List<String> apiResponseImport,
    List<String> dataSourceAppendLines,
    [bool isAppendEOF = false]) async {
  if (doesFileExist(destinationPath)) {
    try {
      if (apiResponseImport.isNotEmpty) {
        await addImport(destinationPath, apiResponseImport);
      }
      if (isAppendEOF) {
        await appendLinesToFile(destinationPath, dataSourceAppendLines);
      } else {
        await findAndReplace(destinationPath, '{}', '{\n}');
        await addCodeAboveBraces(destinationPath, dataSourceAppendLines);
      }
    } catch (e) {
      print('Error: $e');
    }
  } else {
    print('File at $destinationPath not exists');
  }
}