Hello ,
I need every time when I pull from the repository to run these commands :
sudo git pull origin
php artisan migrate
sudo npm update
sudo npm run prod
How to put all the commands above in one command (alias) ? like: update-project.
Thanks
Since you clearly have
npm
and this is happening in a directory with apackage.json
, I recommend familiarizing yourself with npm-run-all(run-s
,run-p
), or equivalent, then you won't be tied to bash (can run on windows without bash installed, for example).Also, there's pretty much no reason any of these commands should require
sudo
, and especially thenpm
ones are wildly unsafe.update
can run arbitrary installation lifecycle scripts from unknown parties, andrun
well... runs the actual code of the dependencies in accordance with how your scripts call it. If this doesn't work withoutsudo
in your case, you should probably fix the file permissions instead of giving superuser access to these already insecure tools.Finally, you said "every time when I pull from the repository". These is a small chance you might be interested in git hooks, eg through git-hooks-js or husky
It's also very unlikely you want to run
git pull
every time you pull, because that would never end...lmao
Thanks Mihail Malo
when I run
npm update
I got this error :`
Wow, what an amazing error!
Good job, npm developers!
It tells you WHY this happened, and also tells you the correct way to fix it!
I would recommend you to use a
Makefile
The syntax's quite simple.
here is an example:
After you only need to call
make update_and_compile_prod
(make command_name), and it will run smoothly :)Also, you can add this command to the script list on your package.json and run it with npm.
You can also try to investigate if you can use a githook to trigger that action every time you pull
Thanks
Have you considered putting the commands in a single shell script? That way if you need to add more steps, you do it in one place.
It also means if you gave to migrate to a new server or development machine, you know exactly what you need to run. You don't have to rely on memory of what is and is not part of an alias.
Thanks for this answer, do you have any idea how could be this shell script ?
Thanks
Something like this in your
.bash_aliases
will do if I understand your question correctly.Thanks Zafri
create a deploy.sh in your root with the following content.
this is how you can so this.
codebysamgan.com/creating-a-deploy...