Created
July 1, 2021 08:40
-
-
Save MikelArnaiz/91ce6ab999601b70707f2ce2dc28204e to your computer and use it in GitHub Desktop.
Merge prettierignore and gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"scripts": { | |
"prettier:check": "./bin/prettier.sh --check", | |
"prettier:fix": "./bin/prettier.sh --write", | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# There are files that we don't want prettier to format. | |
# We define those in the .prettierignore file. | |
# | |
# Furthermore, it doesn't make much sense to format files that are not tracked by git. | |
# In order to avoid repeating a list of files both in .gitignore and .prettierignore | |
# this script will concat those two files and create a new temporaty file. | |
# | |
# We do this becaude ATTOW the prettier --ignore-path flag only accepts one path | |
MODE_WRITE=--write | |
MODE_CHECK=--check | |
if [ "$1" = $MODE_WRITE ] || [ "$1" = $MODE_CHECK ] | |
then | |
MODE=$1 | |
echo "Running format script with $MODE flag"; | |
IGNORE_TEMP_FILE='.temp-prettierignore' | |
cat .prettierignore .gitignore > $IGNORE_TEMP_FILE | |
prettier '**/*.{js,ts,tsx,md,json,scss,yml}' $MODE --ignore-path $IGNORE_TEMP_FILE; | |
rm $IGNORE_TEMP_FILE | |
else | |
echo "Format not run. Need either $MODE_WRITE or $MODE_CHECK flag" >&2 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment