Last active
August 29, 2015 13:56
-
-
Save mirontoli/8824709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Minify { | |
<# | |
.Synopsis | |
Short description | |
.DESCRIPTION | |
Long description | |
.EXAMPLE | |
Example of how to use this cmdlet | |
.EXAMPLE | |
Another example of how to use this cmdlet | |
#> | |
[CmdletBinding()] | |
Param | |
( | |
[Parameter(Mandatory=$true, | |
ValueFromPipelineByPropertyName=$true, | |
Position=0)] | |
$Path | |
, $YuiPath = ".\Yahoo.Yui.Compressor.dll" | |
, [Parameter(HelpMessage="The character encoding for the original file. The default is the UTF8.")] | |
[Microsoft.PowerShell.Commands.FileSystemCmdletProviderEncoding] | |
$EncodingIn = [Microsoft.PowerShell.Commands.FileSystemCmdletProviderEncoding]::UTF8 | |
, $Obfuscate = $true | |
, [Parameter(HelpMessage="The character encoding for the minified file. The default is the UTF8.")] | |
[Microsoft.PowerShell.Commands.FileSystemCmdletProviderEncoding] | |
$EncodingOut = [Microsoft.PowerShell.Commands.FileSystemCmdletProviderEncoding]::UTF8 | |
, [System.Globalization.CultureInfo]$Culture = [System.Globalization.CultureInfo]::InvariantCulture | |
) | |
$toolPath = Resolve-Path $YuiPath | |
[void][Reflection.Assembly]::LoadFile($toolPath) | |
$jsPath = Resolve-Path $Path | |
$item = Get-Item $jsPath | |
$content = Get-Content $item -Raw -Encoding $EncodingIn | |
$isVerboseLogging = $false | |
$preserveAllSemicolons = $false | |
$disableOptimizations = $false | |
$lineBreakPosition = -1 | |
$compressedContent = [Yahoo.Yui.Compressor.JavaScriptCompressor]::Compress($content ` | |
, $isVerboseLogging, $Obfuscate, $preserveAllSemicolons ` | |
, $disableOptimizations, $lineBreakPosition, [System.Text.Encoding]::$EncodingOut, $Culture) | |
$newName = $item.BaseName + ".min.js" | |
$compressedContent | Out-File -FilePath (Join-Path $item.Directory.FullName $newName) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment