Compare commits

..

5 Commits

Author SHA1 Message Date
8f12b643b8 Fix calling commands individually 2017-12-25 09:42:09 +01:00
3fea4a6c78 Fix sourcing files 2017-12-25 09:37:24 +01:00
b821339e69 Optimize dockerfile 2017-12-25 09:36:05 +01:00
6b856f9731 Split formatters, add dry run exit codes 2017-12-25 09:32:13 +01:00
e664352139 Fix while condition for non existing files 2017-12-25 08:41:17 +01:00
7 changed files with 141 additions and 56 deletions

View File

@ -17,20 +17,23 @@ RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
RUN curl -L http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar -o /usr/local/bin/php-cs-fixer && \
chmod a+x /usr/local/bin/php-cs-fixer
WORKDIR /app
# add csscomb and prettier
RUN yarn add prettier csscomb --global && \
ln -s /node_modules/.bin/prettier /usr/local/bin/prettier && \
ln -s /node_modules/.bin/csscomb /usr/local/bin/csscomb
ln -s /app/node_modules/.bin/prettier /usr/local/bin/prettier && \
ln -s /app/node_modules/.bin/csscomb /usr/local/bin/csscomb
COPY ["src/entry.sh", "/entry.sh"]
COPY ["src/entry.sh", "/app/entry.sh"]
COPY ["src/inc", "/inc"]
COPY ["src/inc", "/app/inc"]
WORKDIR /code
CMD ["/entry.sh"]
ENTRYPOINT ["/entry.sh"]
CMD ["/app/entry.sh"]
ENTRYPOINT ["/app/entry.sh"]
ARG VERSION
ARG COMMIT_SHA

View File

@ -46,6 +46,24 @@ main() {
process
return $?
;;
prettier)
__initVariables "$@"
source ${INCLUDES_PATH}/formatters/prettier.shinc
__prettier
return $?
;;
csscomb)
__initVariables "$@"
source ${INCLUDES_PATH}/formatters/csscomb.shinc
__csscomb
return $?
;;
php-cs-fixer)
__initVariables "$@"
source ${INCLUDES_PATH}/formatters/php-cs-fixer.shinc
__phpFixer
return $?
;;
help|--help|-h)
usage
return 0

View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
__csscomb() {
__msg "Csscomb:"
if [[ ${DRY_RUN} -eq 0 ]]; then
csscomb -v "${CSS_FILES[@]}"
else
csscomb --lint -v "${CSS_FILES[@]}"
fi
return $?
}

View File

@ -0,0 +1,58 @@
#!/usr/bin/env bash
__phpFixer() {
local failed=0
__msg "PHP-cs-fixer"
# Cannot chain php files without specifying a config CS file :(
if [[ ${DRY_RUN} -eq 0 ]]; then
for file in "${PHP_FILES[@]}"; do
php-cs-fixer fix "${file}"
[[ $? -ne 0 ]] && failed=1
done
else
local needs_fixing=()
local invalid_syntax=()
for file in "${PHP_FILES[@]}"; do
php-cs-fixer fix --dry-run "${file}"
case $? in
0)
#all good
;;
4)
invalid_syntax+=("${file}")
;;
8)
needs_fixing+=("${file}")
;;
*)
__err "There was an error with php-cs-fixer configuration"
failed=1
;;
esac
done
if [[ ${#needs_fixing[@]} -gt 0 ]]; then
failed=1
__err "Needs fixing:" 1
for file in "${needs_fixing[@]}"; do
__msg "${file}" 2
done
fi
if [[ ${#invalid_syntax[@]} -gt 0 ]]; then
failed=1
__err "Invalid syntax:" 1
for file in "${invalid_syntax[@]}"; do
__msg "${file}" 2
done
fi
fi
return ${failed}
}

View File

@ -0,0 +1,15 @@
#!/usr/bin/env bash
__prettier() {
__msg "Prettier:"
if [[ ${DRY_RUN} -eq 0 ]]; then
prettier --write "${JS_FILES[@]}"
else
__msg "Listing (: unprettiered :) files:" 1
prettier --list-different "${JS_FILES[@]}"
fi
return $?
}

View File

@ -1,54 +1,31 @@
#!/usr/bin/env bash
__csscomb() {
if [[ ${DRY_RUN} -eq 0 ]]; then
csscomb "$@"
else
csscomb --lint "$@"
fi
}
__prettier() {
if [[ ${DRY_RUN} -eq 0 ]]; then
prettier --write "$@"
else
prettier --list-different "$@"
fi
}
__phpFixer() {
# Cannot chain php files without specifying a config CS file :(
if [[ ${DRY_RUN} -eq 0 ]]; then
for file in "${PHP_FILES[@]}"; do
php-cs-fixer fix "${file}"
done
else
for file in "${PHP_FILES[@]}"; do
php-cs-fixer fix --dry-run "${file}"
done
fi
}
source ${INCLUDES_PATH}/formatters/prettier.shinc
source ${INCLUDES_PATH}/formatters/csscomb.shinc
source ${INCLUDES_PATH}/formatters/php-cs-fixer.shinc
process() {
local failed=0
# Run css comb
if [[ ${#CSS_FILES[@]} -ne 0 ]]; then
__csscomb "${CSS_FILES[@]}"
__csscomb
[[ $? -ne 0 ]] && failed=1
fi
# Run JS prettier
if [[ ${#JS_FILES[@]} -ne 0 ]]; then
__prettier --write "${JS_FILES[@]}"
__prettier
[[ $? -ne 0 ]] && failed=1
fi
# Run PHP cs fixer
if [[ ${#PHP_FILES[@]} -ne 0 ]]; then
__phpFixer ${PHP_FILES[@]}
__phpFixer
[[ $? -ne 0 ]] && failed=1
fi
return ${failed}
}

View File

@ -25,25 +25,25 @@ __initVariables() {
__path_exists "${1}"
if [[ $? -ne 0 ]]; then
__err "Specified path does not exist: ${1}"
continue
else
CSS_FILES+=("${1}")
fi
CSS_FILES+=(${1})
;;
*.js|*.jsx)
__path_exists "${1}"
if [[ $? -ne 0 ]]; then
__err "Specified path does not exist: ${1}"
continue
else
JS_FILES+=("${1}")
fi
JS_FILES+=(${1})
;;
*.php|*.phtml)
__path_exists "${1}"
if [[ $? -ne 0 ]]; then
__err "Specified path does not exist: ${1}"
continue
else
PHP_FILES+=("${1}")
fi
PHP_FILES+=(${1})
;;
esac
shift 1