From b55b47b6890d4cf320db0325a463a956f1e748fc Mon Sep 17 00:00:00 2001
From: chylex <contact@chylex.com>
Date: Tue, 22 Aug 2017 09:48:03 +0200
Subject: [PATCH] Refactor postbuild js/html processing script

---
 Resources/PostBuild.ps1 | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/Resources/PostBuild.ps1 b/Resources/PostBuild.ps1
index ceb83d41..bea71d5a 100644
--- a/Resources/PostBuild.ps1
+++ b/Resources/PostBuild.ps1
@@ -3,10 +3,21 @@ $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'
+function Rewrite-File{
+  [CmdletBinding()]
+  Param([Parameter(Mandatory = $True, ValueFromPipeline = $True)][array] $lines, [Parameter(Mandatory = $True, Position = 1)] $file)
+  
   $lines | Where { $_ -ne '' } | Set-Content -Path $file.FullName
-
   Write-Host "Processed" $file.FullName.Substring($dir.Length)
 }
+
+ForEach($file in Get-ChildItem -Include *.js -Recurse){
+  $lines = Get-Content -Path $file.FullName
+  $lines = ($lines | % { $_.TrimStart() }) -Replace '^(.*?)((?<=^|[;{}()])\s?//(?:\s.*|$))?$', '$1'
+  ,$lines | Rewrite-File $file
+}
+
+ForEach($file in Get-ChildItem -Include *.html -Recurse){
+  $lines = Get-Content -Path $file.FullName
+  ,($lines | % { $_.TrimStart() }) | Rewrite-File $file
+}