Skip to content

Commit 6a0c07f

Browse files
Convert-BuildStep: Adding support for additional properties on .ps1 files ( Issue #123 ). Support for additional parameter types (Issue #125)
1 parent 6390480 commit 6a0c07f

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

Convert-BuildStep.ps1

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,11 @@
385385
if ([switch], [bool] -contains $paramType) {
386386
"`$Parameters.$ParameterName = `$parameters.$ParameterName -match 'true';"
387387
}
388+
if ([psobject], [object],[PSObject[]] -contains $paramType) {
389+
"`$Parameters.$ParameterName = ConvertFrom-JSON @'" +
390+
[Environment]::NewLine +
391+
'${{parameters.$ParameterName}}' + [Environment]::NewLine + "'@"
392+
}
388393
# If the parameter type was a scriptblock
389394
if ([ScriptBlock], [ScriptBlock[]] -contains $paramType) {
390395
"`$Parameters.$ParameterName = foreach (`$p in `$parameters.$ParameterName){ [ScriptBlock]::Create(`$p) }"
@@ -470,8 +475,13 @@ try {
470475
} else {
471476
$out.powershell = "$innerScript" -replace '`\$\{','${'
472477
}
478+
if ($ScriptBlock -and $ScriptBlock.Attributes) {
479+
if ("$($ScriptBlock.Attributes.ConditionString)") {
480+
$out.condition = "$($ScriptBlock.Attributes.ConditionString)"
481+
}
482+
}
473483
$out.name = $Name
474-
$out.displayName = $Name
484+
$out.displayName = $Name
475485
if ($definedParameters) {
476486
$out.parameters = $definedParameters
477487
}
@@ -505,6 +515,23 @@ try {
505515
}
506516
$out.run = "$innerScript" -replace '`\$\{','${'
507517
}
518+
if ($ScriptBlock -and $ScriptBlock.Attributes.Key -ne '') { # If the scriptblock has .Attributes with .Key properties
519+
foreach ($attr in $ScriptBlock.Attributes) { # each of those attributes
520+
if ($attr -isnot [Reflection.AssemblyMetadataAttribute]) { continue }
521+
if ($out.($attr.Key)) { # If it already had the key, use the original case.
522+
$originalNameCase =
523+
foreach ($prop in $out.psobject.properties) {
524+
if ($prop.Name -eq $attr.Key) {
525+
$prop.Name
526+
break
527+
}
528+
}
529+
$out.$originalNameCase = $attr.Value
530+
} else {
531+
$out.($attr.Key) = $attr.value
532+
}
533+
}
534+
}
508535
$out
509536
}
510537
}

0 commit comments

Comments
 (0)