-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBundler.cs
More file actions
99 lines (84 loc) · 2.68 KB
/
Bundler.cs
File metadata and controls
99 lines (84 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// 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/
using System.Buffers;
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 options = BundlerOptions.LoadFromConfigFile(bundlerFile);
foreach (var option in options)
{
DoBundler(bundlerFile, option);
}
}
static void DoBundler(string bundlerFile, BundlerOptions option)
{
if (string.IsNullOrEmpty(option.OutputFileName))
{
return;
}
if (option.InputFiles.Count == 0)
{
return;
}
var rootFolder = Path.GetDirectoryName(bundlerFile);
if (string.IsNullOrEmpty(rootFolder))
{
return;
}
var buffer = ArrayPool<byte>.Shared.Rent(64 * 1024);
try
{
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.OpenRead(inputFile);
var read = reader.Read(buffer, 0, buffer.Length);
if (read >= 3 && buffer[0] == 0xEF && buffer[1] == 0xBB && buffer[2] == 0xBF)
{
writer.Write(buffer, 3, read - 3);
}
else
{
writer.Write(buffer, 0, read);
}
while (reader.Position < reader.Length)
{
read = reader.Read(buffer, 0, buffer.Length);
writer.Write(buffer, 0, read);
}
}
writer.Close();
}
finally
{
ArrayPool<byte>.Shared.Return(buffer);
}
Console.WriteLine($"Bundler Completed .... {option.OutputFileName}");
}
}