Skip to content

Commit

Permalink
fix: leave examples in the example folder when reorganizing a package
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsmits committed Jan 24, 2024
1 parent b963201 commit a2783e0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
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

0 comments on commit a2783e0

Please sign in to comment.