Skip to content

Commit

Permalink
Recurse search support for VSTS extension
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyzwezdin committed Nov 6, 2016
1 parent b11a1d3 commit 96c5b68
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
9 changes: 9 additions & 0 deletions src/MagicChunks/VSTS/MagicChunks/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
"helpMarkDown": "Configuration file path which should be transformed.",
"groupName": "sourcePath"
},
{
"name": "sourcePathRecurse",
"type": "boolean",
"label": "Recursive search",
"defaultValue": "false",
"required": false,
"groupName": "sourcePath",
"helpMarkDown": "Trying to serarch specified file in folder and sub-folders"
},
{
"name": "fileType",
"type": "pickList",
Expand Down
52 changes: 40 additions & 12 deletions src/MagicChunks/VSTS/MagicChunks/transform.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ param(
[String] [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()]
$sourcePath,

[bool]
$sourcePathRecurse,

[String] [Parameter(Mandatory = $true)] [ValidateNotNullOrEmpty()]
$fileType,

Expand All @@ -19,29 +22,54 @@ param(
$transformations
)

# Init Magic Chunks

Add-Type -Path "$PSScriptRoot\MagicChunks.dll"

Write-Host "Transforming file $($sourcePath)"

# Parse transforms

try {
$transforms = New-Object -TypeName MagicChunks.Core.TransformationCollection `


foreach($t in ($transformations.Replace("\", "\\") | ConvertFrom-Json).psobject.properties) {
$transforms.Add($t.name, $t.value)
}
}
catch {
Write-Error -Message "Transforms parsing error: $($_.Exception.Message)" -Exception $_.Exception
throw;
}

if ($targetPathType -eq "source") {
$target = $sourcePath;
}
elseif ($targetPathType -eq "specific") {
$target = $targetPath;
}

[MagicChunks.TransformTask]::Transform(($fileType, $null)[[string]::IsNullOrWhitespace($fileType) -or ($fileType -eq "Auto")], $sourcePath, $target, $transforms)
# Find files to transform

Write-Host "File transformed to $($target)"
if ($sourcePathRecurse) {
$files = Get-ChildItem $sourcePath -Recurse
}
catch {
Write-Error -Message "File transformation error: $($_.Exception.Message)" -Exception $_.Exception
else {
$files = Get-ChildItem $sourcePath
}

foreach ($file in $files) {

# Transform file

Write-Host "Transforming file $($file)"

try {
if ($targetPathType -eq "source") {
$target = $file;
}
elseif ($targetPathType -eq "specific") {
$target = $targetPath;
}

[MagicChunks.TransformTask]::Transform(($fileType, $null)[[string]::IsNullOrWhitespace($fileType) -or ($fileType -eq "Auto")], $sourcePath, $target, $transforms)

Write-Host "File transformed to $($target)"
}
catch {
Write-Error -Message "File $($file) transformation error: $($_.Exception.Message)" -Exception $_.Exception
}
}

0 comments on commit 96c5b68

Please sign in to comment.