copyTemplate function
Implementation
Future<void> copyTemplate(
Directory target,
Uri templatePath,
List<Template> templates,
Map<String, String Function(String)> replacer,
List<String> unsupportedPlatforms,
List<String> remove,
) async {
final directories = <String, Directory>{};
final files = <String, File>{};
for (final template in templates) {
await _collect(
templatePath,
template,
directories,
files,
unsupportedPlatforms,
remove,
);
}
for (final rm in remove) {
final path = target.path + Platform.pathSeparator + rm;
// ignore: exhaustive_cases
switch (FileSystemEntity.typeSync(path)) {
case FileSystemEntityType.directory:
Directory(path).deleteSync(recursive: true);
case FileSystemEntityType.file:
File(path).deleteSync(recursive: true);
}
}
for (final e in directories.entries) {
Directory(target.path + Platform.pathSeparator + e.key).createSync();
}
for (final e in files.entries) {
final targetFile = target.path + Platform.pathSeparator + e.key;
if (_replace(e.key, e.value.path, targetFile, replacer)) {
continue;
}
await _copyMutable(e.value, targetFile);
}
for (final rm in unsupportedPlatforms) {
try {
Directory(
target.path + Platform.pathSeparator + rm,
).deleteSync(recursive: true);
} on PathNotFoundException catch (_) {}
}
}