From 8068ea15dc8c9bcbdeaca74d5a16f447ade2a2b5 Mon Sep 17 00:00:00 2001 From: Afreen Misbah Date: Sat, 19 Jul 2025 19:53:25 +0530 Subject: [PATCH] mgr/dashboard setup husky - setup pre-commit hook - allows ease in catching errors and saves CI resources for nit-picks - includes lint and fix commands - removes dead commands for i18n Signed-off-by: Afreen Misbah --- .../mgr/dashboard/frontend/.husky/pre-commit | 28 +++++++++++++++++++ .../mgr/dashboard/frontend/package-lock.json | 17 +++++++++++ .../mgr/dashboard/frontend/package.json | 10 +++---- 3 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 src/pybind/mgr/dashboard/frontend/.husky/pre-commit diff --git a/src/pybind/mgr/dashboard/frontend/.husky/pre-commit b/src/pybind/mgr/dashboard/frontend/.husky/pre-commit new file mode 100644 index 000000000000..33b9f44ecd02 --- /dev/null +++ b/src/pybind/mgr/dashboard/frontend/.husky/pre-commit @@ -0,0 +1,28 @@ +#!/bin/bash + +echo "Running husky pre-commit hook..." + +cd src/pybind/mgr/dashboard/frontend || exit 1 + +HTML_FILES=$(git diff --cached --name-only --diff-filter=ACMRTUXB -- "*.html" | wc -l) +SCSS_FILES=$(git diff --cached --name-only --diff-filter=ACMRTUXB -- "*.scss" | wc -l) +TS_FILES=$(git diff --cached --name-only --diff-filter=ACMRTUXB -- "*.ts" | wc -l) +GHERKIN_FILES=$(git diff --cached --name-only --diff-filter=ACMRTUXB -- "*.feature" | wc -l) + +if [[ "$HTML_FILES" -gt 0 && "$SCSS_FILES" -eq 0 && "$TS_FILES" -eq 0 ]]; then + echo 'Running "npm lint:html"...' + npm run lint:html +fi + +if [[ "$SCSS_FILES" -gt 0 || "$TS_FILES" -gt 0 || "$GHERKIN_FILES" -gt 0 ]]; then + echo 'Running "npm fix"...' + npm run fix + + # Add fixes to staging: + git add . + + echo 'Running "npm lint"...' + npm run lint +fi + +echo 'Pre-commit hook finished.' diff --git a/src/pybind/mgr/dashboard/frontend/package-lock.json b/src/pybind/mgr/dashboard/frontend/package-lock.json index 7e4a72562abd..8f9ad3443678 100644 --- a/src/pybind/mgr/dashboard/frontend/package-lock.json +++ b/src/pybind/mgr/dashboard/frontend/package-lock.json @@ -97,6 +97,7 @@ "gherkin-lint": "4.2.4", "html-linter": "1.1.1", "htmllint-cli": "0.0.7", + "husky": "9.1.7", "identity-obj-proxy": "3.0.0", "isomorphic-form-data": "2.0.0", "jest": "29.7.0", @@ -24479,6 +24480,22 @@ "node": ">=8.12.0" } }, + "node_modules/husky": { + "version": "9.1.7", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.7.tgz", + "integrity": "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==", + "dev": true, + "license": "MIT", + "bin": { + "husky": "bin.js" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, "node_modules/hyperdyperid": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/hyperdyperid/-/hyperdyperid-1.2.0.tgz", diff --git a/src/pybind/mgr/dashboard/frontend/package.json b/src/pybind/mgr/dashboard/frontend/package.json index 95ec0d359003..cc265518b34d 100644 --- a/src/pybind/mgr/dashboard/frontend/package.json +++ b/src/pybind/mgr/dashboard/frontend/package.json @@ -12,12 +12,8 @@ "build:localize": "node cd --env --pre && nx build --localize", "postbuild:localize": "node cd --res", "env_build": "node cd --env", - "i18n": "npm run i18n:extract && npm run i18n:push && npm run i18n:pull && npm run i18n:merge", + "i18n": "npm run i18n:extract", "i18n:extract": "nx extract-i18n --output-path src/locale --progress=false", - "i18n:push": "npx i18ntool push -c i18n.config.json", - "i18n:pull": "npx i18ntool pull -c i18n.config.json", - "i18n:merge": "npx i18ntool merge -c i18n.config.json", - "i18n:token": "npx i18ntool config token", "test": "jest --watch", "test:ci": "jest --clearCache && JEST_SILENT_REPORTER_DOTS=true jest --detectOpenHandles --coverage --reporters jest-silent-reporter", "pree2e": "rm -f cypress/reports/results-*.xml || true", @@ -38,7 +34,8 @@ "fix": "run-p -csl --aggregate-output fix:*", "compodoc": "compodoc", "doc-build": "compodoc -p tsconfig.app.json", - "doc-serve": "compodoc --port 8444 -s tsconfig.app.json" + "doc-serve": "compodoc --port 8444 -s tsconfig.app.json", + "prepare-husky": "cd ../../../../../ && husky src/pybind/mgr/dashboard/frontend/.husky" }, "private": true, "dependencies": { @@ -130,6 +127,7 @@ "gherkin-lint": "4.2.4", "html-linter": "1.1.1", "htmllint-cli": "0.0.7", + "husky": "9.1.7", "identity-obj-proxy": "3.0.0", "isomorphic-form-data": "2.0.0", "jest": "29.7.0", -- 2.47.3