HTFileSystemResourceContext constructor
HTFileSystemResourceContext({})
Implementation
HTFileSystemResourceContext(
{String? root,
Map<String, HTSource>? cache,
List<HTFilterConfig> includedFilter = const [],
List<HTFilterConfig> excludedFilter = const [],
this.expressionModuleExtensions = const [],
this.binaryModuleExtensions = const [],
bool doScanRoot = false})
: _cached = cache ?? <String, HTSource>{} {
if (root != null) {
this.root = root = getAbsolutePath(dirName: root);
} else {
this.root = root = getAbsolutePath(dirName: path.current);
}
if (doScanRoot) {
final dir = Directory(root);
final folderFilter = HTFilterConfig(root);
final entities = dir.listSync(recursive: true);
for (final filter in includedFilter) {
filter.folder = getAbsolutePath(key: filter.folder, dirName: root);
}
for (final filter in excludedFilter) {
filter.folder = getAbsolutePath(key: filter.folder, dirName: root);
}
for (final entity in entities) {
if (entity is! File) {
continue;
}
final fileFullName = getAbsolutePath(key: entity.path, dirName: root);
var isIncluded = false;
if (includedFilter.isEmpty) {
isIncluded = folderFilter.isWithin(fileFullName);
} else {
for (final filter in includedFilter) {
if (filter.isWithin(fileFullName)) {
isIncluded = true;
break;
}
}
}
if (isIncluded) {
if (excludedFilter.isNotEmpty) {
for (final filter in excludedFilter) {
final isExcluded = filter.isWithin(fileFullName);
if (isExcluded) {
isIncluded = false;
break;
}
}
}
}
if (isIncluded) {
included.add(fileFullName);
}
}
}
}