Move umbraco views to static assets and make that an RCL + Embedded language files (#12324)

* RCL for static assets to replace the nuspec

* Fix build

* Fix unit tests

* clean up in build.ps1

* Removed test (lang files will be removed later anyway)

* Fixed namespaces.. + Ensure we set web root path if missing (e.g. wwwroot folder do not exist) + Added StaticWebAssetBasePath

* fixed namespace

* cleanup

* Set root variable

* Added static assets

* Experimenting with StaticWebAssetBasePath

* Embedded lang files into Umbraco.Core

* Removed legacy test. New test can be implemented instead

* Fixed tests

* clean up

* Fix merge issue
This commit is contained in:
Bjarke Berg
2022-05-02 19:38:33 +02:00
committed by GitHub
parent f00bfc408e
commit 13f6d4791c
54 changed files with 222 additions and 318 deletions

View File

@@ -5,6 +5,8 @@ using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.FileProviders.Internal;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Cache;
using Umbraco.Extensions;
@@ -17,6 +19,7 @@ namespace Umbraco.Cms.Core.Services
public class LocalizedTextServiceFileSources
{
private readonly ILogger<LocalizedTextServiceFileSources> _logger;
private readonly IDirectoryContents _directoryContents;
private readonly IAppPolicyCache _cache;
private readonly IEnumerable<LocalizedTextServiceSupplementaryFileSource>? _supplementFileSources;
private readonly DirectoryInfo? _fileSourceFolder;
@@ -26,6 +29,21 @@ namespace Umbraco.Cms.Core.Services
private readonly Lazy<Dictionary<CultureInfo, Lazy<XDocument>>> _xmlSources;
[Obsolete("Use ctor with all params. This will be removed in Umbraco 12")]
public LocalizedTextServiceFileSources(
ILogger<LocalizedTextServiceFileSources> logger,
AppCaches appCaches,
DirectoryInfo fileSourceFolder,
IEnumerable<LocalizedTextServiceSupplementaryFileSource> supplementFileSources)
:this(
logger,
appCaches,
fileSourceFolder,
supplementFileSources, new NotFoundDirectoryContents())
{
}
/// <summary>
/// This is used to configure the file sources with the main file sources shipped with Umbraco and also including supplemental/plugin based
/// localization files. The supplemental files will be loaded in and merged in after the primary files.
@@ -39,36 +57,37 @@ namespace Umbraco.Cms.Core.Services
ILogger<LocalizedTextServiceFileSources> logger,
AppCaches appCaches,
DirectoryInfo fileSourceFolder,
IEnumerable<LocalizedTextServiceSupplementaryFileSource> supplementFileSources)
IEnumerable<LocalizedTextServiceSupplementaryFileSource> supplementFileSources,
IDirectoryContents directoryContents
)
{
if (logger == null) throw new ArgumentNullException("logger");
if (appCaches == null) throw new ArgumentNullException("cache");
if (fileSourceFolder == null) throw new ArgumentNullException("fileSourceFolder");
_logger = logger;
_directoryContents = directoryContents;
_cache = appCaches.RuntimeCache;
if (fileSourceFolder.Exists == false)
{
_logger.LogWarning("The folder does not exist: {FileSourceFolder}, therefore no sources will be discovered", fileSourceFolder.FullName);
}
else
{
_fileSourceFolder = fileSourceFolder;
_supplementFileSources = supplementFileSources;
}
_fileSourceFolder = fileSourceFolder;
_supplementFileSources = supplementFileSources;
//Create the lazy source for the _xmlSources
_xmlSources = new Lazy<Dictionary<CultureInfo, Lazy<XDocument>>>(() =>
{
var result = new Dictionary<CultureInfo, Lazy<XDocument>>();
if (_fileSourceFolder == null) return result;
foreach (var fileInfo in _fileSourceFolder.GetFiles("*.xml"))
var files = GetLanguageFiles();
if (!files.Any())
{
return result;
}
foreach (var fileInfo in files)
{
var localCopy = fileInfo;
var filename = Path.GetFileNameWithoutExtension(localCopy.FullName).Replace("_", "-");
var filename = Path.GetFileNameWithoutExtension(localCopy.Name).Replace("_", "-");
// TODO: Fix this nonsense... would have to wait until v8 to store the language files with their correct
// names instead of storing them as 2 letters but actually having a 4 letter culture. So now, we
@@ -80,7 +99,7 @@ namespace Umbraco.Cms.Core.Services
{
//we need to open the file to see if we can read it's 'real' culture, we'll use XmlReader since we don't
//want to load in the entire doc into mem just to read a single value
using (var fs = fileInfo.OpenRead())
using (var fs = fileInfo.CreateReadStream())
using (var reader = XmlReader.Create(fs))
{
if (reader.IsStartElement())
@@ -98,7 +117,7 @@ namespace Umbraco.Cms.Core.Services
}
catch (CultureNotFoundException)
{
_logger.LogWarning("The culture {CultureValue} found in the file {CultureFile} is not a valid culture", cultureVal, fileInfo.FullName);
_logger.LogWarning("The culture {CultureValue} found in the file {CultureFile} is not a valid culture", cultureVal, fileInfo.Name);
//If the culture in the file is invalid, we'll just hope the file name is a valid culture below, otherwise
// an exception will be thrown.
}
@@ -119,7 +138,7 @@ namespace Umbraco.Cms.Core.Services
XDocument xdoc;
//load in primary
using (var fs = localCopy.OpenRead())
using (var fs = localCopy.CreateReadStream())
{
xdoc = XDocument.Load(fs);
}
@@ -128,7 +147,7 @@ namespace Umbraco.Cms.Core.Services
MergeSupplementaryFiles(culture, xdoc);
return xdoc;
}, isSliding: true, timeout: TimeSpan.FromMinutes(10), dependentFiles: new[] { localCopy.FullName })!);
}, isSliding: true, timeout: TimeSpan.FromMinutes(10))!);
}
return result;
});
@@ -136,6 +155,30 @@ namespace Umbraco.Cms.Core.Services
}
private IEnumerable<IFileInfo> GetLanguageFiles()
{
var result = new List<IFileInfo>();
if (_fileSourceFolder is not null && _fileSourceFolder.Exists)
{
result.AddRange(
new PhysicalDirectoryContents(_fileSourceFolder.FullName)
.Where(x => !x.IsDirectory && x.Name.EndsWith(".xml"))
);
}
if (_directoryContents.Exists)
{
result.AddRange(
_directoryContents
.Where(x => !x.IsDirectory && x.Name.EndsWith(".xml"))
);
}
return result;
}
/// <summary>
/// Constructor
/// </summary>