-
Notifications
You must be signed in to change notification settings - Fork 25
/
updateTasksCommonProperty.ps1
65 lines (57 loc) · 1.95 KB
/
updateTasksCommonProperty.ps1
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# suppress warnings that we need to use
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidOverwritingBuiltInCmdlets', ""
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidUsingWriteHost', ""
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidUsingInvokeExpression', ""
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidUsingPositionalParameters', ""
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidGlobalVars', ""
)]
param()
# include
. "$(Split-Path $MyInvocation.MyCommand.Path -Parent)/utils/formatJson.ps1"
# object to be updated
# TODO: Add the properties that have to be updated here
$propertyToUpdate = [PSCustomObject]@{
}
# update all the .vscode/tasks.json
Write-Host -ForegroundColor Yellow "Updating tasks.json ..."
Get-ChildItem -Path ../ `
-Force -Include "tasks.json", "common.json" -Recurse | ForEach-Object {
Write-Host $_
$old = Get-Content $_ | ConvertFrom-Json
$tasks = $old.tasks
for ($i = 0; $i -lt $tasks.Count; $i++) {
$task = $tasks[$i]
$oldFields = $task | Get-Member *
$newFields = $propertyToUpdate | Get-Member *
foreach ($field in $newFields) {
$hasField = $false
foreach ($checkField in $oldFields) {
if ($checkField.Name -eq $field.Name) {
$hasField = $true
}
}
if (-not $hasField) {
# need to update
$tasks[$i] | `
Add-Member -MemberType NoteProperty `
-Name $field.Name `
-Value $propertyToUpdate.($field.Name)
}
}
}
# $old | ConvertTo-Json -Depth 100
ConvertTo-Json `
-Depth 100 `
-InputObject $old | `
Format-Json | `
Out-File -FilePath $_
}