Created
March 26, 2014 02:45
-
-
Save nzbart/9776047 to your computer and use it in GitHub Desktop.
Find an remove unused scss variables through basic heuristic. Not particularly fast, but it seems to work okay.
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
$ourContent = ls $PSScriptRoot\MyCode -r -fi *.scss | cat | |
$vars = $ourContent | % { | |
if($_ -match '^\s*\$([a-zA-Z_-]+)\s*:') { | |
$Matches[1] | |
} | |
} | select -Unique | |
$allContent = ls $PSScriptRoot -r -fi *.scss | cat | |
$vars | ? { | |
$search = "\`$$_[^:]*$" | |
$used = $allContent | % { | |
if($_ -match $search) { | |
$true | |
} | |
} | |
if(!$used) { | |
write-host "`$$_" | |
} | |
} |
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
$disused = cat $PSScriptRoot\disused.txt | |
function ContainingDisused($line, $disused) | |
{ | |
foreach($d in $disused) | |
{ | |
if($line -match "\$d") { | |
return $true | |
} | |
} | |
} | |
ls $PSScriptRoot\NewSite\App -r -fi *.scss | % { | |
$originalContent = cat $_.FullName | |
$content = $originalContent | ? { !(ContainingDisused $_ $disused) } | |
if(($content | Out-String) -ne ($originalContent | Out-String)) { | |
[System.IO.File]::WriteAllLines($_.FullName, $content) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment