From 85730eadb0be5270cc93f72bba123fe55b75fb42 Mon Sep 17 00:00:00 2001 From: Elitsa Marinovska Date: Tue, 24 Mar 2020 10:51:53 +0100 Subject: [PATCH] Setting up Smidge --- src/Umbraco.Core/Runtime/IRuntimeMinifier.cs | 2 +- ...oBackOfficeApplicationBuilderExtensions.cs | 25 +++++++ ...coBackOfficeServiceCollectionExtensions.cs | 12 +++ .../Smidge/SmidgeRuntimeMinifier.cs | 75 +++++++++++++++++++ .../Umbraco.Web.BackOffice.csproj | 5 ++ src/Umbraco.Web.UI.NetCore/appsettings.json | 8 +- .../CDF/ClientDependencyRuntimeMinifier.cs | 2 +- 7 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 src/Umbraco.Web.BackOffice/Smidge/SmidgeRuntimeMinifier.cs diff --git a/src/Umbraco.Core/Runtime/IRuntimeMinifier.cs b/src/Umbraco.Core/Runtime/IRuntimeMinifier.cs index f11720ab39..a282293205 100644 --- a/src/Umbraco.Core/Runtime/IRuntimeMinifier.cs +++ b/src/Umbraco.Core/Runtime/IRuntimeMinifier.cs @@ -10,7 +10,7 @@ namespace Umbraco.Core.Runtime string GetHashValue { get; } //return type HtmlHelper - string RequiresCss(string filePath, string pathNameAlias); + string RequiresCss(string filePath, string bundleName); //return type IHtmlString //IClientDependencyPath[] diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeApplicationBuilderExtensions.cs b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeApplicationBuilderExtensions.cs index 1f06a818d6..d537759ba4 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeApplicationBuilderExtensions.cs +++ b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeApplicationBuilderExtensions.cs @@ -1,5 +1,7 @@ using System; using Microsoft.AspNetCore.Builder; +using Smidge; +using Smidge.Models; namespace Umbraco.Web.BackOffice.AspNetCore { @@ -12,6 +14,29 @@ namespace Umbraco.Web.BackOffice.AspNetCore throw new ArgumentNullException(nameof(app)); } + app.UseRuntimeMinifier(); + + return app; + } + + public static IApplicationBuilder UseRuntimeMinifier(this IApplicationBuilder app) + { + app.UseSmidge(bundles => + { + bundles.Create("default-css", + new CssFile("~/assets/css/umbraco.css"), + new CssFile("~/lib/bootstrap-social/bootstrap-social.css"), + new CssFile("~/lib/font-awesome/css/font-awesome.min.css")); + + bundles.Create("index-css", + new CssFile("assets/css/canvasdesigner.css")); + + bundles.Create("default-js", WebFileType.Js, + "//cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js", + "//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.min.js", + "//cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.11/jquery.validate.unobtrusive.min.js"); + }); + return app; } } diff --git a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs index 8f94fba957..89f6b02c93 100644 --- a/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs +++ b/src/Umbraco.Web.BackOffice/AspNetCore/UmbracoBackOfficeServiceCollectionExtensions.cs @@ -1,8 +1,11 @@ +using System.Configuration; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Hosting; +using Smidge; using Umbraco.Composing; using Umbraco.Configuration; using Umbraco.Core; @@ -48,6 +51,8 @@ namespace Umbraco.Web.BackOffice.AspNetCore hostApplicationLifetime, configs); + services.AddRuntimeMinifier(); + return services; } @@ -78,5 +83,12 @@ namespace Umbraco.Web.BackOffice.AspNetCore return services; } + + public static IServiceCollection AddRuntimeMinifier(this IServiceCollection services) + { + services.AddSmidge((IConfiguration) ConfigurationManager.GetSection("smidge")); + + return services; + } } } diff --git a/src/Umbraco.Web.BackOffice/Smidge/SmidgeRuntimeMinifier.cs b/src/Umbraco.Web.BackOffice/Smidge/SmidgeRuntimeMinifier.cs new file mode 100644 index 0000000000..e9565edbc4 --- /dev/null +++ b/src/Umbraco.Web.BackOffice/Smidge/SmidgeRuntimeMinifier.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.IO; +using System.Text; +using Microsoft.Extensions.Configuration; +using Smidge; +using Smidge.Cache; +using Smidge.FileProcessors; +using Smidge.Nuglify; +using Smidge.Models; +using Umbraco.Core.Assets; +using Umbraco.Core.Runtime; + +namespace Umbraco.Web.BackOffice.Smidge +{ + public class SmidgeRuntimeMinifier : IRuntimeMinifier + { + private readonly SmidgeHelper _smidge; + public string GetHashValue => new SmidgeConfig((IConfiguration) ConfigurationManager.GetSection("smidge")).Version; + + public SmidgeRuntimeMinifier(SmidgeHelper smidge) + { + _smidge = smidge; + } + public string RequiresCss(string filePath, string bundleName) + { + throw new NotImplementedException(); + } + + public string RenderCssHere(params string[] path) + { + throw new NotImplementedException(); + } + + public string RequiresJs(string filePath) + { + throw new NotImplementedException(); + } + + public string RenderJsHere() + { + throw new NotImplementedException(); + } + + public IEnumerable GetAssetPaths(AssetType assetType, List attributes) + { + throw new NotImplementedException(); + } + + public string Minify(string src) + { + //TextReader reader = new StringReader(src); + // var jsMinifier = new NuglifyJs(); + + // return jsMinifier.ProcessAsync(); + return ""; + } + + public void Reset() + { + throw new NotImplementedException(); + } + + public string GetScriptForBackOffice() + { + throw new NotImplementedException(); + } + + public IEnumerable GetAssetList() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj b/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj index 36238f1a6d..81a8b4809a 100644 --- a/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj +++ b/src/Umbraco.Web.BackOffice/Umbraco.Web.BackOffice.csproj @@ -10,6 +10,11 @@ + + + + + diff --git a/src/Umbraco.Web.UI.NetCore/appsettings.json b/src/Umbraco.Web.UI.NetCore/appsettings.json index 1c89647efa..11f10cc1db 100644 --- a/src/Umbraco.Web.UI.NetCore/appsettings.json +++ b/src/Umbraco.Web.UI.NetCore/appsettings.json @@ -80,10 +80,14 @@ {"Char": ";", "Replacement": ""}, {"Char": "/", "Replacement": ""}, {"Char": "\\", "Replacement": ""}, - {"Char": ":", "Replacement": ""}, + {"Char": ":", "Replacement": ""} ] } - } + }, + "smidge": { + "dataFolder" : "App_Data/Smidge", + "version" : "1" + } } } diff --git a/src/Umbraco.Web/JavaScript/CDF/ClientDependencyRuntimeMinifier.cs b/src/Umbraco.Web/JavaScript/CDF/ClientDependencyRuntimeMinifier.cs index a2f61aaf72..44f0d4b757 100644 --- a/src/Umbraco.Web/JavaScript/CDF/ClientDependencyRuntimeMinifier.cs +++ b/src/Umbraco.Web/JavaScript/CDF/ClientDependencyRuntimeMinifier.cs @@ -38,7 +38,7 @@ namespace Umbraco.Web.JavaScript.CDF _htmlHelper = new HtmlHelper(new ViewContext(), new ViewPage()); } - public string RequiresCss(string filePath, string pathNameAlias) + public string RequiresCss(string filePath, string bundleName) { throw new NotImplementedException(); //_htmlHelper.ViewContext.GetLoader().RegisterDependency(filePath, pathNameAlias, ClientDependencyType.Css);