Running Gulp on a hook after Git push
I have a Git workflow where I push my Git updates to a bare repo that triggers the following hook after receiving:
#!/bin/sh
git --work-tree=/home/website/stage/public_html --git-dir=/home/website/stage/website.git checkout -f
cd /home/website/stage/public_html/wp-content/themes/theme/src/js/
npm install
gulp
This installs my npm packages from package.json file but gulp command doesn't work. Says 'command not found'.
I don't know if this is the right way to create my dist / gulp folder? Even when I find SSH on the server and try to start npm install
and gulp
, it still produces the same error. I am running on a CentOS server.
Thanks in advance.
source to share
It doesn't work because gulp is not in your server's PATH
On CentOS / Linux, you can check the current path with echo $PATH
Solution 1: add gulp to the path with -g
npm install -g gulp
The parameter -g
installs the package globally on your server. This is handy, but can be problematic if different projects use different versions of gulp.
Solution 2: run the script from node_modules
npm install
(executed without option -g
) installs gulp in the node_modules directory. Execute it from there.
node ./node_modules/gulp/bin/gulp.js
or
./node_modules/gulp/bin/gulp
Solution 3: create npm.script file
A more elegant solution is to add the script to your packages. json
"scripts": { "gulp": "gulp" }
Then you can do
npm run gulp
Scripts npm will automatically use the node_modules folder
source to share