Initial commit

This commit is contained in:
Arnie 2017-12-24 16:37:51 +01:00
commit 9d42de5bb9
4 changed files with 91 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
# Do not track IDE files
# Netbeans
nbproject
*.netbeans*
#PHPStorm
.idea

31
Dockerfile Normal file
View File

@ -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"]

14
Makefile Normal file
View File

@ -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

40
format.sh Executable file
View File

@ -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