diff --git a/add-meta-files-to-sln.csx b/AddMetaFilesToSln.csx similarity index 100% rename from add-meta-files-to-sln.csx rename to AddMetaFilesToSln.csx diff --git a/code-cleanup-on-save.csx b/CodeCleanupOnSave.csx similarity index 100% rename from code-cleanup-on-save.csx rename to CodeCleanupOnSave.csx diff --git a/ImageOptimize.csx b/ImageOptimize.csx new file mode 100644 index 0000000..8e6aca7 --- /dev/null +++ b/ImageOptimize.csx @@ -0,0 +1,45 @@ +/* + 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}"); + }); \ No newline at end of file diff --git a/safe-delete-unused-resx.ahk b/SafetyDelUnusedResx.ahk similarity index 100% rename from safe-delete-unused-resx.ahk rename to SafetyDelUnusedResx.ahk diff --git a/assets/snapshots/20221212212417.png b/assets/snapshots/20221212212417.png index 0a28e51..aaf6f29 100644 Binary files a/assets/snapshots/20221212212417.png and b/assets/snapshots/20221212212417.png differ diff --git a/assets/snapshots/20221212214514.png b/assets/snapshots/20221212214514.png index 0873907..955c0d3 100644 Binary files a/assets/snapshots/20221212214514.png and b/assets/snapshots/20221212214514.png differ diff --git a/assets/snapshots/20221212215259.png b/assets/snapshots/20221212215259.png index 4f3d6dd..7fd28b1 100644 Binary files a/assets/snapshots/20221212215259.png and b/assets/snapshots/20221212215259.png differ diff --git a/assets/snapshots/20221212215853.png b/assets/snapshots/20221212215853.png index bfbf597..35ee168 100644 Binary files a/assets/snapshots/20221212215853.png and b/assets/snapshots/20221212215853.png differ diff --git a/assets/snapshots/img-optimize.cmd b/assets/snapshots/img-optimize.cmd deleted file mode 100644 index 4a697a0..0000000 --- a/assets/snapshots/img-optimize.cmd +++ /dev/null @@ -1,2 +0,0 @@ -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 \ No newline at end of file diff --git a/build.cake b/build.cake new file mode 100644 index 0000000..b0dde1e --- /dev/null +++ b/build.cake @@ -0,0 +1,122 @@ +var target = Argument("target", "Default"); +var configuration = Argument("configuration", "Release"); +var framework = Argument("framework", "net7.0-windows"); +var runtime = Argument("runtime","win-x64"); + +//////////////////////////////////////////////////////////////// +// Tasks + +Task("Clean") + .Does(context => +{ + context.CleanDirectory("./build"); +}); + +Task("Build") + .IsDependentOn("Clean") + .Does(context => +{ + DotNetPublish("./src/dot.csproj", new DotNetPublishSettings { + Configuration = configuration, + EnableCompressionInSingleFile = true, + Framework = framework, + SelfContained = true, + Runtime = runtime, + PublishSingleFile = true + }); +}); + + +// Task("Test") +// .IsDependentOn("Build") +// .Does(context => +// { +// DotNetTest("./test/Spectre.Console.Tests/Spectre.Console.Tests.csproj", new DotNetTestSettings { +// Configuration = configuration, +// NoRestore = true, +// NoBuild = true, +// }); +// +// DotNetTest("./test/Spectre.Console.Cli.Tests/Spectre.Console.Cli.Tests.csproj", new DotNetTestSettings { +// Configuration = configuration, +// NoRestore = true, +// NoBuild = true, +// }); +// +// DotNetTest("./test/Spectre.Console.Analyzer.Tests/Spectre.Console.Analyzer.Tests.csproj", new DotNetTestSettings { +// Configuration = configuration, +// NoRestore = true, +// NoBuild = true, +// }); +// }); + + +// Task("Publish-GitHub") +// .WithCriteria(ctx => BuildSystem.IsRunningOnGitHubActions, "Not running on GitHub Actions") +// //.IsDependentOn("Package") +// .Does(context => +// { +// var apiKey = Argument("github-key", null); +// if(string.IsNullOrWhiteSpace(apiKey)) { +// throw new CakeException("No GitHub API key was provided."); +// } +// +// // Publish to GitHub Packages +// var exitCode = 0; +// foreach(var file in context.GetFiles("./.artifacts/*.nupkg")) +// { +// context.Information("Publishing {0}...", file.GetFilename().FullPath); +// exitCode += StartProcess("dotnet", +// new ProcessSettings { +// Arguments = new ProcessArgumentBuilder() +// .Append("gpr") +// .Append("push") +// .AppendQuoted(file.FullPath) +// .AppendSwitchSecret("-k", " ", apiKey) +// } +// ); +// } +// +// if(exitCode != 0) +// { +// throw new CakeException("Could not push GitHub packages."); +// } +// }); + +// Task("Publish-NuGet") +// //.WithCriteria(ctx => BuildSystem.IsRunningOnGitHubActions, "Not running on GitHub Actions") +// //.IsDependentOn("Package") +// .Does(context => +// { +// var apiKey = Argument("nuget-key", null); +// if(string.IsNullOrWhiteSpace(apiKey)) { +// throw new CakeException("No NuGet API key was provided."); +// } +// +// // Publish to GitHub Packages +// foreach(var file in context.GetFiles("./.artifacts/*.nupkg")) +// { +// context.Information("Publishing {0}...", file.GetFilename().FullPath); +// DotNetNuGetPush(file.FullPath, new DotNetNuGetPushSettings +// { +// Source = "https://api.nuget.org/v3/index.json", +// ApiKey = apiKey, +// SkipDuplicate = true +// }); +// } +// }); + +//////////////////////////////////////////////////////////////// +// Targets + +// Task("Publish") +// .IsDependentOn("Publish-GitHub") +// .IsDependentOn("Publish-NuGet"); + +Task("Default") + .IsDependentOn("Build"); + +//////////////////////////////////////////////////////////////// +// Execution + +RunTarget(target) \ No newline at end of file diff --git a/build.ps1 b/build.ps1 deleted file mode 100644 index 3cb0581..0000000 --- a/build.ps1 +++ /dev/null @@ -1,4 +0,0 @@ -dotnet build -dotnet publish ./src/dot.csproj -f net7.0-windows -c Release -r win-x64 --sc -p:"PublishSingleFile=true" -o ./build/win-x64 -dotnet publish ./src/dot.csproj -f net7.0 -c Release -r linux-x64 --sc -p:"PublishSingleFile=true" -o ./build/linux-x64 -Remove-Item -r ./build/temp \ No newline at end of file diff --git a/dot.sln b/dot.sln index 05dfcf3..7375515 100644 --- a/dot.sln +++ b/dot.sln @@ -11,22 +11,24 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "meta", "meta", "{AD79881E-7 .gitattributes = .gitattributes .gitignore = .gitignore .tgitconfig = .tgitconfig - add-meta-files-to-sln.csx = add-meta-files-to-sln.csx - build.ps1 = build.ps1 - code-cleanup-on-save.csx = code-cleanup-on-save.csx + AddMetaFilesToSln.csx = AddMetaFilesToSln.csx + build.cake = build.cake code-format.cmd = code-format.cmd + CodeCleanupOnSave.csx = CodeCleanupOnSave.csx Directory.Build.props = Directory.Build.props dot.sln.DotSettings = dot.sln.DotSettings + dot.sln.DotSettings.user = dot.sln.DotSettings.user dotnet-tools.json = dotnet-tools.json GenerateResx.targets = GenerateResx.targets - git-clean.ps1 = git-clean.ps1 + git-clean.cmd = git-clean.cmd global.json = global.json + ImageOptimize.csx = ImageOptimize.csx LICENSE = LICENSE README.md = README.md README.zh-CN.md = README.zh-CN.md - safe-delete-unused-resx.ahk = safe-delete-unused-resx.ahk - switch-nuget.ps1 = switch-nuget.ps1 - switch-project.ps1 = switch-project.ps1 + SafetyDelUnusedResx.ahk = SafetyDelUnusedResx.ahk + switch-nuget.cmd = switch-nuget.cmd + switch-project.cmd = switch-project.cmd switcher.json = switcher.json EndProjectSection EndProject diff --git a/git-clean.ps1 b/git-clean.cmd similarity index 100% rename from git-clean.ps1 rename to git-clean.cmd diff --git a/src/CsxEditor.cs b/src/CsxEditor.cs index 6b5a523..9e0d99a 100644 --- a/src/CsxEditor.cs +++ b/src/CsxEditor.cs @@ -1,3 +1,9 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Threading.Tasks; + namespace Dot; // ReSharper disable once UnusedType.Global @@ -7,5 +13,51 @@ internal class CsxEditor #pragma warning disable CA1822 private void Run() #pragma warning restore CA1822 - { } + { + /* + 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(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(p.ExitCode); + }); + } } \ No newline at end of file diff --git a/src/Program.cs b/src/Program.cs index 3229226..e986ddc 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -29,6 +29,6 @@ app.Configure(config => { }); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); -CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); -CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("en-US"); +// CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); +// CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("en-US"); return app.Run(args); \ No newline at end of file diff --git a/switch-nuget.ps1 b/switch-nuget.cmd similarity index 100% rename from switch-nuget.ps1 rename to switch-nuget.cmd diff --git a/switch-project.ps1 b/switch-project.cmd similarity index 100% rename from switch-project.ps1 rename to switch-project.cmd