Browse Source

Merge pull request #6668 from abpframework/bundle-command-improvements

Bundle command improvements
pull/6678/head
Halil İbrahim Kalkan 5 years ago
committed by GitHub
parent
commit
ad9e5f2bdd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      docs/en/CLI.md
  2. 47
      docs/en/UI/Blazor/Global-Scripts-Styles.md
  3. 12
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundleConfig.cs
  4. 48
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlerBase.cs
  5. 9
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingMode.cs
  6. 68
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingService.cs
  7. 2
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/IBundlingService.cs
  8. 26
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/Scripts/ScriptBundler.cs
  9. 37
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/Styles/StyleBundler.cs
  10. 45
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/BundleCommand.cs
  11. 9
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Configuration/AbpCliConfig.cs
  12. 48
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Configuration/ConfigReader.cs
  13. 9
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Configuration/IConfigReader.cs
  14. 9
      framework/src/Volo.Abp.Cli/Properties/launchSettings.json
  15. 13
      framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleContext.cs
  16. 2
      framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleDefinition.cs
  17. 8
      framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleParameterDictionary.cs
  18. 2
      framework/src/Volo.Abp.Core/Volo/Abp/Bundling/IBundleContributor.cs
  19. 4
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/MyProjectNameBundleContributor.cs
  20. 13
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/wwwroot/appsettings.json

2
docs/en/CLI.md

@ -419,4 +419,4 @@ abp bundle [options]
* ```--working-directory``` or ```-wd```: Specifies the working directory. This option is useful when executing directory doesn't contain a Blazor project file.
* ```--force``` or ```-f```: Forces to build project before generating references.
For more details about managing style and script references in Blazor apps, see [Managing Global Scripts & Styles](UI/Blazor/Global-Scripts-Styles.md)
`bundle` command reads the `appsettings.json` file inside the Blazor project for bundling options. For more details about managing style and script references in Blazor apps, see [Managing Global Scripts & Styles](UI/Blazor/Global-Scripts-Styles.md)

47
docs/en/UI/Blazor/Global-Scripts-Styles.md

@ -34,3 +34,50 @@ namespace MyProject.Blazor
```
> There is a BundleContributor class implementing `IBundleContributor` interface coming by default with the startup templates. So, most of the time, you don't need to add it manually.
## Bundling And Minification
`abp bundle` command offers bundling and minification support for client-side resources(JavaScript and CSS files). `abp bundle` command reads the `appsettings.json` file inside the Blazor project and bundles the resources according to the configuration. You can find the bundle configurations inside `AbpCli.Bundle` element.
Here are the options that you can control inside the `appsettings.json` file.
`Mode`: Bundling and minification mode. Possible values are
* `BundleAndMinify`: Bundle all the files into a single file and minify the content.
* `Bundle`: Bundle all files into a single file, but not minify.
* `None`: Add files individually, do not bundle.
`Name`: Bundle file name. Default value is `global`.
`Parameters`: You can define additional key/value pair parameters inside this section. `abp bundle` command automatically sends these parameters to the bundle contributors, and you can check these parameters inside the bundle contributor, take some actions according to these values.
Let's say that you want to exclude some resources from the bundle and control this action using the bundle parameters. You can add a parameter to the bundle section like below.
```json
"AbpCli": {
"Bundle": {
"Mode": "BundleAndMinify", /* Options: None, Bundle, BundleAndMinify */
"Name": "global",
"Parameters": {
"ExcludeThemeFromBundle":"true"
}
}
}
```
You can check this parameter and take action like below.
```csharp
public class MyProjectNameBundleContributor : IBundleContributor
{
public void AddScripts(BundleContext context)
{
}
public void AddStyles(BundleContext context)
{
var excludeThemeFromBundle = bool.Parse(context.Parameters.GetValueOrDefault("ExcludeThemeFromBundle"));
context.Add("mytheme.css", excludeFromBundle: excludeThemeFromBundle);
context.Add("main.css");
}
}
```

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

48
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<BundlerBase> Logger { get; set; }
public abstract string FileExtension { get; }
public abstract string GenerateDefinition(string bundleFilePath);
public abstract string GenerateDefinition(string bundleFilePath,
List<BundleDefinition> 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<BundleDefinition> 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;
}
}
}
}

9
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,
}
}

68
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<BundlingService> 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<DotNetProjectInfo>()
@ -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.IsNullOrEmpty() ? "global" : bundleConfig.Name,
Minify = bundleConfig.Mode == BundlingMode.BundleAndMinify
};
styleDefinitions = StyleBundler.Bundle(options, styleContext);
@ -84,9 +95,13 @@ namespace Volo.Abp.Cli.Bundling
await UpdateDependenciesInHtmlFileAsync(directory, styleDefinitions, scriptDefinitions);
}
private BundleContext GetScriptContext(List<BundleTypeDefinition> bundleDefinitions)
private BundleContext GetScriptContext(List<BundleTypeDefinition> bundleDefinitions,
BundleParameterDictionary parameters)
{
var scriptContext = new BundleContext();
var scriptContext = new BundleContext
{
Parameters = parameters
};
foreach (var bundleDefinition in bundleDefinitions)
{
@ -98,9 +113,13 @@ namespace Volo.Abp.Cli.Bundling
return scriptContext;
}
private BundleContext GetStyleContext(List<BundleTypeDefinition> bundleDefinitions)
private BundleContext GetStyleContext(List<BundleTypeDefinition> bundleDefinitions,
BundleParameterDictionary parameters)
{
var styleContext = new BundleContext();
var styleContext = new BundleContext
{
Parameters = parameters
};
foreach (var bundleDefinition in bundleDefinitions)
{
@ -111,7 +130,8 @@ namespace Volo.Abp.Cli.Bundling
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 +147,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 +159,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 +203,10 @@ namespace Volo.Abp.Cli.Bundling
{
builder.Append($"{additionalProperty.Key}={additionalProperty.Value} ");
}
builder.AppendLine("></script>");
}
builder.Append($" {BundlingConsts.ScriptPlaceholderEnd}");
return builder.ToString();
@ -188,7 +214,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 +229,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 +282,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;
}
}
}
}

2
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);
}
}

26
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<BundleDefinition> bundleDefinitionsExcludingFromBundle)
{
var lastModifiedTicks = File.GetLastWriteTime(bundleFilePath).Ticks;
var builder = new StringBuilder();
builder.AppendLine($"{BundlingConsts.ScriptPlaceholderStart}");
builder.AppendLine($" <script src=\"{Path.GetFileName(bundleFilePath)}?_v={lastModifiedTicks}\"></script>");
builder.AppendLine(
$" <script src=\"{Path.GetFileName(bundleFilePath)}?_v={lastModifiedTicks}\"></script>");
foreach (var bundleDefinition in bundleDefinitionsExcludingFromBundle)
{
builder.Append($" <script src=\"{bundleDefinition.Source}\"");
foreach (var additionalProperty in bundleDefinition.AdditionalProperties)
{
builder.Append($" {additionalProperty.Key}={additionalProperty.Value} ");
}
builder.AppendLine("></script>");
}
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;
}
}
}
}

37
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<BundleDefinition> bundleDefinitionsExcludingFromBundle)
{
var lastModifiedTicks = File.GetLastWriteTime(bundleFilePath).Ticks;
var builder = new StringBuilder();
builder.AppendLine($"{BundlingConsts.StylePlaceholderStart}");
builder.AppendLine($" <link href=\"{Path.GetFileName(bundleFilePath)}?_v={lastModifiedTicks}\" rel=\"stylesheet\"/>");
builder.AppendLine(
$" <link href=\"{Path.GetFileName(bundleFilePath)}?_v={lastModifiedTicks}\" rel=\"stylesheet\"/>");
foreach (var bundleDefinition in bundleDefinitionsExcludingFromBundle)
{
builder.Append($" <link href=\"{bundleDefinition.Source}\" rel=\"stylesheet\"");
foreach (var additionalProperty in bundleDefinition.AdditionalProperties)
{
builder.Append($" {additionalProperty.Key}={additionalProperty.Value} ");
}
builder.AppendLine("/>");
}
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
);
}
}
}
}

45
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 <directory-path> (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";
}
}
}
}

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

48
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Configuration/ConfigReader.cs

@ -0,0 +1,48 @@
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 FileNotFoundException($"appsettings file could not be found. Path:{settingsFilePath}");
}
var settingsFileContent = File.ReadAllText(settingsFilePath);
var documentOptions = new JsonDocumentOptions
{
CommentHandling = JsonCommentHandling.Skip
};
using (var document = JsonDocument.Parse(settingsFileContent,documentOptions))
{
var element = document.RootElement.GetProperty("AbpCli");
var configText = element.GetRawText();
var options = new JsonSerializerOptions
{
Converters =
{
new JsonStringEnumConverter()
},
ReadCommentHandling = JsonCommentHandling.Skip
};
return JsonSerializer.Deserialize<AbpCliConfig>(configText, options);
}
}
}
}

9
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);
}
}

9
framework/src/Volo.Abp.Cli/Properties/launchSettings.json

@ -0,0 +1,9 @@
{
"profiles": {
"Volo.Abp.Cli": {
"commandName": "Project",
"commandLineArgs": "bundle --skip-version-check",
"workingDirectory": "C:\\Github\\volo\\abp\\templates\\app-pro\\aspnet-core\\src\\MyCompanyName.MyProjectName.Blazor"
}
}
}

13
framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleContext.cs

@ -5,17 +5,21 @@ namespace Volo.Abp.Bundling
public class BundleContext
{
public List<BundleDefinition> BundleDefinitions { get; set; }
public BundleParameterDictionary Parameters { get; set; }
public BundleContext()
{
BundleDefinitions = new List<BundleDefinition>();
Parameters = new BundleParameterDictionary();
}
public void Add(string source, Dictionary<string, string> additionalProperties = null)
public void Add(string source, bool excludeFromBundle = false,
Dictionary<string, string> additionalProperties = null)
{
var bundleDefinition = new BundleDefinition
{
Source = source,
ExcludeFromBundle = excludeFromBundle
};
if (additionalProperties != null)
@ -23,7 +27,8 @@ namespace Volo.Abp.Bundling
bundleDefinition.AdditionalProperties = additionalProperties;
}
BundleDefinitions.AddIfNotContains((item) => item.Source == bundleDefinition.Source, () => bundleDefinition);
BundleDefinitions.AddIfNotContains((item) => item.Source == bundleDefinition.Source,
() => bundleDefinition);
}
}
}
}

2
framework/src/Volo.Abp.Core/Volo/Abp/Bundling/BundleDefinition.cs

@ -8,6 +8,8 @@ namespace Volo.Abp.Bundling
public Dictionary<string, string> AdditionalProperties { get; set; }
public bool ExcludeFromBundle { get; set; }
public BundleDefinition()
{
AdditionalProperties = new Dictionary<string, string>();

8
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<string, string>
{
}
}

2
framework/src/Volo.Abp.Core/Volo/Abp/Bundling/IBundleContributor.cs

@ -5,4 +5,4 @@
void AddScripts(BundleContext context);
void AddStyles(BundleContext context);
}
}
}

4
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");
}

13
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Blazor/wwwroot/appsettings.json

@ -7,6 +7,15 @@
"RemoteServices": {
"Default": {
"BaseUrl": "https://localhost:44305"
}
}
}
},
"AbpCli": {
"Bundle": {
"Mode": "BundleAndMinify", /* Options: None, Bundle, BundleAndMinify */
"Name": "global",
"Parameters": {
}
}
}
}

Loading…
Cancel
Save