Skip to content

feat(CssBundler): add BootstrapBlazor.CssBundler tool#576

Merged
ArgoZhang merged 3 commits intomasterfrom
feat-tool
Oct 1, 2025
Merged

feat(CssBundler): add BootstrapBlazor.CssBundler tool#576
ArgoZhang merged 3 commits intomasterfrom
feat-tool

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Oct 1, 2025

Link issues

fixes #575

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add a new BootstrapBlazor.CssBundler console tool to concatenate CSS files based on a JSON configuration.

New Features:

  • Introduce BootstrapBlazor.CssBundler CLI application for bundling CSS files into a single output from a bundler.json config
  • Implement argument parsing and help display via ArgumentsHelper
  • Provide BundlerOptions for loading input and output settings from a JSON file

Build:

  • Add the CssBundler project and include it in the BootstrapBlazor.Extensions solution

Copilot AI review requested due to automatic review settings October 1, 2025 12:48
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Oct 1, 2025

🧙 Sourcery has finished reviewing your pull request!


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto Bot added the enhancement New feature or request label Oct 1, 2025
@bb-auto bb-auto Bot added this to the v9.2.0 milestone Oct 1, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new CSS bundling tool for BootstrapBlazor that combines multiple CSS files into a single output file based on JSON configuration.

  • Adds a new console application BootstrapBlazor.CssBundler as a .NET tool
  • Implements CSS file bundling functionality with JSON-based configuration
  • Includes command-line argument parsing and help text

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/tools/BootstrapBlazor.CssBundler/Program.cs Entry point for the CSS bundler tool
src/tools/BootstrapBlazor.CssBundler/BundlerOptions.cs Configuration model for bundler settings
src/tools/BootstrapBlazor.CssBundler/Bundler.cs Core bundling logic and file processing
src/tools/BootstrapBlazor.CssBundler/BootstrapBlazor.CssBundler.csproj Project configuration for the bundler tool
src/tools/BootstrapBlazor.CssBundler/ArgumentsHelper.cs Command-line argument parsing and help display
BootstrapBlazor.Extensions.slnx Solution file update to include the new tool project

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/tools/BootstrapBlazor.CssBundler/Bundler.cs
Comment thread src/tools/BootstrapBlazor.CssBundler/Bundler.cs
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Remove the hard-coded absolute path in the DEBUG block or make it configurable to avoid environment-specific dependencies.
  • Consider using a dedicated CLI parser (e.g. System.CommandLine) instead of manual args parsing to support flags, defaults, and validation.
  • When concatenating files, insert separators (e.g. newlines or comments) between inputs and add basic exception handling to improve robustness.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Remove the hard-coded absolute path in the DEBUG block or make it configurable to avoid environment-specific dependencies.
- Consider using a dedicated CLI parser (e.g. System.CommandLine) instead of manual args parsing to support flags, defaults, and validation.
- When concatenating files, insert separators (e.g. newlines or comments) between inputs and add basic exception handling to improve robustness.

## Individual Comments

### Comment 1
<location> `src/tools/BootstrapBlazor.CssBundler/Bundler.cs:62` </location>
<code_context>
+
+            using var reader = File.OpenText(inputFile);
+            reader.BaseStream.CopyTo(writer);
+            reader.Close();
+        }
+        writer.Close();
</code_context>

<issue_to_address>
**nitpick:** Explicitly calling Close on a 'using' resource is redundant.

The explicit Close call on 'reader' can be removed, as disposal is handled by the 'using' statement.
</issue_to_address>

### Comment 2
<location> `src/tools/BootstrapBlazor.CssBundler/Bundler.cs:40-43` </location>
<code_context>
+            return;
+        }
+
+        if (option.InputFiles.Count == 0)
+        {
+            return;
+        }
+
</code_context>

<issue_to_address>
**suggestion:** Empty input files list is silently ignored.

Log a message when no input files are provided to notify the user that no bundling occurred.

```suggestion
        if (option.InputFiles.Count == 0)
        {
            Console.WriteLine("No input files provided. Bundling was skipped.");
            return;
        }
```
</issue_to_address>

### Comment 3
<location> `src/tools/BootstrapBlazor.CssBundler/Bundler.cs:52-58` </location>
<code_context>
+        foreach (var file in option.InputFiles)
+        {
+            var inputFile = Path.Combine(rootFolder, file);
+            if (!File.Exists(inputFile))
+            {
+                continue;
+            }
+
</code_context>

<issue_to_address>
**suggestion:** Missing input files are skipped without notification.

Log a warning for each missing file to improve visibility and troubleshooting.

```suggestion
        foreach (var file in option.InputFiles)
        {
            var inputFile = Path.Combine(rootFolder, file);
            if (!File.Exists(inputFile))
            {
                Console.WriteLine($"[Warning] Input file not found: {inputFile}");
                continue;
            }
```
</issue_to_address>

### Comment 4
<location> `src/tools/BootstrapBlazor.CssBundler/BundlerOptions.cs:20` </location>
<code_context>
+    {
+        var json = File.ReadAllText(configFile);
+
+        return JsonSerializer.Deserialize<BundlerOptions>(json, JsonSerializerOptions.Web) ?? new();
+    }
+}
</code_context>

<issue_to_address>
**issue (bug_risk):** Deserialization may fail silently and fallback to empty options.

Malformed config files result in default options without notifying the user. Please handle deserialization errors and inform the user when loading fails.
</issue_to_address>

### Comment 5
<location> `src/tools/BootstrapBlazor.CssBundler/Bundler.cs:35` </location>
<code_context>
+    {
+        var option = BundlerOptions.LoadFromConfigFile(bundlerFile);
+
+        if (string.IsNullOrEmpty(option.OutputFileName))
+        {
+            return;
</code_context>

<issue_to_address>
**issue (complexity):** Consider combining early-return checks and removing redundant resource disposal for clearer and safer code.

```suggestion
// 1. Collapse the three early-return guards into one for clarity
if (string.IsNullOrEmpty(option.OutputFileName)
    || option.InputFiles.Count == 0
    || string.IsNullOrEmpty(rootFolder))
{
    return;
}

var outputPath = Path.Combine(rootFolder, option.OutputFileName);

// 2. Remove manual Close() calls and simplify merging
// Option A: Read all text into a StringBuilder and write once
var sb = new StringBuilder();
foreach (var relative in option.InputFiles)
{
    var inputPath = Path.Combine(rootFolder, relative);
    if (!File.Exists(inputPath)) continue;
    sb.AppendLine(File.ReadAllText(inputPath));
}
File.WriteAllText(outputPath, sb.ToString());

// Option B: Stream-copy without redundant Close()
using (var output = File.Create(outputPath))
{
    foreach (var relative in option.InputFiles)
    {
        var inputPath = Path.Combine(rootFolder, relative);
        if (!File.Exists(inputPath)) continue;
        using var input = File.OpenRead(inputPath);
        input.CopyTo(output);
    }
}

Console.WriteLine($"Bundler Completed .... {option.OutputFileName}");
```

- Combined the three `if (…) return;` checks into a single guard.
- Removed explicit `reader.Close()`/`writer.Close()`: `using`/`using var` already disposes.
- Demonstrated both a memory‐buffered (`StringBuilder` + `WriteAllText`) and a streaming approach—pick the one that best fits your load size.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/tools/BootstrapBlazor.CssBundler/Bundler.cs
Comment thread src/tools/BootstrapBlazor.CssBundler/Bundler.cs
Comment thread src/tools/BootstrapBlazor.CssBundler/Bundler.cs
Comment thread src/tools/BootstrapBlazor.CssBundler/BundlerOptions.cs
Comment thread src/tools/BootstrapBlazor.CssBundler/Bundler.cs
@ArgoZhang ArgoZhang merged commit 3dfb8a5 into master Oct 1, 2025
2 checks passed
@ArgoZhang ArgoZhang deleted the feat-tool branch October 1, 2025 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(CssBundler): add BootstrapBlazor.CssBundler tool

2 participants