-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBundler.cs
More file actions
79 lines (65 loc) · 2.04 KB
/
Bundler.cs
File metadata and controls
79 lines (65 loc) · 2.04 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
// 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.Text;
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;
}
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);
var content = reader.ReadToEnd();
writer.Write(Encoding.UTF8.GetBytes(content));
reader.Close();
}
writer.Close();
Console.WriteLine($"Bundler Completed .... {option.OutputFileName}");
}
}