From 63d799310b0757ee2c1301f9818d0802060abc89 Mon Sep 17 00:00:00 2001 From: Henit Chobisa Date: Sat, 2 Sep 2023 13:47:21 +0530 Subject: [PATCH] [chore] Added Husky for Automating Building and Linting Projects Before Push (#2032) * chore: Added Husky as Root Dependency * chore: Added Husky Prepush Script * chore: Modified Husky Pre-Push Script to Conditionally Build Projects * chore: added husky as dev dependency --- .husky/pre-push | 23 +++++++++++++++++++++++ package.json | 5 ++++- yarn.lock | 5 +++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100755 .husky/pre-push diff --git a/.husky/pre-push b/.husky/pre-push new file mode 100755 index 000000000..1feec0de6 --- /dev/null +++ b/.husky/pre-push @@ -0,0 +1,23 @@ +#!/bin/sh +. "$(dirname -- "$0")/_/husky.sh" + +changed_files=$(git diff --name-only HEAD~1) + +app_changed=$(echo "$changed_files" | grep -E '^apps/app/' || true) +space_changed=$(echo "$changed_files" | grep -E '^apps/space/' || true) +echo $app_changed +echo $space_changed + +if [ -n "$app_changed" ] && [ -n "$space_changed" ]; then + echo "Changes detected in both apps/app and apps/space. Building..." + yarn run lint + yarn run build +elif [ -n "$app_changed" ]; then + echo "Changes detected in apps/app. Building..." + yarn run lint --filter=app + yarn run build --filter=app +elif [ -n "$space_changed" ]; then + echo "Changes detected in apps/space. Building..." + yarn run lint --filter=space + yarn run build --filter=space +fi diff --git a/package.json b/package.json index 804fb7b64..b99978f20 100644 --- a/package.json +++ b/package.json @@ -7,16 +7,19 @@ "packages/*" ], "scripts": { + "prepare": "husky install", "build": "turbo run build", "dev": "turbo run dev", "start": "turbo run start", "lint": "turbo run lint", "clean": "turbo run clean" }, + "devDependencies": { "eslint-config-custom": "*", "prettier": "latest", - "turbo": "latest" + "turbo": "latest", + "husky": "^8.0.3" }, "packageManager": "yarn@1.22.19" } diff --git a/yarn.lock b/yarn.lock index a48c94e92..60cba9408 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4891,6 +4891,11 @@ https-proxy-agent@^5.0.0: agent-base "6" debug "4" +husky@^8.0.3: + version "8.0.3" + resolved "https://registry.yarnpkg.com/husky/-/husky-8.0.3.tgz#4936d7212e46d1dea28fef29bb3a108872cd9184" + integrity sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg== + idb@^7.0.1: version "7.1.1" resolved "https://registry.yarnpkg.com/idb/-/idb-7.1.1.tgz#d910ded866d32c7ced9befc5bfdf36f572ced72b"