manuallyUpsertAppFile method Null safety

Future<File> manuallyUpsertAppFile(
  1. String path,
  2. String contents
)

Create or write to file.

Implementation

Future<File> manuallyUpsertAppFile(String path, String contents) async {
  final dirName = path.split('/').first;

  if (!dirName.contains('.dart')) {
    final dir = Directory(p.join('lib', 'app', dirName));
    final dirExists = await dir.exists();
    if (!dirExists) {
      await dir.create();
    }
  }

  final newFile = File(p.join('lib', 'app', path));
  final fileExists = await newFile.exists();
  if (!fileExists) {
    await newFile.create();
  }
  final writtenFile = await newFile.writeAsString(contents);
  return writtenFile;
}