|
| 1 | +// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved. |
| 2 | +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
| 3 | +// Website: https://www.blazor.zone or https://argozhang.github.io/ |
| 4 | + |
| 5 | +namespace BootstrapBlazor.CssBundler; |
| 6 | + |
| 7 | +internal class Bundler |
| 8 | +{ |
| 9 | + public static void Run(string[] args) |
| 10 | + { |
| 11 | +#if DEBUG |
| 12 | + if (args.Length == 0) |
| 13 | + { |
| 14 | + args = [ |
| 15 | + "C:\\Users\\Argo\\src\\BootstrapBlazor\\src\\BootstrapBlazor\\bundler.json" |
| 16 | + ]; |
| 17 | + } |
| 18 | +#endif |
| 19 | + |
| 20 | + var bundlerFile = ArgumentsHelper.ParseOptions(args); |
| 21 | + |
| 22 | + if (string.IsNullOrEmpty(bundlerFile)) |
| 23 | + { |
| 24 | + ArgumentsHelper.PrintHelp(); |
| 25 | + return; |
| 26 | + } |
| 27 | + |
| 28 | + BundlerCore(bundlerFile); |
| 29 | + } |
| 30 | + |
| 31 | + static void BundlerCore(string bundlerFile) |
| 32 | + { |
| 33 | + var option = BundlerOptions.LoadFromConfigFile(bundlerFile); |
| 34 | + |
| 35 | + if (string.IsNullOrEmpty(option.OutputFileName)) |
| 36 | + { |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + if (option.InputFiles.Count == 0) |
| 41 | + { |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + var rootFolder = Path.GetDirectoryName(bundlerFile); |
| 46 | + if (string.IsNullOrEmpty(rootFolder)) |
| 47 | + { |
| 48 | + return; |
| 49 | + } |
| 50 | + |
| 51 | + using var writer = File.OpenWrite(Path.Combine(rootFolder, option.OutputFileName)); |
| 52 | + foreach (var file in option.InputFiles) |
| 53 | + { |
| 54 | + var inputFile = Path.Combine(rootFolder, file); |
| 55 | + if (!File.Exists(inputFile)) |
| 56 | + { |
| 57 | + continue; |
| 58 | + } |
| 59 | + |
| 60 | + using var reader = File.OpenText(inputFile); |
| 61 | + reader.BaseStream.CopyTo(writer); |
| 62 | + reader.Close(); |
| 63 | + } |
| 64 | + writer.Close(); |
| 65 | + |
| 66 | + Console.WriteLine($"Bundler Completed .... {option.OutputFileName}"); |
| 67 | + } |
| 68 | +} |
0 commit comments