|
7 | 7 | using HandlebarsDotNet;
|
8 | 8 | using SmartCode.Configuration;
|
9 | 9 | using SmartCode.Utilities;
|
| 10 | +using System.Text.RegularExpressions; |
10 | 11 |
|
11 | 12 | namespace SmartCode.App.Outputs
|
12 | 13 | {
|
@@ -69,23 +70,26 @@ public async Task Output(BuildContext context, Output output = null)
|
69 | 70 | {
|
70 | 71 | case Configuration.CreateMode.None:
|
71 | 72 | case Configuration.CreateMode.Incre:
|
72 |
| - { |
73 |
| - _logger.LogWarning( |
74 |
| - $"------ Mode:{output.Mode},Build:{context.BuildKey},FilePath:{filePath} Exists ignore output End! ------"); |
75 |
| - return; |
76 |
| - } |
| 73 | + { |
| 74 | + _logger.LogWarning( |
| 75 | + $"------ Mode:{output.Mode},Build:{context.BuildKey},FilePath:{filePath} Exists ignore output End! ------"); |
| 76 | + return; |
| 77 | + } |
77 | 78 | case Configuration.CreateMode.Full:
|
78 |
| - { |
79 |
| - File.Delete(filePath); |
80 |
| - _logger.LogWarning($"------ Mode:{output.Mode},FilePath:{filePath} Exists Deleted ! ------"); |
81 |
| - break; |
82 |
| - } |
| 79 | + { |
| 80 | + File.Delete(filePath); |
| 81 | + _logger.LogWarning($"------ Mode:{output.Mode},FilePath:{filePath} Exists Deleted ! ------"); |
| 82 | + break; |
| 83 | + } |
83 | 84 | }
|
84 | 85 | }
|
85 | 86 |
|
86 |
| - using (StreamWriter streamWriter = new StreamWriter(filePath)) |
| 87 | + //采购VS默认的UTF-8 WITH BOM 编码 |
| 88 | + using (StreamWriter streamWriter = new StreamWriter(filePath, false, new UTF8Encoding(true))) |
87 | 89 | {
|
88 |
| - await streamWriter.WriteAsync(context.Result.Trim()); |
| 90 | + //强制行尾为 \r\n |
| 91 | + var result = Regex.Replace(context.Result.Trim(), @"[\r\n]+", "\r\n", RegexOptions.Multiline); |
| 92 | + await streamWriter.WriteAsync(result); |
89 | 93 | }
|
90 | 94 |
|
91 | 95 | _logger.LogInformation($"------ Mode:{output.Mode},Build:{context.BuildKey} -> {filePath} End! ------");
|
|
0 commit comments