Last active
March 21, 2025 11:14
-
-
Save inerba/9e883126fc89eaf12663a5e02ba7b9f9 to your computer and use it in GitHub Desktop.
Script Bash per configurare automaticamente Prettier in un progetto.
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 | |
# Funzione per stampare messaggi di stato | |
print_status() { | |
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1" | |
} | |
# 1. Creazione del file `.prettierrc` | |
print_status "Creazione del file .prettierrc..." | |
cat <<EOF > .prettierrc | |
{ | |
"printWidth": 120, | |
"semi": true, | |
"singleQuote": true, | |
"tabWidth": 4, | |
"trailingComma": "all", | |
"plugins": ["prettier-plugin-blade", "prettier-plugin-tailwindcss"], | |
"overrides": [ | |
{ | |
"files": [ | |
"*.blade.php" | |
], | |
"options": { | |
"parser": "blade" | |
} | |
} | |
] | |
} | |
EOF | |
if [ $? -eq 0 ]; then | |
print_status "File .prettierrc creato con successo." | |
else | |
print_status "Errore durante la creazione del file .prettierrc." | |
exit 1 | |
fi | |
# 2. Creazione del file `.prettierignore` | |
print_status "Creazione del file .prettierignore..." | |
cat <<EOF > .prettierignore | |
node_modules | |
dist | |
.env* | |
vendor/ | |
/vendor | |
public/ | |
.git | |
**/.git | |
package-lock.json | |
composer.lock | |
EOF | |
if [ $? -eq 0 ]; then | |
print_status "File .prettierignore creato con successo." | |
else | |
print_status "Errore durante la creazione del file .prettierignore." | |
exit 1 | |
fi | |
# 3. Installazione delle dipendenze npm | |
print_status "Installazione delle dipendenze npm..." | |
npm install --save-dev prettier-plugin-blade@^2 prettier prettier-plugin-tailwindcss | |
if [ $? -eq 0 ]; then | |
print_status "Dipendenze npm installate con successo." | |
else | |
print_status "Errore durante l'installazione delle dipendenze npm." | |
exit 1 | |
fi | |
# Stampa delle istruzioni per configurare VS Code | |
print_status "Setup completato con successo!" | |
echo "" | |
echo "ISTRUZIONI PER CONFIGURARE PRETTIER IN VISUAL STUDIO CODE:" | |
echo "" | |
echo "Se vuoi configurare VS Code per formattare correttamente i file Blade con Prettier, segui questi passaggi:" | |
echo "" | |
echo "1. Apri le impostazioni di VS Code e aggiungi la seguente configurazione:" | |
echo "" | |
echo ' {' | |
echo ' "editor.defaultFormatter": "esbenp.prettier-vscode",' | |
echo ' "[blade]": {' | |
echo ' "editor.defaultFormatter": "esbenp.prettier-vscode"' | |
echo ' },' | |
echo ' "prettier.documentSelectors": [' | |
echo ' "**/*.blade.php"' | |
echo ' ]' | |
echo ' }' | |
echo "" | |
echo "2. Assicurati di aver installato l'estensione Prettier per VS Code (esbenp.prettier-vscode)." | |
echo "" | |
echo "3. Per formattare un documento:" | |
echo " - Usa il comando 'Format Document' dal pannello comandi (Ctrl+Shift+P o Cmd+Shift+P su macOS)." | |
echo " - Oppure abilita la formattazione automatica al salvataggio aggiungendo questa impostazione:" | |
echo ' "editor.formatOnSave": true' | |
echo "" | |
echo "Ora Prettier sarà eseguito ogni volta che salvi un file Blade!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Script Bash per configurare automaticamente Prettier in un progetto.
Questo script esegue le seguenti operazioni:
.prettierrc
con impostazioni personalizzate per Blade e TailwindCSS..prettierignore
per ignorare cartelle e file non necessari.prettier
,prettier-plugin-blade
eprettier-plugin-tailwindcss
.Come usarlo:
curl -sSL https://gist.github.com/inerba/9e883126fc89eaf12663a5e02ba7b9f9/raw/3ec7a1f26c18cdbc994cfcd6fa0da860d9c561c2/setup-prettier.sh | bash
Oppure scarica il file localmente, verifica il contenuto e poi eseguilo.
Prerequisiti: