Skip to content

Instantly share code, notes, and snippets.

@adryx92
Last active March 31, 2023 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adryx92/a56d86f74ab8b125ea5c6842c88c8a36 to your computer and use it in GitHub Desktop.
Save adryx92/a56d86f74ab8b125ea5c6842c88c8a36 to your computer and use it in GitHub Desktop.
Compiling LESS different styles
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"
}
button {
border-color: #0053a1;
}
button {
border-color: #0e5729;
}
@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