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

Leave examples in the example folder when reorganizing a package #91

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
15 changes: 15 additions & 0 deletions Firely.Fhir.Packages.Tests/Packaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,23 @@ public void FolderOrganization()

Assert.AreEqual(@"package\patient.xml", file.FilePath);

//example files already in the correct structure should stay in the example folder
file =
new FileEntry(@"package\examples\example-patient.json", System.Array.Empty<byte>())
.OrganizeToPackageStructure();

Assert.AreEqual(@"package\examples\example-patient.json", file.FilePath);

//example files already in the correct structure should stay in the example folder, but subfolders should be flattened
file =
new FileEntry(@"package\examples\random\example-patient.json", System.Array.Empty<byte>())
.OrganizeToPackageStructure();

Assert.AreEqual(@"package\examples\example-patient.json", file.FilePath);

}


[TestMethod]
public void TestGeneratingIndexFiles()
{
Expand Down
6 changes: 5 additions & 1 deletion Firely.Fhir.Packages/Constants/PackageConsts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#nullable enable

using System.IO;

namespace Firely.Fhir.Packages
{
public static class PackageFileNames
Expand All @@ -18,8 +20,10 @@ public static class PackageFileNames
public const string CANONICALINDEXFILE = ".firely.index.json";
public const string INDEXJSONFILE = ".index.json";
public const string PACKAGEFOLDER = "package";
public const string EXAMPLEFOLDER = "examples";
public static string EXAMPLEFOLDERPATH => PACKAGEFOLDER + Path.DirectorySeparatorChar + EXAMPLEFOLDER;

public static readonly string[] ALL_PACKAGE_FILENAMES = { MANIFEST, LOCKFILE, CANONICALINDEXFILE, INDEXJSONFILE, PACKAGEFOLDER };
public static readonly string[] ALL_PACKAGE_FILENAMES = { MANIFEST, LOCKFILE, CANONICALINDEXFILE, INDEXJSONFILE };

}

Expand Down
8 changes: 5 additions & 3 deletions Firely.Fhir.Packages/Tar/FileEntries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,12 @@ public static FileEntry OrganizeToPackageStructure(this FileEntry file)
{
if (file.match(PackageFileNames.MANIFEST))
return file.ChangeFolder(PackageFileNames.PACKAGEFOLDER);

else if (file.hasExtension(".xml", ".json"))
return file.ChangeFolder(PackageFileNames.PACKAGEFOLDER);

{
return file.FilePath.StartsWith(PackageFileNames.EXAMPLEFOLDERPATH)
? file.ChangeFolder(PackageFileNames.EXAMPLEFOLDERPATH)
: file.ChangeFolder(PackageFileNames.PACKAGEFOLDER);
}
else
return file.ChangeFolder(FOLDER_OTHER);
}
Expand Down