build: 📦 整理构建相关的工程文件 (#64)

This commit is contained in:
2023-11-22 16:02:07 +08:00
committed by GitHub
parent b4b4f23968
commit 20195e7eaf
38 changed files with 95 additions and 134 deletions

44
scripts/code.clean.csx Normal file
View File

@ -0,0 +1,44 @@
using System.Text.RegularExpressions;
using System.Net.Http;
using System.Net.Http.Json;
{
var files = string.Join(
';',
Args[0]
.Split('\n', StringSplitOptions.RemoveEmptyEntries)
.Select(x => x.Replace('\\', '/').Trim())
);
Console.WriteLine(files);
using var p = Process.Start(
new ProcessStartInfo
{
CreateNoWindow = true,
FileName = "dotnet",
Arguments = $"jb cleanupcode --include=\"{files}\" --no-build ../NetAdmin.sln",
UseShellExecute = false,
RedirectStandardOutput = true
}
);
p.WaitForExit();
Console.WriteLine(p.StandardOutput.ReadToEnd());
using var p2 = Process.Start(
new ProcessStartInfo
{
CreateNoWindow = true,
FileName = "git",
Arguments = $"status",
UseShellExecute = false,
RedirectStandardOutput = true
}
);
p2.WaitForExit();
var content = p2.StandardOutput.ReadToEnd();
Console.WriteLine(content);
return content.Contains("working tree clean") ? 0 : 1;
}

7
scripts/code.clean.ps1 Normal file
View File

@ -0,0 +1,7 @@
$files = $( foreach ($line in $( git diff head origin/dev --stat-width 200 ) | findstr '\|')
{
$line.split('\|')[0].trim()
} ) -join ';'
echo $files
dotnet jb cleanupcode --no-build --include = "$files" ./NetAdmin.sln
dotnet script ./PushSign.csx

View File

@ -0,0 +1 @@
dotnet jb cleanupcode --no-build ../NetAdmin.sln

4
scripts/dot.clean.cmd Normal file
View File

@ -0,0 +1,4 @@
call npm --prefix ../src/frontend/admin run prettier
dot rbom -w -e refs -e .git -e node_modules ../
dot trim -w -e refs -e .git -e node_modules ../
dot tolf -w -e refs -e .git -e node_modules ../

78
scripts/gen.cs.tt Normal file
View File

@ -0,0 +1,78 @@
<#@ template language="C#" #>
<#@ assembly name="System.Xml" #>
<#@ output encoding="utf-8" extension="Designer.cs" #>
<#@ import namespace="System.Xml" #>
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System.CodeDom.Compiler;
using System.Diagnostics.CodeAnalysis;
using System.Resources;
using System.Runtime.CompilerServices;
namespace NetAdmin.Infrastructure.Languages;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
public sealed class Ln
{
private static ResourceManager _resourceMan;
/// <summary>
/// Initializes a new instance of the <see cref="Ln" /> class.
/// </summary>
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
public Ln() { }
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Advanced)]
public static ResourceManager ResourceManager {
get {
if (ReferenceEquals(_resourceMan, null)) {
var temp = new ResourceManager("NetAdmin.Infrastructure.Languages.Ln", typeof(Ln).Assembly);
_resourceMan = temp;
}
return _resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Advanced)]
public static CultureInfo Culture { get; set; }
<#
var xml = new XmlDocument();
xml.Load("../assets/res/Ln.resx");
foreach (XmlNode data in xml.SelectNodes("//root/data")!)
{
#>
/// <summary>
/// <#= data.SelectSingleNode("value")?.InnerText #>
/// </summary>
public static string <#=
data.Attributes!["name"].Value.Replace(" ", "_") #> => ResourceManager.GetString("<#= data.Attributes!["name"].Value #>", Culture);
<#
}
#>
}

37
scripts/gen.id.linq Normal file
View File

@ -0,0 +1,37 @@
<Query Kind="Program">
<NuGetReference>Yitter.IdGenerator</NuGetReference>
<Namespace>Yitter.IdGenerator</Namespace>
</Query>
void Main()
{
//第1步全局 初始化(应用程序启动时执行一次):
// 创建 IdGeneratorOptions 对象,可在构造函数中输入 WorkerId
var options = new IdGeneratorOptions();
// options.WorkerIdBitLength = 10; // 默认值6限定 WorkerId 最大值为2^6-1即默认最多支持64个节点。
// options.SeqBitLength = 6; // 默认值6限制每毫秒生成的ID个数。若生成速度超过5万个/秒,建议加大 SeqBitLength 到 10。
// options.BaseTime = Your_Base_Time; // 如果要兼容老系统的雪花算法此处应设置为老系统的BaseTime。
// ...... 其它参数参考 IdGeneratorOptions 定义。
// 保存参数(务必调用,否则参数设置不生效):
YitIdHelper.SetIdGenerator(options);
// 以上过程只需全局一次且应在生成ID之前完成。
//第2步生成ID
// 初始化后在任何需要生成ID的地方调用以下方法
for (int i = 0; i < 20; i++)
{
var newId = YitIdHelper.NextId();
Console.WriteLine(newId);
}
for (int i = 0; i < 20; i++)
{
Console.WriteLine(Guid.NewGuid());
}
}
// You can define other methods, fields, classes and namespaces here

2
scripts/gen.ln.cmd Normal file
View File

@ -0,0 +1,2 @@
dotnet t4 ./gen.resx.tt -o ../assets/res/Ln.resx
dotnet t4 ./gen.cs.tt -o ../dist/backend/NetAdmin.Infrastructure/Ln.cs

39
scripts/gen.resx.tt Normal file
View File

@ -0,0 +1,39 @@
<#@ template language="C#" #>
<#@ output encoding="utf-8" extension="resx" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
id="root"
xmlns="">
<xsd:element name="root" msdata:IsDataSet="true">
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089
</value>
</resheader>
// ReSharper disable DuplicateResource
<#
var regex = new Regex(@"^\d", RegexOptions.Compiled);
foreach (var line in File.ReadLines("../assets/res/ln.txt"))
{
#>
<data name="<#= regex.IsMatch(line) ? "_" : "" #><#= line #>" xml:space="preserve"><value><#= line #></value></data>
<#
}
#>
</root>

10
scripts/git.pr.ps1 Normal file
View File

@ -0,0 +1,10 @@
$branch = $( git branch --show-current )
./dot.clean.cmd
git add ../
../node_modules/.bin/git-cz.ps1
git pull
git push --set-upstream origin $branch
Start-Process -FilePath "https://github.com/nsnail/NetAdmin/compare/main...$branch"
Write-Host "按『Enter』重建分支『Ctrl+C』退出"
Pause
./git.rc.ps1

6
scripts/git.rc.ps1 Normal file
View File

@ -0,0 +1,6 @@
$branch = $( git branch --show-current )
git checkout main
git pull
git branch -D $branch
git branch $branch
git checkout $branch

View File

@ -0,0 +1,65 @@
/*
for %%i in (*.png) do pngquant %%i --force --output %%i --skip-if-larger
for %%i in (*.jpg) do jpegtran -copy none -optimize -perfect %%i %%i
*
*/
var files = Directory
.EnumerateFiles(
"../",
"*.png",
new EnumerationOptions
{
RecurseSubdirectories = true,
AttributesToSkip = FileAttributes.ReparsePoint,
IgnoreInaccessible = true
}
)
.ToArray();
Parallel.ForEach(
files,
file =>
{
var startInfo = new ProcessStartInfo
{
FileName = "pngquant",
Arguments = $"\"{file}\" --force --output \"{file}\" --skip-if-larger"
};
using var p = Process.Start(startInfo);
p.WaitForExit();
Console.WriteLine($"{file}: {p.ExitCode}");
}
);
files = new[] { "*.jpg", "*.jpeg" }
.SelectMany(
x =>
Directory.EnumerateFiles(
"../",
x,
new EnumerationOptions
{
RecurseSubdirectories = true,
AttributesToSkip = FileAttributes.ReparsePoint,
IgnoreInaccessible = true
}
)
)
.ToArray();
Parallel.ForEach(
files,
file =>
{
var startInfo = new ProcessStartInfo
{
FileName = "jpegtran",
Arguments = $"-copy none -optimize -perfect \"{file}\" \"{file}\""
};
using var p = Process.Start(startInfo);
p.WaitForExit();
Console.WriteLine($"{file}: {p.ExitCode}");
}
);

View File

@ -0,0 +1,2 @@
dotnet new uninstall ../
dotnet new --install ../

27
scripts/rename.csx Normal file
View File

@ -0,0 +1,27 @@
#r "nuget: NSExt, 1.1.0"
using NSExt.Extensions;
Console.WriteLine("请输入原始名称NetAdmin");
var oldName = Console.ReadLine().NullOrEmpty("NetAdmin");
Console.WriteLine("请输入替换名称:");
var newName = Console.ReadLine();
foreach (var path in Directory.EnumerateDirectories("../", $"*{oldName}*",
SearchOption.AllDirectories))
{
Console.Write($"{path} --> ");
var newPath = path.Replace(oldName, newName);
Directory.Move(path, newPath);
Console.WriteLine(newPath);
}
Console.WriteLine();
foreach (var path in Directory.EnumerateFiles("../", $"*.*", SearchOption.AllDirectories))
{
File.WriteAllText(path, File.ReadAllText(path).Replace(oldName, newName));
var newPath = path.Replace(oldName, newName);
if (newPath == path) continue;
Console.Write($"{path} --> ");
Directory.Move(path, newPath);
Console.WriteLine(newPath);
}

View File

@ -0,0 +1,22 @@
{
"solution": "NetAdmin.sln",
"mappings": {
"FreeSql.NS": "../refs/FreeSql/FreeSql/FreeSql.csproj",
"FreeSql.DbContext.NS": "../refs/FreeSql/FreeSql.DbContext/FreeSql.DbContext.csproj"
},
"restore": [
{
"name": "NetAdmin.Infrastructure",
"packages": [
{
"packageName": "FreeSql.NS",
"version": "3.2.802-preview20231010-ns1"
},
{
"packageName": "FreeSql.DbContext.NS",
"version": "3.2.802-preview20231010-ns1"
}
]
}
]
}

View File

@ -0,0 +1,17 @@
{
"solution": "NetAdmin.sln",
"mappings": {
"Furion.Pure.NS": "../refs/Furion/framework/Furion.Pure/Furion.Pure.csproj"
},
"restore": [
{
"name": "NetAdmin.Infrastructure",
"packages": [
{
"packageName": "Furion.Pure.NS",
"version": "4.9.1.5-ns1"
}
]
}
]
}

View File

@ -0,0 +1,17 @@
{
"solution": "NetAdmin.sln",
"mappings": {
"NSExt": "../refs/ns-ext/src/NSExt/NSExt.csproj"
},
"restore": [
{
"name": "NetAdmin.Infrastructure",
"packages": [
{
"packageName": "NSExt",
"version": "1.1.0"
}
]
}
]
}

27
scripts/switcher.ps1 Normal file
View File

@ -0,0 +1,27 @@
# https://github.com/RicoSuter/DNT#switch-to-projects
$targets = @{
'1' = 'switch-to-projects'
'2' = 'switch-to-packages'
}
$key = ''
while ($null -eq $targets[$key])
{
$key = Read-Host '请选择1切换到项目引用 2切换到Nuget包引用'
}
$files = Get-ChildItem Switcher.*.json
$file = 9999
while ($null -eq $files[[int]$file - 1])
{
$i = 0
Write-Host '请选择要切换的配置文件文件'
foreach ($file in $files)
{
$i++
Write-Host $i $file.Name
}
$file = Read-Host
}
$file = [int]$file - 1
Copy-Item $files[$file] 'switcher.json' -Force
dotnet dnt $targets[$key] ../NetAdmin.sln
Remove-Item switcher.json

View File

@ -0,0 +1,49 @@
using System.Text.RegularExpressions;
var slnFile = Directory.GetFiles(@"../", "*.sln").First();
var content = File.ReadAllText(slnFile);
content = Regex.Replace(
content,
"Project\\(\"{2150E333-8FDC-42A3-9474-1A3956D46DE8}\"\\) = \"meta\", \"meta\", \"{5198A03D-0CAC-4828-A807-34A693F73859}\"(?:.|\n)*?EndProject",
$$"""
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "meta", "meta", "{5198A03D-0CAC-4828-A807-34A693F73859}"
{{'\t'}}ProjectSection(SolutionItems) = preProject
{{string.Join('\n',
Directory.GetFiles(@"../", "*").Where(x => !x.EndsWith(".sln") && !x.EndsWith(".user"))
.Select(x=>$"\t\t{Path.GetFileName(x)} = {Path.GetFileName(x)}")
)}}
{{'\t'}}EndProject
"""
);
content = Regex.Replace(
content,
"Project\\(\"{2150E333-8FDC-42A3-9474-1A3956D46DE8}\"\\) = \"workflows\", \"workflows\", \"{3C6F049E-3EE8-4D66-9AFF-E8A369032487}\"(?:.|\n)*?EndProject",
$$"""
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{3C6F049E-3EE8-4D66-9AFF-E8A369032487}"
{{'\t'}}ProjectSection(SolutionItems) = preProject
{{string.Join('\n',
Directory.GetFiles(@"../.github/workflows", "*")
.Select(x=>$"\t\t{Path.GetFileName(x)} = .github/workflows/{Path.GetFileName(x)}")
)}}
{{'\t'}}EndProject
"""
);
content = Regex.Replace(
content,
"Project\\(\"{2150E333-8FDC-42A3-9474-1A3956D46DE8}\"\\) = \"scripts\", \"scripts\", \"{BB0B25C9-0901-4923-913F-00F9A6B352A5}\"(?:.|\n)*?EndProject",
$$"""
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{BB0B25C9-0901-4923-913F-00F9A6B352A5}"
{{'\t'}}ProjectSection(SolutionItems) = preProject
{{string.Join('\n',
Directory.GetFiles(@"../scripts", "*")
.Select(x=>$"\t\t{Path.GetFileName(x)} = scripts/{Path.GetFileName(x)}")
)}}
{{'\t'}}EndProject
"""
);
Console.WriteLine(content);
File.WriteAllText(slnFile, content);