Skip to content

Instantly share code, notes, and snippets.

@jstangroome
Forked from tathamoddie/Export-Minified.ps1
Created July 14, 2010 00:51
Show Gist options
  • Save jstangroome/474832 to your computer and use it in GitHub Desktop.
Save jstangroome/474832 to your computer and use it in GitHub Desktop.
Export-Minified
#requires -Version 2
[CmdletBinding()]
param (
[parameter(
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true
)]
[string[]]
$Path
)
begin {
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
$PSScriptFilePath = (Get-Item $MyInvocation.MyCommand.Path).FullName
$PSScriptRoot = Split-Path $PSScriptFilePath -Parent
# Load AjaxMin.dll
Add-Type -Path (Join-Path -Path $PSScriptRoot -ChildPath "AjaxMin.dll")
}
process {
$Path | ForEach-Object {
# Load input data
$InputData = Get-Content $_
$Minifier = New-Object -TypeName Microsoft.Ajax.Utilities.Minifier
# Perform the minification
$OutputData = $Minifier.MinifyStyleSheet($InputData)
$Minifier.Errors | ForEach-Object {
Write-Error $_
}
# Write the output data
$OutputPath = [System.IO.Path]::ChangeExtension($_, ".min" + [System.IO.Path]::GetExtension($_))
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