Created
July 14, 2010 00:50
-
-
Save tathamoddie/474831 to your computer and use it in GitHub Desktop.
PowerShell wrapper for AjaxMin.dll
This file contains hidden or 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
#requires -Version 2 | |
[CmdletBinding()] | |
param ( | |
[parameter(Mandatory=$true)] | |
$InputPath | |
) | |
$ErrorActionPreference = "Stop" | |
Set-PSDebug -Strict | |
$PSScriptFilePath = (Get-Item $MyInvocation.MyCommand.Path).FullName | |
$PSScriptRoot = Split-Path $PSScriptFilePath -Parent | |
# Load input data | |
Write-Verbose "Loading input from $InputPath" | |
$InputData = [System.IO.File]::ReadAllText($InputPath) | |
# Load AjaxMin.dll | |
Add-Type -Path (Join-Path -Path $PSScriptRoot -ChildPath "AjaxMin.dll") | |
$Minifier = New-Object -TypeName Microsoft.Ajax.Utilities.Minifier | |
# Perform the minification | |
switch ([System.IO.Path]::GetExtension($InputPath).ToLowerInvariant()) | |
{ | |
".js" | |
{ | |
Write-Verbose "Processing data as JavaScript" | |
$OutputData = $Minifier.MinifyJavaScript($InputData) | |
} | |
".css" | |
{ | |
Write-Verbose "Processing data as CSS" | |
$OutputData = $Minifier.MinifyStyleSheet($InputData) | |
} | |
default { throw "Unknown filetype." } | |
} | |
$Minifier.Errors | ForEach-Object { | |
throw $_ | |
} | |
# Write the output data | |
$OutputPath = [System.IO.Path]::ChangeExtension($InputPath, ".min" + [System.IO.Path]::GetExtension($InputPath)) | |
Write-Verbose "Writing output to $OutputPath" | |
Set-Content $OutputPath $OutputData |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment