#!/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