writeFile method
Implementation
Future<void> writeFile(Template markdownPage) async {
try {
// [WikiTemplate] files are written in the parent folder.
// Therefore not using the 2 following lines because they
// do not allow to write outside the project:
// AssetId assetId = markdownPage.destinationFilePath.toAssetId();
// buildStep.writeAsString(assetId, contents);
FutureOr<String> contents = markdownPage
.toString()
.replaceAll('\r\n', '\n')
.replaceAll('\n', '\r\n');
var filePath = markdownPage.destinationFilePath.absoluteFilePath;
File(filePath).writeAsString(await contents);
log.log(Level.INFO, 'Wrote file: $filePath');
} on Exception catch (e, stackTrace) {
log.log(
Level.SEVERE,
'Could not write file: ${markdownPage.destinationFilePath}. Error: \n$e',
stackTrace);
}
}