commit 9d42de5bb9cd1a2c582df8478c4456398133a733 Author: Arnie Date: Sun Dec 24 16:37:51 2017 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5e2492c --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# Do not track IDE files +# Netbeans +nbproject +*.netbeans* +#PHPStorm +.idea diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..23674f7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM node:8-slim + +# https support +RUN apt-get update && \ + apt-get install -y apt-transport-https ca-certificates + +# add yarn and php +RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ + echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \ + apt-get update && \ + apt-get install -y yarn php5-cli && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/* /tmp/* /var/tmp/* + + +# add php fixer +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 + +# 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 + +COPY ["format.sh", "/"] + +WORKDIR /code + +CMD ["/format.sh"] + +ENTRYPOINT ["/format.sh"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2e518e9 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ + + +all: build publish + + + +build: + docker build -t yoursystemcz/code-formatter:latest . + +publish: + docker push yoursystemcz/code-formatter:latest + +exec: + docker run --rm -it --entrypoint bash yoursystemcz/code-formatter:latest diff --git a/format.sh b/format.sh new file mode 100755 index 0000000..3cdc800 --- /dev/null +++ b/format.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +if [[ $@ = "" ]]; then + echo "No files provided" + exit 137 +fi + +echo "Running code formatting..." + +# Agregate CSS and JS files into one command +CSS_FILES=() +JS_FILES=() + +# Prepare files for processing +for file in "$@"; do + if [[ ! -f ${file} ]]; then + echo "Could not find the file ${file}" + continue + fi + + if [[ ${file} == *.js ]] || [[ ${file} == *.jsx ]]; then + JS_FILES+=("${file}") + elif [[ ${file} == *.css ]] || [[ ${file} == *.scss ]] || [[ ${file} == *.sass ]] || [[ ${file} == *.less ]]; then + CSS_FILES+=("${file}") + elif [[ ${file} == *.php ]] || [[ ${file} == *.phtml ]]; then + # Cannot chain php files without specifying a config CS file :( + php-cs-fixer fix "${file}" + fi +done + + +# Run css comb +if [[ ${#CSS_FILES[@]} -ne 0 ]]; then + csscomb "${CSS_FILES[@]}" +fi + +# Run JS prettier +if [[ ${#JS_FILES[@]} -ne 0 ]]; then + prettier --write "${JS_FILES[@]}" +fi