Chcę napisać skrypt stopniowy, który będzie uruchamiał ruby (sass). Teraz to robię
task compileCss (type: Exec){
def dir = ""
if (System.properties["os.name"].toLowerCase().contains("windows")) {
dir = "C:\ruby22\bin\sass.bat"
} else {
dir = "/usr/bin/sass"
}
commandLine dir, "--update", "source.scss:dest.css"
}
Nie podoba mi się ten kod ze względu na oczywistą obawę, że ktoś może zainstalować ruby w „niestandardowym” katalogu (takim jak / usr / local / bin :)).
Czy istnieje sposób na sprawdzenie, czy sass jest na drodze i używa tego konkretnego sassa?
Odpowiedzi:
0 dla odpowiedzi № 1Utwórz zadanie, aby wyszukać sassa na ścieżce:
import org.apache.tools.ant.taskdefs.condition.Os
task checkForSassInPath(type: Exec) {
def windows = Os.isFamily(Os.FAMILY_WINDOWS)
executable = windows ? "where" : "which"
args = [(windows ? "sass.bat" : "sass")]
ignoreExitValue = true
standardOutput = new ByteArrayOutputStream()
errorOutput = new ByteArrayOutputStream()
}
checkForSassInPath << {
project.ext.sassInPath = (execResult.exitValue == 0)
if (!project.sassInPath ) {
logger.warn "Cannot find sass in path";
}
}
Następnie możesz zrobić:
task compileCss (type: Exec, dependsOn: checkForSassInPath){
def dir
if ( Os.isFamily(Os.FAMILY_WINDOWS) ) {
dir = project.sassInPath ? "sass.bat" : "C:\ruby22\bin\sass.bat"
} else {
dir = project.sassInPath ? "sass" : "/usr/bin/sass"
}
commandLine dir, "--update", "source.scss:dest.css"
}