diff --git a/Firely.Fhir.Packages.Tests/Packaging.cs b/Firely.Fhir.Packages.Tests/Packaging.cs index fd190a0..4430eba 100644 --- a/Firely.Fhir.Packages.Tests/Packaging.cs +++ b/Firely.Fhir.Packages.Tests/Packaging.cs @@ -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()) + .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()) + .OrganizeToPackageStructure(); + + Assert.AreEqual(@"package\examples\example-patient.json", file.FilePath); + } + [TestMethod] public void TestGeneratingIndexFiles() { diff --git a/Firely.Fhir.Packages/Constants/PackageConsts.cs b/Firely.Fhir.Packages/Constants/PackageConsts.cs index de464ae..a4f6631 100644 --- a/Firely.Fhir.Packages/Constants/PackageConsts.cs +++ b/Firely.Fhir.Packages/Constants/PackageConsts.cs @@ -9,6 +9,8 @@ #nullable enable +using System.IO; + namespace Firely.Fhir.Packages { public static class PackageFileNames @@ -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 }; } diff --git a/Firely.Fhir.Packages/Tar/FileEntries.cs b/Firely.Fhir.Packages/Tar/FileEntries.cs index 793ccf3..a67b13b 100644 --- a/Firely.Fhir.Packages/Tar/FileEntries.cs +++ b/Firely.Fhir.Packages/Tar/FileEntries.cs @@ -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); }