Skip to content

Commit

Permalink
DYN-6901 Pm - retainfolderstructure rework (#15357)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnenov authored Jul 16, 2024
1 parent 29ff5e5 commit 3d4cedd
Show file tree
Hide file tree
Showing 10 changed files with 388 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,9 @@ public bool RetainFolderStructureOverride
/// <summary>
/// The root directory of the package
/// </summary>
private string CurrentPackageDirectory { get; set; }
private IEnumerable<string> CurrentPackageRootDirectories { get; set; }
private static MetadataLoadContext sharedMetaDataLoadContext = null;

/// <summary>
/// A shared MetaDataLoadContext that is used for assembly inspection during package publishing.
/// This member is shared so the behavior is similar to the ReflectionOnlyLoadContext this is replacing.
Expand Down Expand Up @@ -1073,34 +1074,30 @@ internal List<PackageItemRootViewModel> BindParentToChild(Dictionary<string, Pac
}

// Only add the folder items, they contain the files
var updatedItems = GetRootItems(items);
var updatedItems = OrganizePackageRootItems(items);
return updatedItems;
}

/// <summary>
/// Gets the list PackageItemRootViewModel items which will be at the root directory of the package with all the child items.
/// Organizes package items into root items based on common paths and hierarchical structure.
/// This includes determining root items, establishing parent-child relationships, and collecting all child items.
/// </summary>
/// <param name="items"></param>
/// <returns></returns>
private List<PackageItemRootViewModel> GetRootItems(Dictionary<string, PackageItemRootViewModel> items)
/// <param name="items">A dictionary of package item keys and their corresponding PackageItemRootViewModel objects.</param>
/// <returns>A list of PackageItemRootViewModel items representing the organized root items and their child items.</returns>
private List<PackageItemRootViewModel> OrganizePackageRootItems(Dictionary<string, PackageItemRootViewModel> items)
{
var rootItems = items.Values.Where(x => !x.isChild).ToList();
if (!rootItems.Any()) return rootItems;

var roots = new List<PackageItemRootViewModel>();

var commonPaths = GetCommonPaths(items.Keys.ToArray());
if (commonPaths == null) return null;

if (CurrentPackageDirectory != null)
{
roots.Add(new PackageItemRootViewModel(CurrentPackageDirectory));
}
else
{
var commonPaths = GetCommonPaths(items.Keys.ToArray());
if (commonPaths == null) return null;
CurrentPackageRootDirectories = commonPaths;

// Add a new root item for each common path found
commonPaths.ForEach(p => roots.Add(new PackageItemRootViewModel(p)));
}
// Add a new root item for each common path found
commonPaths.ForEach(p => roots.Add(new PackageItemRootViewModel(p)));

// Check each root item and create any missing connections
foreach (var item in rootItems)
Expand Down Expand Up @@ -1532,7 +1529,7 @@ internal static PublishPackageViewModel FromLocalPackage(DynamoViewModel dynamoV
CopyrightHolder = pkg.CopyrightHolder,
CopyrightYear = pkg.CopyrightYear,
IsPublishFromLocalPackage = true,
CurrentPackageDirectory = pkg.RootDirectory,
CurrentPackageRootDirectories = new List<string> { pkg.RootDirectory },
//default retain folder structure to true when publishing a new version from local.
RetainFolderStructureOverride = retainFolderStructure
};
Expand Down Expand Up @@ -2270,7 +2267,7 @@ private void Submit()
{
// begin submission
var pmExtension = dynamoViewModel.Model.GetPackageManagerExtension();
var handle = pmExtension.PackageManagerClient.PublishAsync(Package, RetainFolderStructureOverride ? updatedFiles : contentFiles, MarkdownFiles, IsNewVersion, RetainFolderStructureOverride);
var handle = pmExtension.PackageManagerClient.PublishAsync(Package, RetainFolderStructureOverride ? updatedFiles : contentFiles, MarkdownFiles, IsNewVersion, CurrentPackageRootDirectories, RetainFolderStructureOverride);

// start upload
Uploading = true;
Expand Down Expand Up @@ -2365,11 +2362,7 @@ private void PublishLocally()
var remapper = new CustomNodePathRemapper(DynamoViewModel.Model.CustomNodeManager,
DynamoModel.IsTestMode);
var builder = new PackageDirectoryBuilder(new MutatingFileSystem(), remapper);
if (string.IsNullOrEmpty(Package.RootDirectory))
{
Package.RootDirectory = CurrentPackageDirectory;
}
builder.BuildRetainDirectory(Package, publishPath, updatedFiles, MarkdownFiles);
builder.BuildRetainDirectory(Package, publishPath, CurrentPackageRootDirectories, updatedFiles, MarkdownFiles);
UploadState = PackageUploadHandle.State.Uploaded;
}
else
Expand Down Expand Up @@ -2770,11 +2763,11 @@ internal PackageItemRootViewModel GetExistingRootItemViewModel(string publishPat
{
if (!PackageContents.Any()) return null;
if (PackageContents.Count(x => x.DependencyType.Equals(DependencyType.Folder)) == 1) {
// If there is only one root item, nest it under the new root package folder
// If there is only one root item, this root item becomes the new folder
var item = PackageContents.First(x => x.DependencyType.Equals(DependencyType.Folder));

item = new PackageItemRootViewModel(Path.Combine(publishPath, packageName));
item.AddChildren(new List<PackageItemRootViewModel> { PackageContents.First() } );
item.AddChildren( PackageContents.First().ChildItems.ToList() );

return item;
}
Expand All @@ -2783,6 +2776,9 @@ internal PackageItemRootViewModel GetExistingRootItemViewModel(string publishPat
var rootItem = new PackageItemRootViewModel(Path.Combine(publishPath, packageName));
foreach(var item in PackageContents)
{
// Skip 'bare' custom nodes, they will be represented by their CustomNodePreview counterparts
if(item.DependencyType.Equals(DependencyType.CustomNode)) { continue; }

item.isChild = true;
rootItem.AddChildren(item);
}
Expand Down
Loading

0 comments on commit 3d4cedd

Please sign in to comment.