generateDartCode method
Generate Dart code in path
.
You can edit the data inside with filter
.
path
にDartコードを生成します。
filter
で中身のデータを編集することができます。
Implementation
Future<void> generateDartCode(
String path,
String className, {
String ext = "dart",
String Function(String value)? filter,
}) async {
final baseName = path.last();
final trimedPath = _trimPathPrefix(path);
final editClassName =
className.split("/").distinct().join("_").toPascalCase();
final dir = Directory(path.replaceAll("/$baseName", ""));
if (!dir.existsSync()) {
await dir.create(recursive: true);
}
final output = _removeCodeSnippetValue(
"${import(trimedPath, baseName, editClassName)}\n${header(trimedPath, baseName, editClassName)}\n${body(trimedPath, baseName, editClassName)}",
);
await File("$path.$ext").writeAsString(filter?.call(output) ?? output);
}