Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Gulp in post-receive hook after Git push

I have a Git workflow where I'm pushing my Git updates to a bare repo which triggers the following post-receive hook:

#!/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 the gulp command doesn't work. Says 'command not found'.

I don't know if this is the proper way to build my dist/ folder with gulp? Even when I SSH into the server and try running npm install and gulp it still produces the same error. I am running on a CentOS server.

Thanks in advance.

like image 339
JamesG Avatar asked Oct 28 '25 01:10

JamesG


2 Answers

It's not working because gulp is not in the PATH of your server

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 -g option installs the package globally on your server. It's convenient but it can be problematic if different projects use different versions of gulp.

Solution 2: run the script from node_modules

npm install (run without the -g option) 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 a npm.script

A more elegant solution is to add a script to your packages.json

"scripts": { "gulp": "gulp" }

Then you can do

npm run gulp

npm scripts automatically use the node_modules folder

like image 118
Aurélien Gasser Avatar answered Oct 30 '25 17:10

Aurélien Gasser


You might need to install gulp globally on your build server by running npm install gulp -g

like image 40
RobPethi Avatar answered Oct 30 '25 15:10

RobPethi