getNativeVersion function
获取CLI的本地版本,需要先配置DART_PUB_HOME
Implementation
Future<String?> getNativeVersion() async {
try {
final lockFile = File(path.join(DART_PUB_HOME, 'global_packages/yuro_cli/pubspec.lock'));
if (lockFile.existsSync()) {
final yamlMap = loadYaml(lockFile.readAsStringSync()) as YamlMap;
return yamlMap['packages']['yuro_cli']['version'].toString();
} else {
throw Exception('Yuo can use command "<dart> pub global activate yuro_cli" to get this cli.');
}
} on Exception catch (err) {
logger.e(err.toString());
return null;
}
}