Skip to content

Commit

Permalink
Merge pull request #65 from XiaoHeitu/fix_不一至的行尾
Browse files Browse the repository at this point in the history
Fix 不一至的行尾
  • Loading branch information
Ahoo-Wang authored Mar 3, 2022
2 parents 81c7c0c + a1005f4 commit acd44c8
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/SmartCode.App/Outputs/FileOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using HandlebarsDotNet;
using SmartCode.Configuration;
using SmartCode.Utilities;
using System.Text.RegularExpressions;

namespace SmartCode.App.Outputs
{
Expand Down Expand Up @@ -69,23 +70,26 @@ public async Task Output(BuildContext context, Output output = null)
{
case Configuration.CreateMode.None:
case Configuration.CreateMode.Incre:
{
_logger.LogWarning(
$"------ Mode:{output.Mode},Build:{context.BuildKey},FilePath:{filePath} Exists ignore output End! ------");
return;
}
{
_logger.LogWarning(
$"------ Mode:{output.Mode},Build:{context.BuildKey},FilePath:{filePath} Exists ignore output End! ------");
return;
}
case Configuration.CreateMode.Full:
{
File.Delete(filePath);
_logger.LogWarning($"------ Mode:{output.Mode},FilePath:{filePath} Exists Deleted ! ------");
break;
}
{
File.Delete(filePath);
_logger.LogWarning($"------ Mode:{output.Mode},FilePath:{filePath} Exists Deleted ! ------");
break;
}
}
}

using (StreamWriter streamWriter = new StreamWriter(filePath))
//采购VS默认的UTF-8 WITH BOM 编码
using (StreamWriter streamWriter = new StreamWriter(filePath, false, new UTF8Encoding(true)))
{
await streamWriter.WriteAsync(context.Result.Trim());
//强制行尾为 \r\n
var result = Regex.Replace(context.Result.Trim(), @"[\r\n]+", "\r\n", RegexOptions.Multiline);
await streamWriter.WriteAsync(result);
}

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

0 comments on commit acd44c8

Please sign in to comment.