From dfcffd92f64e381e6a44e7024c2f574a9522b2cb Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 7 Oct 2024 20:10:13 +0200 Subject: [PATCH] wip swift package manager support. first validate old cocoapod support for new sqflite_darwin project --- sqflite_support/lib/spm.dart | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 sqflite_support/lib/spm.dart diff --git a/sqflite_support/lib/spm.dart b/sqflite_support/lib/spm.dart new file mode 100644 index 00000000..6f44428a --- /dev/null +++ b/sqflite_support/lib/spm.dart @@ -0,0 +1,45 @@ +import 'dart:io'; + +import 'package:process_run/shell.dart'; +import 'package:pub_semver/pub_semver.dart'; + +/// Check if spm is enabled +Future flutterHasSpmEnabled() async { + var lines = (await run('flutter config --list', verbose: false)).outLines; + for (var line in lines) { + var parts = line.split(':').map((e) => e.trim()).toList(); + if (parts.length == 2) { + if (parts[0] == 'enable-swift-package-manager') { + return parts[1] == 'true'; + } + } + } + return false; +} + +/// Min supported SPM version (as of 2024-10-07 on main channel) +var minSpmFlutterVersion = Version(3, 26, 0, pre: '0'); + +/// Enable spm +Future enableSpm() async { + var flutterVersion = (await getFlutterBinVersion())!; + if (flutterVersion < minSpmFlutterVersion) { + throw 'Flutter version $flutterVersion is not supported for spm (min: $minSpmFlutterVersion)'; + } + var spmEnabled = await flutterHasSpmEnabled(); + if (spmEnabled) { + stdout.writeln('SPM already enabled'); + return; + } + await run('flutter config --enable-swift-package-manager'); +} + +/// Enable spm +Future disableSpm() async { + var spmEnabled = await flutterHasSpmEnabled(); + if (!spmEnabled) { + stdout.writeln('SPM already disabled'); + return; + } + await run('flutter config --no-enable-swift-package-manager'); +}