|
| 1 | +/// Downloads the powersync-core dynamic library to run the demos using melos |
| 2 | +/// This is only necessary in the monorepo setup |
| 3 | +import 'dart:io'; |
| 4 | + |
| 5 | +final coreUrl = |
| 6 | + 'https://github.com/powersync-ja/powersync-sqlite-core/releases/download/v0.1.8'; |
| 7 | + |
| 8 | +void main() async { |
| 9 | + final powersyncLibsLinuxPath = "packages/powersync_flutter_libs/linux"; |
| 10 | + final powersyncLibsWindowsPath = "packages/powersync_flutter_libs/windows"; |
| 11 | + |
| 12 | + final linuxArm64FileName = "libpowersync_aarch64.so"; |
| 13 | + final linuxX64FileName = "libpowersync_x64.so"; |
| 14 | + final windowsX64FileName = "powersync_x64.dll"; |
| 15 | + |
| 16 | + // Download dynamic library |
| 17 | + await downloadFile("$coreUrl/$linuxArm64FileName", |
| 18 | + "$powersyncLibsLinuxPath/$linuxArm64FileName"); |
| 19 | + await downloadFile("$coreUrl/$linuxX64FileName", |
| 20 | + "$powersyncLibsLinuxPath/$linuxX64FileName"); |
| 21 | + await downloadFile("$coreUrl/$windowsX64FileName", |
| 22 | + "$powersyncLibsWindowsPath/$windowsX64FileName"); |
| 23 | +} |
| 24 | + |
| 25 | +Future<void> downloadFile(String url, String savePath) async { |
| 26 | + print('Downloading: $url'); |
| 27 | + var httpClient = HttpClient(); |
| 28 | + var request = await httpClient.getUrl(Uri.parse(url)); |
| 29 | + var response = await request.close(); |
| 30 | + if (response.statusCode == HttpStatus.ok) { |
| 31 | + var file = File(savePath); |
| 32 | + await response.pipe(file.openWrite()); |
| 33 | + } else { |
| 34 | + print( |
| 35 | + 'Failed to download file: ${response.statusCode} ${response.reasonPhrase}'); |
| 36 | + } |
| 37 | +} |
0 commit comments