publish method
Future<void>
publish({
- GlobalOptions? global,
- PackageFilter? filter,
- bool dryRun = true,
- bool gitTagVersion = true,
- bool force = false,
inherited
Implementation
Future<void> publish({
GlobalOptions? global,
PackageFilter? filter,
bool dryRun = true,
bool gitTagVersion = true,
// yes
bool force = false,
}) async {
final workspace = await createWorkspace(global: global, filter: filter);
logger.command('melos publish${dryRun ? " --dry-run" : ''}');
logger.child(targetStyle(workspace.path)).newLine();
final readRegistryProgress =
logger.progress('Reading pub registry for package information');
Map<String, String?> latestPublishedVersionForPackages;
try {
latestPublishedVersionForPackages =
await _getLatestPublishedVersionForPackages(workspace);
} finally {
readRegistryProgress.finish(
message: successLabel,
showTiming: true,
);
}
final unpublishedPackages = <Package>[
for (final entry in latestPublishedVersionForPackages.entries)
if (entry.value == null ||
entry.value !=
workspace.filteredPackages[entry.key]!.version.toString())
workspace.filteredPackages[entry.key]!,
];
if (unpublishedPackages.isEmpty) {
logger
..newLine()
..success(
'No unpublished packages found - '
'all local packages are already up to date.',
);
return;
}
sortPackagesTopologically(unpublishedPackages);
logger
..newLine()
..warning(
AnsiStyles.bold(
dryRun
? 'The following packages will be validated only (dry run):'
: 'The following packages WILL be published to the registry:',
),
label: false,
dryRun: dryRun,
)
..newLine();
logger.stdout(
listAsPaddedTable(
[
[
AnsiStyles.underline.bold('Package Name'),
AnsiStyles.underline.bold('Registry'),
AnsiStyles.underline.bold('Local'),
],
...unpublishedPackages.map((package) {
return [
AnsiStyles.italic(package.name),
AnsiStyles.dim(latestPublishedVersionForPackages[package.name]),
AnsiStyles.green(package.version.toString()),
];
})
],
paddingSize: 4,
),
);
if (!force) {
final shouldContinue = promptBool();
if (!shouldContinue) throw CancelledException();
logger.newLine();
}
await _publish(
workspace,
unpublishedPackages,
dryRun: dryRun,
gitTagVersion: gitTagVersion,
);
}