@digitoimistodude/code-quality-checks 2.1.2 → 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.husky/pre-commit CHANGED
@@ -2,7 +2,7 @@
2
2
  # Ref: DEV-177, DEV-373, DEV-623
3
3
 
4
4
  # Version:
5
- VERSION="2.1.2 (2026-01-09)"
5
+ VERSION="2.1.3 (2026-01-09)"
6
6
 
7
7
  # Load configuration
8
8
  # First check for local project config, then fall back to package default
@@ -682,16 +682,19 @@ if [ -n "$scss_files" ]; then
682
682
  # Find stylelint config and binary
683
683
  stylelint_config=""
684
684
  stylelint_bin=""
685
+ theme_dir_for_stylelint=""
685
686
  if [ "$CONTEXT" = "dudestack" ]; then
686
687
  # Find stylelint config and binary in theme directories
687
688
  for theme_dir in content/themes/*/; do
688
689
  if [ -f "${theme_dir}.stylelintrc" ]; then
689
- stylelint_config="${theme_dir}.stylelintrc"
690
- stylelint_bin="${theme_dir}node_modules/.bin/stylelint"
690
+ stylelint_config=".stylelintrc"
691
+ stylelint_bin="./node_modules/.bin/stylelint"
692
+ theme_dir_for_stylelint="$theme_dir"
691
693
  break
692
694
  elif [ -f "${theme_dir}.stylelintrc.json" ]; then
693
- stylelint_config="${theme_dir}.stylelintrc.json"
694
- stylelint_bin="${theme_dir}node_modules/.bin/stylelint"
695
+ stylelint_config=".stylelintrc.json"
696
+ stylelint_bin="./node_modules/.bin/stylelint"
697
+ theme_dir_for_stylelint="$theme_dir"
695
698
  break
696
699
  fi
697
700
  done
@@ -717,18 +720,59 @@ if [ -n "$scss_files" ]; then
717
720
  stylelint_cmd="npx stylelint"
718
721
  fi
719
722
 
720
- if ! $stylelint_cmd --config "$stylelint_config" $scss_files 2>/dev/null; then
721
- echo "${RED}${CROSS} FAILED${NC}"
722
- echo " ${RED}Stylelint found errors in SCSS files${NC}"
723
- echo " ${YELLOW}Please fix the following files:${NC}"
723
+ # For dudestack, run stylelint from theme directory with converted paths
724
+ if [ "$CONTEXT" = "dudestack" ] && [ -n "$theme_dir_for_stylelint" ]; then
725
+ # Convert paths: content/themes/dude/file.scss -> file.scss
726
+ theme_prefix="${theme_dir_for_stylelint%/}"
727
+ relative_scss_files=""
724
728
  for file in $scss_files; do
725
- echo " ${YELLOW}• $file${NC}"
729
+ # Only include files from this theme
730
+ case "$file" in
731
+ ${theme_prefix}/*)
732
+ relative_file="${file#${theme_prefix}/}"
733
+ relative_scss_files="$relative_scss_files $relative_file"
734
+ ;;
735
+ esac
726
736
  done
727
- echo " ${YELLOW}To see detailed errors:${NC}"
728
- echo " ${BLUE}$stylelint_cmd --config \"$stylelint_config\" $scss_files${NC}"
729
- exit 1
737
+
738
+ if [ -n "$relative_scss_files" ]; then
739
+ # Save current directory and cd to theme
740
+ original_dir=$(pwd)
741
+ cd "$theme_dir_for_stylelint" || exit 1
742
+
743
+ if ! $stylelint_cmd --config "$stylelint_config" $relative_scss_files 2>/dev/null; then
744
+ cd "$original_dir" || exit 1
745
+ echo "${RED}${CROSS} FAILED${NC}"
746
+ echo " ${RED}Stylelint found errors in SCSS files${NC}"
747
+ echo " ${YELLOW}Please fix the following files:${NC}"
748
+ for file in $scss_files; do
749
+ echo " ${YELLOW}• $file${NC}"
750
+ done
751
+ echo " ${YELLOW}To see detailed errors, run from theme directory:${NC}"
752
+ echo " ${BLUE}cd $theme_dir_for_stylelint && $stylelint_cmd --config \"$stylelint_config\" $relative_scss_files${NC}"
753
+ exit 1
754
+ fi
755
+ cd "$original_dir" || exit 1
756
+ echo "${GREEN}${CHECK} OK${NC}"
757
+ else
758
+ echo "${YELLOW}⚠️ SKIPPED${NC}"
759
+ echo " ${YELLOW}No SCSS files in theme directory${NC}"
760
+ fi
761
+ else
762
+ # Standalone: run from current directory
763
+ if ! $stylelint_cmd --config "$stylelint_config" $scss_files 2>/dev/null; then
764
+ echo "${RED}${CROSS} FAILED${NC}"
765
+ echo " ${RED}Stylelint found errors in SCSS files${NC}"
766
+ echo " ${YELLOW}Please fix the following files:${NC}"
767
+ for file in $scss_files; do
768
+ echo " ${YELLOW}• $file${NC}"
769
+ done
770
+ echo " ${YELLOW}To see detailed errors:${NC}"
771
+ echo " ${BLUE}$stylelint_cmd --config \"$stylelint_config\" $scss_files${NC}"
772
+ exit 1
773
+ fi
774
+ echo "${GREEN}${CHECK} OK${NC}"
730
775
  fi
731
- echo "${GREEN}${CHECK} OK${NC}"
732
776
  else
733
777
  echo "${YELLOW}⚠️ SKIPPED${NC}"
734
778
  echo " ${YELLOW}No .stylelintrc config found${NC}"
package/bin/setup.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ const { setup } = require('../index.js');
3
+ setup();
package/index.js CHANGED
@@ -3,18 +3,43 @@
3
3
  *
4
4
  * Exports the path to husky hooks for direct reference.
5
5
  *
6
- * Usage in your project's .husky/pre-commit:
7
- * node_modules/@digitoimistodude/code-quality-checks/.husky/pre-commit
6
+ * Usage in your project's package.json:
7
+ * "prepare": "dude-code-quality-setup"
8
8
  *
9
9
  * Or import the path:
10
10
  * const { huskyPath } = require('@digitoimistodude/code-quality-checks');
11
11
  */
12
12
 
13
13
  const path = require('path');
14
+ const { execSync } = require('child_process');
15
+
16
+ const huskyPath = path.join(__dirname, '.husky');
17
+ const huskyInternalPath = path.join(__dirname, '.husky', '_');
18
+
19
+ /**
20
+ * Setup husky with absolute path to hooks
21
+ * This ensures hooks work from anywhere in the git repository
22
+ */
23
+ function setup() {
24
+ try {
25
+ // Get the git root directory
26
+ const gitRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim();
27
+
28
+ // Set core.hooksPath to absolute path
29
+ execSync(`git config core.hooksPath "${huskyInternalPath}"`, { cwd: gitRoot });
30
+
31
+ console.log(`✅ Husky hooks configured at: ${huskyInternalPath}`);
32
+ } catch (error) {
33
+ console.error('❌ Failed to setup husky hooks:', error.message);
34
+ process.exit(1);
35
+ }
36
+ }
14
37
 
15
38
  module.exports = {
16
- huskyPath: path.join(__dirname, '.husky'),
39
+ huskyPath,
40
+ huskyInternalPath,
17
41
  preCommitPath: path.join(__dirname, '.husky', 'pre-commit'),
18
42
  preCommitConfigPath: path.join(__dirname, '.husky', 'pre-commit-config'),
19
- commitMsgPath: path.join(__dirname, '.husky', 'commit-msg')
43
+ commitMsgPath: path.join(__dirname, '.husky', 'commit-msg'),
44
+ setup
20
45
  };
package/package.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
2
  "name": "@digitoimistodude/code-quality-checks",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "Code quality definitions and Husky pre-commit hooks for Dude WordPress projects",
5
5
  "main": "index.js",
6
+ "scripts": {
7
+ "postinstall": "node bin/setup.js"
8
+ },
6
9
  "files": [
7
10
  ".husky/pre-commit",
8
11
  ".husky/pre-commit-config",
9
12
  ".husky/commit-msg",
13
+ ".husky/_",
14
+ "bin",
10
15
  "index.js"
11
16
  ],
12
17
  "repository": {