downloadProtoc function
Downloads the protoc compiler for version
.
Implementation
Future<void> downloadProtoc(String version) async {
final platformString = {
'windows': 'win64',
'macos': 'osx-x86_64',
'linux': 'linux-x86_64'
}[Platform.operatingSystem] ??
'unsupported';
if (platformString == 'unsupported') throw 'unsupported platform';
final protocExe = Platform.isWindows ? 'protoc.exe' : 'protoc';
final downloadUri =
Uri.parse('https://github.com/protocolbuffers/protobuf/releases/'
'download/v$version/protoc-$version-$platformString.zip');
protoc = path.join(compilerDirectory.path, 'bin', protocExe);
if (await File(protoc).exists()) {
return;
}
stdout.write('${progressBar(0, colorCompleted: penDone)} '
'downloading dart protoc plugin');
final bytes = await _getWithProgress(downloadUri, (progress) {
final bar = progressBar(progress, colorCompleted: penDone);
stdout
..moveFarLeft()
..write(bar);
});
final bar = progressBar(1.0, colorCompleted: penDone);
stdout
..moveFarLeft()
..write(bar);
stdout.writeln();
stdout
..moveFarLeft()
..write('${progressBar(0, colorCompleted: penDone)} uncompressing protoc');
await unzip(bytes, compilerDirectory.path, progress: (progress) {
stdout
..moveFarLeft()
..write(progressBar(progress, colorCompleted: penDone));
});
stdout.writeln();
if (!Platform.isWindows) {
await Process.run('chmod', ['+x', protoc]);
}
}