-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat(CssBundler): add BootstrapBlazor.CssBundler tool #576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] : ""; | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
src/tools/BootstrapBlazor.CssBundler/BootstrapBlazor.CssBundler.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>net9.0</TargetFrameworks> | ||
| </PropertyGroup> | ||
|
|
||
|
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> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| ]; | ||
|
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)) | ||
|
ArgoZhang marked this conversation as resolved.
|
||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (option.InputFiles.Count == 0) | ||
| { | ||
| return; | ||
| } | ||
|
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; | ||
| } | ||
|
ArgoZhang marked this conversation as resolved.
|
||
|
|
||
| using var reader = File.OpenText(inputFile); | ||
| reader.BaseStream.CopyTo(writer); | ||
| reader.Close(); | ||
|
ArgoZhang marked this conversation as resolved.
|
||
| } | ||
| writer.Close(); | ||
|
ArgoZhang marked this conversation as resolved.
|
||
|
|
||
| Console.WriteLine($"Bundler Completed .... {option.OutputFileName}"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
|
ArgoZhang marked this conversation as resolved.
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.