Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions BootstrapBlazor.Extensions.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@
<File Path="src/readme.md" />
<File Path="src/SourceLink.targets" />
</Folder>
<Folder Name="/src/tools/">
<Project Path="src/tools/BootstrapBlazor.CssBundler/BootstrapBlazor.CssBundler.csproj" />
</Folder>
<Folder Name="/test/">
<Project Path="test/UnitTestEditor/UnitTestEditor.csproj" />
<Project Path="test/UnitTestHoliday/UnitTestHoliday.csproj" />
Expand Down
23 changes: 23 additions & 0 deletions src/tools/BootstrapBlazor.CssBundler/ArgumentsHelper.cs
Original file line number Diff line number Diff line change
@@ -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(" <bundler.json> 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] : "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.0.0</Version>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
Comment thread
ArgoZhang marked this conversation as resolved.
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<TargetFrameworks>net9.0</TargetFrameworks>
</PropertyGroup>

Comment thread
ArgoZhang marked this conversation as resolved.
<PropertyGroup>
<Title>BootstrapBlazor Css Bundler</Title>
<PackageId>BootstrapBlazor.CssBundler</PackageId>
<PackAsTool>true</PackAsTool>
<ToolCommandName>css-bundler</ToolCommandName>
<Authors>Argo Zhang(Argo@live.ca)</Authors>
<Copyright>Copyright 2025</Copyright>
<Company>Longbow</Company>
</PropertyGroup>

<ItemGroup>
<SupportedPlatform Remove="browser" />
</ItemGroup>

</Project>
68 changes: 68 additions & 0 deletions src/tools/BootstrapBlazor.CssBundler/Bundler.cs
Original file line number Diff line number Diff line change
@@ -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"
];
Comment thread
ArgoZhang marked this conversation as resolved.
}
#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))
Comment thread
ArgoZhang marked this conversation as resolved.
{
return;
}

if (option.InputFiles.Count == 0)
{
return;
}
Comment thread
ArgoZhang marked this conversation as resolved.

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;
}
Comment thread
ArgoZhang marked this conversation as resolved.

using var reader = File.OpenText(inputFile);
reader.BaseStream.CopyTo(writer);
reader.Close();
Comment thread
ArgoZhang marked this conversation as resolved.
}
writer.Close();
Comment thread
ArgoZhang marked this conversation as resolved.

Console.WriteLine($"Bundler Completed .... {option.OutputFileName}");
}
}
22 changes: 22 additions & 0 deletions src/tools/BootstrapBlazor.CssBundler/BundlerOptions.cs
Original file line number Diff line number Diff line change
@@ -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<string> InputFiles { get; set; } = [];

public static BundlerOptions LoadFromConfigFile(string configFile)
{
var json = File.ReadAllText(configFile);

return JsonSerializer.Deserialize<BundlerOptions>(json, JsonSerializerOptions.Web) ?? new();
Comment thread
ArgoZhang marked this conversation as resolved.
}
}
8 changes: 8 additions & 0 deletions src/tools/BootstrapBlazor.CssBundler/Program.cs
Original file line number Diff line number Diff line change
@@ -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);