prepareWorkspacePaths static method
Analyzes the workspace, creates bespoke deployment files, and compiles the list of paths whose contents are to be included.
Returns a tuple with the workspace root directory and the list of subpaths in the root directory to include.
If the preparation fails, error messages will be logged and WorkspaceException is thrown.
Implementation
static (Directory, Iterable<String>) prepareWorkspacePaths(
final Directory projectDirectory,
) {
final String projectPackageName = _getPackageName(projectDirectory);
// Find workspace root directory by traversing up until we find a pubspec.yaml with workspace field
final (workspaceRootDir, workspacePubspec) =
findWorkspaceRoot(projectDirectory);
// create map with all workspace packages, map from package name to [WorkspacePackage]
final allWorkspacePackages = <String, WorkspacePackage>{};
for (final packagePath in workspacePubspec.workspace ?? []) {
final pubspec = Pubspec.parse(
File(
p.join(workspaceRootDir.path, packagePath, 'pubspec.yaml'),
).readAsStringSync(),
);
allWorkspacePackages[pubspec.name] = WorkspacePackage(
Directory(packagePath),
pubspec,
);
}
final projectPackage = allWorkspacePackages[projectPackageName];
if (projectPackage == null) {
_throwWorkspaceException(
message:
"The project's package wasn't found among the workspace's packages.",
);
}
final includedPackages = WorkspaceProjectLogic.getWorkspaceDependencies(
allWorkspacePackages: allWorkspacePackages,
package: projectPackage,
included: <String, WorkspacePackage>{
projectPackageName: projectPackage,
},
);
WorkspaceProjectLogic.validateIncludedPackages(
includedPackages.values.map((final package) => package.pubspec),
);
final includedPackagePaths = includedPackages.values
.map((final package) => package.dir.path)
.toList();
_writeSCloudFiles(
workspaceRootDir,
includedPackagePaths,
projectPackage,
);
final includedPaths = [
...includedPackagePaths,
ScloudIgnore.scloudDirName,
];
return (workspaceRootDir, includedPaths);
}