-
Notifications
You must be signed in to change notification settings - Fork 242
/
Sync-Repo.ps1
128 lines (114 loc) · 5.72 KB
/
Sync-Repo.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
<#
.SYNOPSIS
Syncs a Repo of EPAC from/to the origin
.DESCRIPTION
Syncs the sourceDirectory to the destinationDirectory
* Folders
* Docs
* Module
* Schemas
* Scripts
* Scripts-Deprecated
* StarterKit
* Files in root folder ($SourceDirectory)
* CODE_OF_CONDUCT.md
* LICENSE
* mkdocs.yml
* README.md
* SECURITY.md
* SUPPORT.md
* Sync-Repo.ps1
* Sync-FromGH.ps1
* Sync-ToGH.ps1
* .github (workflows for publishing to PSGallery)
.PARAMETER SourceDirectory
Directory with the source (cloned or forked/cloned repo)
.PARAMETER DestinationDirectory
Directory with the destination (cloned or forked/cloned repo)
.PARAMETER SuppressDeleteFiles
Switch parameter to suppress deleting files in $DestinationDirectory tree
.EXAMPLE
Sync-Repo.ps1 -SourceDirectory "C:\Users\johndoe\Documents\GitHub\EPAC" -DestinationDirectory "C:\Users\johndoe\Documents\GitHub\EPAC-Test"
#>
[CmdletBinding()]
param (
# Directory with the source (cloned or forked/cloned repo)
[Parameter(Mandatory = $true, Position = 0)]
[string] $SourceDirectory,
# Directory with the destination (cloned or forked/cloned repo)
[Parameter(Mandatory = $true, Position = 1)]
[string] $DestinationDirectory,
# Switch parameter to suppress deleting files in $DestinationDirectory tree
[Parameter()]
[switch] $SuppressDeleteFiles
)
$InformationPreference = "Continue"
Write-Information "==================================================================================================="
Write-Information "Sync from '$SourceDirectory' to '$DestinationDirectory'"
Write-Information "==================================================================================================="
# Check if directories exist
if (Test-Path $SourceDirectory -PathType Container) {
if (!(Test-Path $DestinationDirectory -PathType Container)) {
$answer = $null
while ($answer -ne "y" -and $answer -ne 'n') {
$answer = Read-Host "Destination directory '$DestinationDirectory' does not exist. Create it (y/n)?"
}
if ($answer -eq "y") {
New-Item "$DestinationDirectory" -ItemType Directory
}
else {
Write-Error "Destination directory '$DestinationDirectory' does not exist - Exiting" -ErrorAction Stop
}
}
if (!($SuppressDeleteFiles)) {
if (Test-Path "$DestinationDirectory/Docs") {
Write-Information "Deleting '$DestinationDirectory/Docs'"
Remove-Item "$DestinationDirectory/Docs" -Recurse
}
if (Test-Path "$DestinationDirectory/Module") {
Write-Information "Deleting '$DestinationDirectory/Module'"
Remove-Item "$DestinationDirectory/Module" -Recurse
}
if (Test-Path "$DestinationDirectory/Schemas") {
Write-Information "Deleting '$DestinationDirectory/Schemas'"
Remove-Item "$DestinationDirectory/Schemas" -Recurse
}
if (Test-Path "$DestinationDirectory/Scripts") {
Write-Information "Deleting '$DestinationDirectory/Scripts'"
Remove-Item "$DestinationDirectory/Scripts" -Recurse
}
if (Test-Path "$DestinationDirectory/Scripts-Deprecated") {
Write-Information "Deleting '$DestinationDirectory/Scripts-Deprecated'"
Remove-Item "$DestinationDirectory/Scripts-Deprecated" -Recurse
}
if (Test-Path "$DestinationDirectory/StarterKit") {
Write-Information "Deleting '$DestinationDirectory/StarterKit'"
Remove-Item "$DestinationDirectory/StarterKit" -Recurse
}
}
Write-Information "Copying '$SourceDirectory/Docs' to '$DestinationDirectory/Docs'"
Copy-Item "$SourceDirectory/Docs" "$DestinationDirectory/Docs" -Recurse -Force
Write-Information "Copying '$SourceDirectory/Module' to '$DestinationDirectory/Module'"
Copy-Item "$SourceDirectory/Module" "$DestinationDirectory/Module" -Recurse -Force
Write-Information "Copying '$SourceDirectory/Schemas' to '$DestinationDirectory/Schemas'"
Copy-Item "$SourceDirectory/Schemas" "$DestinationDirectory/Schemas" -Recurse -Force
Write-Information "Copying '$SourceDirectory/Scripts' to '$DestinationDirectory/Scripts'"
Copy-Item "$SourceDirectory/Scripts" "$DestinationDirectory/Scripts" -Recurse -Force
Write-Information "Copying '$SourceDirectory/Scripts-Deprecated' to '$DestinationDirectory/Scripts-Deprecated'"
Copy-Item "$SourceDirectory/Scripts-Deprecated" "$DestinationDirectory/Scripts-Deprecated" -Recurse -Force
Write-Information "Copying '$SourceDirectory/StarterKit' to '$DestinationDirectory/StarterKit'"
Copy-Item "$SourceDirectory/StarterKit" "$DestinationDirectory/StarterKit" -Recurse -Force
Write-Information "Copying files from root directory and workflows '$SourceDirectory' to '$DestinationDirectory'"
Copy-Item "$SourceDirectory/CODE_OF_CONDUCT.md" "$DestinationDirectory"
Copy-Item "$SourceDirectory/LICENSE" "$DestinationDirectory"
Copy-Item "$SourceDirectory/mkdocs.yml" "$DestinationDirectory"
Copy-Item "$SourceDirectory/README.md" "$DestinationDirectory"
Copy-Item "$SourceDirectory/SECURITY.md" "$DestinationDirectory"
Copy-Item "$SourceDirectory/SUPPORT.md" "$DestinationDirectory"
Copy-Item "$SourceDirectory/Sync-Repo.ps1" "$DestinationDirectory"
Copy-Item "$SourceDirectory/Sync-FromGH.ps1" "$DestinationDirectory"
Copy-Item "$SourceDirectory/Sync-ToGH.ps1" "$DestinationDirectory"
}
else {
Write-Error "The source directory '$SourceDirectory' must exist" -ErrorAction Stop
}