Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run several commands on precommit with husky npm module?

I use husky to check JS before commit. In my package.json i have

"scripts": {
    "lintStyles": "stylelint app/**/*.scss",
    "fixStylesLinting": "stylelint app/**/*.scss --fix",
    "lintJS": "eslint app/**/*.js",
    "fixJSLinting": "eslint --fix app/**/*.js",
    "precommit": "npm run lintJS"
  }

It works, what i don't understand is how can i run both lintJS, lintStyles commands.

like image 465
Rantiev Avatar asked Apr 22 '17 16:04

Rantiev


People also ask

How do I run multiple commands in NPM?

The npm-run-all CLI is installed can be installed via NPM or Yarn: npm install npm-run-all — save-dev , and once installed, it boasts three different commands, based on your needs: npm-run-all (the main command, which has documentation on all of the flags and additions you can pass in via the command line)

What is husky pre-commit?

Husky is a very popular (1 million downloads a month) npm package that allows custom scripts to be ran against your repository. Husky works with any project that uses a package. json file. It also works out of the box with SourceTree!


2 Answers

to include more than one script add &&for ex:

precommit: npm run lint:sass && npm run lint:js

like image 160
chris_r Avatar answered Oct 07 '22 14:10

chris_r


This should work:

"scripts": {
  "lint:scss": "stylelint app/**/*.scss",
  "fixStylesLinting": "stylelint app/**/*.scss --fix",
  "lint:js": "eslint app/**/*.js",
  "fixJSLinting": "eslint --fix app/**/*.js",
  "precommit": "npm run lint:*"
}
like image 1
netweb Avatar answered Oct 07 '22 15:10

netweb