Last active
December 8, 2019 23:14
-
-
Save vtml/b0077cbab764c8302fb2b7ea0120c1c4 to your computer and use it in GitHub Desktop.
Sample Front End Build which triggers Creative Exchange Import
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
This script runs the Front End Build, with an option to trigger Creative Exchange Import to the Web Site | |
.DESCRIPTION | |
This script runs the Front End Build, with an option to trigger Creative Exchange Import process to the specified SXA web site. This can be used on both developer PC's, mainly a back end developer as a back end developer do not neccessarily require the most up to date front end build assets at all times. | |
.PARAMETER SitecoreWebSiteCreativeExchangeFolderPath | |
The main Creative Exchange web site folder path | |
.PARAMETER CreativeExchangeMediaLibraryPath | |
The Media Library path inside Creative Exchange web site folder, mainly where the final front end build assets will be located | |
.PARAMETER Username | |
The Sitecore username. Uses sitecore\admin by default. | |
.PARAMETER Password | |
The Sitecore user's password. Uses 'b' by default, because 'b' is cool. | |
.PARAMETER RunCreativeExchangeImport | |
Whether the Creative Exchange Import should be run. This should be false when run in the Build pipeline, as Creative Exchange Import should only be run in Release pipeline. | |
When running on a local developer PC, this can be set to true, as the compiled front end static assets will copy into the Creative Exchange folder of the web site. | |
.PARAMETER RunYarn | |
Whether the Yarn install and build should be run. This is false when calling from the FED webpack build. | |
.PARAMETER SitecoreHost | |
The Content Management Sitecore Host. eg. https://sc911xc91xp0.dev.local | |
.PARAMETER ScriptSitecorePath | |
The SPE script located within /sitecore/system/Modules/PowerShell/Script Library/SXA/SXA - Creative Exchange/Web API/ for Creative Exchange Import | |
.INPUTS | |
None. You cannot pipe objects to this script. | |
.OUTPUTS | |
None. | |
.EXAMPLE | |
PS> .\FrontEndBuild.ps1 -SitecoreWebSiteCreativeExchangeFolderPath C:\inetpub\wwwroot\acme.sc\App_Data\packages\CreativeExchange\ -CreativeExchangeMediaLibraryPath FileStorage\AU\-\media\Themes\Acme\Explosives\AU\Master -Username sitecore\admin -Password b -RunCreativeExchangeImport $true -RunYarn $true -SitecoreHost https://acme.sc -ScriptSitecorePath /enhanced-ce-import | |
#> | |
param( | |
[string] $SitecoreWebSiteCreativeExchangeFolderPath = "C:\inetpub\wwwroot\acme-sc911xc91xp0-cm.dev.local\App_Data\packages\CreativeExchange\", | |
[string] $CreativeExchangeMediaLibraryPath = "FileStorage\acme\-\media\Themes\ACME\Explosives\Master", | |
[string] $Username = "sitecore\admin", | |
[string] $Password = "b", | |
[bool] $RunCreativeExchangeImport = $true, | |
[bool] $RunYarn = $true, | |
[string] $SitecoreHost = "https://acme.sc", | |
[string] $ScriptSitecorePath = "/enhanced-ce-import" | |
) | |
Push-Location $PSScriptRoot | |
if ($RunYarn) { | |
try { | |
yarn install | |
if($LASTEXITCODE -eq 1) | |
{ | |
Write-Error "Yarn Install Failed" | |
exit 1 | |
} | |
yarn build | |
if($LASTEXITCODE -eq 1) | |
{ | |
Write-Error "Yarn Build Failed" | |
exit 1 | |
} | |
} | |
catch { | |
exit 1 | |
} | |
} | |
if ($RunCreativeExchangeImport) { | |
Write-Host "Build finished. Starting Creative Exchange Import." | |
Pop-Location | |
if ([System.IO.Directory]::Exists($SitecoreWebSiteCreativeExchangeFolderPath)) { | |
Remove-Item -Recurse -Force $SitecoreWebSiteCreativeExchangeFolderPath | |
} | |
$FinalFrontEndPath = $SitecoreWebSiteCreativeExchangeFolderPath + $CreativeExchangeMediaLibraryPath | |
$FinalFrontEndScriptsPath = $FinalFrontEndPath + "\Scripts" | |
$FinalFrontEndSXAScriptsPath = $FinalFrontEndPath + "\SXA Scripts" | |
$FinalFrontEndStylesPath = $FinalFrontEndPath + "\Styles" | |
$FinalFrontEndFontsPath = $FinalFrontEndPath + "\fonts" | |
New-Item -ItemType Directory -Path $FinalFrontEndPath -Force | |
New-Item -ItemType Directory -Path $FinalFrontEndScriptsPath -Force | |
New-Item -ItemType Directory -Path $FinalFrontEndStylesPath -Force | |
New-Item -ItemType Directory -Path $FinalFrontEndSXAScriptsPath -Force | |
New-Item -ItemType Directory -Path $FinalFrontEndFontsPath -Force | |
# Theme JavaScript | |
Copy-Item -Path "$PSScriptRoot\dist\js\*.js" -Destination $FinalFrontEndScriptsPath -Recurse -Force | |
# SXA scripts that have been customised | |
Copy-Item -Path "$PSScriptRoot\src\js\sxa\custom\*" -Destination $FinalFrontEndSXAScriptsPath -Recurse -Force | |
# Theme styles | |
Copy-Item -Path "$PSScriptRoot\dist\themes\Master\*.css" -Destination $FinalFrontEndStylesPath -Recurse -Force | |
# Theme fonts | |
Copy-Item -Path "$PSScriptRoot\src\fonts" -Destination $FinalFrontEndPath -Recurse -Force | |
# Trigger the Creative Exchange Import Sitecore Powershell Extension Script | |
& "$PSScriptRoot\RestfulV2-QueryStringAuth.ps1" -Username $Username -Password $Password -SitecoreHost $SitecoreHost -ScriptSitecorePath $ScriptSitecorePath -Parameters SitePath=/sitecore/content/Habitat SXA Sites/Habitat Home | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment