-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSet-CordovaVersion.ps1
62 lines (54 loc) · 1.72 KB
/
Set-CordovaVersion.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
#!/usr/bin/pwsh
<#
.SYNOPSIS
Set version and build numbers for Cordova app for iOS and Android in config.xml
.DESCRIPTION
This scripts is the port of python code to PowerShell to set version and build numbers for Cordova app for iOS and Android in config.xml
.AUTHOR
Frédéric Ntawiniga based on the python scripts by Simon Prickett
#>
Param (
[ValidateScript({
$StringArray = $_.Split(".")
$ErrorFound = $False
If($StringArray.Length -Lt 3) {
$ErrorFound = $True
}
Else {
Foreach($String in $StringArray) {
If( ($String -Match "^\d+$") -Ne $True) {
$ErrorFound = $True
Break
}
}
}
If($ErrorFound) {
Throw "Build Number must be of the form 0.0.0"
}
Else {
$True
}
})]
[String] $VersionNumber = $(Throw "Version Number (-VersionNumber) Required"),
[ValidateRange(0,[int]::MaxValue)]
[Int] $BuildNumber = $(Throw "Build Number (-BuildNumber) Required"),
[ValidateScript({
If( (Test-Path $_) -Ne $True) {
Throw "ERROR: $($_) file does not exist"
}
$True
})]
[String] $ConfigFile = $(Throw "Config File (-ConfigFile) Required")
)
Process {
[Xml]$XmlTree = Get-Content -Path $ConfigFile
If($XmlTree.widget -Eq $Null) {
Throw "Failed to find a single <widget> element in config.xml"
}
Else {
$XmlTree.widget.version = $VersionNumber
$XmlTree.widget.SetAttribute("android-versionCode", [String]$BuildNumber)
$XmlTree.widget.SetAttribute("ios-CFBundleVersion", [String]$BuildNumber)
$XmlTree.Save($ConfigFile)
}
}