execute static method
Implementation
static Future<void> execute(
List<String> commands, {
int concurrent = defaultConcurrent,
void Function(String)? customCommand,
void Function(String line)? stdout,
}) async {
final workingDirectoryFlutter = find('pubspec.yaml', workingDirectory: '.')
.toList()
.map((e) => e.replaceAll('${separator}pubspec.yaml', ''))
.sorted((a, b) =>
b.split(separator).length.compareTo(a.split(separator).length));
List<Future Function()> futures = [];
for (var e in workingDirectoryFlutter) {
futures.add(() async {
final path = e.replaceAll(current, '.');
try {
print('🚀 $path: ${commands.join(', ')}');
for (var command in commands) {
await command.start(
workingDirectory: e,
showLog: false,
progressOut: (line) {
stdout?.call(line);
},
progressErr: (line) {
if (line.isEmpty) return;
if (line.contains('Waiting for another flutter command')) {
return;
}
printerr(red(line));
},
);
}
customCommand?.call(e);
print('✅ $path: ${commands.join(', ')}');
} catch (e) {
print('❌ $path: ${commands.join(', ')}');
rethrow;
}
});
}
int runnable = 0;
final length = futures.length;
print('📦 Total Packages: $length');
print('---------------------------------------');
for (runnable = 0; runnable < length; runnable += concurrent) {
int take =
runnable + concurrent > length ? length % concurrent : concurrent;
final isolate = futures
.getRange(runnable, runnable + take)
.map((e) => Isolate.run(e));
await Future.wait(isolate);
}
}