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.
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
You might need to install gulp globally on your build server by running npm install gulp -g
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With