Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include all files from Markdown Directory to published package #13607

Merged
merged 8 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1088,8 +1088,6 @@ internal IEnumerable<string> GetAllFiles()

// union with additional files
files = files.Union(AdditionalFiles);
// union with optional markdown files from directory
files = files.Union(MarkdownFiles);
files = files.Union(Assemblies.Select(x => x.Assembly.Location));

return files;
Expand Down Expand Up @@ -1332,12 +1330,12 @@ private void SelectMarkdownDirectory()
}
MarkdownFilesDirectory = directoryPath;

// Append all md files from the directory to files list without affect the package content UI
// Store all files paths from the markdown directory to list without affecting the package content UI
MarkdownFiles = Directory
.GetFiles
(
directoryPath,
"*.md",
"*",
SearchOption.AllDirectories
).ToList();
}
Expand Down Expand Up @@ -1502,18 +1500,18 @@ private void Submit()
{
return;
}
var files = BuildPackage();
var contentFiles = BuildPackage();
try
{
//if buildPackage() returns no files then the package
//is empty so we should return
if (files == null || files.Count() < 1)
if (contentFiles == null || contentFiles.Count() < 1)
{
return;
}
// begin submission
var pmExtension = dynamoViewModel.Model.GetPackageManagerExtension();
var handle = pmExtension.PackageManagerClient.PublishAsync(Package, files, IsNewVersion);
var handle = pmExtension.PackageManagerClient.PublishAsync(Package, contentFiles, MarkdownFiles, IsNewVersion);

// start upload
Uploading = true;
Expand Down Expand Up @@ -1600,7 +1598,7 @@ private void PublishLocally()
var remapper = new CustomNodePathRemapper(DynamoViewModel.Model.CustomNodeManager,
DynamoModel.IsTestMode);
var builder = new PackageDirectoryBuilder(new MutatingFileSystem(), remapper);
builder.BuildDirectory(Package, publishPath, files);
builder.BuildDirectory(Package, publishPath, files, MarkdownFiles);
UploadState = PackageUploadHandle.State.Uploaded;

// Once upload is successful, a display message will appear to ask
Expand Down
45 changes: 27 additions & 18 deletions src/DynamoPackages/PackageDirectoryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Dynamo.PackageManager
{
public interface IPackageDirectoryBuilder
{
IDirectoryInfo BuildDirectory(Package packages, string packagesDirectory, IEnumerable<string> files);
IDirectoryInfo BuildDirectory(Package packages, string packagesDirectory, IEnumerable<string> files, IEnumerable<string> markdownfiles);
}

/// <summary>
Expand All @@ -34,11 +34,8 @@ internal class PackageDirectoryBuilder : IPackageDirectoryBuilder
/// <param name="pathRemapper">For modifying custom node paths</param>
internal PackageDirectoryBuilder(IFileSystem fileSystem, IPathRemapper pathRemapper)
{
if (fileSystem == null) throw new ArgumentNullException("fileSystem");
if (pathRemapper == null) throw new ArgumentNullException("pathRemapper");

this.fileSystem = fileSystem;
this.pathRemapper = pathRemapper;
this.fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
this.pathRemapper = pathRemapper ?? throw new ArgumentNullException(nameof(pathRemapper));
}

#region Public Class Operational Methods
Expand All @@ -50,18 +47,16 @@ internal PackageDirectoryBuilder(IFileSystem fileSystem, IPathRemapper pathRemap
/// <param name="packagesDirectory">The parent directory for the parent directory</param>
/// <param name="files">The collection of files to be moved</param>
/// <returns></returns>
public IDirectoryInfo BuildDirectory(Package package, string packagesDirectory, IEnumerable<string> files)
public IDirectoryInfo BuildDirectory(Package package, string packagesDirectory, IEnumerable<string> contentFiles, IEnumerable<string> markdownFiles)
{
IDirectoryInfo rootDir, dyfDir, binDir, extraDir, docDir;

FormPackageDirectory(packagesDirectory, package.Name, out rootDir, out dyfDir, out binDir, out extraDir, out docDir); // shouldn't do anything for pkg versions
FormPackageDirectory(packagesDirectory, package.Name, out IDirectoryInfo rootDir, out IDirectoryInfo dyfDir, out IDirectoryInfo binDir, out IDirectoryInfo extraDir, out IDirectoryInfo docDir); // shouldn't do anything for pkg versions
package.RootDirectory = rootDir.FullName;

WritePackageHeader(package, rootDir);
RemoveUnselectedFiles(files, rootDir);
CopyFilesIntoPackageDirectory(files, dyfDir, binDir, extraDir, docDir);
RemoveDyfFiles(files, dyfDir);
RemapCustomNodeFilePaths(files, dyfDir.FullName);
RemoveUnselectedFiles(contentFiles, rootDir);
CopyFilesIntoPackageDirectory(contentFiles, markdownFiles, dyfDir, binDir, extraDir, docDir);
RemoveDyfFiles(contentFiles, dyfDir);
RemapCustomNodeFilePaths(contentFiles, dyfDir.FullName);

return rootDir;
}
Expand Down Expand Up @@ -145,9 +140,9 @@ private void WritePackageHeader(Package package, IDirectoryInfo rootDir)
}


internal void CopyFilesIntoPackageDirectory(IEnumerable<string> files, IDirectoryInfo dyfDir,
IDirectoryInfo binDir, IDirectoryInfo extraDir,
IDirectoryInfo docDir)
internal void CopyFilesIntoPackageDirectory(IEnumerable<string> files, IEnumerable<string> markdownFiles,
IDirectoryInfo dyfDir, IDirectoryInfo binDir,
IDirectoryInfo extraDir, IDirectoryInfo docDir)
{
// normalize the paths to ensure correct comparison
var dyfDirPath = NormalizePath(dyfDir.FullName);
Expand All @@ -166,7 +161,7 @@ internal void CopyFilesIntoPackageDirectory(IEnumerable<string> files, IDirector
// determine which folder to put the file in
string targetFolder = extraDirPath;

if (Path.GetDirectoryName(file).EndsWith(DocumentationDirectoryName) || file.EndsWith(".md"))
if (Path.GetDirectoryName(file).EndsWith(DocumentationDirectoryName))
{
targetFolder = docDirPath;
}
Expand All @@ -192,6 +187,20 @@ internal void CopyFilesIntoPackageDirectory(IEnumerable<string> files, IDirector
fileSystem.DeleteFile(destPath);
}

fileSystem.CopyFile(file, destPath);
}
// All files under Markdown directory do not apply to the rule above,
// because they may fall into extra folder instead of docs folder,
// currently there is on obvious way to filter them properly only based on path string.
foreach (var file in markdownFiles.Where(x => x != null))
{
var destPath = Path.Combine(docDirPath, Path.GetFileName(file));

if (fileSystem.FileExists(destPath))
{
fileSystem.DeleteFile(destPath);
}

fileSystem.CopyFile(file, destPath);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/DynamoPackages/PackageManagerClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Dynamo.Graph.Workspaces;
Expand Down Expand Up @@ -207,33 +207,33 @@ private bool ExecuteTermsOfUseCall(bool queryAcceptanceStatus)
}, false);
}

internal PackageUploadHandle PublishAsync(Package package, IEnumerable<string> files, bool isNewVersion)
internal PackageUploadHandle PublishAsync(Package package, IEnumerable<string> files, IEnumerable<string> markdownFiles, bool isNewVersion)
{
var packageUploadHandle = new PackageUploadHandle(PackageUploadBuilder.NewRequestBody(package));

Task.Factory.StartNew(() =>
{
Publish(package, files, isNewVersion, packageUploadHandle);
Publish(package, files, markdownFiles, isNewVersion, packageUploadHandle);
});

return packageUploadHandle;
}

internal void Publish(Package package, IEnumerable<string> files, bool isNewVersion, PackageUploadHandle packageUploadHandle)
internal void Publish(Package package, IEnumerable<string> files, IEnumerable<string> markdownFiles, bool isNewVersion, PackageUploadHandle packageUploadHandle)
{
try
{
ResponseBody ret = null;
if (isNewVersion)
{
var pkg = uploadBuilder.NewPackageVersionUpload(package, packageUploadDirectory, files,
var pkg = uploadBuilder.NewPackageVersionUpload(package, packageUploadDirectory, files, markdownFiles,
packageUploadHandle);
packageUploadHandle.UploadState = PackageUploadHandle.State.Uploading;
ret = this.client.ExecuteAndDeserialize(pkg);
}
else
{
var pkg = uploadBuilder.NewPackageUpload(package, packageUploadDirectory, files,
var pkg = uploadBuilder.NewPackageUpload(package, packageUploadDirectory, files, markdownFiles,
packageUploadHandle);
packageUploadHandle.UploadState = PackageUploadHandle.State.Uploading;
ret = this.client.ExecuteAndDeserialize(pkg);
Expand Down
39 changes: 29 additions & 10 deletions src/DynamoPackages/PackageUploadBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand All @@ -9,11 +9,11 @@ namespace Dynamo.PackageManager
{
public interface IPackageUploadBuilder
{
PackageUpload NewPackageUpload(Package package, string packagesDirectory, IEnumerable<string> files,
PackageUpload NewPackageUpload(Package package, string packagesDirectory, IEnumerable<string> files, IEnumerable<string> markdownFiles,
PackageUploadHandle handle);

PackageVersionUpload NewPackageVersionUpload(Package package, string packagesDirectory,
IEnumerable<string> files, PackageUploadHandle handle);
IEnumerable<string> files, IEnumerable<string> markdownFiles, PackageUploadHandle handle);
}

internal class PackageUploadBuilder : IPackageUploadBuilder
Expand Down Expand Up @@ -56,37 +56,56 @@ public static PackageUploadRequestBody NewRequestBody(Package package)
package.NodeLibraries.Select(x => x.FullName), package.HostDependencies, package.CopyrightHolder, package.CopyrightYear);
}


public PackageUpload NewPackageUpload(Package package, string packagesDirectory, IEnumerable<string> files, PackageUploadHandle handle)
/// <summary>
/// Build a new package and upload
/// </summary>
/// <param name="package"></param>
/// <param name="packagesDirectory"></param>
/// <param name="files"></param>
/// <param name="markdownFiles"></param>
/// <param name="handle"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public PackageUpload NewPackageUpload(Package package, string packagesDirectory, IEnumerable<string> files, IEnumerable<string> markdownFiles, PackageUploadHandle handle)
{
if (package == null) throw new ArgumentNullException("package");
if (packagesDirectory == null) throw new ArgumentNullException("packagesDirectory");
if (files == null) throw new ArgumentNullException("files");
if (handle == null) throw new ArgumentNullException("handle");

return new PackageUpload(NewRequestBody(package),
BuildAndZip(package, packagesDirectory, files, handle).Name);
BuildAndZip(package, packagesDirectory, files, markdownFiles, handle).Name);
}

public PackageVersionUpload NewPackageVersionUpload(Package package, string packagesDirectory, IEnumerable<string> files, PackageUploadHandle handle)
/// <summary>
/// Build a new version of the package and upload
/// </summary>
/// <param name="package"></param>
/// <param name="packagesDirectory"></param>
/// <param name="files"></param>
/// <param name="markdownFiles"></param>
/// <param name="handle"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public PackageVersionUpload NewPackageVersionUpload(Package package, string packagesDirectory, IEnumerable<string> files, IEnumerable<string> markdownFiles, PackageUploadHandle handle)
{
if (package == null) throw new ArgumentNullException("package");
if (packagesDirectory == null) throw new ArgumentNullException("packagesDirectory");
if (files == null) throw new ArgumentNullException("files");
if (handle == null) throw new ArgumentNullException("handle");

return new PackageVersionUpload(NewRequestBody(package), BuildAndZip(package, packagesDirectory, files, handle).Name);
return new PackageVersionUpload(NewRequestBody(package), BuildAndZip(package, packagesDirectory, files, markdownFiles, handle).Name);
}

#endregion

#region Private Class Methods

private IFileInfo BuildAndZip(Package package, string packagesDirectory, IEnumerable<string> files, PackageUploadHandle handle)
private IFileInfo BuildAndZip(Package package, string packagesDirectory, IEnumerable<string> files, IEnumerable<string> markdownFiles, PackageUploadHandle handle)
{
handle.UploadState = PackageUploadHandle.State.Copying;

var dir = builder.BuildDirectory(package, packagesDirectory, files);
var dir = builder.BuildDirectory(package, packagesDirectory, files, markdownFiles);

handle.UploadState = PackageUploadHandle.State.Compressing;

Expand Down
26 changes: 14 additions & 12 deletions test/Libraries/PackageManagerTests/PackageDirectoryBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void BuildPackageDirectory_DoesExpectedNumberOfOperations()

var pkgsDir = @"C:\dynamopackages";

db.BuildDirectory(pkg, pkgsDir, files);
db.BuildDirectory(pkg, pkgsDir, files, Enumerable.Empty<string>());

Assert.AreEqual(5, fs.DirectoriesCreated.Count());
Assert.AreEqual(2, fs.CopiedFiles.Count());
Expand All @@ -50,7 +50,7 @@ public void BuildPackageDirectory_BuildsExpectedDirectories()

var pkgsDir = @"C:\dynamopackages";

db.BuildDirectory(pkg, pkgsDir, files);
db.BuildDirectory(pkg, pkgsDir, files, Enumerable.Empty<string>());

var rootDir = Path.Combine(pkgsDir, pkg.Name);
var binDir = Path.Combine(pkgsDir, pkg.Name, PackageDirectoryBuilder.BinaryDirectoryName);
Expand Down Expand Up @@ -79,7 +79,7 @@ public void BuildPackageDirectory_FormsPackageHeader()
var pkgsDir = @"C:\dynamopackages";

// where the magic happens...
db.BuildDirectory(pkg, pkgsDir, files);
db.BuildDirectory(pkg, pkgsDir, files, Enumerable.Empty<string>());

var rootDir = Path.Combine(pkgsDir, pkg.Name);

Expand Down Expand Up @@ -109,7 +109,7 @@ public void BuildPackageDirectory_RemapsCustomNodePaths()

var pkgsDir = @"C:\dynamopackages";

db.BuildDirectory(pkg, pkgsDir, files);
db.BuildDirectory(pkg, pkgsDir, files, Enumerable.Empty<string>());

var dyfDir = Path.Combine(pkgsDir, pkg.Name, PackageDirectoryBuilder.CustomNodeDirectoryName);

Expand All @@ -130,7 +130,7 @@ public void BuildPackageDirectory_UpdatesTheArgumentPackageWithNewDirectories()

var pkgsDir = @"C:\dynamopackages";

db.BuildDirectory(pkg, pkgsDir, files);
db.BuildDirectory(pkg, pkgsDir, files, Enumerable.Empty<string>());

var rootDir = Path.Combine(pkgsDir, pkg.Name);
var binDir = Path.Combine(pkgsDir, pkg.Name, PackageDirectoryBuilder.BinaryDirectoryName);
Expand Down Expand Up @@ -160,7 +160,7 @@ public void BuildPackageDirectory_CopiesTheOriginalFiles()

var pkgsDir = @"C:\dynamopackages";

db.BuildDirectory(pkg, pkgsDir, files);
db.BuildDirectory(pkg, pkgsDir, files, Enumerable.Empty<string>());

var dyfDir = Path.Combine(pkgsDir, pkg.Name, PackageDirectoryBuilder.CustomNodeDirectoryName);

Expand All @@ -175,7 +175,8 @@ public void BuildPackageDirectory_CopiesTheOriginalFiles()
[Test]
public void BuildPackageDirectory_CopiesMarkDownFiles()
{
var files = new[] { @"C:\file1.md", @"C:\file2.md" };
var files = new[] { @"C:\file1.dyn", @"C:\file2.dyn" };
var markdownFiles = new[] { @"C:\file1.md", @"C:\file2.md", @"C:\image\file3.jpg" };
var pkg = new Package(@"C:\pkg", "Foo", "0.1.0", "MIT");

var fs = new RecordedFileSystem((fn) => files.Contains(fn));
Expand All @@ -185,16 +186,17 @@ public void BuildPackageDirectory_CopiesMarkDownFiles()

var pkgsDir = @"C:\dynamopackages";

db.BuildDirectory(pkg, pkgsDir, files);
db.BuildDirectory(pkg, pkgsDir, files, markdownFiles);

var mdDir = Path.Combine(pkgsDir, pkg.Name, PackageDirectoryBuilder.DocumentationDirectoryName);

Assert.AreEqual(2, fs.CopiedFiles.Count());
Assert.AreEqual(5, fs.CopiedFiles.Count());
Assert.AreEqual(0, fs.DeletedFiles.Count());
Assert.AreEqual(0, fs.DeletedDirectories.Count());

Assert.IsTrue(fs.CopiedFiles.Any(x => ComparePaths(x.Item2, Path.Combine(mdDir, "file1.md"))));
Assert.IsTrue(fs.CopiedFiles.Any(x => ComparePaths(x.Item2, Path.Combine(mdDir, "file2.md"))));
Assert.IsTrue(fs.CopiedFiles.Any(x => ComparePaths(x.Item2, Path.Combine(mdDir, "file3.jpg"))));
}

[Test]
Expand All @@ -211,7 +213,7 @@ public void BuildPackageDirectory_DeletesTheOriginalFiles()

var pkgsDir = @"C:\dynamopackages";

db.BuildDirectory(pkg, pkgsDir, files);
db.BuildDirectory(pkg, pkgsDir, files, Enumerable.Empty<string>());

// The original files are moved

Expand Down Expand Up @@ -242,7 +244,7 @@ public void BuildPackageDirectory_DoesNotIncludeUnselectedFiles()

var db = new PackageDirectoryBuilder(fs, MockMaker.Empty<IPathRemapper>());
var pkgsDir = @"C:\dynamopackages";
db.BuildDirectory(pkg, pkgsDir, files);
db.BuildDirectory(pkg, pkgsDir, files, Enumerable.Empty<string>());

Assert.AreEqual(5, fs.DirectoriesCreated.Count());
Assert.AreEqual(4, fs.CopiedFiles.Count());
Expand Down Expand Up @@ -277,7 +279,7 @@ public void CopyFilesIntoPackageDirectory_DoesNotMoveFilesAlreadyWithinDirectory
var doc = new Mock<IDirectoryInfo>();
doc.SetupGet((i) => i.FullName).Returns(() => "C:/foo/doc");

f.CopyFilesIntoPackageDirectory(files, dyf.Object, bin.Object, extra.Object, doc.Object);
f.CopyFilesIntoPackageDirectory(files, Enumerable.Empty<string>(), dyf.Object, bin.Object, extra.Object, doc.Object);

// no files should be copied, they are all already within their intended directory
Assert.IsEmpty(fs.CopiedFiles);
Expand Down
Loading