Skip to content

Commit acd44c8

Browse files
authored
Merge pull request #65 from XiaoHeitu/fix_不一至的行尾
Fix 不一至的行尾
2 parents 81c7c0c + a1005f4 commit acd44c8

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/SmartCode.App/Outputs/FileOutput.cs

+16-12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using HandlebarsDotNet;
88
using SmartCode.Configuration;
99
using SmartCode.Utilities;
10+
using System.Text.RegularExpressions;
1011

1112
namespace SmartCode.App.Outputs
1213
{
@@ -69,23 +70,26 @@ public async Task Output(BuildContext context, Output output = null)
6970
{
7071
case Configuration.CreateMode.None:
7172
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+
}
7778
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+
}
8384
}
8485
}
8586

86-
using (StreamWriter streamWriter = new StreamWriter(filePath))
87+
//采购VS默认的UTF-8 WITH BOM 编码
88+
using (StreamWriter streamWriter = new StreamWriter(filePath, false, new UTF8Encoding(true)))
8789
{
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);
8993
}
9094

9195
_logger.LogInformation($"------ Mode:{output.Mode},Build:{context.BuildKey} -> {filePath} End! ------");

0 commit comments

Comments
 (0)