forked from TOMP-WG/TOMP-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge-API.ps1
More file actions
114 lines (95 loc) · 3.14 KB
/
merge-API.ps1
File metadata and controls
114 lines (95 loc) · 3.14 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
$path = ".\work\"
If(!(test-path -PathType container $path))
{
New-Item -ItemType Directory -Path $path
}
$ask = 'y'
$join = "";
If ($args.count -ne 0) {
$files = $args
$drafts = @()
$ask = 'n'
}
Else {
Write-Host "fetch files"
$files = Get-ChildItem -Path . -Filter "TOMP-API-*.yaml"
$drafts = Get-ChildItem -Path "./draft modules/" -Filter "TOMP-API-*.yaml"
}
If ($args[0] -eq 'all') {
Write-Host "fetch files"
$files = Get-ChildItem -Path . -Filter "TOMP-API-*.yaml"
$drafts = Get-ChildItem -Path "./draft modules/" -Filter "TOMP-API-*.yaml"
$ask = 'n'
}
If ($args[0] -eq 'mp') {
Write-Host "merge mp files"
$files = @()
$drafts = Get-ChildItem -Path "./MP modules/" -Filter "TOMP-API-*.yaml"
$ask = 'n'
}
Write-Host $files
ForEach ($arg in $files){
if ('TOMP-API-1-CORE.yaml' -cne $arg) {
if (('TOMP-API-2-OFFERS.yaml' -cne $arg) -and ('TOMP-API-4-PURCHASE.yaml' -cne $arg)) {
$defaultValue = 'N'
$display = "Add $($arg) [y/N]"
}
else {
$defaultValue = 'Y'
$display = "Add $($arg) [Y/n]"
}
if ('y' -eq $ask) {
$confirmation = Read-Host $display
}
else {
$confirmation = 'y'
}
if ([string]::IsNullOrWhiteSpace($confirmation)) {
$confirmation = $defaultValue
}
if ($confirmation -eq 'y' -or $confirmation -eq 'Y') {
$dest = ".\work\$($arg)"
$dest = $dest -replace "\\draft modules\\", "\\"
$dest = $dest -replace "\\MP modules\\", "\\"
Write-Host $dest
(gc .\$arg) -replace 'TOMP-API-1-CORE.yaml', '' | Out-File -encoding ASCII $dest
(gc .\work\$arg) -replace 'TOMP-API-2-OFFERS.yaml', '' | Out-File -encoding ASCII $dest
(gc .\work\$arg) -replace 'TOMP-API-4-PURCHASE.yaml', '' | Out-File -encoding ASCII $dest
$join = -join($join, " ", $dest);
}
}
}
ForEach ($arg in $drafts){
If ($args[0] -eq 'mp') {
$confirmation = 'y'
}
else {
$confirmation = Read-Host "Add $($arg) [y/N]"
}
if ($confirmation -eq 'y') {
If ($args[0] -eq 'mp') {
(gc ".\MP modules\$arg") -replace '../TOMP-API-1-CORE.yaml', '' | Out-File -encoding ASCII .\work\$arg
}
else {
(gc ".\draft modules\$arg") -replace '../TOMP-API-1-CORE.yaml', '' | Out-File -encoding ASCII .\work\$arg
}
$join = -join($join, " .\work\", $arg );
}
}
$join = -join("yaml-merge ", $join, " .\TOMP-API-1-CORE.yaml > .\TOMP-API-BOM.yaml");
Write-Host $join
Invoke-Expression $join
#$content = Get-Content -Path .\TOMP-API-BOM.yaml -Raw
#Set-Content -Path .\TOMP-API.yaml -Value $content -Encoding utf8
$in = '.\TOMP-API-BOM.yaml'
$out = '.\TOMP-API.yaml'
If ($args[0] -eq 'mp') {
$out = '.\TOMP-API-MP.yaml'
}
$text = Get-Content $in -Raw
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
$sw = New-Object System.IO.StreamWriter($out, $false, $utf8NoBom)
$sw.Write($text)
$sw.Close()
Remove-Item .\TOMP-API-BOM.yaml
Remove-Item -LiteralPath $path -Recurse -Force -Confirm:$false