-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuild.ps1
123 lines (104 loc) · 3.07 KB
/
Build.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
$ThemesPath = Resolve-Path (Join-Path (Get-Location) "./themes")
$DistPath = Resolve-Path (Join-Path (Get-Location) "./dist")
$ConsoleNames = @(
"Black",
"Blue",
"Green",
"Aqua",
"Red",
"Purple",
"Yellow",
"White",
"Gray",
"LightBlue",
"LightGreen",
"LightAqua",
"LightRed",
"LightPurple",
"LightYellow",
"BrightWhite"
)
$HexPattern = "([A-Z0-9]{2})([A-Z0-9]{2})([A-Z0-9]{2})"
Function Format-RightPad($Value, $Length) {
$Builder = [System.Text.StringBuilder]::new()
$Builder.Append($Value) | Out-Null
for ($i = $Value.Length - 1; $i -lt $Length; $i++) {
$Builder.Append(' ') | Out-Null
}
return $Builder.ToString()
}
Function Format-DwordHex($Hex)
{
if ($Hex -NotMatch $HexPattern) {
throw ("Invalid Hex: {0}" -f $Hex)
}
return $Hex -Replace $HexPattern, "00`$3`$2`$1"
}
Write-Output "[X] Building Themes"
Write-Output (" - Themes: {0}" -f $ThemesPath)
Write-Output (" - Dist: {0}" -f $DistPath)
# Clean Dist folder
Write-Output "[X] Cleaning Dist"
if (Test-Path "./dist")
{
Write-Output " - Cleaned"
Remove-Item "./dist" -Force -Recurse | Out-Null
}
else
{
Write-Output " - Not Found"
}
Write-Output "[X] Creating Dist"
New-Item -Path $DistPath -ItemType Directory | Out-Null
# Go through each themes
Write-Output "[X] Parsing Themes"
$Themes = Get-ChildItem -Path $ThemesPath
foreach($Theme in $Themes)
{
$ThemePath = $Theme.FullName
$ThemeData = (Get-Content $ThemePath) -Join "`n" | ConvertFrom-Json
Write-Output (" - Building Theme: {0}" -f $ThemeData.Name)
# Header
$Contents = @(
"Windows Registry Editor Version 5.00",
"",
"; ===============================================================",
("; == win-cmd-colors - {0}" -f $ThemeData.Description),
";"
)
# Build Human-Readable Table
$Index = 0
$NameWidth = ($ThemeData.Colors | % { $_.Key.Length } | Measure-Object -Maximum).Maximum
$ThemeData.Colors | % {
$Data = (
$Index,
(Format-RightPad $ConsoleNames[$Index] 15),
(Format-RightPad $_.Key $NameWidth),
$_.Color
)
$Contents += ("; {0:00} {1} {2} #{3}" -f $Data)
$Index++
}
# Build Reg Table
$Contents += @(
";",
"",
"[HKEY_CURRENT_USER\Console]"
)
$Index = 0
$ThemeData.Colors | % {
$Data = (
$Index,
(Format-DwordHex $_.Color)
)
$Contents += ("`"ColorTable{0:00}`"=dword:{1}" -f $Data)
$Index++
}
# Build Reg Settings
$Contents += ("`"ScreenColors`"=dword:000000{0:x}{1:x}" -f ($ThemeData.ScreenColors.Background, $ThemeData.ScreenColors.Foreground))
$Contents += ("`"PopupColors`"=dword:000000{0:x}{1:x}" -f ($ThemeData.PopupColors.Background, $ThemeData.PopupColors.Foreground))
# Output Theme
$Filename = "{0}.reg" -f [System.IO.Path]::GetFileNameWithoutExtension($Theme.Name);
$OutputPath = Join-Path $DistPath $Filename
$Contents | Set-Content -Path $OutputPath -Encoding Ascii
}