From 420fc50f26f8ed725651a4266f2f411ce7c4d92d Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Sun, 22 Dec 2024 23:21:03 +0100 Subject: [PATCH] chore: add husky --- .env.checksum | 1 + .gitignore | 3 +++ .husky/pre-push | 31 +++++++++++++++++++++++++++++++ package.json | 4 +++- pnpm-lock.yaml | 10 ++++++++++ 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 .env.checksum create mode 100644 .husky/pre-push diff --git a/.env.checksum b/.env.checksum new file mode 100644 index 0000000..862d82c --- /dev/null +++ b/.env.checksum @@ -0,0 +1 @@ +59c6aadf9774ee13a19485674685f1d3e67171da330713e09e1793a98b39fc90 diff --git a/.gitignore b/.gitignore index 0035d70..2c6ada5 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,6 @@ pnpm-debug.log* *.njsproj *.sln *.sw? + +# Local Netlify folder +.netlify diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100644 index 0000000..d1f9920 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,31 @@ +# Define the checksum file +CHECKSUM_FILE=".env.checksum" + +# Calculate the current checksum of the .env file +CURRENT_CHECKSUM=$(shasum -a 256 .env | awk '{ print $1 }') + +# Check if checksum file exists +if [ -f "$CHECKSUM_FILE" ]; then + # Read the previous checksum + PREVIOUS_CHECKSUM=$(cat "$CHECKSUM_FILE") + + # Compare the current checksum with the previous checksum + if [ "$CURRENT_CHECKSUM" = "$PREVIOUS_CHECKSUM" ]; then + echo ".env file has not changed. Skipping Netlify environment import." + exit 0 + fi +fi + +# If the checksum is different or the file doesn't exist, import the variables +echo "Importing environment variables to Netlify..." +netlify env:import .env + +if [ $? -ne 0 ]; then + echo "Failed to import environment variables to Netlify. Aborting push." + exit 1 +fi + +# Save the new checksum +echo "$CURRENT_CHECKSUM" > "$CHECKSUM_FILE" + +echo "Environment variables imported successfully." diff --git a/package.json b/package.json index 7109b45..7f576e2 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "test": "vitest", "types": "tsc --noEmit", "lint": "eslint --ext .ts,.js,.vue --ignore-path .gitignore --fix src", - "pwa:asset": "npx vue-pwa-asset-generator -a public/img/logo.png --no-manifest" + "pwa:asset": "npx vue-pwa-asset-generator -a public/img/logo.png --no-manifest", + "prepare": "husky" }, "dependencies": { "@intlify/unplugin-vue-i18n": "^1.6.0", @@ -67,6 +68,7 @@ "eslint-plugin-simple-import-sort": "^10.0.0", "eslint-plugin-unused-imports": "^3.2.0", "eslint-plugin-vue": "^9.31.0", + "husky": "^9.1.7", "prettier": "^3.4.1", "sass": "^1.81.0", "tailwindcss": "^3.4.17", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ac21d73..9416ec9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -168,6 +168,9 @@ importers: eslint-plugin-vue: specifier: ^9.31.0 version: 9.31.0(eslint@8.57.1) + husky: + specifier: ^9.1.7 + version: 9.1.7 prettier: specifier: ^3.4.1 version: 3.4.1 @@ -2587,6 +2590,11 @@ packages: resolution: {integrity: sha512-AXcZb6vzzrFAUE61HnN4mpLqd/cSIwNQjtNWR0euPm6y0iqx3G4gOXaIDdtdDwZmhwe82LA6+zinmW4UBWVePQ==} engines: {node: '>=16.17.0'} + husky@9.1.7: + resolution: {integrity: sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==} + engines: {node: '>=18'} + hasBin: true + idb@7.1.1: resolution: {integrity: sha512-gchesWBzyvGHRO9W8tzUWFDycow5gwjvFKfyV9FF32Y7F50yZMp7mP+T2mJIWFx49zicqyC4uefHM17o6xKIVQ==} @@ -6635,6 +6643,8 @@ snapshots: human-signals@5.0.0: {} + husky@9.1.7: {} + idb@7.1.1: {} ignore@5.2.4: {}