forked from Sitecore/Sitecore.Demo.Platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-themes.ps1
28 lines (26 loc) · 1.21 KB
/
build-themes.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
[CmdletBinding()]
Param(
[string]$FrontEndPath = ".\Frontend",
[string]$ItemsPath = ".\items"
)
function Update-ThemeTokens($filePath, $itemPath) {
Write-Host "Update-ThemeTokens for $filePath - $itemPath"
$blob = [Convert]::ToBase64String([IO.File]::ReadAllBytes($filePath))
$size = (Get-Item $filePath).length
$content = Get-Content -Path "$itemPath" -Verbose
$content = $content -replace '%blob%', $blob
$content = $content -replace '%size%', $size
$itemPath = "$itemPath" -replace '.template', ''
$content | Set-Content -Path "$itemPath" -Verbose
}
Get-ChildItem $FrontEndPath -Depth 0 -Directory | ForEach-Object {
Push-Location (Join-Path $FrontEndPath $_.Name)
npm --loglevel=error run build
Pop-Location
$css = [io.path]::combine($FrontEndPath, $_.Name, "styles\pre-optimized-min.css")
$item = [io.path]::combine($ItemsPath, "Project\Global\Themes\Demo SXA Sites\", $_.Name, "styles\pre-optimized-min.yml.template")
Update-ThemeTokens $css $item
$js = [io.path]::combine($FrontEndPath, $_.Name, "scripts\pre-optimized-min.js")
$item = [io.path]::combine($ItemsPath, "Project\Global\Themes\Demo SXA Sites\", $_.Name, "scripts\pre-optimized-min.yml.template")
Update-ThemeTokens $js $item
}