Last active
March 31, 2023 15:15
-
-
Save adryx92/a56d86f74ab8b125ea5c6842c88c8a36 to your computer and use it in GitHub Desktop.
Compiling LESS different styles
This file contains 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
function CompileCSS { | |
param ( | |
$DestStyle | |
) | |
$srcLESSPath = $PSScriptRoot + "\style.less" | |
$destCSSPath = $PSScriptRoot + "\style.css" | |
$currStyleName | |
$destStyleName | |
if ($DestStyle -eq 1) { | |
$destStyleName = 1 | |
$currStyleName = 2 | |
} | |
elseif ($DestStyle -eq 2) { | |
$destStyleName = 2 | |
$currStyleName = 1 | |
} | |
# replace style | |
(Get-Content $srcLESSPath).Replace('@current-style: ' + $currStyleName, '@current-style: ' + $destStyleName) | Set-Content $srcLESSPath | |
# compile | |
lessc $srcLESSPath $destCSSPath | |
} | |
# https://devblogs.microsoft.com/scripting/use-a-powershell-function-to-see-if-a-command-exists/ | |
function Test-CommandExists { | |
Param ( | |
$Command | |
) | |
# to avoid printing exception error | |
$oldPreference = $ErrorActionPreference | |
$ErrorActionPreference = "stop" | |
try {if(Get-Command $Command){RETURN $true}} | |
Catch {RETURN $false} | |
Finally {$ErrorActionPreference=$oldPreference} | |
} | |
$destStyle = $args[0] | |
if (Test-CommandExists("lessc")) { | |
CompileCSS($destStyle) | |
} | |
else { | |
Write-Error "less compiler not found" | |
} |
This file contains 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
button { | |
border-color: #0053a1; | |
} |
This file contains 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
button { | |
border-color: #0e5729; | |
} |
This file contains 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
@current-style: 1; // <- the script replaces this | |
@1-color: #0053a1; | |
@2-color: #0e5729; | |
button { | |
border-color: if((@current-style = 1), | |
@1-color, | |
@2-color); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment