Commit | Line | Data |
---|---|---|
758a629f DV |
1 | #!/bin/sh |
2 | # usage (run from any directory) : | |
3 | # env/jsc.sh /path/to/script.js | |
4 | # or with jshint options: | |
5 | # env/jsc.sh /path/to/script.js "{option1:true,option2:false,option3:25}" | |
6 | ||
7 | alias jsc="/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc" | |
8 | FILE="${1}" | |
9 | OPTS="${2}" | |
10 | ||
11 | FILE_CONTENT=$(cat "${FILE}") | |
12 | ||
13 | if [ -L $BASH_SOURCE ]; then | |
14 | ENV_HOME="$( cd "$( dirname "$(readlink "$BASH_SOURCE")" )" && pwd )" | |
15 | else | |
16 | ENV_HOME="$( cd "$( dirname "$BASH_SOURCE" )" && pwd )" | |
17 | fi | |
18 | ||
19 | LINT_RESULT=$(jsc "${ENV_HOME}"/jsc.js -- "${FILE}" "${FILE_CONTENT}" "${OPTS}" "${ENV_HOME}") | |
20 | ||
21 | ERRORS=$(echo ${LINT_RESULT} | egrep [^\s] -c) | |
22 | ||
23 | if [[ ${ERRORS} -ne 0 ]]; then | |
24 | echo "[jshint] Error(s) in ${FILE}:" | |
25 | printf "%s\n" "${LINT_RESULT}" | |
26 | else | |
27 | echo "[jshint] ${FILE} passed!" | |
28 | fi | |
29 | ||
30 | exit $((0 + ${ERRORS})) |