diff --git a/BootstrapBlazor.Extensions.slnx b/BootstrapBlazor.Extensions.slnx index eb64485c..8b9db58a 100644 --- a/BootstrapBlazor.Extensions.slnx +++ b/BootstrapBlazor.Extensions.slnx @@ -97,6 +97,9 @@ + + + diff --git a/src/tools/BootstrapBlazor.CssBundler/ArgumentsHelper.cs b/src/tools/BootstrapBlazor.CssBundler/ArgumentsHelper.cs new file mode 100644 index 00000000..f85a837b --- /dev/null +++ b/src/tools/BootstrapBlazor.CssBundler/ArgumentsHelper.cs @@ -0,0 +1,23 @@ +// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +namespace BootstrapBlazor.CssBundler; + +static class ArgumentsHelper +{ + public static void PrintHelp() + { + Console.ForegroundColor = ConsoleColor.Cyan; + Console.WriteLine("Usage: BootstrapBlazorCssBundler [options]"); + Console.WriteLine("Options:"); + Console.WriteLine(" ConfigFileFullPath D:\\Argo\\src\\BootstrapBlazor\\src\\BootstrapBlazor\\bundler.json"); + Console.WriteLine(); + Console.ForegroundColor = ConsoleColor.Gray; + } + + public static string? ParseOptions(string[] args) + { + return args.Length > 0 ? args[0] : ""; + } +} diff --git a/src/tools/BootstrapBlazor.CssBundler/BootstrapBlazor.CssBundler.csproj b/src/tools/BootstrapBlazor.CssBundler/BootstrapBlazor.CssBundler.csproj new file mode 100644 index 00000000..40de8d43 --- /dev/null +++ b/src/tools/BootstrapBlazor.CssBundler/BootstrapBlazor.CssBundler.csproj @@ -0,0 +1,29 @@ + + + + 1.0.0 + Exe + net9.0 + enable + enable + + + + net9.0 + + + + BootstrapBlazor Css Bundler + BootstrapBlazor.CssBundler + true + css-bundler + Argo Zhang(Argo@live.ca) + Copyright 2025 + Longbow + + + + + + + diff --git a/src/tools/BootstrapBlazor.CssBundler/Bundler.cs b/src/tools/BootstrapBlazor.CssBundler/Bundler.cs new file mode 100644 index 00000000..9e059b41 --- /dev/null +++ b/src/tools/BootstrapBlazor.CssBundler/Bundler.cs @@ -0,0 +1,68 @@ +// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +namespace BootstrapBlazor.CssBundler; + +internal class Bundler +{ + public static void Run(string[] args) + { +#if DEBUG + if (args.Length == 0) + { + args = [ + "C:\\Users\\Argo\\src\\BootstrapBlazor\\src\\BootstrapBlazor\\bundler.json" + ]; + } +#endif + + var bundlerFile = ArgumentsHelper.ParseOptions(args); + + if (string.IsNullOrEmpty(bundlerFile)) + { + ArgumentsHelper.PrintHelp(); + return; + } + + BundlerCore(bundlerFile); + } + + static void BundlerCore(string bundlerFile) + { + var option = BundlerOptions.LoadFromConfigFile(bundlerFile); + + if (string.IsNullOrEmpty(option.OutputFileName)) + { + return; + } + + if (option.InputFiles.Count == 0) + { + return; + } + + var rootFolder = Path.GetDirectoryName(bundlerFile); + if (string.IsNullOrEmpty(rootFolder)) + { + return; + } + + using var writer = File.OpenWrite(Path.Combine(rootFolder, option.OutputFileName)); + foreach (var file in option.InputFiles) + { + var inputFile = Path.Combine(rootFolder, file); + if (!File.Exists(inputFile)) + { + continue; + } + + using var reader = File.OpenText(inputFile); + reader.BaseStream.CopyTo(writer); + reader.Close(); + } + writer.Close(); + + Console.WriteLine($"Bundler Completed .... {option.OutputFileName}"); + } +} diff --git a/src/tools/BootstrapBlazor.CssBundler/BundlerOptions.cs b/src/tools/BootstrapBlazor.CssBundler/BundlerOptions.cs new file mode 100644 index 00000000..6a545a84 --- /dev/null +++ b/src/tools/BootstrapBlazor.CssBundler/BundlerOptions.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License +// See the LICENSE file in the project root for more information. +// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone + +using System.Text.Json; + +namespace BootstrapBlazor.CssBundler; + +sealed class BundlerOptions +{ + public string? OutputFileName { get; set; } + + public List InputFiles { get; set; } = []; + + public static BundlerOptions LoadFromConfigFile(string configFile) + { + var json = File.ReadAllText(configFile); + + return JsonSerializer.Deserialize(json, JsonSerializerOptions.Web) ?? new(); + } +} diff --git a/src/tools/BootstrapBlazor.CssBundler/Program.cs b/src/tools/BootstrapBlazor.CssBundler/Program.cs new file mode 100644 index 00000000..5b86bf17 --- /dev/null +++ b/src/tools/BootstrapBlazor.CssBundler/Program.cs @@ -0,0 +1,8 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the Apache 2.0 License +// See the LICENSE file in the project root for more information. +// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone + +using BootstrapBlazor.CssBundler; + +Bundler.Run(args);