Skip to content

Commit

Permalink
added support for -raw flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Ivarsson committed Aug 13, 2019
1 parent 0b6b409 commit 8eef9a8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
17 changes: 11 additions & 6 deletions RegexReplace/RegexReplace.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ param(
[String]
$ReplaceRegex,
[Bool]
$UseUTF8 = $true
$UseUTF8 = $true,
[Bool]
$UseRAW = $true
)

Trace-VstsEnteringInvocation $MyInvocation
Expand All @@ -33,14 +35,17 @@ try {

foreach ($path in $inputPaths) {
Write-Host "...in file $path"
$getContentCommand = "Get-Content $path"
$setContentCommand = "Set-Content $path"
if ($UseUTF8) {
$text = Get-Content $path -Encoding UTF8
$text -replace $findRegex, $replaceRegex | Set-Content $path -Encoding UTF8
$getContentCommand = $getContentCommand + " -Encoding UTF8"
$setContentCommand = $setContentCommand + " -Encoding UTF8"
}
else {
$text = Get-Content $path
$text -replace $findRegex, $replaceRegex | Set-Content $path
if ($UseRAW) {
$getContentCommand = $getContentCommand + " -Raw"
}
$text = iex $getContentCommand
$text -replace $findRegex, $replaceRegex | iex $setContentCommand
}
}
finally {
Expand Down
12 changes: 10 additions & 2 deletions RegexReplace/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"friendlyName": "RegEx Find & Replace",
"description": "Find & Replace using Regular Expressions",
"helpMarkDown": "[More Information](https://github.com/knom/vsts-regex-tasks/)",
"releaseNotes": "What's new in version 3.*<br />Multiple input search paths<br />Empty replace value<br />Minimatch support for search paths<br />UTF-8 Support<br/>Click [here](https://github.com/knom/vsts-regex-tasks/) for more Information.",
"releaseNotes": "What's new in version 3.*<br />Multiple input search paths<br />Empty replace value<br />Minimatch support for search paths<br />UTF-8 Support<br />-Raw when loading files<br/>Click [here](https://github.com/knom/vsts-regex-tasks/) for more Information.",
"category": "Utility",
"visibility": [
"Build",
Expand All @@ -13,7 +13,7 @@
"author": "knom",
"version": {
"Major": 3,
"Minor": 0,
"Minor": 1,
"Patch": 0
},
"demands": [
Expand Down Expand Up @@ -53,6 +53,14 @@
"defaultValue": "true",
"required": true,
"helpMarkDown": "Reads and writes the files using UTF-8 Encoding; otherwise ASCII encoding is used."
},
{
"name": "UseRAW",
"type": "boolean",
"label": "Use -Raw when reading file",
"defaultValue": "true",
"required": true,
"helpMarkDown": "Reads the files using -Raw option. Requires Powershell version v3 or higher"
}
],
"instanceNameFormat": "RegEx Find & Replace",
Expand Down
2 changes: 1 addition & 1 deletion vss-extension.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifestVersion": 1,
"id": "regexreplace-task",
"name": "RegexReplace Build Task",
"version": "2.1.0",
"version": "3.1.0",
"publisher": "knom",
"targets": [{
"id": "Microsoft.VisualStudio.Services"
Expand Down

0 comments on commit 8eef9a8

Please sign in to comment.