-
Notifications
You must be signed in to change notification settings - Fork 1
/
staging.ps1
95 lines (81 loc) · 3.07 KB
/
staging.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
83
84
85
86
87
88
89
90
91
92
93
94
95
$includePackages = "ja0", "mv", "pv", "util", "v", "cw", "gs"
$knownPackages = Get-ChildItem -Directory |
Where-Object {
if (Test-Path variable:local:includePackages) {
$includePackages.Contains([System.IO.Path]::GetFileName($_))
} else {
Test-Path (Join-Path $_ "manifest.xml")
}
} |
ForEach-Object {
$_.Name
} |
Sort-Object
$xmlSettings = New-Object System.XMl.XmlWriterSettings
$xmlSettings.Indent = $true
$xmlSettings.IndentChars = " "
$xmlSettings.NewLineChars = "`n"
$packagesWriter = [System.XMl.XmlWriter]::Create("packages.xml", $xmlSettings)
$packagesWriter.WriteStartDocument()
$packagesWriter.WriteStartElement("packages")
$knownPackages |
ForEach-Object {
$path = $_
$manifest = Join-Path $path "manifest.xml"
$package = ([xml](Get-Content $manifest)).package
$version = $package.version |
ForEach-Object {
if (([string]$_) -match "^\d+(?:.\d+){1,3}") {
try {
[Version]($matches[0])
} catch {
[Version]::new()
}
} else {
[Version]::new()
}
}
$packagesWriter.WriteStartElement("package")
$packagesWriter.WriteElementString("name", $package.name)
$packagesWriter.WriteElementString("version", $package.version)
$packagesWriter.WriteElementString("type", $package.type)
$dependencies = $package.dependencies.dependency |
Where-Object {
if ($_.optional -is [string]) {
$c = $_.optional[0]
$c -eq "t" -or $c -eq "y" -or $c -eq "1"
} else {
$true
}
} |
ForEach-Object {
if ($_ -is [Xml.XmlElement]) {
$_.'#text'
} else {
$_
}
}
if ($dependencies.Count -gt 0) {
$packagesWriter.WriteStartElement("dependencies")
$dependencies |
ForEach-Object {
$packagesWriter.WriteElementString("dependency", $_)
}
$packagesWriter.WriteEndElement()
}
$packagesWriter.WriteStartElement("files")
Get-ChildItem $path -Recurse -File |
ForEach-Object {
$relativePath = (Resolve-Path $_.FullName -Relative).Replace(".\", "")
$packagesWriter.WriteStartElement('file')
$packagesWriter.WriteAttributeString('size', $_.Length)
$packagesWriter.WriteString($relativePath.Replace("\", "/"))
$packagesWriter.WriteEndElement()
}
$packagesWriter.WriteEndElement()
$packagesWriter.WriteEndElement()
}
$packagesWriter.WriteEndElement()
$packagesWriter.WriteEndDocument()
$packagesWriter.Flush()
$packagesWriter.Close()