publish method
Future<List<PublishResult> >
publish(
- FileSystemEntity fileSystemEntity,
- List<
String> targets, { - Map<
String, dynamic> ? publishArguments, - Map<
String, String> ? variables,
inherited
Publish an application to a third party provider
This method publishes an application to a third party provider.
Implementation
Future<List<PublishResult>> publish(
FileSystemEntity fileSystemEntity,
List<String> targets, {
Map<String, dynamic>? publishArguments,
Map<String, String>? variables,
}) async {
List<PublishResult> publishResultList = [];
try {
for (String target in targets) {
ProgressBar progressBar = ProgressBar(
format: 'Publishing to $target: {bar} {value}/{total} {percentage}%',
);
Map<String, dynamic>? newPublishArguments = {};
if (publishArguments != null) {
for (var key in publishArguments.keys) {
// Keep app- prefixed arguments
if (key.startsWith('app-')) {
newPublishArguments.putIfAbsent(
key,
() => publishArguments[key],
);
continue;
}
// Handle target-prefixed arguments, remove the target prefix and keep the rest
if (!key.startsWith('$target-')) continue;
dynamic value = publishArguments[key];
if (value is List) {
// ignore: prefer_for_elements_to_map_fromiterable
value = Map.fromIterable(
value,
key: (e) => e.split('=')[0],
value: (e) => e.split('=')[1],
);
}
newPublishArguments.putIfAbsent(
key.replaceAll('$target-', ''),
() => value,
);
}
}
if (newPublishArguments.keys.isEmpty) {
newPublishArguments = publishArguments;
}
PublishResult publishResult = await _publisher.publish(
fileSystemEntity,
target: target,
environment: variables ?? globalVariables,
publishArguments: newPublishArguments,
onPublishProgress: (sent, total) {
if (!progressBar.isActive) {
progressBar.start(total, sent);
} else {
progressBar.update(sent);
}
},
);
if (progressBar.isActive) progressBar.stop();
logger.info(
'Successfully published ${publishResult.url}'.brightGreen(),
);
publishResultList.add(publishResult);
}
} on Error catch (error) {
logger.severe(error.toString().brightRed());
logger.severe(error.stackTrace.toString().brightRed());
rethrow;
}
return publishResultList;
}