16 lines
443 B
Dart
16 lines
443 B
Dart
import "package:path/path.dart" as p;
|
|
|
|
String shortenPath(String fullPath, String? projectRoot) {
|
|
if (projectRoot == null || projectRoot.isEmpty) return fullPath;
|
|
|
|
final root = p.normalize(projectRoot);
|
|
final norm = p.normalize(fullPath);
|
|
|
|
if (norm.startsWith(root)) {
|
|
final rel = norm.substring(root.length);
|
|
// trim leading separator
|
|
return rel.startsWith(p.separator) ? rel.substring(1) : rel;
|
|
}
|
|
|
|
return fullPath;
|
|
}
|