@@ -2,50 +2,58 @@ $ErrorActionPreference = 'Stop'
2
2
3
3
<#
4
4
. SYNOPSIS
5
- Updates the metadata nuspec file with the specified information.
5
+ Updates the metadata nuspec file with the specified information.
6
6
7
7
. DESCRIPTION
8
- When a key and value is specified, update the metadata element with the specified key
9
- and the corresponding value in the specified NuspecFile.
10
- Singlular metadata elements are the only ones changed at this time.
8
+ When a key and value is specified, update the metadata element with the specified key
9
+ and the corresponding value in the specified NuspecFile.
10
+ Singlular metadata elements are the only ones changed at this time.
11
11
12
12
. PARAMETER key
13
- The element that should be updated in the metadata section.
13
+ The element that should be updated in the metadata section.
14
14
15
15
. PARAMETER value
16
- The value to update with.
16
+ The value to update with.
17
17
18
18
. PARAMETER NuspecFile
19
- The metadata/nuspec file to update
19
+ The metadata/nuspec file to update
20
20
21
21
. EXAMPLE
22
- Update-Metadata -key releaseNotes -value "https://github.com/majkinetor/AU/releases/latest"
22
+ PS> Update-Metadata -key releaseNotes -value "https://github.com/majkinetor/AU/releases/latest"
23
23
24
24
. EXAMPLE
25
- Update-Metadata -key releaseNotes -value "https://github.com/majkinetor/AU/releases/latest" -NuspecFile ".\package.nuspec"
25
+ PS> Update-Metadata -key releaseNotes -value "https://github.com/majkinetor/AU/releases/latest" -NuspecFile ".\package.nuspec"
26
26
27
27
. EXAMPLE
28
- This is an example of changing the Title of the nuspec file
29
- Update-Metadata -data @{ title = 'My Awesome Title' }
30
- - or -
31
- @{ title = 'My Awesome Title' } | Update-Metadata
28
+ PS> @{ title = 'My Awesome Title' } | Update-Metadata
29
+
30
+ This is an example of changing the Title of the nuspec file
31
+ Update-Metadata -data @{ title = 'My Awesome Title' }
32
32
33
33
. EXAMPLE
34
- This is an example of changing the id and version attributes for the dependency key
35
- Update-Metadata -data @{ dependency = 'kb2919355|1.0.20160915' }
36
- - or -
37
- @{ dependency = 'kb2919355|1.0.20160915' } | Update-Metadata
34
+ PS> Update-Metadata -data @{ dependency = 'kb2919355|1.0.20160915' }
35
+
36
+ This is an example of changing the id and version attributes for the dependency key
38
37
39
38
. EXAMPLE
40
- This is an example of changing the src and target attributes
41
- Update-Metadata -data @{ file = 'tools\**,tools' }
42
- - or -
43
- @{ file = 'tools\**|tools' } | Update-Metadata
39
+ PS> @{ dependency = 'kb2919355|1.0.20160915' } | Update-Metadata
40
+
41
+ . EXAMPLE
42
+ PS> Update-Metadata -data @{ file = 'tools\**,tools' }
43
+
44
+ This is an example of changing the src and target attributes
44
45
45
46
. EXAMPLE
46
- This is an example of changing the file src and target attributes for the first file element in the nuspec file.
47
- If only one file element is found the change value is omitted.
48
- @{ file = 'tools\**|tools,1' } | Update-Metadata
47
+ PS> @{ file = 'tools\**|tools' } | Update-Metadata
48
+
49
+ . EXAMPLE
50
+ PS> @{ file = 'tools\**|tools,1' } | Update-Metadata
51
+
52
+ This is an example of changing the file src and target attributes for the first file element in the nuspec file.
53
+ If only one file element is found the change value is omitted.
54
+
55
+ . INPUTS
56
+ A hashtable of key+value pairs can be used instead of specifically use an argument.
49
57
50
58
. NOTES
51
59
Will now show a warning if the specified key doesn't exist in the nuspec file.
@@ -56,6 +64,8 @@ If only one file element is found the change value is omitted.
56
64
While the parameter `NuspecFile` accepts globbing patterns,
57
65
it is expected to only match a single file.
58
66
67
+ The ability to update the file and dependency metadata was included in version 0.4.0.
68
+
59
69
. LINK
60
70
https://wormiecorp.github.io/Wormies-AU-Helpers/docs/functions/update-metadata
61
71
#>
@@ -66,7 +76,7 @@ function Update-Metadata {
66
76
[Parameter (Mandatory = $true , ParameterSetName = " Single" )]
67
77
[string ]$value ,
68
78
[Parameter (Mandatory = $true , ParameterSetName = " Multiple" , ValueFromPipeline = $true )]
69
- [hashtable ]$data = @ {$key = $value },
79
+ [hashtable ]$data = @ { $key = $value },
70
80
[ValidateScript ( { Test-Path $_ })]
71
81
[SupportsWildcards ()]
72
82
[string ]$NuspecFile = " .\*.nuspec"
@@ -84,44 +94,46 @@ function Update-Metadata {
84
94
' ^(file)$' {
85
95
$metaData = " files"
86
96
$NodeGroup = $nu.package .$metaData
87
- $NodeData , [int ]$change = $data [$_ ] -split (" ," )
97
+ $NodeData , [int ]$change = $data [$_ ] -split (" ," )
88
98
$NodeCount = $nu.package .$metaData.ChildNodes.Count
89
- $src , $target , $exclude = $NodeData -split (" \|" )
99
+ $src , $target , $exclude = $NodeData -split (" \|" )
90
100
$NodeAttributes = [ordered ] @ {
91
- " src" = $src
92
- " target" = $target
93
- " exclude" = $exclude
94
- }
95
- $change = @ {$true = " 0" ;$false = ($change - 1 )}[ ([string ]::IsNullOrEmpty($change )) ]
101
+ " src" = $src
102
+ " target" = $target
103
+ " exclude" = $exclude
104
+ }
105
+ $change = @ {$true = " 0" ; $false = ($change - 1 ) }[ ([string ]::IsNullOrEmpty($change )) ]
96
106
if ($NodeCount -eq 3 ) {
97
107
$NodeGroup = $NodeGroup ." $_ "
98
- } else {
108
+ }
109
+ else {
99
110
$NodeGroup = $NodeGroup .$_ [$change ]
100
111
}
101
112
}
102
113
' ^(dependency)$' {
103
- $MetaNode = $_ -replace (" y" , " ies" )
114
+ $MetaNode = $_ -replace (" y" , " ies" )
104
115
$metaData = " metadata"
105
- $NodeData , [int ]$change = $data [$_ ] -split (" ," )
116
+ $NodeData , [int ]$change = $data [$_ ] -split (" ," )
106
117
$NodeGroup = $nu.package .$metaData .$MetaNode
107
118
$NodeCount = $nu.package .$metaData .$MetaNode.ChildNodes.Count
108
- $id , $version , $include , $exclude = $NodeData -split (" \|" )
119
+ $id , $version , $include , $exclude = $NodeData -split (" \|" )
109
120
$NodeAttributes = [ordered ] @ {
110
- " id" = $id
111
- " version" = $version
112
- " include" = $include
113
- " exclude" = $exclude
114
- }
115
- $change = @ {$true = " 0" ;$false = ($change - 1 )}[ ([string ]::IsNullOrEmpty($change )) ]
121
+ " id" = $id
122
+ " version" = $version
123
+ " include" = $include
124
+ " exclude" = $exclude
125
+ }
126
+ $change = @ {$true = " 0" ; $false = ($change - 1 ) }[ ([string ]::IsNullOrEmpty($change )) ]
116
127
if ($NodeCount -eq 3 ) {
117
128
$NodeGroup = $NodeGroup ." $_ "
118
- } else {
129
+ }
130
+ else {
119
131
$NodeGroup = $NodeGroup .$_ [$change ]
120
132
}
121
133
}
122
134
default {
123
135
if ( $nu.package.metadata ." $_ " ) {
124
- $nu.package.metadata ." $_ " = $data [$_ ]
136
+ $nu.package.metadata ." $_ " = [ string ] $data [$_ ]
125
137
}
126
138
else {
127
139
Write-Warning " $_ does not exist on the metadata element in the nuspec file"
@@ -139,12 +151,13 @@ function Update-Metadata {
139
151
if (! ([string ]::IsNullOrEmpty($NodeAttributes [$attrib ])) ) {
140
152
if (! [string ]::IsNullOrEmpty( $NodeGroup.Attributes ) ) {
141
153
$NodeGroup.SetAttribute ($attrib , $NodeAttributes [$attrib ] )
142
- } else {
154
+ }
155
+ else {
143
156
Write-Warning " Attribute $attrib not defined for $_ in the nuspec file"
144
157
}
145
158
}
146
159
}
147
- }
160
+ }
148
161
}
149
162
150
163
$utf8NoBom = New-Object System.Text.UTF8Encoding($false )
0 commit comments