Modified the package installer to use target folders ( based on the Nuget specification ) rather than file extensions

This commit is contained in:
Shaun Walker 2020-05-15 17:43:45 -04:00
parent 3cbb6e3e6e
commit 8a1e83ff7f
6 changed files with 25 additions and 20 deletions

View File

@ -27,5 +27,6 @@
<file src="..\Shared\bin\Release\netstandard2.1\[Owner].[Module]s.Shared.Oqtane.dll" target="lib" />
<file src="..\Shared\bin\Release\netstandard2.1\[Owner].[Module]s.Shared.Oqtane.pdb" target="lib" />
<file src="..\wwwroot\**\*.*" target="wwwroot" />
<file src="..\content\**\*.*" target="content" />
</files>
</package>

View File

@ -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.

View File

@ -1 +1 @@
This is the location where static resources such as images or style sheets should be located
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.

View File

@ -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;
}
}
}

View File

@ -163,7 +163,7 @@ namespace Oqtane
services.AddSingleton<IDatabaseManager, DatabaseManager>();
// 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<IModuleDefinitionRepository, ModuleDefinitionRepository>();

View File

@ -0,0 +1 @@
This is the location where static resources such as images or style sheets should be located