makePlaybookFile function
Creates the playbook name (in snake case) holding contents in
folderPath, inside creationPath when it's given, and returns its path.
Exits when the file already exists, unless forceCreate.
Implementation
Future<String> makePlaybookFile(
String name,
String contents, {
String folderPath = playbooksFolder,
bool forceCreate = false,
String? creationPath,
}) async {
await MetroService.makeDirectory(folderPath);
await MetroService.createDirectoriesFromCreationPath(
creationPath,
folderPath,
);
final String filePath = MetroService.createPathForDartFile(
folderPath: folderPath,
className: name,
prefix: "playbook",
creationPath: creationPath,
);
final File file = File(filePath);
if (file.existsSync() && !forceCreate) {
MetroConsole.writeInRed('$filePath already exists');
exit(1);
}
await file.writeAsString(contents);
final String link = MetroConsole.hyperlink('${name}_playbook', filePath);
MetroConsole.writeInGreen('[Playbook] $link created 🎉');
return filePath;
}