From 77b5c95f75e3b756b5a4a9c110b274f7797124ce Mon Sep 17 00:00:00 2001
From: chylex <contact@chylex.com>
Date: Mon, 21 Aug 2017 09:41:15 +0200
Subject: [PATCH] Add basic js minification (trim whitespace and remove single
 line comments)

---
 Resources/PostBuild.ps1 | 12 ++++++++++++
 TweetDuck.csproj        |  5 ++++-
 2 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 Resources/PostBuild.ps1

diff --git a/Resources/PostBuild.ps1 b/Resources/PostBuild.ps1
new file mode 100644
index 00000000..ceb83d41
--- /dev/null
+++ b/Resources/PostBuild.ps1
@@ -0,0 +1,12 @@
+Param([Parameter(Mandatory = $True, Position = 1)][string] $dir)
+$ErrorActionPreference = "Stop"
+
+Set-Location $dir
+
+ForEach($file in Get-ChildItem -Include *.js, *.html -Recurse){
+  $lines = Get-Content -Path $file.FullName
+  $lines = ($lines | % { $_.TrimStart() }) -Replace '^(.*?)((?<=^|[;{}()] )//\s.*)?$', '$1'
+  $lines | Where { $_ -ne '' } | Set-Content -Path $file.FullName
+
+  Write-Host "Processed" $file.FullName.Substring($dir.Length)
+}
diff --git a/TweetDuck.csproj b/TweetDuck.csproj
index 58df2848..3a17f620 100644
--- a/TweetDuck.csproj
+++ b/TweetDuck.csproj
@@ -323,6 +323,7 @@
     <None Include="Resources\icon-small.ico" />
     <None Include="Resources\icon-tray-new.ico" />
     <None Include="Resources\icon-tray.ico" />
+    <None Include="Resources\PostBuild.ps1" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Resources\Plugins\" />
@@ -382,7 +383,9 @@ if $(ConfigurationName) == Debug (
   rmdir "$(TargetDir)plugins\official\.debug" /S /Q
   mkdir "$(TargetDir)plugins\user\.debug"
   xcopy "$(ProjectDir)Resources\Plugins\.debug\*" "$(TargetDir)plugins\user\.debug\" /E /Y
-)</PostBuildEvent>
+)
+
+powershell -ExecutionPolicy Unrestricted -File "$(ProjectDir)Resources\PostBuild.ps1" "$(TargetDir)\"</PostBuildEvent>
   </PropertyGroup>
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
     <PropertyGroup>