Skip to content

Commit

Permalink
wip swift package manager support. first validate old cocoapod suppor…
Browse files Browse the repository at this point in the history
…t for new sqflite_darwin project
  • Loading branch information
alextekartik committed Oct 7, 2024
1 parent f31da03 commit dfcffd9
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions sqflite_support/lib/spm.dart
Original file line number Diff line number Diff line change
@@ -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<bool> 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<void> 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<void> disableSpm() async {
var spmEnabled = await flutterHasSpmEnabled();
if (!spmEnabled) {
stdout.writeln('SPM already disabled');
return;
}
await run('flutter config --no-enable-swift-package-manager');
}

0 comments on commit dfcffd9

Please sign in to comment.