mirror of
				https://github.com/nsnail/ns-ext.git
				synced 2025-10-31 22:55:27 +08:00 
			
		
		
		
	refactor: ♻️ 2.0 (#3)
This commit is contained in:
		
							
								
								
									
										26
									
								
								scripts/clean.ln.csx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								scripts/clean.ln.csx
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | ||||
| using System.Text.RegularExpressions; | ||||
|  | ||||
| var csFiles = Directory.EnumerateFiles(@"../src/backend", $"*.cs", new EnumerationOptions { RecurseSubdirectories = true }); | ||||
| foreach (var lnFile in Directory.EnumerateFiles("../assets/res", "*.ln")) | ||||
| { | ||||
|     var newLines = new List<string>(); | ||||
|     foreach (var line in File.ReadAllLines(lnFile)) | ||||
|     { | ||||
|         var found = false; | ||||
|         foreach (var csFile in csFiles) | ||||
|         { | ||||
|             if (File.ReadAllText(csFile).Contains($"Ln.{(Regex.IsMatch(line, @"^\d") ? "_" : "") + line}")) | ||||
|             { | ||||
|                 found = true; | ||||
|                 newLines.Add(line); | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         if (!found) | ||||
|         { | ||||
|             Console.WriteLine(line); | ||||
|         } | ||||
|     } | ||||
|     File.WriteAllLines(lnFile, newLines); | ||||
| } | ||||
							
								
								
									
										44
									
								
								scripts/code.clean.csx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								scripts/code.clean.csx
									
									
									
									
									
										Normal 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 ../NSExt.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; | ||||
| } | ||||
							
								
								
									
										4
									
								
								scripts/code.clean.ps1
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								scripts/code.clean.ps1
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| dotnet jb cleanupcode --no-build --include = $( $( git status --porcelain | Where-Object { $_ -match "^\s*[MA]" } | ForEach-Object { $_.TrimStart(" M").TrimStart(" A") } ) -join ";" ) ../NSExt.sln | ||||
| 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 ../ | ||||
							
								
								
									
										77
									
								
								scripts/gen.cs.tt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								scripts/gen.cs.tt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,77 @@ | ||||
| <#@ template language="C#" #> | ||||
| <#@ assembly name="System.Xml" #> | ||||
| <#@ output encoding="utf-8" extension="Designer.cs" #> | ||||
|  | ||||
| //------------------------------------------------------------------------------ | ||||
| // <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 NSExt.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")] | ||||
| [System.Diagnostics.DebuggerNonUserCode] | ||||
| [System.Runtime.CompilerServices.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("NSExt.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 System.Xml.XmlDocument(); | ||||
|     xml.Load("../assets/res/Ln.resx"); | ||||
|     foreach (System.Xml.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); | ||||
| <# | ||||
|     } | ||||
| #> | ||||
| } | ||||
							
								
								
									
										2
									
								
								scripts/gen.ln.cmd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								scripts/gen.ln.cmd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| dotnet t4 ./gen.resx.tt -o ../assets/res/Ln.resx | ||||
| dotnet t4 ./gen.cs.tt -o ../dist/backend/NSExt/Ln.cs | ||||
							
								
								
									
										39
									
								
								scripts/gen.resx.tt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								scripts/gen.resx.tt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| <#@ template language="C#" #> | ||||
| <#@ output encoding="utf-8" extension="resx" #> | ||||
| <?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> | ||||
|    <# | ||||
|     var regex = new System.Text.RegularExpressions.Regex(@"^\d", System.Text.RegularExpressions.RegexOptions.Compiled); | ||||
|     foreach (var file in System.IO.Directory.GetFiles("../assets/res/", "*.ln")) | ||||
|     { | ||||
|         foreach (var line in System.IO.File.ReadLines(file)) | ||||
|         { | ||||
| #> | ||||
|     <data name="<#= regex.IsMatch(line) ? "_" : "" #><#= line #>" xml:space="preserve"><value><#= line #></value></data> | ||||
| <# | ||||
|         } | ||||
|     } | ||||
| #> | ||||
| </root> | ||||
							
								
								
									
										11
									
								
								scripts/git.pr.ps1
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								scripts/git.pr.ps1
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| $branch = $( git branch --show-current ) | ||||
| git add ../ | ||||
| ./code.clean.ps1 | ||||
| git add ../ | ||||
| ../node_modules/.bin/git-cz.ps1 | ||||
| git pull | ||||
| git push --set-upstream origin $branch | ||||
| Start-Process -FilePath "https://github.com/nsnail/NSExt/compare/main...$branch" | ||||
| Write-Host "按『Enter』重建分支,『Ctrl+C』退出" | ||||
| Pause | ||||
| ./git.rc.ps1 | ||||
							
								
								
									
										6
									
								
								scripts/git.rc.ps1
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								scripts/git.rc.ps1
									
									
									
									
									
										Normal 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 | ||||
							
								
								
									
										65
									
								
								scripts/image.optimize.csx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								scripts/image.optimize.csx
									
									
									
									
									
										Normal 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}"); | ||||
|     } | ||||
| ); | ||||
							
								
								
									
										2
									
								
								scripts/install.as.tpl.ps1
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								scripts/install.as.tpl.ps1
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,2 @@ | ||||
| dotnet new uninstall ../ | ||||
| dotnet new --install ../ | ||||
							
								
								
									
										27
									
								
								scripts/rename.csx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								scripts/rename.csx
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| #r "nuget: NSExt, 1.1.0" | ||||
| using NSExt.Extensions; | ||||
|  | ||||
| Console.WriteLine("请输入原始名称(NSExt):"); | ||||
| var oldName = Console.ReadLine().NullOrEmpty("NSExt"); | ||||
| 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); | ||||
| } | ||||
							
								
								
									
										1
									
								
								scripts/resharper.full.ps1
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								scripts/resharper.full.ps1
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | ||||
| dotnet jb cleanupcode --no-build ../NSExt.sln | ||||
							
								
								
									
										17
									
								
								scripts/switcher.nsext.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								scripts/switcher.nsext.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,17 @@ | ||||
| { | ||||
|   "solution": "NSExt.sln", | ||||
|   "mappings": { | ||||
|     "NSExt": "../refs/ns-ext/src/NSExt/NSExt.csproj" | ||||
|   }, | ||||
|   "restore": [ | ||||
|     { | ||||
|       "name": "NSExt", | ||||
|       "packages": [ | ||||
|         { | ||||
|           "packageName": "NSExt", | ||||
|           "version": "1.1.0" | ||||
|         } | ||||
|       ] | ||||
|     } | ||||
|   ] | ||||
| } | ||||
							
								
								
									
										27
									
								
								scripts/switcher.ps1
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								scripts/switcher.ps1
									
									
									
									
									
										Normal 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 = 读取-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 = 读取-Host | ||||
| } | ||||
| $file = [int]$file - 1 | ||||
| Copy-Item $files[$file] 'switcher.json' -Force | ||||
| dotnet dnt $targets[$key] ../NSExt.sln | ||||
| Remove-Item switcher.json | ||||
							
								
								
									
										63
									
								
								scripts/sync.sln.files.csx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								scripts/sync.sln.files.csx
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,63 @@ | ||||
| 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 | ||||
| """ | ||||
| ); | ||||
|  | ||||
| content = Regex.Replace( | ||||
|     content, | ||||
|     "Project\\(\"{2150E333-8FDC-42A3-9474-1A3956D46DE8}\"\\) = \"build\", \"build\", \"{8E4C93BA-9493-4892-80C4-5E174C504829}\"(?:.|\n)*?EndProject", | ||||
|     $$""" | ||||
| Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{8E4C93BA-9493-4892-80C4-5E174C504829}" | ||||
| {{'\t'}}ProjectSection(SolutionItems) = preProject | ||||
| {{string.Join('\n', | ||||
|              Directory.GetFiles(@"../build", "*") | ||||
|                       .Select(x=>$"\t\t{Path.GetFileName(x)} = build/{Path.GetFileName(x)}") | ||||
|                       )}} | ||||
| {{'\t'}}EndProject | ||||
| """ | ||||
| ); | ||||
|  | ||||
| Console.WriteLine(content); | ||||
| File.WriteAllText(slnFile, content); | ||||
		Reference in New Issue
	
	Block a user
	 GitHub
						GitHub