|
|
|
@ -29,7 +29,7 @@ public class BundlingService : IBundlingService, ITransientDependency |
|
|
|
public IStyleBundler StyleBundler { get; set; } |
|
|
|
public IConfigReader ConfigReader { get; set; } |
|
|
|
|
|
|
|
public async Task BundleAsync(string directory, bool forceBuild) |
|
|
|
public async Task BundleAsync(string directory, bool forceBuild, string projectType = BundlingConsts.WebAssembly) |
|
|
|
{ |
|
|
|
var projectFiles = Directory.GetFiles(directory, "*.csproj"); |
|
|
|
if (!projectFiles.Any()) |
|
|
|
@ -40,9 +40,9 @@ public class BundlingService : IBundlingService, ITransientDependency |
|
|
|
|
|
|
|
var projectFilePath = projectFiles[0]; |
|
|
|
|
|
|
|
CheckProjectIsSupportedType(projectFilePath); |
|
|
|
CheckProjectIsSupportedType(projectFilePath, projectType); |
|
|
|
|
|
|
|
var config = ConfigReader.Read(PathHelper.GetWwwRootPath(directory)); |
|
|
|
var config = projectType == BundlingConsts.WebAssembly? ConfigReader.Read(PathHelper.GetWwwRootPath(directory)): ConfigReader.Read(directory); |
|
|
|
var bundleConfig = config.Bundle; |
|
|
|
|
|
|
|
if (forceBuild) |
|
|
|
@ -55,9 +55,9 @@ public class BundlingService : IBundlingService, ITransientDependency |
|
|
|
DotNetProjectBuilder.BuildProjects(projects, string.Empty); |
|
|
|
} |
|
|
|
|
|
|
|
var frameworkVersion = GetTargetFrameworkVersion(projectFilePath); |
|
|
|
var frameworkVersion = GetTargetFrameworkVersion(projectFilePath, projectType); |
|
|
|
var projectName = Path.GetFileNameWithoutExtension(projectFilePath); |
|
|
|
var assemblyFilePath = PathHelper.GetAssemblyFilePath(directory, frameworkVersion, projectName); |
|
|
|
var assemblyFilePath = projectType == BundlingConsts.WebAssembly? PathHelper.GetWebAssemblyFilePath(directory, frameworkVersion, projectName) : PathHelper.GetMauiBlazorAssemblyFilePath(directory, projectName); |
|
|
|
var startupModule = GetStartupModule(assemblyFilePath); |
|
|
|
|
|
|
|
var bundleDefinitions = new List<BundleTypeDefinition>(); |
|
|
|
@ -65,7 +65,7 @@ public class BundlingService : IBundlingService, ITransientDependency |
|
|
|
bundleDefinitions = bundleDefinitions.OrderByDescending(t => t.Level).ToList(); |
|
|
|
|
|
|
|
var styleContext = GetStyleContext(bundleDefinitions, bundleConfig.Parameters); |
|
|
|
var scriptContext = GetScriptContext(bundleDefinitions, bundleConfig.Parameters); |
|
|
|
var scriptContext = GetScriptContext(bundleDefinitions, bundleConfig.Parameters, projectType); |
|
|
|
string styleDefinitions; |
|
|
|
string scriptDefinitions; |
|
|
|
|
|
|
|
@ -101,17 +101,20 @@ public class BundlingService : IBundlingService, ITransientDependency |
|
|
|
} |
|
|
|
|
|
|
|
private BundleContext GetScriptContext(List<BundleTypeDefinition> bundleDefinitions, |
|
|
|
BundleParameterDictionary parameters) |
|
|
|
BundleParameterDictionary parameters, string projectType) |
|
|
|
{ |
|
|
|
var scriptContext = new BundleContext |
|
|
|
{ |
|
|
|
Parameters = parameters |
|
|
|
}; |
|
|
|
|
|
|
|
scriptContext.BundleDefinitions.AddIfNotContains( |
|
|
|
x => x.Source == "_framework/blazor.webassembly.js", |
|
|
|
() => new BundleDefinition { Source = "_framework/blazor.webassembly.js" }); |
|
|
|
|
|
|
|
if (projectType == BundlingConsts.WebAssembly) |
|
|
|
{ |
|
|
|
scriptContext.BundleDefinitions.AddIfNotContains( |
|
|
|
x => x.Source == "_framework/blazor.webassembly.js", |
|
|
|
() => new BundleDefinition { Source = "_framework/blazor.webassembly.js" }); |
|
|
|
} |
|
|
|
|
|
|
|
foreach (var bundleDefinition in bundleDefinitions) |
|
|
|
{ |
|
|
|
var contributor = CreateContributorInstance(bundleDefinition.BundleContributorType); |
|
|
|
@ -283,24 +286,41 @@ public class BundlingService : IBundlingService, ITransientDependency |
|
|
|
.SingleOrDefault(AbpModule.IsAbpModule); |
|
|
|
} |
|
|
|
|
|
|
|
private string GetTargetFrameworkVersion(string projectFilePath) |
|
|
|
private string GetTargetFrameworkVersion(string projectFilePath, string projectType) |
|
|
|
{ |
|
|
|
var document = new XmlDocument(); |
|
|
|
document.Load(projectFilePath); |
|
|
|
|
|
|
|
return document.SelectSingleNode("//TargetFramework").InnerText; |
|
|
|
return projectType switch { |
|
|
|
BundlingConsts.WebAssembly => document.SelectSingleNode("//TargetFramework").InnerText, |
|
|
|
BundlingConsts.MauiBlazor => document.SelectNodes("//TargetFrameworks")[0].InnerText, |
|
|
|
_ => null |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
private void CheckProjectIsSupportedType(string projectFilePath) |
|
|
|
private void CheckProjectIsSupportedType(string projectFilePath, string projectType) |
|
|
|
{ |
|
|
|
var document = new XmlDocument(); |
|
|
|
document.Load(projectFilePath); |
|
|
|
|
|
|
|
var sdk = document.DocumentElement.GetAttribute("Sdk"); |
|
|
|
if (sdk != BundlingConsts.SupportedWebAssemblyProjectType) |
|
|
|
|
|
|
|
switch (projectType) |
|
|
|
{ |
|
|
|
throw new BundlingException( |
|
|
|
$"Unsupported project type. Project type must be {BundlingConsts.SupportedWebAssemblyProjectType}."); |
|
|
|
case BundlingConsts.WebAssembly: |
|
|
|
if (sdk != BundlingConsts.SupportedWebAssemblyProjectType) |
|
|
|
{ |
|
|
|
throw new BundlingException( |
|
|
|
$"Unsupported project type. Project type must be {BundlingConsts.SupportedWebAssemblyProjectType}."); |
|
|
|
} |
|
|
|
break; |
|
|
|
case BundlingConsts.MauiBlazor: |
|
|
|
if (sdk != BundlingConsts.SupportedMauiBlazorProjectType) |
|
|
|
{ |
|
|
|
throw new BundlingException( |
|
|
|
$"Unsupported project type. Project type must be {BundlingConsts.SupportedMauiBlazorProjectType}."); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|