readRepositoryUrl function
Reads the canonical repository URL of the project at directory.
- Dart / Flutter:
repository:inpubspec.yaml. - TypeScript:
repositoryinpackage.json(either the shorthand string form or the{ "type": "git", "url": "..." }object form).
The returned URL is normalized: git+ prefix and trailing .git or /
are stripped so the value is usable as a browsable web URL.
Throws an Exception if no repository URL can be found.
Implementation
Future<String> readRepositoryUrl(Directory directory) async {
final type = detectProjectType(directory);
return switch (type) {
ProjectType.dart || ProjectType.flutter => _readFromPubspec(directory),
ProjectType.typescript => _readFromPackageJson(directory),
ProjectType.none => throw Exception(
cError('No repository URL: the project has no manifest.'),
),
};
}