forked from SitecorePowerShell/Console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPost_Build.ps1
More file actions
121 lines (86 loc) · 4.3 KB
/
Post_Build.ps1
File metadata and controls
121 lines (86 loc) · 4.3 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
115
116
117
118
119
120
#
# Copies contents of _Deploy folders into the various deployment sites, as specified within deploy_user.json
#
Param([string]$projectfilter)
# Load dependents scripts
. "$PSScriptRoot\Deploy_Functions.ps1"
# Load configuration files
$deployConfig = Get-Content "$PSScriptRoot\deploy.json" | ConvertFrom-Json
$userConfig = Get-Content "$PSScriptRoot\deploy.user.json" | ConvertFrom-Json
# Set source folder
$sourceFolder = $PSScriptRoot
# Convert the variables into a hashtable for replacement
$variables = @{ "%%sourceFolder%%" = $sourceFolder }
Write-Host -ForegroundColor Cyan "*******************************************"
Write-Host -ForegroundColor Cyan " Sitecore PowerShell Extensions Deployment"
Write-Host -ForegroundColor Cyan "*******************************************"
Write-Host
if ($projectFilter) {
Write-Host "Applying project filter: $projectFilter"
}
Write-Host
Write-Host -ForegroundColor Blue "Building user configuration with variable replacements"
Write-Host
# First copy user configuration to a deploy folder
$userConfigPath = Join-Path $sourceFolder $deployConfig.userConfigurationFolder
$deployFolderFullPath = Join-Path $sourceFolder $deployConfig.deployFolder
$deployUserConfigPath = Join-Path $deployFolderFullPath $deployConfig.userConfigurationFolder
Get-ChildItem $userConfigPath -Recurse | ? { $_.Extension -eq ".config" } | % {
$targetFile = $deployUserConfigPath + $_.FullName.SubString($userConfigPath.Length);
Copy-ItemWithStructure $_.FullName $targetFile
Write-Host "--- Copied $targetFile"
}
# Perform variable replacement on configuration files in deploy folder
$variablesRegexKeys = $variables.keys | % { [System.Text.RegularExpressions.Regex]::Escape($_) }
$variablesRegex = [regex]($variablesRegexKeys -join '|')
$regexCallback = { $variables[$args[0].Value] }
Get-ChildItem $deployUserConfigPath -Recurse -Include *.config | % {
$file = [System.IO.File]::ReadAllText($_.FullName)
$file = $variablesRegex.Replace($file, $regexCallback)
Set-Content -Path $_ -Value $file
}
# Loop over the sites to deploy
foreach ( $site in $userConfig.sites )
{
$site = Update-FromDefaultSite $site
# Get folders to deploy to from configuration and based on the destination site's version
$deployProjects = $deployConfig.deployProjects | Filter-ProjectsForSite -version $site.version -projectFilter $projectFilter
Write-Host
Write-Host -ForegroundColor Cyan "Deploying to $($site.path)"
Write-Host
foreach ($deployProject in $deployProjects)
{
$deployFolder = Get-DeployFolder $sourceFolder $deployConfig $deployProject.project
$projectFolder = Get-ProjectFolder $sourceFolder $deployProject.project
Write-Host
Write-Host -ForegroundColor Green "Copying from $deployFolder to $($site.path)"
Write-Host
$siteWebsiteFolder = Join-Path $site.path $deployConfig.sitecoreWebsiteFolder
$filesToCopy = Get-ChildItem $deployFolder -Recurse | ? { $_.PSIsContainer -eq $False }
if ($site.junction -and $deployProject.junctionPoints -ne $null) {
# Deploy any files that are not included in junction-folders
$filesToCopy = $filesToCopy | Filter-JunctionPoints $deployProject
# Create the junction points
$deployProject.junctionPoints | % {
$sourcePath = Join-Path $projectFolder $_
$sitePath = Join-Path $siteWebsiteFolder $_
Create-Junction $sitePath $sourcePath
Write-Host "--- Created junction at $sitePath"
}
}
$filesToCopy | % {
$targetFile = $siteWebsiteFolder + $_.FullName.SubString($deployFolder.Length);
Copy-ItemWithStructure $_.FullName $targetFile
Write-Host "--- Copied $targetFile"
}
}
# Deploy UserConfiguration
Write-Host
Write-Host -ForegroundColor Blue "Copying user configuration to $($site.path)"
Write-Host
Get-ChildItem $deployUserConfigPath -Recurse | ? { $_.Extension -eq ".config" } | % {
$targetFile = $siteWebsiteFolder + $_.FullName.SubString($deployUserConfigPath.Length);
Copy-ItemWithStructure $_.FullName $targetFile
Write-Host "--- Copied $targetFile"
}
}