Skip to content

Instantly share code, notes, and snippets.

@mirontoli
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mirontoli/8824709 to your computer and use it in GitHub Desktop.
Save mirontoli/8824709 to your computer and use it in GitHub Desktop.
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