-
Notifications
You must be signed in to change notification settings - Fork 17
/
updatePackageDetails.ps1
82 lines (72 loc) · 2.18 KB
/
updatePackageDetails.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# This file will update the android manifests and info.plist files to new version and package names if needed.
# This is a very handy tool for updating continuous integration stuff
# Usage: "updatePackageDetails.ps1 versionNumber versionName <[packageName] [packageReplacement]>"
function Syntax {
Write-Host "Usage: 'updatePackageDetails.ps1 versionNumber versionName <[packageName] [packageReplacement]>'"
Exit
}
if ( $args.Length -eq 0 -or $args[0] -eq "/?" -or $args.Length -eq 1 -or $args.Length -eq 3 ) {
Syntax;
} else {
$vNumb=$args[0];
$vName=$args[1];
if( $args.Length -eq 4 ) {
$pName=$args[2];
$pRepl=$args[3];
}
}
function BackupFile($file) {
if( (Test-Path "$file.bak")){
Move-Item "$file.bak" "$file" -force;
}
Copy-Item "$file" "$file.bak";
}
function UpdateManifest($file){
BackupFile $file;
Write-Host "Updating $file";
[xml]$xml = Get-Content "$file";
$nodes = $xml.SelectNodes("/manifest");
foreach($node in $nodes) {
$node.SetAttribute("android:versionCode", "$vNumb");
$node.SetAttribute("android:versionName", "$vName");
if( $pName -and $pRepl ){
$package = $node.GetAttribute("package");
$package = $package -replace "$pName", "$pRepl";
$node.SetAttribute("package", "$package");
}
}
$xml.Save("$file");
}
function SetNodeText($node, $text){
$node.'#text' = "$text";
}
function ReplaceNodeText($node, $find, $replace){
$text = $node.'#text' -replace "$find", "$replace";
SetNodeText $node $text;
}
function UpdatePlist($file){
BackupFile $file;
Write-Host "Updating $file";
[xml]$xml = Get-Content "$file";
$nodes = $xml.SelectNodes("/plist/dict/key");
foreach($node in $nodes) {
switch ($node.'#text') {
"CFBundleVersion" { SetNodeText $node.get_NextSibling() "$vName"; }
"CFBundleShortVersionString" { SetNodeText $node.get_NextSibling() "$vNumb"; }
"CFBundleIdentifier" {
if( $pName -and $pRepl ){
ReplaceNodeText $node.get_NextSibling() "$pName" "$pRepl";
}
}
}
}
$xml.Save("$file");
}
$manifests = Get-ChildItem Source/*/Properties/AndroidManifest.xml;
$plists = Get-ChildItem Source/*/Info.plist;
foreach($manifest in $manifests){
UpdateManifest $manifest;
}
foreach($plist in $plists){
UpdatePlist $plist;
}