/
MagicChunks.psm1
40 lines (32 loc) · 1.14 KB
/
MagicChunks.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Function Format-MagicChunks() {
<#
.SYNOPSIS
Transforms source document with specified transformations
#>
[CmdletBinding()]
param(
[Parameter(Mandatory=$True, ValueFromPipeline=$True)]
[System.IO.FileInfo]$path,
[Parameter()]
[string]$target,
[Parameter(Mandatory=$True)]
[hashtable]$transformations,
[Parameter()]
[string]$type
)
PROCESS {
Add-Type -Path "$PSScriptRoot\MagicChunks.dll"
Write-Host "Transforming file $($path)"
try {
$transforms = New-Object -TypeName MagicChunks.Core.TransformationCollection `
foreach($t in $transformations.GetEnumerator()) {
$transforms.Add($t.Key, $t.Value)
}
[MagicChunks.TransformTask]::Transform($type, $path, ($target, $path)[[string]::IsNullOrWhiteSpace($target)], $transforms)
Write-Host "File transformed to $(($target, $path)[[string]::IsNullOrWhiteSpace($target)])"
}
catch {
Write-Error -Message "File transformation error: $($_.Exception.Message)" -Exception $_.Exception
}
}
}