diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/BasicThemeBundleContributor.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/BasicThemeBundleContributor.cs index edef97eb52..6d6e8e12ed 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/BasicThemeBundleContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/BasicThemeBundleContributor.cs @@ -4,12 +4,12 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme { public class BasicThemeBundleContributor : IBundleContributor { - public void AddScripts(BundleContext context) + public void AddScripts(BundleContext context, BundleParameterDictionary parameters) { } - public void AddStyles(BundleContext context) + public void AddStyles(BundleContext context, BundleParameterDictionary parameters) { context.Add("_content/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/libs/abp/css/theme.css"); } diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/ThemingBundleContributor.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/ThemingBundleContributor.cs index 70382a7dba..ea4b2fa000 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/ThemingBundleContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.Theming/ThemingBundleContributor.cs @@ -4,12 +4,12 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.Theming { public class ThemingBundleContributor : IBundleContributor { - public void AddScripts(BundleContext context) + public void AddScripts(BundleContext context, BundleParameterDictionary parameters) { } - public void AddStyles(BundleContext context) + public void AddStyles(BundleContext context, BundleParameterDictionary parameters) { context.BundleDefinitions.Insert(0, new BundleDefinition { diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ComponentsWebAssemblyBundleContributor.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ComponentsWebAssemblyBundleContributor.cs index 9f05ff24d1..343cb2c164 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ComponentsWebAssemblyBundleContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/ComponentsWebAssemblyBundleContributor.cs @@ -4,12 +4,12 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly { public class ComponentsWebAssemblyBundleContributor : IBundleContributor { - public void AddScripts(BundleContext context) + public void AddScripts(BundleContext context, BundleParameterDictionary parameters) { context.Add("_content/Volo.Abp.AspNetCore.Components.WebAssembly/libs/abp/js/abp.js"); } - public void AddStyles(BundleContext context) + public void AddStyles(BundleContext context, BundleParameterDictionary parameters) { } diff --git a/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUIBundleContributor.cs b/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUIBundleContributor.cs index 5dcc51c76a..31c5e70f31 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUIBundleContributor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/BlazoriseUIBundleContributor.cs @@ -4,13 +4,13 @@ namespace Volo.Abp.BlazoriseUI { public class BlazoriseUIBundleContributor : IBundleContributor { - public void AddScripts(BundleContext context) + public void AddScripts(BundleContext context, BundleParameterDictionary parameters) { context.Add("_content/Blazorise/blazorise.js"); context.Add("_content/Blazorise.Bootstrap/blazorise.bootstrap.js"); } - public void AddStyles(BundleContext context) + public void AddStyles(BundleContext context, BundleParameterDictionary parameters) { context.Add("_content/Blazorise/blazorise.css"); context.Add("_content/Blazorise.Bootstrap/blazorise.bootstrap.css"); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundleConfig.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundleConfig.cs new file mode 100644 index 0000000000..3fb1dd91c9 --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundleConfig.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using Volo.Abp.Bundling; + +namespace Volo.Abp.Cli.Bundling +{ + public class BundleConfig + { + public BundlingMode Mode { get; set; } + public string Name { get; set; } + public BundleParameterDictionary Parameters { get; set; } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlerBase.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlerBase.cs index 525548db87..4145c34e68 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlerBase.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlerBase.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Logging; using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; @@ -13,12 +14,13 @@ namespace Volo.Abp.Cli.Bundling { public abstract class BundlerBase : IBundler, ITransientDependency { - private static string[] _minFileSuffixes = { "min", "prod" }; + private static string[] _minFileSuffixes = {"min", "prod"}; protected IMinifier Minifier { get; } public ILogger Logger { get; set; } public abstract string FileExtension { get; } - public abstract string GenerateDefinition(string bundleFilePath); + public abstract string GenerateDefinition(string bundleFilePath, + List bundleDefinitionsExcludingFromBundle); protected BundlerBase(IMinifier minifier) { @@ -27,11 +29,15 @@ namespace Volo.Abp.Cli.Bundling public string Bundle(BundleOptions options, BundleContext context) { - var bundleFilePath = Path.Combine(PathHelper.GetWwwRootPath(options.Directory), $"{options.BundleName}{FileExtension}"); - var bundledContent = BundleFiles(options, context); + var bundleFilePath = Path.Combine(PathHelper.GetWwwRootPath(options.Directory), + $"{options.BundleName}{FileExtension}"); + var bundleFileDefinitions = context.BundleDefinitions.Where(t => t.ExcludeFromBundle == false).ToList(); + var fileDefinitionsExcludingFromBundle = context.BundleDefinitions.Where(t => t.ExcludeFromBundle).ToList(); + + var bundledContent = BundleFiles(options, bundleFileDefinitions); File.WriteAllText(bundleFilePath, bundledContent); - return GenerateDefinition(bundleFilePath); + return GenerateDefinition(bundleFilePath,fileDefinitionsExcludingFromBundle); } private bool IsMinFile(string fileName) @@ -47,34 +53,40 @@ namespace Volo.Abp.Cli.Bundling return false; } - private string BundleFiles(BundleOptions options, BundleContext context) + private string BundleFiles(BundleOptions options, List bundleDefinitions) { - var staticAssetsFilePath = Path.Combine(options.Directory, "bin", "Debug", options.FrameworkVersion, $"{options.ProjectFileName}.StaticWebAssets.xml"); + var staticAssetsFilePath = Path.Combine(options.Directory, "bin", "Debug", options.FrameworkVersion, + $"{options.ProjectFileName}.StaticWebAssets.xml"); if (!File.Exists(staticAssetsFilePath)) { - throw new BundlingException("Unable to find static web assets file. You need to build the project to generate static web assets file."); + throw new BundlingException( + "Unable to find static web assets file. You need to build the project to generate static web assets file."); } var staticAssetsDefinitions = new XmlDocument(); staticAssetsDefinitions.Load(staticAssetsFilePath); var builder = new StringBuilder(); - foreach (var definition in context.BundleDefinitions) + foreach (var definition in bundleDefinitions) { string content; if (definition.Source.StartsWith("_content")) { var pathFragments = definition.Source.Split('/').ToList(); var basePath = $"{pathFragments[0]}/{pathFragments[1]}"; - var path = staticAssetsDefinitions.SelectSingleNode($"//ContentRoot[@BasePath='{basePath}']").Attributes["Path"].Value; + var path = staticAssetsDefinitions.SelectSingleNode($"//ContentRoot[@BasePath='{basePath}']") + .Attributes["Path"].Value; var absolutePath = definition.Source.Replace(basePath, path); content = GetFileContent(absolutePath, options.Minify); } else if (definition.Source.StartsWith("_framework")) { var slashIndex = definition.Source.IndexOf('/'); - var fileName = definition.Source.Substring(slashIndex + 1, definition.Source.Length - slashIndex - 1); - var filePath = Path.Combine(PathHelper.GetFrameworkFolderPath(options.Directory, options.FrameworkVersion), fileName); + var fileName = + definition.Source.Substring(slashIndex + 1, definition.Source.Length - slashIndex - 1); + var filePath = + Path.Combine(PathHelper.GetFrameworkFolderPath(options.Directory, options.FrameworkVersion), + fileName); content = GetFileContent(filePath, false); } else @@ -83,7 +95,8 @@ namespace Volo.Abp.Cli.Bundling content = GetFileContent(filePath, options.Minify); } - content = ProcessBeforeAddingToTheBundle(definition.Source, Path.Combine(options.Directory, "wwwroot"), content); + content = ProcessBeforeAddingToTheBundle(definition.Source, Path.Combine(options.Directory, "wwwroot"), + content); builder.AppendLine(content); } @@ -101,16 +114,19 @@ namespace Volo.Abp.Cli.Bundling } catch (NUglifyException ex) { - Logger.LogWarning($"Unable to minify the file: {Path.GetFileName(filePath)}. Adding file to the bundle without minification.", ex); + Logger.LogWarning( + $"Unable to minify the file: {Path.GetFileName(filePath)}. Adding file to the bundle without minification.", + ex); } } return content; } - protected virtual string ProcessBeforeAddingToTheBundle(string referencePath, string bundleDirectory, string fileContent) + protected virtual string ProcessBeforeAddingToTheBundle(string referencePath, string bundleDirectory, + string fileContent) { return fileContent; } } -} +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingMode.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingMode.cs new file mode 100644 index 0000000000..8789d631d1 --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingMode.cs @@ -0,0 +1,9 @@ +namespace Volo.Abp.Cli.Bundling +{ + public enum BundlingMode + { + None, + Bundle, + BundleAndMinify, + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingService.cs index 810d7b4335..bed770dede 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingService.cs @@ -11,6 +11,7 @@ using Volo.Abp.Bundling; using Volo.Abp.Cli.Build; using Volo.Abp.Cli.Bundling.Scripts; using Volo.Abp.Cli.Bundling.Styles; +using Volo.Abp.Cli.Configuration; using Volo.Abp.DependencyInjection; using Volo.Abp.Minify.Scripts; using Volo.Abp.Minify.Styles; @@ -26,17 +27,27 @@ namespace Volo.Abp.Cli.Bundling public ILogger Logger { get; set; } public IScriptBundler ScriptBundler { get; set; } public IStyleBundler StyleBundler { get; set; } + public IConfigReader ConfigReader { get; set; } - public async Task BundleAsync(string directory, bool forceBuild, bool bundle, bool minify, string bundleName) + public async Task BundleAsync(string directory, bool forceBuild) { var projectFiles = Directory.GetFiles(directory, "*.csproj"); if (!projectFiles.Any()) { - throw new BundlingException("No project file found in the directory. The working directory must have a Blazor project file."); + throw new BundlingException( + "No project file found in the directory. The working directory must have a Blazor project file."); } var projectFilePath = projectFiles[0]; + var config = ConfigReader.Read(PathHelper.GetWwwRootPath(directory)); + var bundleConfig = config?.Bundle; + + if (bundleConfig == null) + { + throw new BundlingException("Bundle section is missing in the appsettings.json configuration file."); + } + if (forceBuild) { var projects = new List() @@ -56,20 +67,20 @@ namespace Volo.Abp.Cli.Bundling FindBundleContributorsRecursively(startupModule, 0, bundleDefinitions); bundleDefinitions = bundleDefinitions.OrderByDescending(t => t.Level).ToList(); - var styleContext = GetStyleContext(bundleDefinitions); - var scriptContext = GetScriptContext(bundleDefinitions); + var styleContext = GetStyleContext(bundleDefinitions,bundleConfig.Parameters); + var scriptContext = GetScriptContext(bundleDefinitions,bundleConfig.Parameters); string styleDefinitions; string scriptDefinitions; - if (bundle || minify) + if (bundleConfig.Mode is BundlingMode.Bundle || bundleConfig.Mode is BundlingMode.BundleAndMinify) { var options = new BundleOptions { Directory = directory, FrameworkVersion = frameworkVersion, ProjectFileName = projectName, - BundleName = bundleName, - Minify = minify + BundleName = bundleConfig.Name, + Minify = bundleConfig.Mode == BundlingMode.BundleAndMinify }; styleDefinitions = StyleBundler.Bundle(options, styleContext); @@ -84,34 +95,37 @@ namespace Volo.Abp.Cli.Bundling await UpdateDependenciesInHtmlFileAsync(directory, styleDefinitions, scriptDefinitions); } - private BundleContext GetScriptContext(List bundleDefinitions) + private BundleContext GetScriptContext(List bundleDefinitions, + BundleParameterDictionary parameters) { var scriptContext = new BundleContext(); foreach (var bundleDefinition in bundleDefinitions) { var contributor = CreateContributorInstance(bundleDefinition.BundleContributorType); - contributor.AddScripts(scriptContext); + contributor.AddScripts(scriptContext, parameters); } scriptContext.Add("_framework/blazor.webassembly.js"); return scriptContext; } - private BundleContext GetStyleContext(List bundleDefinitions) + private BundleContext GetStyleContext(List bundleDefinitions, + BundleParameterDictionary parameters) { var styleContext = new BundleContext(); foreach (var bundleDefinition in bundleDefinitions) { var contributor = CreateContributorInstance(bundleDefinition.BundleContributorType); - contributor.AddStyles(styleContext); + contributor.AddStyles(styleContext, parameters); } return styleContext; } - private async Task UpdateDependenciesInHtmlFileAsync(string directory, string styleDefinitions, string scriptDefinitions) + private async Task UpdateDependenciesInHtmlFileAsync(string directory, string styleDefinitions, + string scriptDefinitions) { var htmlFilePath = Path.Combine(PathHelper.GetWwwRootPath(directory), "index.html"); if (!File.Exists(htmlFilePath)) @@ -127,8 +141,10 @@ namespace Volo.Abp.Cli.Bundling content = await reader.ReadToEndAsync(); } - content = UpdatePlaceholders(content, BundlingConsts.StylePlaceholderStart, BundlingConsts.StylePlaceholderEnd, styleDefinitions); - content = UpdatePlaceholders(content, BundlingConsts.ScriptPlaceholderStart, BundlingConsts.ScriptPlaceholderEnd, scriptDefinitions); + content = UpdatePlaceholders(content, BundlingConsts.StylePlaceholderStart, + BundlingConsts.StylePlaceholderEnd, styleDefinitions); + content = UpdatePlaceholders(content, BundlingConsts.ScriptPlaceholderStart, + BundlingConsts.ScriptPlaceholderEnd, scriptDefinitions); using (var writer = new StreamWriter(htmlFilePath, false, fileEncoding)) { @@ -137,11 +153,13 @@ namespace Volo.Abp.Cli.Bundling } } - private string UpdatePlaceholders(string content, string placeholderStart, string placeholderEnd, string definitions) + private string UpdatePlaceholders(string content, string placeholderStart, string placeholderEnd, + string definitions) { var placeholderStartIndex = content.IndexOf(placeholderStart); var placeholderEndIndex = content.IndexOf(placeholderEnd); - var updatedContent = content.Remove(placeholderStartIndex, (placeholderEndIndex + placeholderEnd.Length) - placeholderStartIndex); + var updatedContent = content.Remove(placeholderStartIndex, + (placeholderEndIndex + placeholderEnd.Length) - placeholderStartIndex); return updatedContent.Insert(placeholderStartIndex, definitions); } @@ -179,8 +197,10 @@ namespace Volo.Abp.Cli.Bundling { builder.Append($"{additionalProperty.Key}={additionalProperty.Value} "); } + builder.AppendLine(">"); } + builder.Append($" {BundlingConsts.ScriptPlaceholderEnd}"); return builder.ToString(); @@ -188,7 +208,7 @@ namespace Volo.Abp.Cli.Bundling private IBundleContributor CreateContributorInstance(Type bundleContributorType) { - return (IBundleContributor)Activator.CreateInstance(bundleContributorType); + return (IBundleContributor) Activator.CreateInstance(bundleContributorType); } private void FindBundleContributorsRecursively( @@ -203,7 +223,8 @@ namespace Volo.Abp.Cli.Bundling if (bundleContributors.Count > 1) { - throw new BundlingException($"Each project must contain only one class implementing {nameof(IBundleContributor)}"); + throw new BundlingException( + $"Each project must contain only one class implementing {nameof(IBundleContributor)}"); } if (bundleContributors.Any()) @@ -255,10 +276,11 @@ namespace Volo.Abp.Cli.Bundling var sdk = document.DocumentElement.GetAttribute("Sdk"); if (sdk != BundlingConsts.SupportedWebAssemblyProjectType) { - throw new BundlingException($"Unsupported project type. Project type must be {BundlingConsts.SupportedWebAssemblyProjectType}."); + throw new BundlingException( + $"Unsupported project type. Project type must be {BundlingConsts.SupportedWebAssemblyProjectType}."); } return document.SelectSingleNode("//TargetFramework").InnerText; } } -} +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/IBundlingService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/IBundlingService.cs index 9ddb4d7e96..817735ee20 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/IBundlingService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/IBundlingService.cs @@ -4,6 +4,6 @@ namespace Volo.Abp.Cli.Bundling { public interface IBundlingService { - Task BundleAsync(string directory, bool forceBuild, bool bundle, bool minify, string bundleName); + Task BundleAsync(string directory, bool forceBuild); } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/Scripts/ScriptBundler.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/Scripts/ScriptBundler.cs index 674b3ec7fd..32b8e2e863 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/Scripts/ScriptBundler.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/Scripts/ScriptBundler.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using System.IO; using System.Text; +using Volo.Abp.Bundling; using Volo.Abp.DependencyInjection; using Volo.Abp.Minify.Scripts; @@ -13,22 +15,36 @@ namespace Volo.Abp.Cli.Bundling.Scripts public ScriptBundler(IJavascriptMinifier minifier) : base(minifier) { - } - public override string GenerateDefinition(string bundleFilePath) + public override string GenerateDefinition(string bundleFilePath, + List bundleDefinitionsExcludingFromBundle) { var lastModifiedTicks = File.GetLastWriteTime(bundleFilePath).Ticks; var builder = new StringBuilder(); builder.AppendLine($"{BundlingConsts.ScriptPlaceholderStart}"); - builder.AppendLine($" "); + builder.AppendLine( + $" "); + + foreach (var bundleDefinition in bundleDefinitionsExcludingFromBundle) + { + builder.Append($" "); + } + builder.Append($" {BundlingConsts.ScriptPlaceholderEnd}"); return builder.ToString(); } - protected override string ProcessBeforeAddingToTheBundle(string referencePath, string bundleDirectory, string fileContent) + protected override string ProcessBeforeAddingToTheBundle(string referencePath, string bundleDirectory, + string fileContent) { return fileContent.EnsureEndsWith(';') + Environment.NewLine; } } -} +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/Styles/StyleBundler.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/Styles/StyleBundler.cs index 414c6bec41..c566aa6ae7 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/Styles/StyleBundler.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/Styles/StyleBundler.cs @@ -1,5 +1,7 @@ -using System.IO; +using System.Collections.Generic; +using System.IO; using System.Text; +using Volo.Abp.Bundling; using Volo.Abp.DependencyInjection; using Volo.Abp.Minify.Styles; @@ -12,26 +14,41 @@ namespace Volo.Abp.Cli.Bundling.Styles public StyleBundler(ICssMinifier minifier) : base(minifier) { - } - public override string GenerateDefinition(string bundleFilePath) + public override string GenerateDefinition(string bundleFilePath, + List bundleDefinitionsExcludingFromBundle) { var lastModifiedTicks = File.GetLastWriteTime(bundleFilePath).Ticks; var builder = new StringBuilder(); builder.AppendLine($"{BundlingConsts.StylePlaceholderStart}"); - builder.AppendLine($" "); + builder.AppendLine( + $" "); + + foreach (var bundleDefinition in bundleDefinitionsExcludingFromBundle) + { + builder.Append($" "); + } + builder.Append($" {BundlingConsts.StylePlaceholderEnd}"); return builder.ToString(); } - protected override string ProcessBeforeAddingToTheBundle(string referencePath, string bundleDirectory, string fileContent) + protected override string ProcessBeforeAddingToTheBundle(string referencePath, string bundleDirectory, + string fileContent) { return CssRelativePathAdjuster.Adjust( - fileContent, - referencePath, - bundleDirectory - ); + fileContent, + referencePath, + bundleDirectory + ); } } -} +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/BundleCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/BundleCommand.cs index e8554f89ae..266e2f6a72 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/BundleCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/BundleCommand.cs @@ -27,26 +27,7 @@ namespace Volo.Abp.Cli.Commands var forceBuild = commandLineArgs.Options.ContainsKey(Options.ForceBuild.Short) || commandLineArgs.Options.ContainsKey(Options.ForceBuild.Long); - - var bundle = commandLineArgs.Options.ContainsKey(Options.Bundle.Short) || - commandLineArgs.Options.ContainsKey(Options.Bundle.Long); - - var minify = commandLineArgs.Options.ContainsKey(Options.Minify.Short) || - commandLineArgs.Options.ContainsKey(Options.Minify.Long); - - var name = commandLineArgs.Options.GetOrNull( - Options.Name.Short, - Options.Name.Long - ); - - if ((minify || bundle) && name.IsNullOrEmpty()) - { - throw new CliUsageException( - "Please specify a bundle name." + - Environment.NewLine + Environment.NewLine + - GetUsageInfo() - ); - } + if (!Directory.Exists(workingDirectory)) { @@ -59,7 +40,7 @@ namespace Volo.Abp.Cli.Commands try { - await BundlingService.BundleAsync(workingDirectory, forceBuild, bundle, minify, name); + await BundlingService.BundleAsync(workingDirectory, forceBuild); } catch (BundlingException ex) { @@ -85,10 +66,6 @@ namespace Volo.Abp.Cli.Commands sb.AppendLine(""); sb.AppendLine("-wd|--working-directory (default: empty)"); sb.AppendLine("-f | --force (default: false)"); - sb.AppendLine("-f | --force (default: false)"); - sb.AppendLine("-b | --bundle (default: false)"); - sb.AppendLine("-m | --minify (default: false)"); - sb.AppendLine("-n | --name (default: empty)"); sb.AppendLine(""); sb.AppendLine("See the documentation for more info: https://docs.abp.io/en/abp/latest/CLI"); @@ -108,24 +85,6 @@ namespace Volo.Abp.Cli.Commands public const string Short = "f"; public const string Long = "force"; } - - public static class Bundle - { - public const string Short = "b"; - public const string Long = "bundle"; - } - - public static class Minify - { - public const string Short = "m"; - public const string Long = "minify"; - } - - public static class Name - { - public const string Short = "n"; - public const string Long = "name"; - } } } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Configuration/AbpCliConfig.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Configuration/AbpCliConfig.cs new file mode 100644 index 0000000000..e71f54c097 --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Configuration/AbpCliConfig.cs @@ -0,0 +1,9 @@ +using Volo.Abp.Cli.Bundling; + +namespace Volo.Abp.Cli.Configuration +{ + public class AbpCliConfig + { + public BundleConfig Bundle { get; set; } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Configuration/ConfigReader.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Configuration/ConfigReader.cs new file mode 100644 index 0000000000..f010ac3a56 --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Configuration/ConfigReader.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text.Json; +using System.Text.Json.Serialization; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.Cli.Configuration +{ + public class ConfigReader : IConfigReader, ITransientDependency + { + const string appSettingFileName = "appsettings.json"; + + public AbpCliConfig Read(string directory) + { + var settingsFilePath = Path.Combine(directory, appSettingFileName); + + if (!File.Exists(settingsFilePath)) + { + throw new Exception(); + } + + var settingsFileContent = File.ReadAllText(settingsFilePath); + + using (var document = JsonDocument.Parse(settingsFileContent)) + { + var element = document.RootElement.GetProperty("AbpCli"); + var configText = element.GetRawText(); + var options = new JsonSerializerOptions + { + Converters = + { + new JsonStringEnumConverter() + } + }; + return JsonSerializer.Deserialize(configText,options); + } + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Configuration/IConfigReader.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Configuration/IConfigReader.cs new file mode 100644 index 0000000000..ed97dbe11f --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Configuration/IConfigReader.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; + +namespace Volo.Abp.Cli.Configuration +{ + public interface IConfigReader + { + AbpCliConfig Read(string directory); + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleContext.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleContext.cs index 69f6e8d9e9..f2f94872ae 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleContext.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleContext.cs @@ -11,11 +11,13 @@ namespace Volo.Abp.Bundling BundleDefinitions = new List(); } - public void Add(string source, Dictionary additionalProperties = null) + public void Add(string source, bool excludeFromBundle = false, + Dictionary additionalProperties = null) { var bundleDefinition = new BundleDefinition { Source = source, + ExcludeFromBundle = excludeFromBundle }; if (additionalProperties != null) @@ -23,7 +25,8 @@ namespace Volo.Abp.Bundling bundleDefinition.AdditionalProperties = additionalProperties; } - BundleDefinitions.AddIfNotContains((item) => item.Source == bundleDefinition.Source, () => bundleDefinition); + BundleDefinitions.AddIfNotContains((item) => item.Source == bundleDefinition.Source, + () => bundleDefinition); } } -} +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleDefinition.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleDefinition.cs index 7a3bf315be..3450a682df 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleDefinition.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleDefinition.cs @@ -8,6 +8,8 @@ namespace Volo.Abp.Bundling public Dictionary AdditionalProperties { get; set; } + public bool ExcludeFromBundle { get; set; } + public BundleDefinition() { AdditionalProperties = new Dictionary(); diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleParameterDictionary.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleParameterDictionary.cs new file mode 100644 index 0000000000..dc23b97a16 --- /dev/null +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleParameterDictionary.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic; + +namespace Volo.Abp.Bundling +{ + public class BundleParameterDictionary : Dictionary + { + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Core/Volo/Abp/Bundling/IBundleContributor.cs b/framework/src/Volo.Abp.Core/Volo/Abp/Bundling/IBundleContributor.cs index 5388070cbd..e21fa4c4d0 100644 --- a/framework/src/Volo.Abp.Core/Volo/Abp/Bundling/IBundleContributor.cs +++ b/framework/src/Volo.Abp.Core/Volo/Abp/Bundling/IBundleContributor.cs @@ -2,7 +2,7 @@ { public interface IBundleContributor { - void AddScripts(BundleContext context); - void AddStyles(BundleContext context); + void AddScripts(BundleContext context, BundleParameterDictionary parameters); + void AddStyles(BundleContext context, BundleParameterDictionary parameters); } -} +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.Http.Client.IdentityModel.WebAssembly/Volo/Abp/Http/Client/IdentityModel/WebAssembly/IdentityModelWebAssemblyBundleContributor.cs b/framework/src/Volo.Abp.Http.Client.IdentityModel.WebAssembly/Volo/Abp/Http/Client/IdentityModel/WebAssembly/IdentityModelWebAssemblyBundleContributor.cs index 7ee8c8108f..90ef6b7b09 100644 --- a/framework/src/Volo.Abp.Http.Client.IdentityModel.WebAssembly/Volo/Abp/Http/Client/IdentityModel/WebAssembly/IdentityModelWebAssemblyBundleContributor.cs +++ b/framework/src/Volo.Abp.Http.Client.IdentityModel.WebAssembly/Volo/Abp/Http/Client/IdentityModel/WebAssembly/IdentityModelWebAssemblyBundleContributor.cs @@ -4,12 +4,12 @@ namespace Volo.Abp.Http.Client.IdentityModel.WebAssembly { public class IdentityModelWebAssemblyBundleContributor : IBundleContributor { - public void AddScripts(BundleContext context) + public void AddScripts(BundleContext context, BundleParameterDictionary parameters) { context.Add("_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"); } - public void AddStyles(BundleContext context) + public void AddStyles(BundleContext context, BundleParameterDictionary parameters) { } diff --git a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBundleContributor.cs b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBundleContributor.cs index a30dbc8f78..913a01caa7 100644 --- a/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBundleContributor.cs +++ b/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBundleContributor.cs @@ -4,11 +4,11 @@ namespace MyCompanyName.MyProjectName.Blazor { public class MyProjectNameBundleContributor : IBundleContributor { - public void AddScripts(BundleContext context) + public void AddScripts(BundleContext context, BundleParameterDictionary parameters) { } - public void AddStyles(BundleContext context) + public void AddStyles(BundleContext context, BundleParameterDictionary parameters) { context.Add("main.css"); }