writeFile function
Write content to a file
Implementation
bool writeFile({
required String cwd,
required String content,
bool force = false,
}) {
// Extract the directory path from the full path
final directoryPath = path.dirname(cwd);
if (fileExist(cwd) && !force) {
return false;
}
try {
// Create the directory if it doesn't exist
if (!Directory(directoryPath).existsSync()) {
Directory(directoryPath).createSync(recursive: true);
}
final file = File(cwd);
file.writeAsStringSync(content);
return true;
} catch (e) {
logger.e('Failed to create directory: $directoryPath', error: e);
return false;
}
}