Search code examples
jquerydrupalgulphuskylint-staged

Husky and lint-staged unable to run gulp command


Am trying to run gulp commands from package.json. But unable to execute.

This is my package.json.

  "scripts": {       
    "deploy": "gulp deploy",
    "lint": "eslint",
    "lint-fix": "eslint --ext .js"
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "*": [
      "gulp locale-sass", // not working
      "npm run lint", // working fine
      "git add"
    ]
  },
  "devDependencies": {
    "@open-tech-world/cli-progress-bar": "^1.0.6",
    "colors": "^1.4.0",
    "console-table-printer": "^1.1.58",
    "del": "^5.1.0",
    "eslint": "^6.8.0",
    "eslint-plugin-deprecate": "^0.7.0",
    "glob": "^7.1.6",
    "gulp": "^4.0.2",
    "gulp-changed": "^4.0.2",
    "gulp-clean": "^0.4.0",
    "gulp-clean-css": "^4.2.0",
    "gulp-compass": "^2.1.0",
    "gulp-concat": "^2.6.1",
    "gulp-consolidate": "0.2.0",
    "gulp-css-globbing": "^0.2.2",
    "gulp-debug": "^4.0.0",
    "gulp-eslint": "^6.0.0",
    "gulp-ext-replace": "^0.3.0",
    "gulp-if": "^3.0.0",
    "gulp-jshint": "^2.1.0",
    "gulp-livereload": "^4.0.2",
    "gulp-load-plugins": "^2.0.2",
    "gulp-rename": "^2.0.0",
    "gulp-replace": "^1.0.0",
    "gulp-sass": "^4.0.2",
    "gulp-sass-lint": "^1.4.0",
    "gulp-scan": "^0.1.4",
    "gulp-shell": "^0.7.1",
    "gulp-sourcemaps": "^2.6.5",
    "gulp-svg-symbols": "^3.2.3",
    "gulp-svgmin": "^2.2.0",
    "gulp-terser": "^1.2.0",
    "gulp-util": "^3.0.8",
    "gulp-watch": "^5.0.1",
    "husky": "^4.2.5",
    "jshint": "^2.11.0",
    "jshint-stylish": "2.2.1",
    "lint-staged": "^10.2.2",
    "minimist": "^1.2.0",
    "node-sass-asset-functions": "^0.1.0",
    "npm-audit-resolver": "^2.2.0",
    "path": "^0.12.7",
    "sass-lint": "^1.13.1",
    "through2": "^3.0.1"
  }
}

npm run lint is working fine.

Here gulp locale-sass is not working.

✖ gulp locale-sass && npm run lint: Task never defined: &&

list available tasks, try running: gulp --tasks

Using gulpfile /u02/home/user01/drupal/drupal-7.9/sites/medic/gulpfile.js

husky > pre-commit hook failed (add --no-verify to bypass)


Solution

  • I resolved by modifying srcipt section by adding "locale-sass" and in lint-staged npm run gulp locale-sass instead of gulp locale-sass

    "scripts": {       
        "deploy": "gulp deploy",
        "lint": "eslint",
        "lint-fix": "eslint --ext .js",
        "locale-sass": "gulp locale-sass"
      },
      "husky": {
        "hooks": {
          "pre-commit": "lint-staged"
        }
      },
      "lint-staged": {
        "*": [
          "npm run gulp locale-sass", // Working
          "npm run lint", // working
          "git add"
        ]
      },