-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-fromtemplate.ps1
146 lines (119 loc) · 4.45 KB
/
update-fromtemplate.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
Param (
)
$ErrorActionPreference = "Stop"
function Update-Myself {
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true, Position = 0)]
[string]$SourcePath
)
#check that the destination file exists
if (Test-Path $SourcePath) {
#The path of THIS script
$CurrentScript = $MyInvocation.ScriptName
if (!($SourcePath -eq $CurrentScript )) {
if ($(Get-Item $SourcePath).LastWriteTimeUtc -gt $(Get-Item $CurrentScript ).LastWriteTimeUtc) {
write-host "Updating $SourcePath"
Copy-Item $SourcePath $CurrentScript
#If the script was updated, run it with orginal parameters
&$CurrentScript $script:args
exit
}
}
}
write-host "No update required"
}
# Remove a file or folder quietly
# Like linux "rm -rf"
function Remove-IfItemExists($item) {
if (Test-Path $item) {
echo "Removing $item"
Remove-Item $item -r -force
}
}
$configfile = "repository.json"
if (!(Test-Path -path $configfile)) {
Write-Output "repository.json not found"
exit 1
}
if ((Test-Path -path temp)) {
Write-Output "Removing existing temp directory"
rm .\temp\ -Recurse -Force
}
mkdir temp
# make sure latest version of cortside.templates is installed
#dotnet new --install cortside.templates
git clone https://github.com/cortside/coeus.git temp/coeus
# hack to set last write time to last git commit instead of time repo was cloned
cd temp/coeus/authorization-api
(get-item .\update-fromtemplate.ps1).LastWriteTime = get-date((git log -1 --format=%aI .\update-fromtemplate.ps1))
cd ../../..
Update-Myself .\temp\coeus\authorization-api\update-fromtemplate.ps1
$config = get-content $configfile | ConvertFrom-Json
$service = $config.service
$repository = $config.repository.name
$database = $config.database.name
if ($service -eq "" -or $repository -eq "") {
echo "missing parameters"
exit 1
}
$hasDatabase = $false
if ($database -ne "") {
$hasDatabase = $true
}
echo "service: $service"
echo "repository: $repository"
echo "database: $database"
echo "hasDatabase: $hasDatabase"
cp .\temp\coeus\authorization-api\clean.ps1
cp .\temp\coeus\authorization-api\format.ps1
cp .\temp\coeus\authorization-api\create-release.ps1
cp .\temp\coeus\authorization-api\generate-changelog.ps1
cp .\temp\coeus\authorization-api\update-nugetpackages.ps1
cp .\temp\coeus\authorization-api\src\.editorconfig .\src\.editorconfig
cp .\temp\coeus\authorization-api\.gitignore
Remove-IfItemExists update-template.ps1
#cp .\temp\coeus\authorization-api\.gitattributes
#git commit -m "Saving files before refreshing line endings" .gitattributes
#git add --renormalize .
cp .\temp\coeus\authorization-api\build.ps1
cp .\temp\coeus\authorization-api\dependabot.ps1
cp .\temp\coeus\authorization-api\update-targetframework.ps1
#((Get-Content -path build.ps1 -Raw) -replace 'Cortside.Authorization',$repository) | Set-Content -NoNewline -Path build.ps1 -Encoding utf8
if ($hasDatabase) {
cp .\temp\coeus\authorization-api\add-migration.ps1
cp .\temp\coeus\authorization-api\generate-sql.ps1
cp .\temp\coeus\authorization-api\generate-sqltriggers.ps1
#git mv .\Generate-SqlTriggers.ps1 .\generate-sqltriggers.ps1
cp .\temp\coeus\authorization-api\remove-migration.ps1
cp .\temp\coeus\authorization-api\repository.psm1
cp .\temp\coeus\authorization-api\update-database.ps1
# ((Get-Content -path generate-sqltriggers.ps1 -Raw) -replace 'Cortside.Authorization',$repository) | Set-Content -NoNewline -Path generate-sqltriggers.ps1 -Encoding utf8
if (Test-Path -path "src/sql/TriggerScripts") {
rm src/sql/TriggerScripts/GenerateTriggers.sql
rm "src/sql/TriggerScripts/delete all triggers.sql"
rm src/sql/proc/spWriteStringToFile.proc.sql
rm src/sql/TriggerScripts
rm src/sql/proc
}
if (Test-Path -path "src/version.json") {
rm src/version.json
}
if (Test-Path -path "set-params.ps1") {
((Get-Content -path set-params.ps1 -Raw) -replace '\\src\\version.json','\repository.json') | Set-Content -NoNewline -Path set-params.ps1 -Encoding utf8
}
}
if (Test-Path -path "update-version.ps1") {
rm update-version.ps1
}
if (Test-Path -path ".\\src\\sql\\table\\AuditLog.table.sql") {
git mv src\sql\table\AuditLog.table.sql src\sql\table\001-AuditLog.table.sql
}
if (Test-Path -path ".\\src\\sql\\table\\000-AuditLogTransaction.table.sql") {
cp .\temp\coeus\authorization-api\src\sql\table\000-AuditLogTransaction.table.sql src\sql\table
cp .\temp\coeus\authorization-api\src\sql\table\001-AuditLog.table.sql src\sql\table
}
# cleanup
rm .\temp\ -Recurse -Force
git status