From 8a1e83ff7f60f3342101137c55e917bf286918e9 Mon Sep 17 00:00:00 2001 From: Shaun Walker Date: Fri, 15 May 2020 17:43:45 -0400 Subject: [PATCH] Modified the package installer to use target folders ( based on the Nuget specification ) rather than file extensions --- .../External/Package/[Owner].[Module]s.nuspec | 1 + .../Templates/External/content/resources.txt | 1 + .../Templates/External/wwwroot/resources.txt | 2 +- .../Infrastructure/InstallationManager.cs | 38 ++++++++++--------- Oqtane.Server/Startup.cs | 2 +- Oqtane.Server/wwwroot/resources.txt | 1 + 6 files changed, 25 insertions(+), 20 deletions(-) create mode 100644 Oqtane.Client/Modules/Admin/ModuleCreator/Templates/External/content/resources.txt create mode 100644 Oqtane.Server/wwwroot/resources.txt diff --git a/Oqtane.Client/Modules/Admin/ModuleCreator/Templates/External/Package/[Owner].[Module]s.nuspec b/Oqtane.Client/Modules/Admin/ModuleCreator/Templates/External/Package/[Owner].[Module]s.nuspec index 57071160..64c81a8d 100644 --- a/Oqtane.Client/Modules/Admin/ModuleCreator/Templates/External/Package/[Owner].[Module]s.nuspec +++ b/Oqtane.Client/Modules/Admin/ModuleCreator/Templates/External/Package/[Owner].[Module]s.nuspec @@ -27,5 +27,6 @@ + \ No newline at end of file diff --git a/Oqtane.Client/Modules/Admin/ModuleCreator/Templates/External/content/resources.txt b/Oqtane.Client/Modules/Admin/ModuleCreator/Templates/External/content/resources.txt new file mode 100644 index 00000000..ac84ee50 --- /dev/null +++ b/Oqtane.Client/Modules/Admin/ModuleCreator/Templates/External/content/resources.txt @@ -0,0 +1 @@ +This is the location where static resources for third party libraries should be located ( the third party library assemblies will be included in the /lib folder ). They should be placed in subfolders which match the naming convention of the third party library. When the module package is deployed the static resource subfolders will be extracted under the web root. \ No newline at end of file diff --git a/Oqtane.Client/Modules/Admin/ModuleCreator/Templates/External/wwwroot/resources.txt b/Oqtane.Client/Modules/Admin/ModuleCreator/Templates/External/wwwroot/resources.txt index 2542de03..91780f80 100644 --- a/Oqtane.Client/Modules/Admin/ModuleCreator/Templates/External/wwwroot/resources.txt +++ b/Oqtane.Client/Modules/Admin/ModuleCreator/Templates/External/wwwroot/resources.txt @@ -1 +1 @@ -This is the location where static resources such as images or style sheets should be located \ No newline at end of file +This is the location where static resources such as images or style sheets for this module will be located. Static assets can be organized in subfolders. When the module package is deployed the assets will be extracted under the web root in a folder that matches the module name. \ No newline at end of file diff --git a/Oqtane.Server/Infrastructure/InstallationManager.cs b/Oqtane.Server/Infrastructure/InstallationManager.cs index b1f73543..adce62e9 100644 --- a/Oqtane.Server/Infrastructure/InstallationManager.cs +++ b/Oqtane.Server/Infrastructure/InstallationManager.cs @@ -28,7 +28,7 @@ namespace Oqtane.Infrastructure { var webRootPath = _environment.WebRootPath; - var install = UnpackPackages(folders, webRootPath); + var install = InstallPackages(folders, webRootPath); if (install && restart) { @@ -36,7 +36,7 @@ namespace Oqtane.Infrastructure } } - public static bool UnpackPackages(string folders, string webRootPath) + public static bool InstallPackages(string folders, string webRootPath) { bool install = false; string binFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location); @@ -44,14 +44,12 @@ namespace Oqtane.Infrastructure foreach (string folder in folders.Split(',')) { string sourceFolder = Path.Combine(webRootPath, folder); - - // create folder if it does not exist if (!Directory.Exists(sourceFolder)) { Directory.CreateDirectory(sourceFolder); } - // iterate through packages + // iterate through Nuget packages in source folder foreach (string packagename in Directory.GetFiles(sourceFolder, "*.nupkg")) { string name = Path.GetFileNameWithoutExtension(packagename); @@ -89,29 +87,33 @@ namespace Oqtane.Infrastructure // deploy to appropriate locations foreach (ZipArchiveEntry entry in archive.Entries) { + string foldername = Path.GetDirectoryName(entry.FullName).Split('\\')[0]; string filename = Path.GetFileName(entry.FullName); - switch (Path.GetExtension(filename).ToLower()) + + switch (foldername) { - case ".pdb": - case ".dll": + case "lib": if (binFolder != null) entry.ExtractToFile(Path.Combine(binFolder, filename), true); break; - case ".png": - case ".jpg": - case ".jpeg": - case ".gif": - case ".svg": - case ".js": - case ".css": - string entryPath = Utilities.PathCombine(entry.FullName.Replace("wwwroot", name).Split('/')); - filename = Path.Combine(sourceFolder, entryPath); + case "wwwroot": + filename = Path.Combine(sourceFolder, Utilities.PathCombine(entry.FullName.Replace("wwwroot", name).Split('/'))); if (!Directory.Exists(Path.GetDirectoryName(filename))) { Directory.CreateDirectory(Path.GetDirectoryName(filename)); } - entry.ExtractToFile(filename, true); break; + case "content": + if (Path.GetDirectoryName(entry.FullName) != "content") // assets must be in subfolders + { + filename = Path.Combine(webRootPath, Utilities.PathCombine(entry.FullName.Replace("content", "").Split('/'))); + if (!Directory.Exists(Path.GetDirectoryName(filename))) + { + Directory.CreateDirectory(Path.GetDirectoryName(filename)); + } + entry.ExtractToFile(filename, true); + } + break; } } } diff --git a/Oqtane.Server/Startup.cs b/Oqtane.Server/Startup.cs index 34f73ffe..b47cdd4f 100644 --- a/Oqtane.Server/Startup.cs +++ b/Oqtane.Server/Startup.cs @@ -163,7 +163,7 @@ namespace Oqtane services.AddSingleton(); // install any modules or themes ( this needs to occur BEFORE the assemblies are loaded into the app domain ) - InstallationManager.UnpackPackages("Modules,Themes", _webRoot); + InstallationManager.InstallPackages("Modules,Themes", _webRoot); // register transient scoped core services services.AddTransient(); diff --git a/Oqtane.Server/wwwroot/resources.txt b/Oqtane.Server/wwwroot/resources.txt new file mode 100644 index 00000000..2542de03 --- /dev/null +++ b/Oqtane.Server/wwwroot/resources.txt @@ -0,0 +1 @@ +This is the location where static resources such as images or style sheets should be located \ No newline at end of file